Github PR #2934 - Fixes #2764 - Removing last condition or action in Trigger/Automatization/Postmaster breaks dialogues.
This commit is contained in:
parent
a976b9fb43
commit
95e5a46d4b
4 changed files with 104 additions and 14 deletions
|
@ -151,6 +151,7 @@ class App.UiElement.postmaster_match
|
|||
|
||||
# remove filter
|
||||
item.find('.js-remove').bind('click', (e) =>
|
||||
return if $(e.currentTarget).hasClass('is-disabled')
|
||||
$(e.target).closest('.js-filterElement').remove()
|
||||
@rebuildAttributeSelectors(item)
|
||||
)
|
||||
|
|
|
@ -109,14 +109,16 @@ class App.UiElement.ticket_perform_action
|
|||
item.append(element)
|
||||
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, {}, attribute)
|
||||
|
||||
return item
|
||||
else
|
||||
|
||||
for groupAndAttribute, meta of params[attribute.name]
|
||||
for groupAndAttribute, meta of params[attribute.name]
|
||||
|
||||
# build and append
|
||||
element = @placeholder(item, attribute, params, groups, elements)
|
||||
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, meta, attribute)
|
||||
item.append(element)
|
||||
# build and append
|
||||
element = @placeholder(item, attribute, params, groups, elements)
|
||||
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, meta, attribute)
|
||||
item.append(element)
|
||||
|
||||
@disableRemoveForOneAttribute(item)
|
||||
item
|
||||
|
||||
@buildAttributeSelector: (elementFull, groups, elements) ->
|
||||
|
@ -145,6 +147,13 @@ class App.UiElement.ticket_perform_action
|
|||
optgroup.append("<option value=\"#{elementKey}\" #{selected}>#{displayName}</option>")
|
||||
selection
|
||||
|
||||
# disable - if we only have one attribute
|
||||
@disableRemoveForOneAttribute: (elementFull) ->
|
||||
if elementFull.find('.js-attributeSelector select').length > 1
|
||||
elementFull.find('.js-remove').removeClass('is-disabled')
|
||||
else
|
||||
elementFull.find('.js-remove').addClass('is-disabled')
|
||||
|
||||
@updateAttributeSelectors: (elementFull) ->
|
||||
|
||||
# enable all
|
||||
|
@ -157,10 +166,7 @@ class App.UiElement.ticket_perform_action
|
|||
)
|
||||
|
||||
# disable - if we only have one attribute
|
||||
if elementFull.find('.js-attributeSelector select').length > 1
|
||||
elementFull.find('.js-remove').removeClass('is-disabled')
|
||||
else
|
||||
elementFull.find('.js-remove').addClass('is-disabled')
|
||||
@disableRemoveForOneAttribute(elementFull)
|
||||
|
||||
@rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@ class App.UiElement.ticket_selector
|
|||
triggerSearch()
|
||||
)
|
||||
|
||||
@disableRemoveForOneAttribute(item)
|
||||
item
|
||||
|
||||
@preview: (item) ->
|
||||
|
@ -240,6 +241,13 @@ class App.UiElement.ticket_selector
|
|||
optgroup.append("<option value=\"#{elementKey}\">#{displayName}</option>")
|
||||
selection
|
||||
|
||||
# disable - if we only have one attribute
|
||||
@disableRemoveForOneAttribute: (elementFull) ->
|
||||
if elementFull.find('.js-attributeSelector select').length > 1
|
||||
elementFull.find('.js-remove').removeClass('is-disabled')
|
||||
else
|
||||
elementFull.find('.js-remove').addClass('is-disabled')
|
||||
|
||||
@updateAttributeSelectors: (elementFull) ->
|
||||
|
||||
# enable all
|
||||
|
@ -252,10 +260,7 @@ class App.UiElement.ticket_selector
|
|||
)
|
||||
|
||||
# disable - if we only have one attribute
|
||||
if elementFull.find('.js-attributeSelector select').length > 1
|
||||
elementFull.find('.js-remove').removeClass('is-disabled')
|
||||
else
|
||||
elementFull.find('.js-remove').addClass('is-disabled')
|
||||
@disableRemoveForOneAttribute(elementFull)
|
||||
|
||||
|
||||
@rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
||||
|
|
|
@ -285,3 +285,81 @@ test( "ticket_perform_action backwards check after issue #2782", function() {
|
|||
|
||||
deepEqual(params, test_params, 'form param check')
|
||||
});
|
||||
|
||||
test( "ticket_perform_action rows manipulation", function() {
|
||||
App.TicketPriority.refresh([
|
||||
{
|
||||
id: 2,
|
||||
name: '2 normal',
|
||||
active: false,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
name: '1 low',
|
||||
active: true,
|
||||
},
|
||||
])
|
||||
|
||||
App.TicketState.refresh([
|
||||
{
|
||||
id: 1,
|
||||
name: 'new',
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'open',
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'closed',
|
||||
active: false,
|
||||
},
|
||||
])
|
||||
|
||||
$('#forms').append('<hr><h1>ticket_perform_action rows manipulation</h1><form id="form99"></form>')
|
||||
var el = $('#form99')
|
||||
var defaults = {
|
||||
ticket_perform_action1: {
|
||||
'ticket.state_id': {
|
||||
value: '2'
|
||||
}
|
||||
}
|
||||
}
|
||||
new App.ControllerForm({
|
||||
el: el,
|
||||
model: {
|
||||
configure_attributes: [
|
||||
{
|
||||
name: 'ticket_perform_action99',
|
||||
display: 'TicketPerformAction99',
|
||||
tag: 'ticket_perform_action',
|
||||
null: true,
|
||||
},
|
||||
]
|
||||
},
|
||||
params: defaults,
|
||||
autofocus: true
|
||||
})
|
||||
|
||||
equal(true, true)
|
||||
|
||||
var selector = '[data-attribute-name="ticket_perform_action99"] '
|
||||
|
||||
$(selector + '.js-remove').click()
|
||||
|
||||
equal($(selector + '.js-filterElement').length, 1, 'prevents removing single initial row')
|
||||
|
||||
$(selector + '.js-add').click()
|
||||
|
||||
equal($(selector + '.js-filterElement').length, 2, 'adds 2nd row')
|
||||
|
||||
$(selector + ' .js-remove:last').click()
|
||||
|
||||
equal($(selector + '.js-filterElement').length, 1, 'removes 2nd row')
|
||||
|
||||
$(selector + '.js-remove:last').click()
|
||||
|
||||
equal($(selector + ' .js-filterElement').length, 1, 'prevents removing last row')
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue