Change behaviour for rendering of selected but not active options. Show also not active options if selected.

This commit is contained in:
Martin Edenhofer 2016-05-23 21:20:18 +02:00
parent f9ff436630
commit 37317f2a42
2 changed files with 72 additions and 41 deletions

View file

@ -146,8 +146,14 @@ class App.UiElement.ApplicationUiElement
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()
@ -175,28 +181,11 @@ class App.UiElement.ApplicationUiElement
@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,8 +194,28 @@ 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) ->

View file

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