diff --git a/app/assets/javascripts/app/controllers/_ui_element/postmaster_match.coffee b/app/assets/javascripts/app/controllers/_ui_element/postmaster_match.coffee index 99c052191..71196d269 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/postmaster_match.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/postmaster_match.coffee @@ -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) ) diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee index 999881ae5..01f263c46 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee @@ -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("") 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) -> diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee index e69c5fd89..a6ca32c52 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee @@ -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("") 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) -> diff --git a/public/assets/tests/form_ticket_perform_action.js b/public/assets/tests/form_ticket_perform_action.js index 3c8045e02..5983b5728 100644 --- a/public/assets/tests/form_ticket_perform_action.js +++ b/public/assets/tests/form_ticket_perform_action.js @@ -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('

ticket_perform_action rows manipulation

') + 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') +});