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 27bc860
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 13 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
2 changes: 1 addition & 1 deletion app/validators/custom_form_present_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(record,table_name,field)
def validate
return unless @record.properties.present?
@record.send(@table_name).send(@field).each_with_index do |field, index|
field_label = field['label']
field_label = I18n.locale.to_s == I18n.default_locale.to_s ? field['label'] : "Local_label #{field['local_label']}"
next unless field['required'] && (@record.properties[field_label].blank? || @record.properties[field_label][0].blank?)
@record.errors.add(field_label, I18n.t('cannot_be_blank')) if field['type'] != 'file'
end
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 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' }
%span.help-block
= field_message(field_props['label'], errors)
8 changes: 4 additions & 4 deletions app/views/shared/fields/_radio_group.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
%abbr{ title: 'required' }= '*' if field_props['required'] || false
= label.html_safe
- if I18n.locale.to_s == I18n.default_locale.to_s
= f.input field_props['label'].gsub(' ', '_'), as: :radio_buttons, 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']] }, label: false, input_html: { id: field_props['label'].gsub(' ', '_').gsub("'", ""), title: field_props['description'], name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", class: "#{I18n.locale.to_s != I18n.default_locale.to_s ? 'd-none1' : ''}", 'data-option': "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }
= f.input field_props['local_label'], :as => :hidden, 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 }
= f.input remove_field_prop_unicode(field_props), as: :radio_buttons, 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']] }, label: false, input_html: { id: field_props['label'].gsub(' ', '_').gsub("'", ""), title: field_props['description'], name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", class: "#{I18n.locale.to_s != I18n.default_locale.to_s ? 'd-none1' : ''}", 'data-option': "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }
= f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", :as => :hidden, 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 }
- else
= f.input field_props['local_label'].gsub(' ', '_'), as: :radio_buttons, 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']] }, label: false, input_html: { id: field_props['local_label'].gsub(' ', '_').gsub("'", ""), title: field_props['description'], name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}]", class: "#{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none1' : ''}", 'data-option': "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize }
= f.input field_props['label'], :as => :hidden, input_html: { name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", id: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize }
= f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", as: :radio_buttons, 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']] }, label: false, input_html: { id: field_props['local_label'].gsub(' ', '_').gsub("'", ""), title: field_props['description'], name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}]", class: "#{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none1' : ''}", 'data-option': "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize }
= f.input remove_field_prop_unicode(field_props), :as => :hidden, input_html: { name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", id: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize }

%span.help-block
= field_message(field_props['label'], errors)
4 changes: 2 additions & 2 deletions app/views/shared/fields/_select.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%abbr{ title: 'required' }= '*' if field_props['required'] || false
= label.gsub('[', '[').gsub(']', ']').html_safe

= f.input field_props['label'].gsub(' ', '_'), 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 field_props["local_label"].gsub(' ', '_'), 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 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
%span.help-block
= field_message(label, errors)

0 comments on commit 27bc860

Please sign in to comment.