Improved task bar - use local storage now issue #57.

This commit is contained in:
Martin Edenhofer 2013-04-20 15:28:39 +02:00
parent ac8c88e67a
commit 8da2e5c557
2 changed files with 70 additions and 17 deletions

View file

@ -1,4 +1,4 @@
class TicketZoom extends App.Controller class App.TicketZoom extends App.Controller
events: events:
'click .submit': 'update' 'click .submit': 'update'
'click [data-type=reply]': 'reply' 'click [data-type=reply]': 'reply'
@ -71,6 +71,10 @@ class TicketZoom extends App.Controller
@load(data) @load(data)
App.Store.write( @key, data ) App.Store.write( @key, data )
error: =>
App.TaskManager.remove( @task_key )
@release()
) )
@doNotLog = 1 @doNotLog = 1
@ -593,7 +597,13 @@ class TicketZoomRouter extends App.ControllerPermanent
constructor: (params) -> constructor: (params) ->
super super
@log 'zoom router', params @log 'zoom router', params
App.TaskManager.add( 'Ticket', @ticket_id, TicketZoom, params ) # cleanup params
clean_params =
ticket_id: params.ticket_id
article_id: params.article_id
nav: params.nav
App.TaskManager.add( 'Ticket', @ticket_id, 'TicketZoom', clean_params )
App.Config.set( 'ticket/zoom/:ticket_id', TicketZoomRouter, 'Routes' ) App.Config.set( 'ticket/zoom/:ticket_id', TicketZoomRouter, 'Routes' )
App.Config.set( 'ticket/zoom/:ticket_id/nav/:nav', TicketZoomRouter, 'Routes' ) App.Config.set( 'ticket/zoom/:ticket_id/nav/:nav', TicketZoomRouter, 'Routes' )

View file

@ -9,10 +9,10 @@ class App.TaskManager
_instance ?= new _Singleton _instance ?= new _Singleton
_instance.all() _instance.all()
@add: ( type, type_id, callback, params ) -> @add: ( type, type_id, callback, params, to_not_show ) ->
if _instance == undefined if _instance == undefined
_instance ?= new _Singleton _instance ?= new _Singleton
_instance.add( type, type_id, callback, params ) _instance.add( type, type_id, callback, params, to_not_show )
@remove: ( key ) -> @remove: ( key ) ->
if _instance == undefined if _instance == undefined
@ -31,12 +31,27 @@ class _Singleton extends Spine.Module
@tasks = {} @tasks = {}
@task_count = 0 @task_count = 0
# reopen tasks
cache = App.Store.get( 'tasks' )
if cache
task_count = 0
for task in cache
task_count += 1
setTimeout(
->
task = cache.shift()
App.TaskManager.add(task.type, task.type_id, task.callback, task.params, true)
task_count * 500
)
all: -> all: ->
@tasks @tasks
add: ( type, type_id, callback, params ) -> add: ( type, type_id, callback, params, to_not_show = false ) ->
for key, task of @tasks for key, task of @tasks
if task.type is type && task.type_id is type_id if task.type is type && task.type_id is type_id
console.log('STOP TASK, already exists', task)
return key if to_not_show
$('#content').empty() $('#content').empty()
$('.content_permanent').hide() $('.content_permanent').hide()
$('#content_permanent_' + key ).show() $('#content_permanent_' + key ).show()
@ -47,26 +62,39 @@ class _Singleton extends Spine.Module
else else
task.active = true task.active = true
App.Event.trigger 'ui:rerender' App.Event.trigger 'ui:rerender'
@syncTasks()
return key return key
@task_count++ @task_count++
for task_key, task of @tasks if !to_not_show
task.active = false for task_key, task of @tasks
task.active = false
active = true
if to_not_show
active = false
console.log('start...', type, type_id, callback, params, @task_count )
if active
$('#content').empty()
$('#content').empty()
$('#content_permanent').append('<div id="content_permanent_' + @task_count + '" class="content_permanent"></div>') $('#content_permanent').append('<div id="content_permanent_' + @task_count + '" class="content_permanent"></div>')
$('.content_permanent').hide()
$('#content_permanent_' + @task_count ).show() if active
params['el'] = $('#content_permanent_' + @task_count ) $('.content_permanent').hide()
a = new callback( params ) $('#content_permanent_' + @task_count ).show()
params_app = _.clone(params)
params_app['el'] = $('#content_permanent_' + @task_count )
params_app['task_key'] = @task_count
a = new App[callback]( params_app )
task = task =
type: type type: type
type_id: type_id type_id: type_id
params: params params: params
worker: a callback: callback
active: true worker: a
active: active
@tasks[@task_count] = task @tasks[@task_count] = task
App.Event.trigger 'ui:rerender' App.Event.trigger 'ui:rerender'
@syncTasks()
@task_count @task_count
@ -75,8 +103,23 @@ class _Singleton extends Spine.Module
@tasks[key].worker.release() @tasks[key].worker.release()
delete @tasks[key] delete @tasks[key]
App.Event.trigger 'ui:rerender' App.Event.trigger 'ui:rerender'
@syncTasks()
reset: => reset: =>
@tasks = {} @tasks = {}
App.Event.trigger 'ui:rerender' App.Event.trigger 'ui:rerender'
syncTasks: =>
store = []
for task_key, task of @tasks
item =
type: task.type
type_id: task.type_id
params: task.params
callback: task.callback
active: task.active
store.push item
console.log('to write', store)
App.Store.write( 'tasks', store )