Skip to content

Commit

Permalink
[FEATURE] Translate Checkbox group field
Browse files Browse the repository at this point in the history
refs OSC-17
  • Loading branch information
Bunhok committed Sep 23, 2022
1 parent 8fe0ae4 commit 23036c4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/custom_form_builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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 ( ->
Expand Down Expand Up @@ -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]
Expand Down
16 changes: 15 additions & 1 deletion app/assets/javascripts/multiple_form/form.coffee
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -15,6 +15,8 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN
_copyTextAreaTextToLocalLanguage()
_copyNumberToLocalLanguage()
_copyDateToLocalLanguage()
_checkCheckbox()
_uncheckCheckbox()

_initICheckBox = ->
$('.i-checks').iCheck
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/program_streams/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions app/views/shared/fields/_checkbox_group.haml
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 23036c4

Please sign in to comment.