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 467bfcb1f..8634d7793 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -1475,7 +1475,7 @@ class App.ControllerForm extends App.Controller # check all filter values as array # 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 # no data filter matched @@ -1523,9 +1523,9 @@ class App.ControllerForm extends App.Controller # set selected attributes _selectedOptions: (attribute) -> - return if !attribute.options + # check if selected / checked need to be set check = (value, record) -> if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean' @@ -1533,14 +1533,12 @@ class App.ControllerForm extends App.Controller if record.value.toString() is value.toString() || record.name.toString() is value.toString() record.selected = 'selected' 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 ) ) record.selected = 'selected' record.checked = 'checked' + # lookup of any record for record in attribute.options if _.isArray( attribute.value ) @@ -1550,6 +1548,16 @@ class App.ControllerForm extends App.Controller if typeof attribute.value is 'string' || typeof attribute.value is 'number' || typeof attribute.value is 'boolean' 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 _disabledOptions: (attribute) -> diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee index 96050555f..bcaaa601a 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee @@ -49,35 +49,13 @@ class Index extends App.ControllerContent # set defaults 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) => - - # only filter on collections - return collection if type isnt 'collection' - - # 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() ) - ) + filter = {} + groupFilter = App.Config.get('customer_ticket_create_group_ids') + if groupFilter + if !_.isArray(groupFilter) + groupFilter = [groupFilter] + filter.group_id = groupFilter @html App.view('customer_ticket_create')( head: 'New Ticket' ) @@ -87,8 +65,7 @@ class Index extends App.ControllerContent model: App.Ticket screen: 'create_web' autofocus: true - filter: - group_id: groupFilter + filter: filter params: defaults ) diff --git a/db/migrate/20140831000001_create_object_manager.rb b/db/migrate/20140831000001_create_object_manager.rb index b60c7de2e..47945adf9 100644 --- a/db/migrate/20140831000001_create_object_manager.rb +++ b/db/migrate/20140831000001_create_object_manager.rb @@ -240,18 +240,23 @@ class CreateObjectManager < ActiveRecord::Migration :filter => [2,3,4], }, }, - :create_web => {}, + :create_web => { + :Customer => { + :filter => [1,4], + :default => 1, + }, + }, :edit => { :Agent => { :nulloption => false, - :null => false, - :filter => [2,3,4], + :null => false, + :filter => [2,3,4], }, :Customer => { :nulloption => false, - :null => true, - :filter => [2,4], - :default => 2, + :null => true, + :filter => [2,4], + :default => 2, }, }, },