diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 4e1ea8647..c747590f9 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -406,39 +406,43 @@ class App.ControllerForm extends App.Controller param[name] = $(element).ceg() # get form elements - array = lookupForm.serializeArray() + array = lookupForm.serializeArrayWithType() # array to names - for key in array + for item in array # check if item is-hidden and should not be used - if lookupForm.find('[name="' + key.name + '"]').hasClass('is-hidden') || lookupForm.find('div[data-name="' + key.name + '"]').hasClass('is-hidden') - delete param[key.name] + if lookupForm.find('[name="' + item.name + '"]').hasClass('is-hidden') || lookupForm.find('div[data-name="' + item.name + '"]').hasClass('is-hidden') + delete param[item.name] continue # collect all params, push it to an array if already exists - if param[key.name] isnt undefined - if typeof param[key.name] is 'string' - param[key.name] = [param[key.name], key.value.trim()] + value = item.value.trim() + if item.type is 'boolean' + if value is '' + value = undefined + else if value is 'true' + value = true + else if value is 'false' + value = false + if item.type is 'integer' + if value is '' + value = undefined else - param[key.name].push key.value.trim() + value = parseInt(value) + if param[item.name] isnt undefined + if typeof param[item.name] is 'string' + param[item.name] = [param[item.name], value] + else + param[item.name].push value else - param[key.name] = key.value.trim() + param[item.name] = value # data type conversion for key of param - # get boolean - if key.substr(0,9) is '{boolean}' - newKey = key.substr(9, key.length) - if param[key] && param[key].toString() is 'true' - param[newKey] = true - else - param[newKey] = false - delete param[key] - # get {date} - else if key.substr(0,6) is '{date}' + if key.substr(0,6) is '{date}' newKey = key.substr(6, key.length) if lookupForm.find("[data-name=\"#{newKey}\"]").hasClass('is-hidden') param[newKey] = null diff --git a/app/assets/javascripts/app/controllers/_ui_element/active.coffee b/app/assets/javascripts/app/controllers/_ui_element/active.coffee index 1cb8b20cb..5df38ce0c 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/active.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/active.coffee @@ -12,10 +12,6 @@ class App.UiElement.active extends App.UiElement.ApplicationUiElement { name: 'inactive', value: false } ] - # set data type - if attribute.name - attribute.name = '{boolean}' + attribute.name - # build options list based on config @getConfigOptionList(attribute, params) @@ -26,4 +22,6 @@ class App.UiElement.active extends App.UiElement.ApplicationUiElement @selectedOptions(attribute, params) # return item - $( App.view('generic/select')( attribute: attribute ) ) \ No newline at end of file + item = $( App.view('generic/select')(attribute: attribute) ) + item.find('select').data('field-type', 'boolean') + item \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/boolean.coffee b/app/assets/javascripts/app/controllers/_ui_element/boolean.coffee index 5855903c7..56ebaca1b 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/boolean.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/boolean.coffee @@ -10,10 +10,6 @@ class App.UiElement.boolean extends App.UiElement.ApplicationUiElement ] attribute.translate = true - # set data type - if attribute.name - attribute.name = '{boolean}' + attribute.name - # build options list based on config @getConfigOptionList(attribute, params) @@ -23,5 +19,6 @@ class App.UiElement.boolean extends App.UiElement.ApplicationUiElement # finde selected/checked item of list @selectedOptions(attribute, params) - # return item - $(App.view('generic/select')(attribute: attribute)) \ No newline at end of file + item = $(App.view('generic/select')(attribute: attribute)) + item.find('select').data('field-type', 'boolean') + item \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee index dd645ec12..f85efb00f 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee @@ -12,6 +12,8 @@ class App.UiElement.holiday_selector item = $( App.view('calendar/holiday_selector')( attribute: attribute, days: days_new ) ) + item.find('.js-boolean').data('field-type', 'boolean') + # add date picker attributeDatepicket = name: "#{attribute.name}_date" @@ -68,9 +70,10 @@ class App.UiElement.holiday_selector placeholderDate: date placeholderSummary: summary nameSummary: "public_holidays::#{date}::summary" - nameActive: "{boolean}public_holidays::#{date}::active" + nameActive: "public_holidays::#{date}::active" ) item.find('.settings-list-controlRow').before(template) + item.find('.js-boolean').data('field-type', 'boolean') ) item diff --git a/app/assets/javascripts/app/controllers/_ui_element/integer.coffee b/app/assets/javascripts/app/controllers/_ui_element/integer.coffee index 6f5f7a7b4..7587c4d28 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/integer.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/integer.coffee @@ -3,4 +3,6 @@ class App.UiElement.integer @render: (attribute) -> attribute.type = 'number' attribute.step = '1' - $( App.view('generic/input')( attribute: attribute ) ) + item = $( App.view('generic/input')(attribute: attribute) ) + item.find('select').data('field-type', 'integer') + item \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee b/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee index 1d9648b2d..0ba864fa5 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee @@ -22,7 +22,6 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi select: 'Select' boolean: 'Boolean' integer: 'Integer' - autocompletion: 'Autocompletion (AJAX remote URL)' configureAttributes = [ { name: attribute.name, display: '', tag: 'select', null: false, options: options, translate: true, default: 'input', disabled: attribute.disabled }, @@ -37,7 +36,7 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi params: params ) item.find('.js-dataType').html(dataType.form) - + item.find('.js-boolean').data('field-type', 'boolean') item @dataScreens: (attribute, localParams, params) -> @@ -130,12 +129,14 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi init = false if params && !params.id init = true - $(App.view('object_manager/screens')( + item = $(App.view('object_manager/screens')( attribute: attribute data: objects[object] params: params init: init )) + item.find('.js-boolean').data('field-type', 'boolean') + item @input: (item, localParams, params) -> configureAttributes = [ @@ -284,11 +285,36 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi addRow.find('.js-value').val('') addRow.find('.js-selected').prop('checked', false) ) + item.on('change', '.js-key', (e) -> + key = $(e.target).val() + valueField = $(e.target).closest('tr').find('.js-value[name]') + valueField.attr('name', "data_option::options::#{key}") + ) item.on('click', '.js-remove', (e) -> $(e.target).closest('tr').remove() ) + lastSelected = undefined + item.on('click', '.js-selected', (e) -> + checked = $(e.target).prop('checked') + value = $(e.target).attr('value') + if checked && lastSelected && lastSelected is value + $(e.target).prop('checked', false) + lastSelected = false + return + lastSelected = value + ) @boolean: (item, localParams, params) -> + lastSelected = undefined + item.on('click', '.js-selected', (e) -> + checked = $(e.target).prop('checked') + value = $(e.target).attr('value') + if checked && lastSelected && lastSelected is value + $(e.target).prop('checked', false) + lastSelected = false + return + lastSelected = value + ) @autocompletion: (item, localParams, params) -> configureAttributes = [ diff --git a/app/assets/javascripts/app/controllers/_ui_element/timer.coffee b/app/assets/javascripts/app/controllers/_ui_element/timer.coffee index 860ccb8ce..d6fd28adf 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/timer.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/timer.coffee @@ -80,7 +80,7 @@ class App.UiElement.timer 0: true timer = $( App.view('generic/timer')( attribute: attribute, days: days, hours: hours, minutes: minutes ) ) - + timer.find('.js-boolean').data('field-type', 'boolean') timer.find('.select-value').bind('click', (e) => @select(e) ) diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco index 1d84b3952..e68b1a976 100644 --- a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco +++ b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco @@ -11,7 +11,7 @@