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.

This commit is contained in:
Martin Edenhofer 2018-07-20 10:31:03 +02:00
parent c61dd3eab4
commit 45ed1b3638
6 changed files with 78 additions and 87 deletions

View file

@ -556,6 +556,10 @@ class App.Controller extends Spine.Controller
stopPropagation: (e) -> stopPropagation: (e) ->
e.stopPropagation() e.stopPropagation()
preventDefaultAndstopPropagation: (e) ->
e.preventDefault()
e.stopPropagation()
startLoading: (el) => startLoading: (el) =>
return if @initLoadingDone && !el return if @initLoadingDone && !el
@initLoadingDone = true @initLoadingDone = true

View file

@ -1,4 +1,6 @@
class App.TicketZoom extends App.Controller class App.TicketZoom extends App.Controller
@include App.TicketNavigable
elements: elements:
'.main': 'main' '.main': 'main'
'.ticketZoom': 'ticketZoom' '.ticketZoom': 'ticketZoom'
@ -763,8 +765,9 @@ class App.TicketZoom extends App.Controller
for key, value of ticketParams for key, value of ticketParams
ticket[key] = value ticket[key] = value
if macro.perform
App.Ticket.macro( App.Ticket.macro(
macro: macro macro: macro.perform
ticket: ticket ticket: ticket
callback: callback:
tagAdd: (tag) => tagAdd: (tag) =>
@ -823,23 +826,23 @@ class App.TicketZoom extends App.Controller
ticket.article = article ticket.article = article
if !ticket.article if !ticket.article
@submitPost(e, ticket) @submitPost(e, ticket, macro)
return return
# verify if time accounting is enabled # verify if time accounting is enabled
if @Config.get('time_accounting') isnt true if @Config.get('time_accounting') isnt true
@submitPost(e, ticket) @submitPost(e, ticket, macro)
return return
# verify if time accounting is active for ticket # verify if time accounting is active for ticket
time_accounting_selector = @Config.get('time_accounting_selector') time_accounting_selector = @Config.get('time_accounting_selector')
if !App.Ticket.selector(ticket, time_accounting_selector['condition']) if !App.Ticket.selector(ticket, time_accounting_selector['condition'])
@submitPost(e, ticket) @submitPost(e, ticket, macro)
return return
# time tracking # time tracking
if @permissionCheck('ticket.customer') if @permissionCheck('ticket.customer')
@submitPost(e, ticket) @submitPost(e, ticket, macro)
return return
new App.TicketZoomTimeAccounting( new App.TicketZoomTimeAccounting(
@ -850,13 +853,15 @@ class App.TicketZoom extends App.Controller
submitCallback: (params) => submitCallback: (params) =>
if params.time_unit if params.time_unit
ticket.article.time_unit = 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') taskAction = @$('.js-secondaryActionButtonLabel').data('type')
if macro && macro.ux_flow_next_up
taskAction = macro.ux_flow_next_up
# submit changes # submit changes
@ajax( @ajax(
id: "ticket_update_#{ticket.id}" id: "ticket_update_#{ticket.id}"
@ -878,53 +883,27 @@ class App.TicketZoom extends App.Controller
if @sidebarWidget if @sidebarWidget
@sidebarWidget.commit() @sidebarWidget.commit()
if taskAction is 'closeNextInOverview' if taskAction is 'closeNextInOverview' || taskAction is 'next_from_overview'
if @overview_id App.Event.trigger('overview:fetch')
current_position = 0 @taskOpenNextTicketInOverview()
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)
# 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 return
# fallback, close task if taskAction is 'closeTab' || taskAction is 'next_task'
taskAction = 'closeTab' App.Event.trigger('overview:fetch')
@taskCloseTicket(true)
if taskAction is 'closeTab'
App.TaskManager.remove(@taskKey)
nextTaskUrl = App.TaskManager.nextTaskUrl()
if nextTaskUrl
@navigate nextTaskUrl
return
@navigate '#'
return return
@autosaveStart() @autosaveStart()
@muteTask() @muteTask()
@formEnable(e) @formEnable(e)
App.Event.trigger('overview:fetch')
error: (settings, details) => error: (settings, details) =>
error = undefined
if settings && settings.responseJSON && settings.responseJSON.error
error = settings.responseJSON.error
App.Event.trigger 'notify', { App.Event.trigger 'notify', {
type: 'error' 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 timeout: 2000
} }
@autosaveStart() @autosaveStart()

View file

@ -1,13 +1,11 @@
class App.TicketZoomAttributeBar extends App.Controller class App.TicketZoomAttributeBar extends App.Controller
@include App.TicketNavigable
elements: elements:
'.js-submitDropdown': 'buttonDropdown' '.js-submitDropdown': 'buttonDropdown'
'.js-reset': 'resetButton' '.js-reset': 'resetButton'
events: events:
'mousedown .js-openDropdownMacro': 'toggleMacroMenu' 'mousedown .js-openDropdownMacro': 'toggleMacroMenu'
'click .js-openDropdownMacro': 'stopPropagation' 'click .js-openDropdownMacro': 'preventDefaultAndstopPropagation'
'mouseup .js-dropdownActionMacro': 'performTicketMacro' 'mouseup .js-dropdownActionMacro': 'performTicketMacro'
'mouseenter .js-dropdownActionMacro': 'onActionMacroMouseEnter' 'mouseenter .js-dropdownActionMacro': 'onActionMacroMouseEnter'
'mouseleave .js-dropdownActionMacro': 'onActionMacroMouseLeave' 'mouseleave .js-dropdownActionMacro': 'onActionMacroMouseLeave'
@ -72,7 +70,10 @@ class App.TicketZoomAttributeBar extends App.Controller
@render() @render()
toggleMacroMenu: => toggleMacroMenu: =>
if @buttonDropdown.hasClass('is-open') then @closeMacroMenu() else @openMacroMenu() if @buttonDropdown.hasClass('is-open')
@closeMacroMenu()
return
@openMacroMenu()
openMacroMenu: => openMacroMenu: =>
@buttonDropdown.addClass 'is-open' @buttonDropdown.addClass 'is-open'
@ -86,19 +87,8 @@ class App.TicketZoomAttributeBar extends App.Controller
macroId = $(e.currentTarget).data('id') macroId = $(e.currentTarget).data('id')
macro = App.Macro.find(macroId) macro = App.Macro.find(macroId)
@callback(e, macro.perform) @callback(e, macro)
@closeMacroMenu() @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) => onActionMacroMouseEnter: (e) =>
@$(e.currentTarget).addClass('is-active') @$(e.currentTarget).addClass('is-active')

View file

@ -70,4 +70,4 @@ class App.TicketZoomOverviewNavigator extends App.Controller
else else
return return
@openTicket(id, url) @taskOpenTicket(id, url)

View file

@ -5,23 +5,39 @@
# #
# Relies on @overview_id and @ticket_id instance variables # Relies on @overview_id and @ticket_id instance variables
App.TicketNavigable = App.TicketNavigable =
openTicket: (ticket_id, url) -> taskOpenTicket: (ticket_id, url) ->
# coerce Ticket objects to id # coerce Ticket objects to id
ticket_id = ticket_id.id if (ticket_id instanceof App.Ticket) ticket_id = ticket_id.id if (ticket_id instanceof App.Ticket)
@taskLoadTicket(ticket_id)
@loadTicketTask(ticket_id) @navigate(url ? "ticket/zoom/#{ticket_id}")
@navigate url ? "ticket/zoom/#{ticket_id}"
# preserves overview information # preserves overview information
loadTicketTask: (ticket_id) -> taskLoadTicket: (ticket_id) ->
App.TaskManager.execute( App.TaskManager.execute(
key: "Ticket-#{ticket_id}" key: "Ticket-#{ticket_id}"
controller: 'TicketZoom' controller: 'TicketZoom'
params: { ticket_id: ticket_id, overview_id: @overview_id } params:
ticket_id: ticket_id
overview_id: @overview_id
show: true show: true
) )
openNextTicketInOverview: -> taskOpenNextTicketInOverview: ->
return if !(@overview_id? && @ticket?) if !(@overview_id? && @ticket?)
@taskCloseTicket(true)
return
next_ticket = App.Overview.find(@overview_id).nextTicket(@ticket) 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 '#'

View file

@ -24,12 +24,13 @@
</span> </span>
</ul> </ul>
</div> </div>
<form class="buttonDropdown">
<% if @macroDisabled: %> <% if @macroDisabled: %>
<div class="btn btn--primary js-submit"><%- @T('Update') %></div> <button class="btn btn--primary js-submit"><%- @T('Update') %></button>
<% else: %> <% else: %>
<div class="buttonDropdown dropdown dropup js-submitDropdown"> <div class="buttonDropdown dropdown dropup js-submitDropdown">
<div class="btn btn--primary btn--split--first js-submit"><%- @T('Update') %></div> <button class="btn btn--primary btn--split--first js-submit"><%- @T('Update') %></button>
<div class="btn btn--primary btn--slim btn--split--last js-openDropdownMacro"><%- @Icon('arrow-up') %></div> <button class="btn btn--primary btn--slim btn--split--last js-openDropdownMacro"><%- @Icon('arrow-up') %></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="userAction"> <ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="userAction">
<% for macro in @macros: %> <% for macro in @macros: %>
<li class="js-dropdownActionMacro" role="menuitem" data-id="<%= macro.id %>"><%- @T(macro.displayName()) %> <li class="js-dropdownActionMacro" role="menuitem" data-id="<%= macro.id %>"><%- @T(macro.displayName()) %>
@ -37,3 +38,4 @@
</ul> </ul>
</div> </div>
<% end %> <% end %>
</form>