Improved bind/unbind of controllers.

This commit is contained in:
Martin Edenhofer 2016-05-29 01:53:12 +02:00
parent c5ed8776ce
commit db224d5bc3
5 changed files with 29 additions and 16 deletions

View file

@ -23,6 +23,12 @@ class App.TicketCreate extends App.Controller
if @ticket_id && @article_id
@split = "/#{@ticket_id}/#{@article_id}"
load = (data) =>
App.Collection.loadAssets(data.assets)
@formMeta = data.form_meta
@buildScreen(params)
@bindId = App.TicketCreateCollection.one(load)
# lisen if view need to be rerendered
@bind 'ticket_create_rerender', (defaults) =>
@log 'notice', 'error', defaults
@ -33,11 +39,8 @@ class App.TicketCreate extends App.Controller
return if !@authenticate(true)
@render()
load = (data) =>
App.Collection.loadAssets(data.assets)
@formMeta = data.form_meta
@buildScreen(params)
@bindId = App.TicketCreateCollection.one(load)
release: =>
App.TicketCreateCollection.unbindById(@bindId)
currentChannel: =>
if !type

View file

@ -126,8 +126,7 @@ class Navbar extends App.Controller
release: =>
if @vertical
$(window).off 'resize.navbar', @autoFoldTabs
if @bindId
App.OverviewIndexCollection.unbind(@bindId)
App.OverviewIndexCollection.unbindById(@bindId)
autoFoldTabs: =>
items = App.OverviewIndexCollection.get()

View file

@ -16,33 +16,38 @@ class App._CollectionSingletonBase
@set(data)
@callback(data)
get: ->
@collection_data
get: =>
@collectionData
set: (data) ->
set: (data) =>
App.SessionStorage.set("collection-#{@event}", data)
@collection_data = data
@collectionData = data
bind: (callback, init = true, one = false) ->
bind: (callback, init = true, one = false) =>
@counter += 1
localCounter = @counter
# start init call if needed
if init
if @collection_data is undefined
if @collectionData is undefined
@fetch()
else
callback(@collection_data)
callback(@collectionData)
return if one
@callbacks[@counter] =
@callbacks[localCounter] =
callback: callback
one: one
localCounter
unbind: (callback) ->
unbind: (callback) =>
for counter, attr of @callbacks
if callback is attr.callback
delete @callbacks[counter]
unbindById: (counter) =>
delete @callbacks[counter]
fetch: =>
if App.WebSocket.support()
App.WebSocket.send(event: @event)

View file

@ -17,6 +17,9 @@ class App.OverviewIndexCollection
@unbind: (callback) ->
_instance.unbind(callback)
@unbindById: (id) ->
_instance.unbindById(id)
@trigger: ->
_instance.trigger()

View file

@ -17,6 +17,9 @@ class App.TicketCreateCollection
@unbind: (callback) ->
_instance.unbind(callback)
@unbindById: (id) ->
_instance.unbindById(id)
@trigger: ->
_instance.trigger()