diff --git a/app/assets/javascripts/client_enrollments/form.coffee b/app/assets/javascripts/client_enrollments/form.coffee index 2fd3db1f50..4fe8f0c817 100644 --- a/app/assets/javascripts/client_enrollments/form.coffee +++ b/app/assets/javascripts/client_enrollments/form.coffee @@ -1,5 +1,6 @@ CIF.Client_enrollmentsNew = CIF.Client_enrollmentsCreate = CIF.Client_enrollmentsEdit = CIF.Client_enrollmentsUpdate = CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Client_enrolled_programsEdit = CIF.Client_enrolled_programsUpdate = do -> + checkedItems = [] _init = -> _initSelect2() _initFileInput() @@ -8,6 +9,14 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien _initICheckBox() _initDatePicker() _preventEditDatepickerClientEnrollment() + _setAnotherLanguageFieldValue() + _hideAnotherLanguageField() + _copyInputTextToLocalLanguage() + _copyTextAreaTextToLocalLanguage() + _copyNumberToLocalLanguage() + _copyDateToLocalLanguage() + _checkCheckbox() + _uncheckCheckbox() _initICheckBox = -> $('.i-checks').iCheck @@ -64,8 +73,22 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien _toggleCheckingRadioButton = -> $('input[type="radio"]').on 'ifChecked', (e) -> + el = $(@) + el.parents('.radio_buttons').next().children('#' + el.data('option')).val(el.data('value')) $(@).parents('span.radio').siblings('.radio').find('.iradio_square-green').removeClass('checked') + _checkCheckbox = -> + $('input[type="checkbox"]').on 'ifChecked', (e) -> + el = $(@) + checkedItems.push(el.data('value')) + el.parents('.check_boxes').next().children('#' + el.data('checkbox')).val(checkedItems).trigger('change') + + _uncheckCheckbox = -> + $('input[type="checkbox"]').on 'ifUnchecked', (e) -> + el = $(@) + checkedItems.splice(checkedItems.indexOf(el.data('value')), 1) + el.parents('.check_boxes').next().children('#' + el.data('checkbox')).val(checkedItems).trigger('change') + _initSelect2 = -> $('select').select2() @@ -81,4 +104,34 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien prevent = new CIF.PreventRequiredFileUploader() prevent.preventFileUploader() + _setAnotherLanguageFieldValue = -> + $('select').on 'select2-selecting', (e) -> + $('#' + $(e.target).data('label')).val($(e.choice.element).data('value')).trigger("change") + return + + _hideAnotherLanguageField = -> + $('.client-enrollment').find('.d-none').parent().addClass('hide') + + _copyInputTextToLocalLanguage = -> + $('input[type="text"]').on 'keyup', (e) -> + el = $(@) + if el.hasClass('date-picker') + else + el.parent().next().find('#' + el.data('local-input')).val(el.val()) + + _copyTextAreaTextToLocalLanguage = -> + $('textarea').on 'keyup', (e) -> + el = $(@) + el.parent().next().find('#' + el.data('local-textarea')).val(el.val()) + + _copyNumberToLocalLanguage = -> + $('input[type="number"]').on 'keyup mouseup', (e) -> + el = $(@) + el.parent().next().find('#' + el.data('local-number')).val(el.val()) + + _copyDateToLocalLanguage = -> + $('input.form-builder-date').on 'changeDate', (e) -> + el = $(@) + el.next('#' + el.data('local-date')).val(el.val()) + { init: _init } diff --git a/app/assets/javascripts/custom_form_builder.coffee b/app/assets/javascripts/custom_form_builder.coffee index bdcc4905f8..1216fdea09 100644 --- a/app/assets/javascripts/custom_form_builder.coffee +++ b/app/assets/javascripts/custom_form_builder.coffee @@ -56,12 +56,13 @@ class CIF.CustomFormBuilder self.preventClickEnterOrTab(fld) ),50 - eventFileOption: -> + eventFileOption: (fields = []) -> self = @ onadd: (fld) -> $('.file-field').find('.className-wrap, .placeholder-wrap, .subtype-wrap, .value-wrap, .access-wrap, .description-wrap, .name-wrap').hide() self.handleCheckingForm() self.preventClickEnterOrTab(fld) + self.handleAddTranslateLabelField(fld, fields) onclone: (fld) -> setTimeout ( -> self.handleCheckingForm() @@ -74,7 +75,6 @@ class CIF.CustomFormBuilder $('.number-field').find('.className-wrap, .placeholder-wrap, .value-wrap, .step-wrap, .access-wrap, .description-wrap, .name-wrap').hide() self.handleCheckingForm() self.preventClickEnterOrTab(fld) - console.log(fields) self.handleAddTranslateLabelField(fld, fields) onclone: (fld) -> setTimeout ( -> @@ -278,6 +278,6 @@ class CIF.CustomFormBuilder if fields[index - 1] localLabel = if fields[index - 1][localLabelName] then fields[index - 1][localLabelName] else localLabel frmHolder = fldElement.find('.frm-holder') - localLabelBlock = "