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 @@ class="is-inactive"<% end %> data-date="<%= day %>"> diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco index 85a1f7f6c..24f7e4b7e 100644 --- a/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco +++ b/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco @@ -1,7 +1,7 @@ diff --git a/app/assets/javascripts/app/views/generic/input.jst.eco b/app/assets/javascripts/app/views/generic/input.jst.eco index ee309c9a8..bbcfbfe34 100644 --- a/app/assets/javascripts/app/views/generic/input.jst.eco +++ b/app/assets/javascripts/app/views/generic/input.jst.eco @@ -1,4 +1 @@ -placeholder="<%- @Ti(@attribute.placeholder) %>"<% end %> <%= @attribute.required %> <%= @attribute.autofocus %> <%- @attribute.autocapitalize %> <%- @attribute.autocomplete %> <% if @attribute.min isnt undefined: %> min="<%= @attribute.min %>"<% end %><% if @attribute.max isnt undefined: %> max="<%= @attribute.max %>"<% end %><% if @attribute.step: %> step="<%= @attribute.step %>"<% end %><% if @attribute.disabled: %> disabled<% end %>/> -<% if @attribute.disabled: %> - -<% end %> \ No newline at end of file +placeholder="<%- @Ti(@attribute.placeholder) %>"<% end %> <%= @attribute.required %> <%= @attribute.autofocus %> <%- @attribute.autocapitalize %> <%- @attribute.autocomplete %> <% if @attribute.min isnt undefined: %> min="<%= @attribute.min %>"<% end %><% if @attribute.max isnt undefined: %> max="<%= @attribute.max %>"<% end %><% if @attribute.step: %> step="<%= @attribute.step %>"<% end %><% if @attribute.disabled: %> disabled<% end %>/> \ No newline at end of file diff --git a/app/assets/javascripts/app/views/generic/select.jst.eco b/app/assets/javascripts/app/views/generic/select.jst.eco index 710756869..12d043ed8 100644 --- a/app/assets/javascripts/app/views/generic/select.jst.eco +++ b/app/assets/javascripts/app/views/generic/select.jst.eco @@ -9,13 +9,4 @@ <% if not @attribute.multiple: %> <%- @Icon('arrow-down') %> <% end %> -<% if @attribute.disabled: %> -<% if @attribute.options: %> -<% for row in @attribute.options: %> - <% if row.selected: %> - - <% end %> -<% end %> -<% end %> -<% end %> diff --git a/app/assets/javascripts/app/views/generic/timer.jst.eco b/app/assets/javascripts/app/views/generic/timer.jst.eco index fd531f5fa..4e1f5a727 100644 --- a/app/assets/javascripts/app/views/generic/timer.jst.eco +++ b/app/assets/javascripts/app/views/generic/timer.jst.eco @@ -6,21 +6,21 @@
<%- @T('Day') %>
<% for day, dayLong of @days: %>
<%- @T(dayLong) %>
- + <% end %>
<%- @T('Hour') %>
<% for hour, hourLong of @hours: %>
<%- hourLong %>
- + <% end %>
<%- @T('Minute') %>
<% for minute, minuteLong of @minutes: %>
<%- minuteLong %>
- + <% end %>
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/layout_ref/local_modal.jst.eco b/app/assets/javascripts/app/views/layout_ref/local_modal.jst.eco index d1e953d24..934b27630 100644 --- a/app/assets/javascripts/app/views/layout_ref/local_modal.jst.eco +++ b/app/assets/javascripts/app/views/layout_ref/local_modal.jst.eco @@ -273,9 +273,9 @@ diff --git a/app/assets/javascripts/app/views/layout_ref/primary_email.jst.eco b/app/assets/javascripts/app/views/layout_ref/primary_email.jst.eco index 8e40c7db8..6ce262945 100644 --- a/app/assets/javascripts/app/views/layout_ref/primary_email.jst.eco +++ b/app/assets/javascripts/app/views/layout_ref/primary_email.jst.eco @@ -366,7 +366,7 @@
- @@ -424,7 +424,7 @@
- diff --git a/app/assets/javascripts/app/views/object_manager/attribute/boolean.jst.eco b/app/assets/javascripts/app/views/object_manager/attribute/boolean.jst.eco index d24c01284..51408ec45 100644 --- a/app/assets/javascripts/app/views/object_manager/attribute/boolean.jst.eco +++ b/app/assets/javascripts/app/views/object_manager/attribute/boolean.jst.eco @@ -1,7 +1,4 @@
-
-
- @@ -14,16 +11,16 @@
true - + - + checked<% end %>/>
false - + - + checked<% end %>/>
diff --git a/app/assets/javascripts/app/views/object_manager/attribute/select.jst.eco b/app/assets/javascripts/app/views/object_manager/attribute/select.jst.eco index e385f6ca5..448859052 100644 --- a/app/assets/javascripts/app/views/object_manager/attribute/select.jst.eco +++ b/app/assets/javascripts/app/views/object_manager/attribute/select.jst.eco @@ -1,7 +1,4 @@
-
-
- diff --git a/app/assets/javascripts/app/views/object_manager/screens.jst.eco b/app/assets/javascripts/app/views/object_manager/screens.jst.eco index ea147b486..1c9337972 100644 --- a/app/assets/javascripts/app/views/object_manager/screens.jst.eco +++ b/app/assets/javascripts/app/views/object_manager/screens.jst.eco @@ -20,7 +20,7 @@ <%= screen %>
<% for key, defaultValue of options: %> - <%- @T(key) %>: checked<% end %> value="true"> + <%- @T(key) %>: checked<% end %> value="true"> <% end %> <% end %> <% end %> diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6a168d270..829c16c6f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -203,6 +203,47 @@ jQuery.fn.removeAttrs = function(regex) { }); }; +// based on jquery serializeArray +// changes +// - set type based on data('field-type') +// - also catch [disabled] params +jQuery.fn.extend( { + serializeArrayWithType: function() { + var r20 = /%20/g, + rbracket = /\[\]$/, + rCRLF = /\r?\n/g, + rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, + rsubmittable = /^(?:input|select|textarea|keygen)/i; + var rcheckableType = ( /^(?:checkbox|radio)$/i ); + return this.map( function() { + + // Can add propHook for "elements" to filter or add form elements + var elements = jQuery.prop( this, "elements" ); + return elements ? jQuery.makeArray( elements ) : this; + } ) + .filter( function() { + var type = this.type; + + return this.name && + rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && + ( this.checked || !rcheckableType.test( type ) ); + } ) + .map( function( i, elem ) { + var $elem = jQuery( this ); + var val = $elem.val(); + var type = $elem.data('field-type'); + + return val == null ? + null : + jQuery.isArray( val ) ? + jQuery.map( val, function( val ) { + return { name: elem.name, value: val.replace( rCRLF, "\r\n" ), type: type }; + } ) : + { name: elem.name, value: val.replace( rCRLF, "\r\n" ), type: type }; + } ).get(); + } +} ); + // start application jQuery(function(){ new App.Run(); diff --git a/public/assets/tests/form.js b/public/assets/tests/form.js index 8c6e54863..e9d6bf617 100644 --- a/public/assets/tests/form.js +++ b/public/assets/tests/form.js @@ -862,7 +862,7 @@ test("form required_if + shown_if", function() { equal(el.find('[name="input4"]').is(":visible"), false, 'check visible attribute of input4 ') - el.find('[name="{boolean}active"]').val('false').trigger('change') + el.find('[name="active"]').val('false').trigger('change') test_params = { input1: "some not used default33", active: false, @@ -875,7 +875,7 @@ test("form required_if + shown_if", function() { equal(el.find('[name="input4"]').is(":visible"), false, 'check visible attribute of input4') - el.find('[name="{boolean}active"]').val('true').trigger('change') + el.find('[name="active"]').val('true').trigger('change') test_params = { input1: "some not used default33", input2: "some name66",