Improved autosave.
This commit is contained in:
parent
536cc11ba1
commit
356e169355
2 changed files with 16 additions and 9 deletions
|
@ -120,6 +120,10 @@ class App.TicketCreate extends App.Controller
|
||||||
|
|
||||||
show: =>
|
show: =>
|
||||||
@navupdate "#ticket/create/id/#{@id}#{@split}", type: 'menu'
|
@navupdate "#ticket/create/id/#{@id}#{@split}", type: 'menu'
|
||||||
|
@autosaveStart()
|
||||||
|
|
||||||
|
hide: =>
|
||||||
|
@autosaveStop()
|
||||||
|
|
||||||
changed: =>
|
changed: =>
|
||||||
formCurrent = @formParam( @$('.ticket-create') )
|
formCurrent = @formParam( @$('.ticket-create') )
|
||||||
|
@ -127,19 +131,25 @@ class App.TicketCreate extends App.Controller
|
||||||
return false if !diff || _.isEmpty(diff)
|
return false if !diff || _.isEmpty(diff)
|
||||||
return true
|
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 = =>
|
update = =>
|
||||||
data = @formParam(@$('.ticket-create'))
|
data = @formParam(@$('.ticket-create'))
|
||||||
|
return if _.isEmpty(data)
|
||||||
diff = difference(@autosaveLast, data)
|
diff = difference(@autosaveLast, data)
|
||||||
if !@autosaveLast || (diff && !_.isEmpty(diff))
|
if _.isEmpty(@autosaveLast) || !_.isEmpty(diff)
|
||||||
@autosaveLast = data
|
@autosaveLast = data
|
||||||
@log 'debug', 'form hash changed', diff, data
|
@log 'debug', 'form hash changed', diff, data
|
||||||
App.TaskManager.update(@task_key, { 'state': data })
|
App.TaskManager.update(@task_key, { 'state': data })
|
||||||
|
|
||||||
# check it task title in task need to be updated
|
# check it task title in task need to be updated
|
||||||
title = @$('[name=title]').val()
|
if @latestTitle isnt data.title
|
||||||
if @latestTitle isnt title
|
@latestTitle = data.title
|
||||||
@latestTitle = title
|
|
||||||
App.TaskManager.touch(@task_key)
|
App.TaskManager.touch(@task_key)
|
||||||
|
|
||||||
@el.on('change.local blur.local keyup.local paste.local input.local', 'form, .js-textarea', (e) =>
|
@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()
|
$('#tags').tokenfield()
|
||||||
|
|
||||||
# start auto save
|
|
||||||
@autosave()
|
|
||||||
|
|
||||||
# update taskbar with new meta data
|
# update taskbar with new meta data
|
||||||
App.TaskManager.touch(@task_key)
|
App.TaskManager.touch(@task_key)
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,6 @@ class App.TicketZoom extends App.Controller
|
||||||
@positionPageHeaderStop()
|
@positionPageHeaderStop()
|
||||||
|
|
||||||
# stop autosave
|
# stop autosave
|
||||||
@clearDelay("ticket-zoom-auto-save-#{@ticket_id}")
|
|
||||||
@autosaveStop()
|
@autosaveStop()
|
||||||
|
|
||||||
changed: =>
|
changed: =>
|
||||||
|
@ -404,6 +403,7 @@ class App.TicketZoom extends App.Controller
|
||||||
@main.scrollTop( @main.prop('scrollHeight') )
|
@main.scrollTop( @main.prop('scrollHeight') )
|
||||||
|
|
||||||
autosaveStop: =>
|
autosaveStop: =>
|
||||||
|
@clearDelay('ticket-zoom-form-update')
|
||||||
@autosaveLast = {}
|
@autosaveLast = {}
|
||||||
@el.off('change.local blur.local keyup.local paste.local input.local')
|
@el.off('change.local blur.local keyup.local paste.local input.local')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue