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..a67be16b19 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) -> + console.log($(@).val()) + checkedItems.push($(@).val()) + console.log(checkedItems) + + _uncheckCheckbox = -> + $('input[type="checkbox"]').on 'ifUnchecked', (e) -> + console.log($(@).val()) + checkedItems.splice(checkedItems.indexOf($(@).val()), 1) + console.log(checkedItems) + _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/controllers/client_enrollments_controller.rb b/app/controllers/client_enrollments_controller.rb index aa8d379537..33a73297f5 100644 --- a/app/controllers/client_enrollments_controller.rb +++ b/app/controllers/client_enrollments_controller.rb @@ -51,6 +51,7 @@ def show def create @client_enrollment = @client.client_enrollments.new(client_enrollment_params) + binding.pry authorize(@client) && authorize(@client_enrollment) if @client_enrollment.save redirect_to client_client_enrolled_program_path(@client, @client_enrollment, program_stream_id: @program_stream), notice: t('.successfully_created') diff --git a/app/views/shared/fields/_checkbox_group.haml b/app/views/shared/fields/_checkbox_group.haml index 72cec97cfa..80b2fe7eb6 100644 --- a/app/views/shared/fields/_checkbox_group.haml +++ b/app/views/shared/fields/_checkbox_group.haml @@ -1,8 +1,11 @@ +- 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}"] }, 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'], :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 } %span.help-block = field_message(field_props['label'], errors)