diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index bd243964a..edc998281 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -361,7 +361,7 @@ class App.TicketCreate extends App.Controller e.preventDefault() @navigate '#' - submit: (e) -> + submit: (e) => e.preventDefault() # get params @@ -443,49 +443,48 @@ class App.TicketCreate extends App.Controller form: e.target errors: errors ) + return # save ticket, create article - else - - # check attachment - if article['body'] - if App.Utils.checkAttachmentReference(article['body']) - if @$('.richtext .attachments .attachment').length < 1 - if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) - return - - # disable form - @formDisable(e) - ui = @ - ticket.save( - done: -> - - # notify UI - ui.notify - type: 'success' - msg: App.i18n.translateInline('Ticket %s created!', @number) - link: "#ticket/zoom/#{@id}" - timeout: 4000 - - # close ticket create task - App.TaskManager.remove(ui.task_key) - - # scroll to top - ui.scrollTo() - - # access to group - group_ids = _.map(App.Session.get('group_ids'), (id) -> id.toString()) - if group_ids && _.contains(group_ids, @group_id.toString()) - ui.navigate "#ticket/zoom/#{@id}" + # check attachment + if article['body'] + if App.Utils.checkAttachmentReference(article['body']) + if @$('.richtext .attachments .attachment').length < 1 + if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) return - # if not, show start screen - ui.navigate '#' + # disable form + @formDisable(e) + ui = @ + ticket.save( + done: -> - fail: -> - ui.log 'save failed!' - ui.formEnable(e) - ) + # notify UI + ui.notify + type: 'success' + msg: App.i18n.translateInline('Ticket %s created!', @number) + link: "#ticket/zoom/#{@id}" + timeout: 4000 + + # close ticket create task + App.TaskManager.remove(ui.task_key) + + # scroll to top + ui.scrollTo() + + # access to group + group_ids = _.map(App.Session.get('group_ids'), (id) -> id.toString()) + if group_ids && _.contains(group_ids, @group_id.toString()) + ui.navigate "#ticket/zoom/#{@id}" + return + + # if not, show start screen + ui.navigate '#' + + fail: -> + ui.log 'save failed!' + ui.formEnable(e) + ) class Sidebar extends App.Controller constructor: -> diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index a8058dbee..85159f38b 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -29,14 +29,14 @@ class App.TicketZoom extends App.Controller else @overview_id = false - @key = 'ticket::' + @ticket_id + @key = "ticket::#{@ticket_id}" cache = App.SessionStorage.get(@key) if cache @load(cache) - update = => - @fetch(@ticket_id, false) # check if ticket has beed updated every 30 min + update = => + @fetch() @interval(update, 1800000, 'pull_check') # fetch new data if triggered @@ -48,29 +48,46 @@ class App.TicketZoom extends App.Controller # check if we already have the request queued #@log 'notice', 'TRY', @ticket_id, new Date(data.updated_at), new Date(@ticketUpdatedAtLastCall) update = => - @fetch(@ticket_id, false) + @fetch() if !@ticketUpdatedAtLastCall || ( new Date(data.updated_at).toString() isnt new Date(@ticketUpdatedAtLastCall).toString() ) - @delay(update, 500, "ticket-zoom-#{@ticket_id}") + @delay(update, 1200, "ticket-zoom-#{@ticket_id}") ) # rerender view, e. g. on langauge change @bind('ui:rerender', => - @fetch(@ticket_id, true) + @fetch(true) ) - fetch: (ticket_id, force) -> + fetchStart: (force) => + if !force && @fetchIsRunning + @fetchIsRunningAgain = true + return false + if force + @fetchIsRunningAgain = false + @fetchIsRunning = true + true + + fetchDone: => + @fetchIsRunning = false + if @fetchIsRunningAgain + @fetchIsRunningAgain = false + @fetch() + + fetch: (force) => return if !@Session.get() + return if !@fetchStart(force) # get data @ajax( - id: "ticket_zoom_#{ticket_id}" + id: "ticket_zoom_#{@ticket_id}" type: 'GET' - url: "#{@apiPath}/tickets/#{ticket_id}?all=true" + url: "#{@apiPath}/tickets/#{@ticket_id}?all=true" processData: true success: (data, status, xhr) => + @fetchDone() # check if ticket has changed - newTicketRaw = data.assets.Ticket[ticket_id] + newTicketRaw = data.assets.Ticket[@ticket_id] if @ticketUpdatedAtLastCall && !force # return if ticket hasnt changed @@ -88,10 +105,11 @@ class App.TicketZoom extends App.Controller if !@doNotLog @doNotLog = 1 - @recentView('Ticket', ticket_id) + @recentView('Ticket', @ticket_id) error: (xhr) => - @renderDone = false + @fetchDone() + statusText = xhr.statusText status = xhr.status detail = xhr.responseText @@ -99,6 +117,8 @@ class App.TicketZoom extends App.Controller # ignore if request is aborted return if statusText is 'abort' + @renderDone = false + # if ticket is already loaded, ignore status "0" - network issues e. g. temp. not connection if @ticketUpdatedAtLastCall && status is 0 console.log('network issues e. g. temp. not connection', status, statusText, detail) @@ -190,9 +210,6 @@ class App.TicketZoom extends App.Controller return @activeState = true - # start autosave - @autosaveStart() - # if ticket is shown the first time if !@shown @shown = true @@ -206,6 +223,9 @@ class App.TicketZoom extends App.Controller # observe content header position @positionPageHeaderStart() + # start autosave + @autosaveStart() + hide: => @activeState = false @@ -349,6 +369,8 @@ class App.TicketZoom extends App.Controller task_key: @task_key formMeta: @formMeta markForm: @markForm + tags: @tags + links: @links ) # render init content @@ -667,7 +689,7 @@ class App.TicketZoom extends App.Controller @autosaveStart() @muteTask() - @fetch(ticket.id, false) + @fetch() # enable form @formEnable(e) diff --git a/test/browser/taskbar_task_test.rb b/test/browser/taskbar_task_test.rb index 74e895303..32f8d1824 100644 --- a/test/browser/taskbar_task_test.rb +++ b/test/browser/taskbar_task_test.rb @@ -53,7 +53,7 @@ class TaskbarTaskTest < TestCase tasks_close_all() click(css: 'a[href="#new"]') - click(css: 'a[href="#ticket/create"]', wait: 2) + click(css: 'a[href="#ticket/create"]', wait: 0.8) set( css: '.active .newTicket input[name="title"]', value: 'INBOUND TEST#1', @@ -62,9 +62,10 @@ class TaskbarTaskTest < TestCase css: '.active .newTicket [data-name="body"]', value: 'INBOUND BODY TEST#1', ) + sleep 2 click(css: 'a[href="#new"]') - click(css: 'a[href="#ticket/create"]', wait: 2) + click(css: 'a[href="#ticket/create"]', wait: 0.8) set( css: '.active .newTicket input[name="title"]', value: 'OUTBOUND TEST#1', @@ -73,7 +74,7 @@ class TaskbarTaskTest < TestCase css: '.active .newTicket [data-name="body"]', value: 'OUTBOUND BODY TEST#1', ) - sleep 4 + sleep 2 logout() sleep 4