diff --git a/app/assets/javascripts/client_enrollment_trackings/form.coffee b/app/assets/javascripts/client_enrollment_trackings/form.coffee index 04c6a2f1f5..d5e4fc0f84 100644 --- a/app/assets/javascripts/client_enrollment_trackings/form.coffee +++ b/app/assets/javascripts/client_enrollment_trackings/form.coffee @@ -1,12 +1,20 @@ CIF.Client_enrollment_trackingsNew = CIF.Client_enrollment_trackingsCreate = CIF.Client_enrollment_trackingsEdit = CIF.Client_enrollment_trackingsUpdate = CIF.Client_enrolled_program_trackingsUpdate = CIF.Client_enrolled_program_trackingsNew = CIF.Client_enrolled_program_trackingsCreate = CIF.Client_enrolled_program_trackingsEdit = do -> + checkedItems = [] _init = -> _initSelect2() _initFileInput() _preventRequireFileUploader() _toggleCheckingRadioButton() _initICheckBox() + _setAnotherLanguageFieldValue() + _hideAnotherLanguageField() + _checkCheckbox() + _uncheckCheckbox() + _copyNumberToLocalLanguage() + _copyInputTextToLocalLanguage() + _copyTextAreaTextToLocalLanguage() _initICheckBox = -> $('.i-checks').iCheck @@ -14,8 +22,10 @@ CIF.Client_enrolled_program_trackingsNew = CIF.Client_enrolled_program_trackings radioClass: 'iradio_square-green' _toggleCheckingRadioButton = -> - $('input[type="radio"]').on 'ifChecked', (e) -> - $(@).parents('span.radio').siblings('.radio').find('.iradio_square-green').removeClass('checked') + $('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') _initSelect2 = -> $('select').select2() @@ -32,4 +42,46 @@ CIF.Client_enrolled_program_trackingsNew = CIF.Client_enrolled_program_trackings 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-enrolled-program-tracking').find('.d-none').parent().addClass('hide') + + _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') + + _copyNumberToLocalLanguage = -> + $('input[type="number"]').on 'keyup mouseup', (e) -> + el = $(@) + el.parent().next().find('#' + el.data('local-number')).val(el.val()) + + _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()) + + _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/program_streams/form.coffee b/app/assets/javascripts/program_streams/form.coffee index 2e950e7f99..ae6aba7f81 100644 --- a/app/assets/javascripts/program_streams/form.coffee +++ b/app/assets/javascripts/program_streams/form.coffee @@ -499,7 +499,9 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C $('.links a').trigger('click') _handleInitProgramFields = -> + trackings = $('.tracking-builder') elements = ['#enrollment', '#exit-program'] + $.merge(elements, trackings) _initMultipleFormBuilder(0, elements) for element in elements if element.id == 'enrollment' and $('#program_stream_id').val() != '' @@ -507,8 +509,8 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C else if element.id == 'exit-program' and $('#program_stream_id').val() != '' _preventRemoveField(EXIT_PROGRAM_URL, '#exit-program') - trackings = $('.tracking-builder') - _initMultipleFormBuilder(0, trackings) + # trackings = $('.tracking-builder') + # _initMultipleFormBuilder(0, trackings) _preventRemoveField(TRACKING_URL, '') if $('#program_stream_id').val() != '' _initButtonSave = -> @@ -521,7 +523,9 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C $('#program_stream_rules').val(_handleStringfyRules(rules)) _handleSetValueToField = -> + console.log(@formBuilder) for formBuilder in @formBuilder + console.log(formBuilder.actions.save()) element = formBuilder.element specialCharacters = { "&": "&", "<": "<", ">": ">", '"': "&qoute;" } format = new CIF.FormatSpecialCharacters() diff --git a/app/models/concerns/update_field_labels_form_builder.rb b/app/models/concerns/update_field_labels_form_builder.rb index df8efb0d1c..61f22c04b6 100644 --- a/app/models/concerns/update_field_labels_form_builder.rb +++ b/app/models/concerns/update_field_labels_form_builder.rb @@ -2,6 +2,7 @@ module UpdateFieldLabelsFormBuilder def labels_update(new_fields, old_fields, objects) labels_changed = [] field_labels_changed = [] + old_fields = [] if old_fields.empty? fields_changed = new_fields - old_fields fields_changed.each do |field_changed| old_fields.each do |entity| diff --git a/app/views/shared/fields/_checkbox_group.haml b/app/views/shared/fields/_checkbox_group.haml index 5a91c3a743..95603f51af 100644 --- a/app/views/shared/fields/_checkbox_group.haml +++ b/app/views/shared/fields/_checkbox_group.haml @@ -6,7 +6,6 @@ - if I18n.locale.to_s == I18n.default_locale.to_s = f.input remove_field_prop_unicode(field_props), collection: field_props['values'].map { |f| [ f['label'], f['label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}", 'data-value': f['local_label']] }, as: :check_boxes, required: (field_props['required'] || false), label: false, input_html: { name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}][]", title: field_props['description'], 'data-checkbox': "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize } - = f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", collection: field_props['values'].map { |f| [ f['local_label'], f['local_label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}"] }, input_html: { name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", id: "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize, multiple: true, class: 'd-none' }, label: false - else = f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", collection: field_props['values'].map { |f| [ f['local_label'], f['local_label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}", 'data-value': f['label']] }, as: :check_boxes, required: (field_props['required'] || false), input_html: { name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", 'data-checkbox': "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize }, label: false = f.input remove_field_prop_unicode(field_props), collection: field_props['values'].map { |f| [ f['label'], f['label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}"] }, required: (field_props['required'] || false), label: false, input_html: { name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}][]", title: field_props['description'], id: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize, multiple: true, class: 'd-none' } diff --git a/app/views/shared/fields/_select.haml b/app/views/shared/fields/_select.haml index 513d6cda48..df1c691f16 100644 --- a/app/views/shared/fields/_select.haml +++ b/app/views/shared/fields/_select.haml @@ -5,6 +5,6 @@ = label.gsub('&#91;', '[').gsub('&#93;', ']').html_safe = f.input remove_field_prop_unicode(field_props), collection: field_props['values'].map { |f| [format_placeholder(f['label']), f['label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}", 'data-value': f['local_label']] }, required: (field_props['required'] || false), input_html: { id: field_props['label'].gsub(' ', '_').gsub("'", ""), class: "#{field_props['ClassName']} #{I18n.locale.to_s != I18n.default_locale.to_s ? 'd-none' : ''}", multiple: field_props['multiple'].present?, name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), 'data-label': field_props["local_label"].gsub(' ', '_').gsub("'", "") }, label: false - = f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", collection: field_props['values'].map { |f| [format_placeholder(f['local_label']), f['local_label'], id: "custom_field_property_properties_#{field_props["local_label"].gsub('"', '&qoute;').html_safe}_#{f['local_label'].html_safe}", 'data-value': f['label']] }, required: (field_props['required'] || false), input_html: { id: field_props["local_label"].gsub(' ', '_').gsub("'", ""), class: "#{field_props['ClassName']} #{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none' : ''}", multiple: field_props['multiple'].present?, name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), 'data-label': field_props["label"].gsub(' ', '_').gsub("'", "") }, label: false + = f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", collection: field_props['values'].map { |f| [format_placeholder(f['local_label']), f['local_label'], id: "custom_field_property_properties_#{field_props["local_label"].gsub('"', '&qoute;').html_safe}_#{f['local_label'].html_safe}", 'data-value': f['label']] }, required: (field_props['required'] || false), input_html: { id: field_props["local_label"].gsub(' ', '_').gsub("'", ""), class: "#{field_props['ClassName']} #{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none1' : ''}", multiple: field_props['multiple'].present?, name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), 'data-label': field_props["label"].gsub(' ', '_').gsub("'", "") }, label: false %span.help-block = field_message(label, errors)