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:
'click .submit': 'update'
'click [data-type=reply]': 'reply'
@ -71,6 +71,10 @@ class TicketZoom extends App.Controller
@load(data)
App.Store.write( @key, data )
error: =>
App.TaskManager.remove( @task_key )
@release()
)
@doNotLog = 1
@ -593,7 +597,13 @@ class TicketZoomRouter extends App.ControllerPermanent
constructor: (params) ->
super
@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/nav/:nav', TicketZoomRouter, 'Routes' )

View file

@ -9,10 +9,10 @@ class App.TaskManager
_instance ?= new _Singleton
_instance.all()
@add: ( type, type_id, callback, params ) ->
@add: ( type, type_id, callback, params, to_not_show ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.add( type, type_id, callback, params )
_instance.add( type, type_id, callback, params, to_not_show )
@remove: ( key ) ->
if _instance == undefined
@ -31,12 +31,27 @@ class _Singleton extends Spine.Module
@tasks = {}
@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: ->
@tasks
add: ( type, type_id, callback, params ) ->
add: ( type, type_id, callback, params, to_not_show = false ) ->
for key, task of @tasks
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_permanent').hide()
$('#content_permanent_' + key ).show()
@ -47,26 +62,39 @@ class _Singleton extends Spine.Module
else
task.active = true
App.Event.trigger 'ui:rerender'
@syncTasks()
return key
@task_count++
for task_key, task of @tasks
task.active = false
if !to_not_show
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').hide()
$('#content_permanent_' + @task_count ).show()
params['el'] = $('#content_permanent_' + @task_count )
a = new callback( params )
if active
$('.content_permanent').hide()
$('#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 =
type: type
type_id: type_id
params: params
worker: a
active: true
type: type
type_id: type_id
params: params
callback: callback
worker: a
active: active
@tasks[@task_count] = task
App.Event.trigger 'ui:rerender'
@syncTasks()
@task_count
@ -75,8 +103,23 @@ class _Singleton extends Spine.Module
@tasks[key].worker.release()
delete @tasks[key]
App.Event.trigger 'ui:rerender'
@syncTasks()
reset: =>
@tasks = {}
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 )