Fixed issue #949 - Sometimes pending time is show as first ticket attribute.

This commit is contained in:
Rolf Schmidt 2018-02-26 11:40:57 +01:00
parent 8d725040a9
commit 1e311034a0
2 changed files with 49 additions and 3 deletions

View file

@ -828,14 +828,29 @@ set new attributes of model (remove already available attributes)
@updateAttributes: (attributes) ->
return if !@className
if _.isEmpty(@org_configure_attributes)
@org_configure_attributes = clone(@configure_attributes)
# use jquery instead of ._clone() because we need a deep copy of the obj
@org_configure_attributes = $.extend(true, [], @configure_attributes)
for attribute in attributes
@attributes.push attribute.name
@configure_attributes.push attribute
found = false
for attribute_model, index in @configure_attributes
continue if attribute_model.name != attribute.name
@configure_attributes[index] = _.extend(attribute_model, attribute)
found = true
break
if !found
@configure_attributes.push attribute
@resetAttributes: ->
return if _.isEmpty(@org_configure_attributes)
@configure_attributes = @org_configure_attributes
# use jquery instead of ._clone() because we need a deep copy of the obj
@configure_attributes = $.extend(true, [], @org_configure_attributes)
@resetCallbacks: ->
@SUBSCRIPTION_ITEM = {}

View file

@ -407,4 +407,35 @@ App.Delay.set( function() {
1400
);
test("updateAttributes will change existing attributes and add new ones", function() {
App.Ticket.resetAttributes();
var attributesBefore = _.clone(App.Ticket.configure_attributes);
var updateAttribute = _.clone(attributesBefore[0]);
updateAttribute['new_option_1239393'] = 1;
App.Ticket.updateAttributes([
updateAttribute,
{
name: 'new_attribute_1010101',
display: 'New Attribute',
tag: 'input',
readonly: 1,
},
]);
var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes);
equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements')
equal(attributesAfterUpdate[attributesAfterUpdate.length - 1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element')
equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes got updated with the new option')
App.Ticket.resetAttributes();
var attributesAfterReset = _.clone(App.Ticket.configure_attributes);
equal(attributesAfterReset.length, attributesBefore.length, 'new attributes list has the same elements after reset')
equal(attributesAfterReset[0]['new_option_1239393'], undefined, 'first element of the new attributes has no attribute new_option_1239393')
});
}