Added model instance method to check if record is already stored online.

This commit is contained in:
Martin Edenhofer 2013-06-22 22:59:31 +02:00
parent 35e12c58a5
commit 0dad3bbcf3
2 changed files with 13 additions and 6 deletions

View file

@ -137,7 +137,7 @@ class _taskManagerSingleton extends App.Controller
if task.key isnt key if task.key isnt key
if task.active if task.active
task.active = false task.active = false
if !task.isNew() if task.isOnline()
task.save() task.save()
else else
changed = false changed = false
@ -148,14 +148,14 @@ class _taskManagerSingleton extends App.Controller
changed = true changed = true
task.notify = false task.notify = false
if changed if changed
if !task.isNew() if task.isOnline()
task.save() task.save()
else else
for task in tasks for task in tasks
if @activeTask isnt task.key if @activeTask isnt task.key
if task.active if task.active
task.active = false task.active = false
if !task.isNew() if task.isOnline()
task.save() task.save()
# start worker for task if not exists # start worker for task if not exists
@ -211,7 +211,9 @@ class _taskManagerSingleton extends App.Controller
task = @get( key ) task = @get( key )
if !task if !task
throw "No such task with '#{key}' to update" throw "No such task with '#{key}' to update"
return if task.isNew() @log 'notice', task.isOnline()
@log 'notice', task, task.id, task.isOnline()
return if !task.isOnline()
for item, value of params for item, value of params
task.updateAttribute(item, value) task.updateAttribute(item, value)
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
@ -233,7 +235,7 @@ class _taskManagerSingleton extends App.Controller
if !task if !task
throw "No such task with '#{key}' to notify" throw "No such task with '#{key}' to notify"
task.notify = true task.notify = true
if !task.isNew() if task.isOnline()
task.save() task.save()
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
@ -246,7 +248,7 @@ class _taskManagerSingleton extends App.Controller
prio++ prio++
if task.prio isnt prio if task.prio isnt prio
task.prio = prio task.prio = prio
if !task.isNew() if task.isOnline()
task.save() task.save()
reset: => reset: =>

View file

@ -82,3 +82,8 @@ class App.Model extends Spine.Model
params: @, params: @,
) )
isOnline: ->
return false if !@id
return true if typeof @id is 'number' # in case of real database id
return true if @id[0] isnt 'c'
return false