Change behaviour for rendering of selected but not active options. Show also not active options if selected.
This commit is contained in:
parent
f9ff436630
commit
37317f2a42
2 changed files with 72 additions and 41 deletions
|
@ -8,7 +8,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
|
|
||||||
return if !attribute.options
|
return if !attribute.options
|
||||||
|
|
||||||
if _.isArray( attribute.options )
|
if _.isArray(attribute.options)
|
||||||
# reverse if we have to exit early, if configured
|
# reverse if we have to exit early, if configured
|
||||||
if attribute.order
|
if attribute.order
|
||||||
if attribute.order == 'DESC'
|
if attribute.order == 'DESC'
|
||||||
|
@ -38,7 +38,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
return if !attribute.options
|
return if !attribute.options
|
||||||
return if !attribute.nulloption
|
return if !attribute.nulloption
|
||||||
if _.isArray( attribute.options )
|
if _.isArray( attribute.options )
|
||||||
attribute.options.unshift( { name: '-', value: '' } )
|
attribute.options.unshift({ name: '-', value: '' })
|
||||||
else
|
else
|
||||||
attribute.options[''] = '-'
|
attribute.options[''] = '-'
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ class App.UiElement.ApplicationUiElement
|
||||||
return if !attribute.options
|
return if !attribute.options
|
||||||
selection = attribute.options
|
selection = attribute.options
|
||||||
attribute.options = []
|
attribute.options = []
|
||||||
if _.isArray( selection )
|
if _.isArray(selection)
|
||||||
for row in selection
|
for row in selection
|
||||||
if attribute.translate
|
if attribute.translate
|
||||||
row.name = App.i18n.translateInline( row.name )
|
row.name = App.i18n.translateInline(row.name)
|
||||||
attribute.options.push row
|
attribute.options.push row
|
||||||
else
|
else
|
||||||
order = _.sortBy(
|
order = _.sortBy(
|
||||||
|
@ -59,7 +59,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
for key in order
|
for key in order
|
||||||
name_new = selection[key]
|
name_new = selection[key]
|
||||||
if attribute.translate
|
if attribute.translate
|
||||||
name_new = App.i18n.translateInline( name_new )
|
name_new = App.i18n.translateInline(name_new)
|
||||||
attribute.options.push {
|
attribute.options.push {
|
||||||
name: name_new
|
name: name_new
|
||||||
value: key
|
value: key
|
||||||
|
@ -81,9 +81,9 @@ class App.UiElement.ApplicationUiElement
|
||||||
if typeof attribute.filter is 'function'
|
if typeof attribute.filter is 'function'
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-function'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-function'
|
||||||
|
|
||||||
all = App[ attribute.relation ].search( sortBy: attribute.sortBy )
|
all = App[ attribute.relation ].search(sortBy: attribute.sortBy)
|
||||||
|
|
||||||
list = attribute.filter( all, 'collection', params )
|
list = attribute.filter(all, 'collection', params)
|
||||||
|
|
||||||
# data based filter
|
# data based filter
|
||||||
else if attribute.filter[ attribute.name ]
|
else if attribute.filter[ attribute.name ]
|
||||||
|
@ -92,7 +92,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data', filter
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data', filter
|
||||||
|
|
||||||
# check all records
|
# check all records
|
||||||
for record in App[ attribute.relation ].search( sortBy: attribute.sortBy )
|
for record in App[ attribute.relation ].search(sortBy: attribute.sortBy)
|
||||||
|
|
||||||
# check all filter attributes
|
# check all filter attributes
|
||||||
for key in filter
|
for key in filter
|
||||||
|
@ -108,7 +108,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-array', attribute.filter
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-array', attribute.filter
|
||||||
|
|
||||||
# check all records
|
# check all records
|
||||||
for record in App[ attribute.relation ].search( sortBy: attribute.sortBy )
|
for record in App[ attribute.relation ].search(sortBy: attribute.sortBy)
|
||||||
|
|
||||||
# check all filter attributes
|
# check all filter attributes
|
||||||
for key in attribute.filter
|
for key in attribute.filter
|
||||||
|
@ -125,29 +125,35 @@ class App.UiElement.ApplicationUiElement
|
||||||
if value['id'].toString() is params[ attribute.name ].toString()
|
if value['id'].toString() is params[ attribute.name ].toString()
|
||||||
hit = true
|
hit = true
|
||||||
if !hit
|
if !hit
|
||||||
currentRecord = App[ attribute.relation ].find( params[ attribute.name ] )
|
currentRecord = App[ attribute.relation ].find(params[ attribute.name ])
|
||||||
list.push currentRecord
|
list.push currentRecord
|
||||||
|
|
||||||
# no data filter matched
|
# no data filter matched
|
||||||
else
|
else
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data no filter matched'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data no filter matched'
|
||||||
list = App[ attribute.relation ].search( sortBy: attribute.sortBy )
|
list = App[ attribute.relation ].search(sortBy: attribute.sortBy)
|
||||||
else
|
else
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-no filter defined'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-no filter defined'
|
||||||
list = App[ attribute.relation ].search( sortBy: attribute.sortBy )
|
list = App[ attribute.relation ].search(sortBy: attribute.sortBy)
|
||||||
|
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList', attribute, list
|
App.Log.debug 'ControllerForm', '_getRelationOptionList', attribute, list
|
||||||
|
|
||||||
# build options list
|
# build options list
|
||||||
@buildOptionList( list, attribute )
|
@buildOptionList(list, attribute)
|
||||||
|
|
||||||
# build options list
|
# build options list
|
||||||
@buildOptionList: (list, attribute) ->
|
@buildOptionList: (list, attribute) ->
|
||||||
|
|
||||||
for item in list
|
for item in list
|
||||||
|
|
||||||
|
# check if element is selected, show it anyway - ignore active state
|
||||||
|
activeSupport = ('active' of item)
|
||||||
|
isSelected = false
|
||||||
|
if activeSupport && !item.active
|
||||||
|
isSelected = @_selectedOptionsIsSelected(attribute.value, {name: item.name || '', value: item.id})
|
||||||
|
|
||||||
# if active or if active doesn't exist
|
# if active or if active doesn't exist
|
||||||
if item.active || !( 'active' of item )
|
if item.active || !activeSupport || isSelected
|
||||||
name_new = '?'
|
name_new = '?'
|
||||||
if item.displayName
|
if item.displayName
|
||||||
name_new = item.displayName()
|
name_new = item.displayName()
|
||||||
|
@ -169,34 +175,17 @@ class App.UiElement.ApplicationUiElement
|
||||||
return if typeof attribute.filter isnt 'function'
|
return if typeof attribute.filter isnt 'function'
|
||||||
App.Log.debug 'ControllerForm', '_filterOption:filter-function'
|
App.Log.debug 'ControllerForm', '_filterOption:filter-function'
|
||||||
|
|
||||||
attribute.options = attribute.filter( attribute.options, attribute )
|
attribute.options = attribute.filter(attribute.options, attribute)
|
||||||
|
|
||||||
# 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
|
# lookup of any record, if it need to be selected
|
||||||
check = (value, record) ->
|
|
||||||
if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean'
|
|
||||||
|
|
||||||
# if name or value is matching
|
|
||||||
if record.value.toString() is value.toString() || record.name.toString() is 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
|
for record in attribute.options
|
||||||
|
if @_selectedOptionsIsSelected(attribute.value, record)
|
||||||
if _.isArray( attribute.value )
|
record.selected = 'selected'
|
||||||
for value in attribute.value
|
record.checked = 'checked'
|
||||||
check( value, record )
|
|
||||||
|
|
||||||
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
|
# if noting is selected / checked, use default as selected / checked
|
||||||
selected = false
|
selected = false
|
||||||
|
@ -205,14 +194,34 @@ class App.UiElement.ApplicationUiElement
|
||||||
selected = true
|
selected = true
|
||||||
if !selected
|
if !selected
|
||||||
for record in attribute.options
|
for record in attribute.options
|
||||||
if typeof attribute.default is 'string' || typeof attribute.default is 'number' || typeof attribute.default is 'boolean'
|
if @_selectedOptionsIsSelected(attribute.default, record)
|
||||||
check( attribute.default, record )
|
record.selected = 'selected'
|
||||||
|
record.checked = 'checked'
|
||||||
|
|
||||||
|
@_selectedOptionsIsSelected: (value, record) ->
|
||||||
|
if _.isArray(value)
|
||||||
|
for valueItem in value
|
||||||
|
if @_selectedOptionsIsSelectedItem(valueItem, record)
|
||||||
|
return true
|
||||||
|
if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean'
|
||||||
|
if @_selectedOptionsIsSelectedItem(value, record)
|
||||||
|
return true
|
||||||
|
false
|
||||||
|
|
||||||
|
@_selectedOptionsIsSelectedItem: (value, record) ->
|
||||||
|
# if name or value is matching
|
||||||
|
if typeof value is 'string' || typeof value is 'number' || typeof value is 'boolean'
|
||||||
|
if record.value.toString() is value.toString() || record.name.toString() is value.toString()
|
||||||
|
return true
|
||||||
|
else if ( value && record.value && _.include(value, record.value) ) || ( value && record.name && _.include(value, record.name) )
|
||||||
|
return true
|
||||||
|
false
|
||||||
|
|
||||||
# set disabled attributes
|
# set disabled attributes
|
||||||
@disabledOptions: (attribute) ->
|
@disabledOptions: (attribute) ->
|
||||||
|
|
||||||
return if !attribute.options
|
return if !attribute.options
|
||||||
return if !_.isArray( attribute.options )
|
return if !_.isArray(attribute.options)
|
||||||
|
|
||||||
for record in attribute.options
|
for record in attribute.options
|
||||||
if record.disable is true
|
if record.disable is true
|
||||||
|
|
|
@ -31,6 +31,13 @@ test('form checks', function() {
|
||||||
active: true,
|
active: true,
|
||||||
created_at: '2014-06-10T10:17:54.000Z',
|
created_at: '2014-06-10T10:17:54.000Z',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
name: '5 xxx very high',
|
||||||
|
note: 'some note 5',
|
||||||
|
active: false,
|
||||||
|
created_at: '2014-06-10T10:17:56.000Z',
|
||||||
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
App.TicketState.refresh([
|
App.TicketState.refresh([
|
||||||
|
@ -78,11 +85,13 @@ test('form checks', function() {
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
/* working hours and escalation_times */
|
/* working hours and escalation_times */
|
||||||
$('#forms').append('<hr><h1>form condition check</h1><form id="form1"></form>')
|
$('#forms').append('<hr><h1>form condition check</h1><form id="form1"></form>')
|
||||||
var el = $('#form1')
|
var el = $('#form1')
|
||||||
var defaults = {
|
var defaults = {
|
||||||
|
priority1_id: '1',
|
||||||
|
priority2_id: ['1', '2'],
|
||||||
|
priority3_id: '2',
|
||||||
working_hours: {
|
working_hours: {
|
||||||
mon: {
|
mon: {
|
||||||
active: true,
|
active: true,
|
||||||
|
@ -136,6 +145,9 @@ test('form checks', function() {
|
||||||
el: el,
|
el: el,
|
||||||
model: {
|
model: {
|
||||||
configure_attributes: [
|
configure_attributes: [
|
||||||
|
{ name: 'priority1_id', display: 'Priroity1', tag: 'select', relation: 'TicketPriority', null: true },
|
||||||
|
{ name: 'priority2_id', display: 'Priroity2', tag: 'select', multiple: true, relation: 'TicketPriority', null: true },
|
||||||
|
{ name: 'priority3_id', display: 'Priroity3', tag: 'select', relation: 'TicketPriority', null: true },
|
||||||
{ name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
|
{ name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
|
||||||
{ name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
|
{ name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
|
||||||
]
|
]
|
||||||
|
@ -145,6 +157,9 @@ test('form checks', function() {
|
||||||
})
|
})
|
||||||
var params = App.ControllerForm.params(el)
|
var params = App.ControllerForm.params(el)
|
||||||
var test_params = {
|
var test_params = {
|
||||||
|
priority1_id: '1',
|
||||||
|
priority2_id: ['1', '2'],
|
||||||
|
priority3_id: '2',
|
||||||
first_response_time: '150',
|
first_response_time: '150',
|
||||||
first_response_time_in_text: '02:30',
|
first_response_time_in_text: '02:30',
|
||||||
solution_time: '',
|
solution_time: '',
|
||||||
|
@ -199,12 +214,20 @@ test('form checks', function() {
|
||||||
}
|
}
|
||||||
deepEqual(params, test_params, 'form param check')
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
|
// check possible options
|
||||||
|
equal(el.find('[name="priority1_id"] option').length, 3)
|
||||||
|
equal(el.find('[name="priority2_id"] option').length, 4)
|
||||||
|
equal(el.find('[name="priority3_id"] option').length, 4)
|
||||||
|
|
||||||
// change sla times
|
// change sla times
|
||||||
el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
|
el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
|
||||||
el.find('#update_time').click()
|
el.find('#update_time').click()
|
||||||
|
|
||||||
var params = App.ControllerForm.params(el)
|
var params = App.ControllerForm.params(el)
|
||||||
var test_params = {
|
var test_params = {
|
||||||
|
priority1_id: '1',
|
||||||
|
priority2_id: ['1', '2'],
|
||||||
|
priority3_id: '2',
|
||||||
working_hours: {
|
working_hours: {
|
||||||
mon: {
|
mon: {
|
||||||
active: true,
|
active: true,
|
||||||
|
@ -259,7 +282,6 @@ test('form checks', function() {
|
||||||
}
|
}
|
||||||
deepEqual(params, test_params, 'form param check')
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
|
|
||||||
/* empty params or defaults */
|
/* empty params or defaults */
|
||||||
$('#forms').append('<hr><h1>form condition check</h1><form id="form2"></form>')
|
$('#forms').append('<hr><h1>form condition check</h1><form id="form2"></form>')
|
||||||
var el = $('#form2')
|
var el = $('#form2')
|
||||||
|
@ -369,7 +391,7 @@ test('form checks', function() {
|
||||||
},
|
},
|
||||||
'ticket.priority_id': {
|
'ticket.priority_id': {
|
||||||
operator: 'is',
|
operator: 'is',
|
||||||
value: ['1', '3'],
|
value: ['1', '2', '3'], // show also invalid proirity, because it's selected
|
||||||
},
|
},
|
||||||
'ticket.created_at': {
|
'ticket.created_at': {
|
||||||
operator: 'before (absolute)',
|
operator: 'before (absolute)',
|
||||||
|
|
Loading…
Reference in a new issue