Improved bind/unbind of controllers.
This commit is contained in:
parent
c5ed8776ce
commit
db224d5bc3
5 changed files with 29 additions and 16 deletions
|
@ -23,6 +23,12 @@ class App.TicketCreate extends App.Controller
|
||||||
if @ticket_id && @article_id
|
if @ticket_id && @article_id
|
||||||
@split = "/#{@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
|
# lisen if view need to be rerendered
|
||||||
@bind 'ticket_create_rerender', (defaults) =>
|
@bind 'ticket_create_rerender', (defaults) =>
|
||||||
@log 'notice', 'error', defaults
|
@log 'notice', 'error', defaults
|
||||||
|
@ -33,11 +39,8 @@ class App.TicketCreate extends App.Controller
|
||||||
return if !@authenticate(true)
|
return if !@authenticate(true)
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
load = (data) =>
|
release: =>
|
||||||
App.Collection.loadAssets(data.assets)
|
App.TicketCreateCollection.unbindById(@bindId)
|
||||||
@formMeta = data.form_meta
|
|
||||||
@buildScreen(params)
|
|
||||||
@bindId = App.TicketCreateCollection.one(load)
|
|
||||||
|
|
||||||
currentChannel: =>
|
currentChannel: =>
|
||||||
if !type
|
if !type
|
||||||
|
|
|
@ -126,8 +126,7 @@ class Navbar extends App.Controller
|
||||||
release: =>
|
release: =>
|
||||||
if @vertical
|
if @vertical
|
||||||
$(window).off 'resize.navbar', @autoFoldTabs
|
$(window).off 'resize.navbar', @autoFoldTabs
|
||||||
if @bindId
|
App.OverviewIndexCollection.unbindById(@bindId)
|
||||||
App.OverviewIndexCollection.unbind(@bindId)
|
|
||||||
|
|
||||||
autoFoldTabs: =>
|
autoFoldTabs: =>
|
||||||
items = App.OverviewIndexCollection.get()
|
items = App.OverviewIndexCollection.get()
|
||||||
|
|
|
@ -16,33 +16,38 @@ class App._CollectionSingletonBase
|
||||||
@set(data)
|
@set(data)
|
||||||
@callback(data)
|
@callback(data)
|
||||||
|
|
||||||
get: ->
|
get: =>
|
||||||
@collection_data
|
@collectionData
|
||||||
|
|
||||||
set: (data) ->
|
set: (data) =>
|
||||||
App.SessionStorage.set("collection-#{@event}", 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
|
@counter += 1
|
||||||
|
localCounter = @counter
|
||||||
|
|
||||||
# start init call if needed
|
# start init call if needed
|
||||||
if init
|
if init
|
||||||
if @collection_data is undefined
|
if @collectionData is undefined
|
||||||
@fetch()
|
@fetch()
|
||||||
else
|
else
|
||||||
callback(@collection_data)
|
callback(@collectionData)
|
||||||
return if one
|
return if one
|
||||||
|
|
||||||
@callbacks[@counter] =
|
@callbacks[localCounter] =
|
||||||
callback: callback
|
callback: callback
|
||||||
one: one
|
one: one
|
||||||
|
localCounter
|
||||||
|
|
||||||
unbind: (callback) ->
|
unbind: (callback) =>
|
||||||
for counter, attr of @callbacks
|
for counter, attr of @callbacks
|
||||||
if callback is attr.callback
|
if callback is attr.callback
|
||||||
delete @callbacks[counter]
|
delete @callbacks[counter]
|
||||||
|
|
||||||
|
unbindById: (counter) =>
|
||||||
|
delete @callbacks[counter]
|
||||||
|
|
||||||
fetch: =>
|
fetch: =>
|
||||||
if App.WebSocket.support()
|
if App.WebSocket.support()
|
||||||
App.WebSocket.send(event: @event)
|
App.WebSocket.send(event: @event)
|
||||||
|
|
|
@ -17,6 +17,9 @@ class App.OverviewIndexCollection
|
||||||
@unbind: (callback) ->
|
@unbind: (callback) ->
|
||||||
_instance.unbind(callback)
|
_instance.unbind(callback)
|
||||||
|
|
||||||
|
@unbindById: (id) ->
|
||||||
|
_instance.unbindById(id)
|
||||||
|
|
||||||
@trigger: ->
|
@trigger: ->
|
||||||
_instance.trigger()
|
_instance.trigger()
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ class App.TicketCreateCollection
|
||||||
@unbind: (callback) ->
|
@unbind: (callback) ->
|
||||||
_instance.unbind(callback)
|
_instance.unbind(callback)
|
||||||
|
|
||||||
|
@unbindById: (id) ->
|
||||||
|
_instance.unbindById(id)
|
||||||
|
|
||||||
@trigger: ->
|
@trigger: ->
|
||||||
_instance.trigger()
|
_instance.trigger()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue