Init version with postmaster filter.

This commit is contained in:
Martin Edenhofer 2014-06-06 14:16:13 +02:00
parent 8edef05d85
commit 965fc4d303
4 changed files with 324 additions and 14 deletions

View file

@ -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 = $("<div>#{ displayName }: <input name=\"#{ key }\" type=\"input\" value=\"#{ defaultValue }\" class=\"form-control\"/><a href=\"#\" class=\"glyphicon glyphicon-minus remove\"></a></div>")
# 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 = $('
<div class="postmaster_match" style="margin-left: 40px;">
<div class="list"></div>
<hr>
<div>
<div class="addSelection"></div>
<div class="add"><a href="#" class="glyphicon glyphicon-plus"></a></div>
</div>
</div>')
# 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 = $("<div>#{ displayName }: <input name=\"#{ key }\" type=\"input\" value=\"#{ defaultValue }\" class=\"form-control\"/><a href=\"#\" class=\"glyphicon glyphicon-minus remove\"></a></div>")
# 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 = $('
<div class="perform_set" style="margin-left: 40px;">
<div class="list"></div>
<hr>
<div>
<div class="addSelection"></div>
<div class="add"><a href="#" class="glyphicon glyphicon-plus"></a></div>
</div>
</div>')
# 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 = $('<div class="input_select"></div>')
@ -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 <form>
else if form.is('form')
# find form if current is <form>
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 <form>
else if form.parents('form')[0]
form = form.parents('form')
form = $( form.parents('form')[0] )
# find form based on parents next <form>, 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

View file

@ -15,7 +15,7 @@ class App.ChannelEmail extends App.ControllerTabs
},
{
name: 'Outbound',
target: 'c-outbound',
target: 'c-outbound',
controller: App.ChannelEmailOutbound,
},
{

View file

@ -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' },

View file

@ -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('<hr><h1>form postmaster filter</h1><form id="form5"></form>')
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('<hr><h1>form selector</h1><div><form id="form6"></form></div>')
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()' );
});