Improved autosave.

This commit is contained in:
Martin Edenhofer 2016-06-03 21:00:52 +02:00
parent 536cc11ba1
commit 356e169355
2 changed files with 16 additions and 9 deletions

View file

@ -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)

View file

@ -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')