Skip to content

Commit

Permalink
[FEATURE] Translate form builder
Browse files Browse the repository at this point in the history
refs OSC-17
  • Loading branch information
Bunhok committed Aug 26, 2022
1 parent b0eb1c4 commit 5a86bf9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
84 changes: 77 additions & 7 deletions app/assets/javascripts/program_streams/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
_filterSelecting()
_selectServiceTypeTableResult()
_handleTimeOfFrequencyInput()
elements = ['#enrollment', '#exit-program']
_initMultipleFormBuilder(0, elements)

_initDataTable = ->
$('.custom-field-table').each ->
Expand Down Expand Up @@ -249,7 +251,7 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
$('#trackings').on 'cocoon:after-insert', (e, element) ->
trackingBuilder = $(element).find('.tracking-builder')
$(element).attr('id', Date.now())
_initProgramBuilder(trackingBuilder, [])
# _initProgramBuilder(trackingBuilder, [])
_editTrackingFormName()
_handleRemoveCocoon()
_initSelect2TimeOfFrequency()
Expand All @@ -259,6 +261,64 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
_custom_field_list()
_initCheckbox()

_initMultipleFormBuilder = (startIndex, elements) ->
if startIndex < elements.length
dataElement = JSON.parse($(elements[startIndex]).children('span').text())
builderOption = new CIF.CustomFormBuilder()
specialCharacters = { '&amp;': '&', '&lt;': '<', '&gt;': '>', "&qoute;": '"' }
format = new CIF.FormatSpecialCharacters()
fields = format.formatSpecialCharacters((dataElement || []), specialCharacters)
console.log(fields, 'fieldssssss')

$(elements[startIndex]).formBuilder(
templates: separateLine: (fieldData) ->
{ field: '<hr/>' }
fields: builderOption.thematicBreak()
dataType: 'json'
formData: JSON.stringify(fields)
disableFields: ['autocomplete', 'header', 'hidden', 'button', 'checkbox']
showActionButtons: false
messages: {
cannotBeEmpty: 'name_separated_with_underscore'
}
stickyControls: {
enable: true
offset:
width: '17%'
right: 78
left: 'auto'
}
typeUserEvents: {
'checkbox-group': builderOption.eventCheckboxOption()
date: builderOption.eventDateOption()
file: builderOption.eventFileOption()
number: builderOption.eventNumberOption()
'radio-group': builderOption.eventRadioOption()
select: builderOption.eventSelectOption()
text: builderOption.eventTextFieldOption()
textarea: builderOption.eventTextAreaOption()
separateLine: builderOption.eventSeparateLineOption()
paragraph: builderOption.eventParagraphOption()
}
onAddOption: (optionTemplate, optionIndex) ->
index = optionIndex.index + 1
if !optionTemplate.local_label
optionTemplate.local_label = "Local option #{index}"
optionTemplate.local_value = "Local option #{index}"
return optionTemplate
onOpenFieldEdit: (editPanel) ->
$(editPanel).find('.option-local_value').hide()
typeUserEvents:
select:
onadd: (fld) ->
console.log(fld, 'dssaaffddd')
).promise.then((form) ->
form.element = elements[startIndex]
@formBuilder.push form
startIndex++
_initMultipleFormBuilder(startIndex, elements)
)

_initProgramBuilder = (element, data) ->
builderOption = new CIF.CustomFormBuilder()
specialCharacters = { '&amp;': '&', '&lt;': '<', '&gt;': '>', "&qoute;": '"' }
Expand Down Expand Up @@ -294,9 +354,18 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
textarea: builderOption.eventTextAreaOption()
separateLine: builderOption.eventSeparateLineOption()
paragraph: builderOption.eventParagraphOption()
})
formBuilder.element = element
@formBuilder.push formBuilder
}
onAddOption: (optionTemplate, optionIndex) ->
index = optionIndex.index + 1
optionTemplate.local_label = "Local option #{index}"
optionTemplate.local_value = "local-option-#{index}"
return optionTemplate
onOpenFieldEdit: (editPanel) ->
$(editPanel).find('.option-local_value').hide()
).promise

form.element = element
@formBuilder.push form

_editTrackingFormName = ->
inputNames = $(".program_stream_trackings_name input[type='text']")
Expand Down Expand Up @@ -441,7 +510,7 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
_handleInitProgramFields = ->
for element in $('#enrollment, #exit-program')
dataElement = JSON.parse($(element).children('span').text())
_initProgramBuilder($(element), (dataElement || []))
# _initProgramBuilder($(element), (dataElement || []))

if element.id == 'enrollment' and $('#program_stream_id').val() != ''
_preventRemoveField(ENROLLMENT_URL, '#enrollment')
Expand All @@ -451,7 +520,7 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
trackings = $('.tracking-builder')
for tracking in trackings
trackingValue = JSON.parse($(tracking).children('span').text())
_initProgramBuilder(tracking, (trackingValue || []))
# _initProgramBuilder(tracking, (trackingValue || []))
_preventRemoveField(TRACKING_URL, '') if $('#program_stream_id').val() != ''

_initButtonSave = ->
Expand All @@ -465,10 +534,11 @@ 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()
fields = format.formatSpecialCharacters(JSON.parse(formBuilder.actions.save()), specialCharacters)
fields = format.formatSpecialCharacters(formBuilder.actions.save(), specialCharacters)
fields = JSON.stringify(fields)
if $(element).is('#enrollment')
$('#program_stream_enrollment').val(fields)
Expand Down
1 change: 0 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Rails.application.configure do
config.assets.js_compressor = :terser
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
Expand Down

0 comments on commit 5a86bf9

Please sign in to comment.