Github PR #2934 - Fixes #2764 - Removing last condition or action in Trigger/Automatization/Postmaster breaks dialogues.

This commit is contained in:
Mantas Masalskis 2020-02-19 09:56:55 +01:00 committed by Thorsten Eckel
parent a976b9fb43
commit 95e5a46d4b
4 changed files with 104 additions and 14 deletions

View file

@ -151,6 +151,7 @@ class App.UiElement.postmaster_match
# remove filter # remove filter
item.find('.js-remove').bind('click', (e) => item.find('.js-remove').bind('click', (e) =>
return if $(e.currentTarget).hasClass('is-disabled')
$(e.target).closest('.js-filterElement').remove() $(e.target).closest('.js-filterElement').remove()
@rebuildAttributeSelectors(item) @rebuildAttributeSelectors(item)
) )

View file

@ -109,7 +109,7 @@ class App.UiElement.ticket_perform_action
item.append(element) item.append(element)
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, {}, attribute) @rebuildAttributeSelectors(item, element, groupAndAttribute, elements, {}, attribute)
return item else
for groupAndAttribute, meta of params[attribute.name] for groupAndAttribute, meta of params[attribute.name]
@ -117,6 +117,8 @@ class App.UiElement.ticket_perform_action
element = @placeholder(item, attribute, params, groups, elements) element = @placeholder(item, attribute, params, groups, elements)
@rebuildAttributeSelectors(item, element, groupAndAttribute, elements, meta, attribute) @rebuildAttributeSelectors(item, element, groupAndAttribute, elements, meta, attribute)
item.append(element) item.append(element)
@disableRemoveForOneAttribute(item)
item item
@buildAttributeSelector: (elementFull, groups, elements) -> @buildAttributeSelector: (elementFull, groups, elements) ->
@ -145,6 +147,13 @@ class App.UiElement.ticket_perform_action
optgroup.append("<option value=\"#{elementKey}\" #{selected}>#{displayName}</option>") optgroup.append("<option value=\"#{elementKey}\" #{selected}>#{displayName}</option>")
selection 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) -> @updateAttributeSelectors: (elementFull) ->
# enable all # enable all
@ -157,10 +166,7 @@ class App.UiElement.ticket_perform_action
) )
# disable - if we only have one attribute # disable - if we only have one attribute
if elementFull.find('.js-attributeSelector select').length > 1 @disableRemoveForOneAttribute(elementFull)
elementFull.find('.js-remove').removeClass('is-disabled')
else
elementFull.find('.js-remove').addClass('is-disabled')
@rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) -> @rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->

View file

@ -200,6 +200,7 @@ class App.UiElement.ticket_selector
triggerSearch() triggerSearch()
) )
@disableRemoveForOneAttribute(item)
item item
@preview: (item) -> @preview: (item) ->
@ -240,6 +241,13 @@ class App.UiElement.ticket_selector
optgroup.append("<option value=\"#{elementKey}\">#{displayName}</option>") optgroup.append("<option value=\"#{elementKey}\">#{displayName}</option>")
selection 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) -> @updateAttributeSelectors: (elementFull) ->
# enable all # enable all
@ -252,10 +260,7 @@ class App.UiElement.ticket_selector
) )
# disable - if we only have one attribute # disable - if we only have one attribute
if elementFull.find('.js-attributeSelector select').length > 1 @disableRemoveForOneAttribute(elementFull)
elementFull.find('.js-remove').removeClass('is-disabled')
else
elementFull.find('.js-remove').addClass('is-disabled')
@rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) -> @rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->

View file

@ -285,3 +285,81 @@ test( "ticket_perform_action backwards check after issue #2782", function() {
deepEqual(params, test_params, 'form param check') 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')
});