From 356e169355a6538844cc152ca6f5ce14581b5005 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 3 Jun 2016 21:00:52 +0200 Subject: [PATCH] Improved autosave. --- .../controllers/agent_ticket_create.coffee | 23 ++++++++++++------- .../app/controllers/ticket_zoom.coffee | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index afc05b72f..bd243964a 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -120,6 +120,10 @@ class App.TicketCreate extends App.Controller show: => @navupdate "#ticket/create/id/#{@id}#{@split}", type: 'menu' + @autosaveStart() + + hide: => + @autosaveStop() changed: => formCurrent = @formParam( @$('.ticket-create') ) @@ -127,19 +131,25 @@ class App.TicketCreate extends App.Controller return false if !diff || _.isEmpty(diff) return true - autosave: => + autosaveStop: => + @clearDelay('ticket-create-form-update') + @el.off('change.local blur.local keyup.local paste.local input.local') + + autosaveStart: => + if !@autosaveLast + @autosaveLast = App.TaskManager.get(@task_key).state || {} update = => data = @formParam(@$('.ticket-create')) + return if _.isEmpty(data) diff = difference(@autosaveLast, data) - if !@autosaveLast || (diff && !_.isEmpty(diff)) + if _.isEmpty(@autosaveLast) || !_.isEmpty(diff) @autosaveLast = data @log 'debug', 'form hash changed', diff, data App.TaskManager.update(@task_key, { 'state': data }) # check it task title in task need to be updated - title = @$('[name=title]').val() - if @latestTitle isnt title - @latestTitle = title + if @latestTitle isnt data.title + @latestTitle = data.title App.TaskManager.touch(@task_key) @el.on('change.local blur.local keyup.local paste.local input.local', 'form, .js-textarea', (e) => @@ -334,9 +344,6 @@ class App.TicketCreate extends App.Controller $('#tags').tokenfield() - # start auto save - @autosave() - # update taskbar with new meta data App.TaskManager.touch(@task_key) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 313e88d81..57a4c4445 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -122,7 +122,6 @@ class App.TicketZoom extends App.Controller @positionPageHeaderStop() # stop autosave - @clearDelay("ticket-zoom-auto-save-#{@ticket_id}") @autosaveStop() changed: => @@ -404,6 +403,7 @@ class App.TicketZoom extends App.Controller @main.scrollTop( @main.prop('scrollHeight') ) autosaveStop: => + @clearDelay('ticket-zoom-form-update') @autosaveLast = {} @el.off('change.local blur.local keyup.local paste.local input.local')