From 23036c4229a5e84425cdd065616283b7e67d6b77 Mon Sep 17 00:00:00 2001 From: bunhok Date: Thu, 22 Sep 2022 17:49:31 +0700 Subject: [PATCH] [FEATURE] Translate Checkbox group field refs OSC-17 --- app/assets/javascripts/common.coffee | 3 +++ .../javascripts/custom_form_builder.coffee | 6 ++++-- app/assets/javascripts/multiple_form/form.coffee | 16 +++++++++++++++- .../javascripts/program_streams/form.coffee | 2 +- app/views/shared/fields/_checkbox_group.haml | 10 ++++++++-- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/common.coffee b/app/assets/javascripts/common.coffee index 6f41eb03e0..e00eb9e307 100644 --- a/app/assets/javascripts/common.coffee +++ b/app/assets/javascripts/common.coffee @@ -151,6 +151,9 @@ CIF.Common = setTimeout(-> if self.type == 'radio' && confirm('Clear selection/លុបចោលការជ្រើសរើស?') $(self).closest('.radio_buttons.form-group').find('input').removeAttr('checked').iCheck('update'); + localOptionElement = $(self).closest('.radio_buttons.form-group').next() + if localOptionElement + localOptionElement.children('input').val('') else return , 0) diff --git a/app/assets/javascripts/custom_form_builder.coffee b/app/assets/javascripts/custom_form_builder.coffee index 53f4bc1ada..bdcc4905f8 100644 --- a/app/assets/javascripts/custom_form_builder.coffee +++ b/app/assets/javascripts/custom_form_builder.coffee @@ -24,7 +24,7 @@ class CIF.CustomFormBuilder self.handleCheckingForm() self.preventClickEnterOrTab(fld) - eventCheckboxOption: -> + eventCheckboxOption: (fields = []) -> self = @ onadd: (fld) -> $('.other-wrap, .className-wrap, .access-wrap, .description-wrap, .name-wrap, .toggle-wrap, .inline-wrap').hide() @@ -33,6 +33,7 @@ class CIF.CustomFormBuilder self.addOptionCallback(fld) self.generateValueForSelectOption(fld) self.preventClickEnterOrTab(fld) + self.handleAddTranslateLabelField(fld, fields) onclone: (fld) -> setTimeout ( -> self.handleCheckingForm() @@ -73,6 +74,7 @@ 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 ( -> @@ -270,7 +272,7 @@ class CIF.CustomFormBuilder handleAddTranslateLabelField: (fld, fields) -> fldElement = $(fld) fldId = fldElement.attr('id') - index = fldId.substr(fldId.length - 1) + index = fldId.substr(fldId.lastIndexOf('-') + 1) localLabelName = "local_label" localLabel = "Local Label" if fields[index - 1] diff --git a/app/assets/javascripts/multiple_form/form.coffee b/app/assets/javascripts/multiple_form/form.coffee index 36663d19e1..eb71c681a2 100644 --- a/app/assets/javascripts/multiple_form/form.coffee +++ b/app/assets/javascripts/multiple_form/form.coffee @@ -1,5 +1,5 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsNew = CIF.Client_custom_fieldsCreate = CIF.Client_enrollmentsNew = CIF.Client_enrollmentsCreate = do -> - + checkedItems = [] _init = -> _initSelect2() _initFileInput() @@ -15,6 +15,8 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN _copyTextAreaTextToLocalLanguage() _copyNumberToLocalLanguage() _copyDateToLocalLanguage() + _checkCheckbox() + _uncheckCheckbox() _initICheckBox = -> $('.i-checks').iCheck @@ -27,6 +29,18 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN 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() diff --git a/app/assets/javascripts/program_streams/form.coffee b/app/assets/javascripts/program_streams/form.coffee index 349b3c6991..764d704d3a 100644 --- a/app/assets/javascripts/program_streams/form.coffee +++ b/app/assets/javascripts/program_streams/form.coffee @@ -286,7 +286,7 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C left: 'auto' } typeUserEvents: { - 'checkbox-group': builderOption.eventCheckboxOption() + 'checkbox-group': builderOption.eventCheckboxOption(fields) date: builderOption.eventDateOption(fields) file: builderOption.eventFileOption() number: builderOption.eventNumberOption(fields) diff --git a/app/views/shared/fields/_checkbox_group.haml b/app/views/shared/fields/_checkbox_group.haml index 72cec97cfa..6b85851867 100644 --- a/app/views/shared/fields/_checkbox_group.haml +++ b/app/views/shared/fields/_checkbox_group.haml @@ -1,8 +1,14 @@ +- label = field_label(field_props) %div{ class: "form-group i-checks #{field_with(field_props['label'],errors)}" } %label.control-label{ class: required?(field_props['required'] || false) } %abbr{ title: 'required' }= '*' if field_props['required'] || false - = field_props['label'].html_safe + = label.html_safe - = f.input field_props['label'], 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}"] }, 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']} + - if I18n.locale.to_s == I18n.default_locale.to_s + = f.input field_props['label'], 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 field_props['local_label'], 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 field_props['local_label'], 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 field_props['label'], 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' } %span.help-block = field_message(field_props['label'], errors)