Fixed group selection in customer ticket create.

This commit is contained in:
Martin Edenhofer 2014-09-22 14:55:14 +02:00
parent ec2f74192f
commit 7127791e50
3 changed files with 37 additions and 46 deletions

View file

@ -1489,7 +1489,7 @@ class App.ControllerForm extends App.Controller
# check all filter values as array # check all filter values as array
# if it's matching, use it for selection # if it's matching, use it for selection
if record['id'] is key if record['id'] is key || ( record['id'] && key && record['id'].toString() is key.toString() )
list.push record list.push record
# no data filter matched # no data filter matched
@ -1537,9 +1537,9 @@ class App.ControllerForm extends App.Controller
# set selected attributes # set selected attributes
_selectedOptions: (attribute) -> _selectedOptions: (attribute) ->
return if !attribute.options return if !attribute.options
# check if selected / checked need to be set
check = (value, record) -> check = (value, record) ->
if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean' if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean'
@ -1547,14 +1547,12 @@ class App.ControllerForm extends App.Controller
if record.value.toString() is value.toString() || record.name.toString() is value.toString() if record.value.toString() is value.toString() || record.name.toString() is value.toString()
record.selected = 'selected' record.selected = 'selected'
record.checked = 'checked' record.checked = 'checked'
# if record.name.toString() is attribute.value.toString()
# record.selected = 'selected'
# record.checked = 'checked'
else if ( value && record.value && _.include( value, record.value ) ) || ( value && record.name && _.include( value, record.name ) ) else if ( value && record.value && _.include( value, record.value ) ) || ( value && record.name && _.include( value, record.name ) )
record.selected = 'selected' record.selected = 'selected'
record.checked = 'checked' record.checked = 'checked'
# lookup of any record
for record in attribute.options for record in attribute.options
if _.isArray( attribute.value ) if _.isArray( attribute.value )
@ -1564,6 +1562,16 @@ class App.ControllerForm extends App.Controller
if typeof attribute.value is 'string' || typeof attribute.value is 'number' || typeof attribute.value is 'boolean' if typeof attribute.value is 'string' || typeof attribute.value is 'number' || typeof attribute.value is 'boolean'
check( attribute.value, record ) check( attribute.value, record )
# if noting is selected / checked, use default as selected / checked
selected = false
for record in attribute.options
if record.selected || record.checked
selected = true
if !selected
for record in attribute.options
if typeof attribute.default is 'string' || typeof attribute.default is 'number' || typeof attribute.default is 'boolean'
check( attribute.default, record )
# set disabled attributes # set disabled attributes
_disabledOptions: (attribute) -> _disabledOptions: (attribute) ->

View file

@ -57,35 +57,12 @@ class Index extends App.ControllerContent
# set defaults # set defaults
defaults = template['options'] || {} defaults = template['options'] || {}
if !( 'state_id' of defaults )
defaults['state_id'] = App.TicketState.findByAttribute( 'name', 'new' )
if !( 'priority_id' of defaults )
defaults['priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' )
groupFilter = (collection, type) => groupFilter = App.Config.get('customer_ticket_create_group_ids')
if groupFilter
# only filter on collections if !_.isArray(groupFilter)
return collection if type isnt 'collection' groupFilter = [groupFilter]
@form_meta.filter.group_id = groupFilter
# get configured ids
group_ids = App.Config.get('customer_ticket_create_group_ids')
# return all groups if no one is selected
return collection if !group_ids
return collection if !_.isArray( group_ids ) && group_ids is ''
return collection if _.isEmpty( group_ids )
if !_.isArray( group_ids )
group_ids = [group_ids]
# filter selected groups
if _.isEmpty( group_ids )
return collection
_.filter(
collection
(item) ->
return item if item && _.contains( group_ids, item.id.toString() )
)
formChanges = (params, attribute, attributes, classname, form, ui) => formChanges = (params, attribute, attributes, classname, form, ui) =>
if @form_meta.dependencies && @form_meta.dependencies[attribute.name] if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
@ -113,12 +90,11 @@ class Index extends App.ControllerContent
@html App.view('customer_ticket_create')( head: 'New Ticket' ) @html App.view('customer_ticket_create')( head: 'New Ticket' )
new App.ControllerForm( new App.ControllerForm(
el: @el.find('.ticket-form-top') el: @el.find('.ticket-form-top')
form_id: @form_id form_id: @form_id
model: App.Ticket model: App.Ticket
screen: 'create_top'#@article_attributes['screen'] screen: 'create_top'
handlers: [ handlers: [
formChanges formChanges
] ]
@ -131,14 +107,14 @@ class Index extends App.ControllerContent
el: @el.find('.article-form-top') el: @el.find('.article-form-top')
form_id: @form_id form_id: @form_id
model: App.TicketArticle model: App.TicketArticle
screen: 'create_top'#@article_attributes['screen'] screen: 'create_top'
params: defaults params: defaults
) )
new App.ControllerForm( new App.ControllerForm(
el: @el.find('.ticket-form-middle') el: @el.find('.ticket-form-middle')
form_id: @form_id form_id: @form_id
model: App.Ticket model: App.Ticket
screen: 'create_middle'#@article_attributes['screen'] screen: 'create_middle'
handlers: [ handlers: [
formChanges formChanges
] ]

View file

@ -179,10 +179,17 @@ class CreateObjectManager < ActiveRecord::Migration
:active => true, :active => true,
:screens => { :screens => {
:create_middle => { :create_middle => {
'-all-' => { :Agent => {
:null => false, :null => false,
:item_class => 'column', :item_class => 'column',
}, },
:Customer => {
:item_class => 'column',
:nulloption => false,
:null => true,
:filter => [1,4],
:default => 1,
},
}, },
:edit => { :edit => {
:Agent => { :Agent => {