Skip to content

Commit

Permalink
[FEATURE] Translate File element
Browse files Browse the repository at this point in the history
refs OSC-17
  • Loading branch information
Bunhok committed Oct 5, 2022
1 parent 27bc860 commit 4fa056f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 10 deletions.
53 changes: 53 additions & 0 deletions app/assets/javascripts/client_enrollments/form.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CIF.Client_enrollmentsNew = CIF.Client_enrollmentsCreate = CIF.Client_enrollmentsEdit = CIF.Client_enrollmentsUpdate =
CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Client_enrolled_programsEdit = CIF.Client_enrolled_programsUpdate = do ->
checkedItems = []
_init = ->
_initSelect2()
_initFileInput()
Expand All @@ -8,6 +9,14 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien
_initICheckBox()
_initDatePicker()
_preventEditDatepickerClientEnrollment()
_setAnotherLanguageFieldValue()
_hideAnotherLanguageField()
_copyInputTextToLocalLanguage()
_copyTextAreaTextToLocalLanguage()
_copyNumberToLocalLanguage()
_copyDateToLocalLanguage()
_checkCheckbox()
_uncheckCheckbox()

_initICheckBox = ->
$('.i-checks').iCheck
Expand Down Expand Up @@ -64,8 +73,22 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien

_toggleCheckingRadioButton = ->
$('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')

_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 All @@ -81,4 +104,34 @@ CIF.Client_enrolled_programsNew = CIF.Client_enrolled_programsCreate = CIF.Clien
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-enrollment').find('.d-none').parent().addClass('hide')

_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())

_copyNumberToLocalLanguage = ->
$('input[type="number"]').on 'keyup mouseup', (e) ->
el = $(@)
el.parent().next().find('#' + el.data('local-number')).val(el.val())

_copyDateToLocalLanguage = ->
$('input.form-builder-date').on 'changeDate', (e) ->
el = $(@)
el.next('#' + el.data('local-date')).val(el.val())

{ init: _init }
6 changes: 3 additions & 3 deletions app/assets/javascripts/custom_form_builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ class CIF.CustomFormBuilder
self.preventClickEnterOrTab(fld)
),50

eventFileOption: ->
eventFileOption: (fields = []) ->
self = @
onadd: (fld) ->
$('.file-field').find('.className-wrap, .placeholder-wrap, .subtype-wrap, .value-wrap, .access-wrap, .description-wrap, .name-wrap').hide()
self.handleCheckingForm()
self.preventClickEnterOrTab(fld)
self.handleAddTranslateLabelField(fld, fields)
onclone: (fld) ->
setTimeout ( ->
self.handleCheckingForm()
Expand All @@ -74,7 +75,6 @@ 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 @@ -278,6 +278,6 @@ class CIF.CustomFormBuilder
if fields[index - 1]
localLabel = if fields[index - 1][localLabelName] then fields[index - 1][localLabelName] else localLabel
frmHolder = fldElement.find('.frm-holder')
localLabelBlock = "<div class='form-group local-label-wrap' style='display: block'><label for='#{localLabelName}'>Local Label</label><div class='input-wrap'><div name='#{localLabelName}' placeholder='Local Label' class='fld-label form-control' id='local-label-#{fldId}' contenteditable='true'>#{localLabel}</div></div></div>"
localLabelBlock = "<div class='form-group local-label-wrap' style='display: block'><label for='#{localLabelName}'>Local Label</label><div class='input-wrap'><div name='#{localLabelName}' placeholder='Local Label' class='fld-label-#{fldId} form-control' id='local-label-#{fldId}' contenteditable='true'>#{localLabel}</div></div></div>"
localLabelBlockElement = $.parseHTML(localLabelBlock)
frmHolder.find('.label-wrap').after(localLabelBlockElement)
1 change: 0 additions & 1 deletion app/assets/javascripts/multiple_form/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN
$('input[type="text"]').on 'keyup', (e) ->
el = $(@)
if el.hasClass('date-picker')
console.log('ddddaaaattteee')
else
el.parent().next().find('#' + el.data('local-input')).val(el.val())

Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/program_streams/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
typeUserEvents: {
'checkbox-group': builderOption.eventCheckboxOption(fields)
date: builderOption.eventDateOption(fields)
file: builderOption.eventFileOption()
file: builderOption.eventFileOption(fields)
number: builderOption.eventNumberOption(fields)
'radio-group': builderOption.eventRadioOption(fields)
select: builderOption.eventSelectOption(fields)
Expand Down Expand Up @@ -522,7 +522,6 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C

_handleSetValueToField = ->
for formBuilder in @formBuilder
console.log(formBuilder.actions.save(), 'form builder actions')
element = formBuilder.element
specialCharacters = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&qoute;" }
format = new CIF.FormatSpecialCharacters()
Expand Down
5 changes: 3 additions & 2 deletions app/views/client_enrolled_programs/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
%td.align-justify
= label
%td.align-justify
- key = convert_bracket(label, @client_enrollment.properties)
- key = I18n.locale.to_s === I18n.default_locale.to_s ? key : "Local_label #{key}"
- if type == 'file'
- key = convert_bracket(key.html_safe, @client_enrollment.properties)
= render 'shared/form_builder/list_attachment', label: key, resource: @client_enrollment
- else
- key = convert_bracket(label, @client_enrollment.properties)
- key = I18n.locale.to_s === I18n.default_locale.to_s ? key : "Local_label #{key}"
= display_custom_properties(@client_enrollment.properties[key])
3 changes: 2 additions & 1 deletion app/views/shared/form_builder/_file_field.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
- label = field_label(property)
%div{data: {used: "#{f.object.file.any?}"}}
= f.input :name, as: :hidden, input_html: { name: "#{entity.object_name}[form_builder_attachments_attributes][#{property['name'].split('-').last}][name]", value: property['label'] }
%label.control-label
%abbr{ title: 'repuired' }
= '*' if property['required'].present? && f.object.file.empty?
= property['label'].html_safe
= label.html_safe

= f.input :file, as: :file, label: false, required: property['required'].present?, input_html: { name: "#{entity.object_name}[form_builder_attachments_attributes][#{property['name'].split('-').last}][file][]", multiple: property['multiple'].present?, value: f.object.file }
%span.help-block.hidden
Expand Down
3 changes: 2 additions & 1 deletion config/deploy/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# server 'db.example.com', user: 'deploy', roles: %w{db}

set :stage, 'staging'
set :branch, proc { `git rev-parse --abbrev-ref staging`.chomp }
set :branch, proc { `git rev-parse --abbrev-ref OSC-17`.chomp }
# set :branch, proc { `git rev-parse --abbrev-ref staging`.chomp }

server '52.220.217.164', user: 'deployer', roles: %w{app web db}

Expand Down

0 comments on commit 4fa056f

Please sign in to comment.