From 45ed1b36383b9ed7d25919a80e71553e9425e57b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 20 Jul 2018 10:31:03 +0200 Subject: [PATCH] Follow up for issue #641 - make macro working also on slower network connections (close tab if macro is executed sucessfully). And disable update button until macro is executed. --- .../_application_controller.coffee | 4 + .../app/controllers/ticket_zoom.coffee | 93 +++++++------------ .../ticket_zoom/attribute_bar.coffee | 22 ++--- .../ticket_zoom/overview_navigator.coffee | 2 +- .../app/lib/mixins/ticket_navigable.coffee | 34 +++++-- .../views/ticket_zoom/attribute_bar.jst.eco | 10 +- 6 files changed, 78 insertions(+), 87 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index 56f4a520a..134919206 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -556,6 +556,10 @@ class App.Controller extends Spine.Controller stopPropagation: (e) -> e.stopPropagation() + preventDefaultAndstopPropagation: (e) -> + e.preventDefault() + e.stopPropagation() + startLoading: (el) => return if @initLoadingDone && !el @initLoadingDone = true diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 94643c3d0..7683aee44 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -1,4 +1,6 @@ class App.TicketZoom extends App.Controller + @include App.TicketNavigable + elements: '.main': 'main' '.ticketZoom': 'ticketZoom' @@ -763,19 +765,20 @@ class App.TicketZoom extends App.Controller for key, value of ticketParams ticket[key] = value - App.Ticket.macro( - macro: macro - ticket: ticket - callback: - tagAdd: (tag) => - return if !@sidebarWidget - return if !@sidebarWidget.reload - @sidebarWidget.reload(tagAdd: tag, source: 'macro') - tagRemove: (tag) => - return if !@sidebarWidget - return if !@sidebarWidget.reload - @sidebarWidget.reload(tagRemove: tag) - ) + if macro.perform + App.Ticket.macro( + macro: macro.perform + ticket: ticket + callback: + tagAdd: (tag) => + return if !@sidebarWidget + return if !@sidebarWidget.reload + @sidebarWidget.reload(tagAdd: tag, source: 'macro') + tagRemove: (tag) => + return if !@sidebarWidget + return if !@sidebarWidget.reload + @sidebarWidget.reload(tagRemove: tag) + ) # set defaults if !@permissionCheck('ticket.customer') @@ -823,23 +826,23 @@ class App.TicketZoom extends App.Controller ticket.article = article if !ticket.article - @submitPost(e, ticket) + @submitPost(e, ticket, macro) return # verify if time accounting is enabled if @Config.get('time_accounting') isnt true - @submitPost(e, ticket) + @submitPost(e, ticket, macro) return # verify if time accounting is active for ticket time_accounting_selector = @Config.get('time_accounting_selector') if !App.Ticket.selector(ticket, time_accounting_selector['condition']) - @submitPost(e, ticket) + @submitPost(e, ticket, macro) return # time tracking if @permissionCheck('ticket.customer') - @submitPost(e, ticket) + @submitPost(e, ticket, macro) return new App.TicketZoomTimeAccounting( @@ -850,13 +853,15 @@ class App.TicketZoom extends App.Controller submitCallback: (params) => if params.time_unit ticket.article.time_unit = params.time_unit - @submitPost(e, ticket) + @submitPost(e, ticket, macro) ) - submitPost: (e, ticket) => - + submitPost: (e, ticket, macro) => taskAction = @$('.js-secondaryActionButtonLabel').data('type') + if macro && macro.ux_flow_next_up + taskAction = macro.ux_flow_next_up + # submit changes @ajax( id: "ticket_update_#{ticket.id}" @@ -878,53 +883,27 @@ class App.TicketZoom extends App.Controller if @sidebarWidget @sidebarWidget.commit() - if taskAction is 'closeNextInOverview' - if @overview_id - current_position = 0 - overview = App.Overview.find(@overview_id) - list = App.OverviewListCollection.get(overview.link) - for ticket in list.tickets - current_position += 1 - if ticket.id is @ticket_id - next = list.tickets[current_position] - if next - # close task - App.TaskManager.remove(@taskKey) + if taskAction is 'closeNextInOverview' || taskAction is 'next_from_overview' + App.Event.trigger('overview:fetch') + @taskOpenNextTicketInOverview() + return - # open task via task manager to get overview information - App.TaskManager.execute( - key: 'Ticket-' + next.id - controller: 'TicketZoom' - params: - ticket_id: next.id - overview_id: @overview_id - show: true - ) - @navigate "ticket/zoom/#{next.id}" - return - - # fallback, close task - taskAction = 'closeTab' - - if taskAction is 'closeTab' - App.TaskManager.remove(@taskKey) - nextTaskUrl = App.TaskManager.nextTaskUrl() - if nextTaskUrl - @navigate nextTaskUrl - return - - @navigate '#' + if taskAction is 'closeTab' || taskAction is 'next_task' + App.Event.trigger('overview:fetch') + @taskCloseTicket(true) return @autosaveStart() @muteTask() @formEnable(e) - App.Event.trigger('overview:fetch') error: (settings, details) => + error = undefined + if settings && settings.responseJSON && settings.responseJSON.error + error = settings.responseJSON.error App.Event.trigger 'notify', { type: 'error' - msg: App.i18n.translateContent(details.error_human || details.error || settings.responseJSON.error || 'Unable to update!') + msg: App.i18n.translateContent(details.error_human || details.error || error || 'Unable to update!') timeout: 2000 } @autosaveStart() diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee index c147c47bf..79e9a79a3 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee @@ -1,13 +1,11 @@ class App.TicketZoomAttributeBar extends App.Controller - @include App.TicketNavigable - elements: '.js-submitDropdown': 'buttonDropdown' '.js-reset': 'resetButton' events: 'mousedown .js-openDropdownMacro': 'toggleMacroMenu' - 'click .js-openDropdownMacro': 'stopPropagation' + 'click .js-openDropdownMacro': 'preventDefaultAndstopPropagation' 'mouseup .js-dropdownActionMacro': 'performTicketMacro' 'mouseenter .js-dropdownActionMacro': 'onActionMacroMouseEnter' 'mouseleave .js-dropdownActionMacro': 'onActionMacroMouseLeave' @@ -72,7 +70,10 @@ class App.TicketZoomAttributeBar extends App.Controller @render() toggleMacroMenu: => - if @buttonDropdown.hasClass('is-open') then @closeMacroMenu() else @openMacroMenu() + if @buttonDropdown.hasClass('is-open') + @closeMacroMenu() + return + @openMacroMenu() openMacroMenu: => @buttonDropdown.addClass 'is-open' @@ -86,19 +87,8 @@ class App.TicketZoomAttributeBar extends App.Controller macroId = $(e.currentTarget).data('id') macro = App.Macro.find(macroId) - @callback(e, macro.perform) + @callback(e, macro) @closeMacroMenu() - @replaceTabWith(macro.ux_flow_next_up) - - replaceTabWith: (dest) => - switch dest - when 'none' - return - when 'next_task' - @closeTab() - when 'next_from_overview' - @closeTab() - @openNextTicketInOverview() onActionMacroMouseEnter: (e) => @$(e.currentTarget).addClass('is-active') diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee index 094bb62b3..18615eb5b 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee @@ -70,4 +70,4 @@ class App.TicketZoomOverviewNavigator extends App.Controller else return - @openTicket(id, url) + @taskOpenTicket(id, url) diff --git a/app/assets/javascripts/app/lib/mixins/ticket_navigable.coffee b/app/assets/javascripts/app/lib/mixins/ticket_navigable.coffee index b44492345..2ccf55731 100644 --- a/app/assets/javascripts/app/lib/mixins/ticket_navigable.coffee +++ b/app/assets/javascripts/app/lib/mixins/ticket_navigable.coffee @@ -5,23 +5,39 @@ # # Relies on @overview_id and @ticket_id instance variables App.TicketNavigable = - openTicket: (ticket_id, url) -> + taskOpenTicket: (ticket_id, url) -> # coerce Ticket objects to id ticket_id = ticket_id.id if (ticket_id instanceof App.Ticket) - - @loadTicketTask(ticket_id) - @navigate url ? "ticket/zoom/#{ticket_id}" + @taskLoadTicket(ticket_id) + @navigate(url ? "ticket/zoom/#{ticket_id}") # preserves overview information - loadTicketTask: (ticket_id) -> + taskLoadTicket: (ticket_id) -> App.TaskManager.execute( key: "Ticket-#{ticket_id}" controller: 'TicketZoom' - params: { ticket_id: ticket_id, overview_id: @overview_id } + params: + ticket_id: ticket_id + overview_id: @overview_id show: true ) - openNextTicketInOverview: -> - return if !(@overview_id? && @ticket?) + taskOpenNextTicketInOverview: -> + if !(@overview_id? && @ticket?) + @taskCloseTicket(true) + return next_ticket = App.Overview.find(@overview_id).nextTicket(@ticket) - @openTicket(next_ticket.id) + if next_ticket + @taskCloseTicket() + @taskLoadTicket(next_ticket.id) + return + @taskCloseTicket(true) + + taskCloseTicket: (openNext = false) -> + App.TaskManager.remove(@taskKey) + return if !openNext + nextTaskUrl = App.TaskManager.nextTaskUrl() + if nextTaskUrl + @navigate nextTaskUrl + return + @navigate '#' diff --git a/app/assets/javascripts/app/views/ticket_zoom/attribute_bar.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/attribute_bar.jst.eco index c95c7d837..65bec635a 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/attribute_bar.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/attribute_bar.jst.eco @@ -24,16 +24,18 @@ +
<% if @macroDisabled: %> -
<%- @T('Update') %>
+ <% else: %> -<% end %> \ No newline at end of file +<% end %> +
\ No newline at end of file