diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index cc8ddc75c..3c3e6a39b 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -255,6 +255,214 @@ class App.ControllerForm extends App.Controller item = $( App.view('generic/select')( attribute: attribute ) ) + # postmaster_match + else if attribute.tag is 'postmaster_match' + addItem = (key, displayName, el, defaultValue = '') => + itemInput = $("
#{ displayName }:
") + + # remove on click + itemInput.find('.remove').bind('click', (e) -> + e.preventDefault() + key = $(e.target).prev().attr('name') + return if !key + $(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').show() + $(e.target).parent().parent().parent().find('.list [name="' + key + '"]').parent().remove() + ) + + # add new item + el.parent().parent().parent().find('.list').append(itemInput) + el.parent().parent().parent().find('.addSelection select').val('') + el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').hide() + + # scaffold of match elements + item = $(' +
+
+
+
+
+
+
+
') + + # select shown attributes + loopData = [ + { + value: 'from' + name: 'From' + }, + { + value: 'to' + name: 'To' + }, + { + value: 'cc' + name: 'Cc' + }, + { + value: 'subject' + name: 'Subject' + }, + { + value: 'body' + name: 'Body' + }, + #{ + # value: '-' + # name: '' + # disable: true + #}, + ] + for listItem in loopData + listItem.value = "#{ attribute.name }::#{listItem.value}" + add = { name: '', display: '', tag: 'select', multiple: false, null: false, nulloption: true, options: loopData, translate: true } + item.find('.addSelection').append( @formGenItem( add ) ) + + # bind add click + item.find('.add').bind('click', (e) -> + e.preventDefault() + name = $(@).parent().parent().find('.addSelection').find('select').val() + displayName = $(@).parent().parent().find('.addSelection').find('select option:selected').html() + return if !name + addItem( name, displayName, $(@) ) + ) + + # show default values + loopDataValue = {} + if attribute.value + for key, value of attribute.value + displayName = key + for listItem in loopData + if listItem.value is "#{ attribute.name }::#{key}" + addItem( "#{ attribute.name }::#{key}", listItem.name, item.find('.add a'), value ) + + # postmaster_set + else if attribute.tag is 'postmaster_set' + addItem = (key, displayName, el, defaultValue = '') => + itemInput = $("
#{ displayName }:
") + + # remove on click + itemInput.find('.remove').bind('click', (e) -> + e.preventDefault() + key = $(e.target).prev().attr('name') + return if !key + $(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').show() + $(e.target).parent().parent().parent().find('.list [name="' + key + '"]').parent().remove() + ) + + # add new item + el.parent().parent().parent().find('.list').append(itemInput) + el.parent().parent().parent().find('.addSelection select').val('') + el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').hide() + + # scaffold of perform elements + item = $(' +
+
+
+
+
+
+
+
') + + + # select shown attributes + loopData = [ + { + value: 'from' + name: 'From' + }, + { + value: 'to' + name: 'To' + }, + { + value: 'cc' + name: 'Cc' + }, + { + value: 'subject' + name: 'Subject' + }, + { + value: 'body' + name: 'Body' + }, + { + value: '' + name: '-' + disable: true + }, + { + value: 'x-zammad-ticket-priority' + name: 'Ticket Priority' + }, + { + value: 'x-zammad-ticket-state' + name: 'Ticket State' + }, + { + value: 'x-zammad-ticket-customer' + name: 'Ticket Customer' + }, + { + value: 'x-zammad-ticket-group' + name: 'Ticket Group' + }, + { + value: 'x-zammad-ticket-owner' + name: 'Ticket Owner' + }, + { + value: '' + name: '-' + disable: true + }, + { + value: 'x-zammad-article-visibility' + name: 'Article Visibility' + }, + { + value: 'x-zammad-article-type' + name: 'Article Type' + }, + { + value: 'x-zammad-article-sender' + name: 'Article Sender' + }, + { + value: '' + name: '-' + disable: true + }, + { + value: 'x-zammad-ignore' + name: 'Ignore Message' + }, + ] + for listItem in loopData + listItem.value = "#{ attribute.name }::#{listItem.value}" + add = { name: '', display: '', tag: 'select', multiple: false, null: false, nulloption: true, options: loopData, translate: true } + item.find('.addSelection').append( @formGenItem( add ) ) + + item.find('.add').bind('click', (e) -> + e.preventDefault() + name = $(@).parent().parent().find('.addSelection').find('select').val() + displayName = $(@).parent().parent().find('.addSelection').find('select option:selected').html() + return if !name + addItem( name, displayName, $(@) ) + ) + + # show default values + loopDataValue = {} + if attribute.value + for key, value of attribute.value + displayName = key + for listItem in loopData + if listItem.value is "#{ attribute.name }::#{key}" + addItem( "#{ attribute.name }::#{key}", listItem.name, item.find('.add a'), value ) + # select else if attribute.tag is 'input_select' item = $('
') @@ -1231,27 +1439,27 @@ class App.ControllerForm extends App.Controller param = {} # create jquery object if not already exists - if typeof form isnt 'function' + if form instanceof jQuery + # do nothing + else form = $(form) - # find form based on sub elements - if form.children()[0] - form = form.children().parents('form') - - # find form based on parents next
- else if form.is('form') + # find form if current is + if form.is('form') form = form + # find form based on sub elements + else if form.find('form')[0] + form = $( form.find('form')[0] ) + # find form based on parents next else if form.parents('form')[0] - form = form.parents('form') + form = $( form.parents('form')[0] ) - # find form based on parents next , not really good! - else if form.parents().find('form')[0] - form = form.parents().find('form') else App.Log.error 'ControllerForm', 'no form found!', form + # get form elements array = form.serializeArray() # 1:1 and boolean params diff --git a/app/assets/javascripts/app/controllers/_channel/email.js.coffee b/app/assets/javascripts/app/controllers/_channel/email.js.coffee index 9a99eb4e8..34f81008f 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.js.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.js.coffee @@ -15,7 +15,7 @@ class App.ChannelEmail extends App.ControllerTabs }, { name: 'Outbound', - target: 'c-outbound', + target: 'c-outbound', controller: App.ChannelEmailOutbound, }, { diff --git a/app/assets/javascripts/app/models/postmaster_filter.js.coffee b/app/assets/javascripts/app/models/postmaster_filter.js.coffee index 1e08ad590..744857193 100644 --- a/app/assets/javascripts/app/models/postmaster_filter.js.coffee +++ b/app/assets/javascripts/app/models/postmaster_filter.js.coffee @@ -6,8 +6,8 @@ class App.PostmasterFilter extends App.Model @configure_attributes = [ { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 250, 'null': false, 'class': 'span4' }, { name: 'channel', display: 'Channel', type: 'input', readonly: 1 }, - { name: 'match', display: 'Match all of the following', tag: 'input_select', count_min: 2, count_max: 88, multiple: true, 'null': false, 'class': 'span4', select: { 'class': 'span2', multiple: false, options: { from: 'From', to: 'To', cc: 'Cc', subject: 'Subject', body: 'Body' } }, input: { limit: 250, type: 'text', 'class': 'span3' }, }, - { name: 'perform', display: 'Perform action of the following', tag: 'input_select', count_min: 2, count_max: 88, multiple: true, 'null': false, 'class': 'span4', select: { 'class': 'span2', multiple: false, options: { from: 'From', to: 'To', cc: 'Cc', subject: 'Subject', body: 'Body', 'x-zammad-priority': 'Ticket Priority', 'x-zammad-state': 'Ticket State', 'x-zammad-customer': 'Ticket Customer', 'x-zammad-ignore': 'Ignore Message', 'x-zammad-group': 'Ticket Group', 'x-zammad-owner': 'Ticket Owner', 'x-zammad-article-visibility': 'Article Visibility', 'x-zammad-article-type': 'Article Type', 'x-zammad-article-sender': 'Article Sender' } }, input: { limit: 250, type: 'text', 'class': 'span3' }, }, + { name: 'match', display: 'Match all of the following', tag: 'postmaster_match' }, + { name: 'perform', display: 'Perform action of the following', tag: 'postmaster_set' }, { name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, 'null': true, 'class': 'span4' }, { name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 }, { name: 'active', display: 'Active', tag: 'boolean', type: 'boolean', 'default': true, 'null': false, 'class': 'span4' }, diff --git a/public/assets/tests/form.js b/public/assets/tests/form.js index 8ff803a94..16954acfc 100644 --- a/public/assets/tests/form.js +++ b/public/assets/tests/form.js @@ -367,3 +367,105 @@ test( "form dependend fields check", function() { deepEqual( params, test_params, 'form param check' ); }); +test( "form postmaster filter", function() { + +// check match area + +// check set area + +// add match rule + +// add set rule + + $('#forms').append('

form postmaster filter

') + var el = $('#form5') + var defaults = { + input2: 'some name', + match: { + from: 'some@address', + subject: 'some subject', + }, + set: { + to: 'some@address', + 'x-zammad-ticket-group': 'some group', + }, + } + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' }, + { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' }, + { name: 'match', display: 'Match', tag: 'postmaster_match', null: false, default: false}, + { name: 'set', display: 'Set', tag: 'postmaster_set', null: false, default: false}, + ], + }, + params: defaults, + }); + params = App.ControllerForm.params( el ) + test_params = { + input1: "some not used default", + input2: "some name", + match: { + from: 'some@address', + subject: 'some subject', + }, + set: { + to: 'some@address', + 'x-zammad-ticket-group': 'some group', + }, + }; + deepEqual( params, test_params, 'form param check' ); + el.find('[name="set::to"]').next().click() + App.Delay.set( function() { + test( "form param check after remove click", function() { + params = App.ControllerForm.params( el ) + test_params = { + input1: "some not used default", + input2: "some name", + match: { + from: 'some@address', + subject: 'some subject', + }, + set: { + 'x-zammad-ticket-group': 'some group', + }, + }; + deepEqual( params, test_params, 'form param check' ); + }); + }, + 1000 + ); + +}); + +test( "form selector", function() { + $('#forms').append('

form selector

') + var el = $('#form6') + var defaults = { + input2: 'some name66', + } + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default33' }, + { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' }, + ], + }, + params: defaults, + }); + test_params = { + input1: "some not used default33", + input2: "some name66", + }; + params = App.ControllerForm.params( el ) + deepEqual( params, test_params, 'form param check via $("#form")' ); + + params = App.ControllerForm.params( el.find('input') ) + deepEqual( params, test_params, 'form param check via $("#form").find("input")' ); + + params = App.ControllerForm.params( el.parent() ) + deepEqual( params, test_params, 'form param check via $("#form").parent()' ); + +});