Improved memory management, moved to findNative(). Use own event sub system.
This commit is contained in:
parent
c85ff7b775
commit
19d57cf21d
2 changed files with 49 additions and 35 deletions
|
@ -61,14 +61,14 @@ class App.Controller extends Spine.Controller
|
||||||
clearDelay: (delay_id) =>
|
clearDelay: (delay_id) =>
|
||||||
App.Delay.clear(delay_id, @controllerId)
|
App.Delay.clear(delay_id, @controllerId)
|
||||||
|
|
||||||
delay: (callback, timeout, delay_id) =>
|
delay: (callback, timeout, delay_id, queue = true) =>
|
||||||
App.Delay.set(callback, timeout, delay_id, @controllerId)
|
App.Delay.set(callback, timeout, delay_id, @controllerId, queue)
|
||||||
|
|
||||||
clearInterval: (interval_id) =>
|
clearInterval: (interval_id) =>
|
||||||
App.Interval.clear(interval_id, @controllerId)
|
App.Interval.clear(interval_id, @controllerId)
|
||||||
|
|
||||||
interval: (callback, interval, interval_id) =>
|
interval: (callback, interval, interval_id, queue = true) =>
|
||||||
App.Interval.set(callback, interval, interval_id, @controllerId)
|
App.Interval.set(callback, interval, interval_id, @controllerId, queue)
|
||||||
|
|
||||||
releaseController: =>
|
releaseController: =>
|
||||||
App.Event.unbindLevel(@controllerId)
|
App.Event.unbindLevel(@controllerId)
|
||||||
|
@ -226,9 +226,9 @@ class App.Controller extends Spine.Controller
|
||||||
false
|
false
|
||||||
|
|
||||||
permissionCheck: (key) ->
|
permissionCheck: (key) ->
|
||||||
user_id = App.Session.get('id')
|
userId = App.Session.get('id')
|
||||||
return false if !user_id
|
return false if !userId
|
||||||
user = App.User.find(user_id)
|
user = App.User.findNative(userId)
|
||||||
return false if !user
|
return false if !user
|
||||||
user.permission(key)
|
user.permission(key)
|
||||||
|
|
||||||
|
@ -282,9 +282,9 @@ class App.Controller extends Spine.Controller
|
||||||
if @permissionCheck('ticket.agent')
|
if @permissionCheck('ticket.agent')
|
||||||
@$('div.ticket-popover, span.ticket-popover').bind('click', (e) =>
|
@$('div.ticket-popover, span.ticket-popover').bind('click', (e) =>
|
||||||
id = $(e.target).data('id')
|
id = $(e.target).data('id')
|
||||||
if id
|
return if !id
|
||||||
ticket = App.Ticket.find(id)
|
ticket = App.Ticket.findNative(id)
|
||||||
@navigate ticket.uiUrl()
|
@navigate ticket.uiUrl()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ticketPopupsDestroy()
|
@ticketPopupsDestroy()
|
||||||
|
@ -299,12 +299,12 @@ class App.Controller extends Spine.Controller
|
||||||
delay: 100
|
delay: 100
|
||||||
placement: position
|
placement: position
|
||||||
title: ->
|
title: ->
|
||||||
ticket_id = $(@).data('id')
|
ticketId = $(@).data('id')
|
||||||
ticket = App.Ticket.fullLocal(ticket_id)
|
ticket = App.Ticket.find(ticketId)
|
||||||
App.Utils.htmlEscape(ticket.title)
|
App.Utils.htmlEscape(ticket.title)
|
||||||
content: ->
|
content: ->
|
||||||
ticket_id = $(@).data('id')
|
ticketId = $(@).data('id')
|
||||||
ticket = App.Ticket.fullLocal(ticket_id)
|
ticket = App.Ticket.fullLocal(ticketId)
|
||||||
html = App.view('popover/ticket')(
|
html = App.view('popover/ticket')(
|
||||||
ticket: ticket
|
ticket: ticket
|
||||||
)
|
)
|
||||||
|
@ -326,9 +326,9 @@ class App.Controller extends Spine.Controller
|
||||||
return if !@permissionCheck('ticket.agent')
|
return if !@permissionCheck('ticket.agent')
|
||||||
@$('div.user-popover, span.user-popover').bind('click', (e) =>
|
@$('div.user-popover, span.user-popover').bind('click', (e) =>
|
||||||
id = $(e.target).data('id')
|
id = $(e.target).data('id')
|
||||||
if id
|
return if !id
|
||||||
user = App.User.find(id)
|
user = App.User.findNative(id)
|
||||||
@navigate user.uiUrl()
|
@navigate user.uiUrl()
|
||||||
)
|
)
|
||||||
|
|
||||||
@userPopupsDestroy()
|
@userPopupsDestroy()
|
||||||
|
@ -342,12 +342,12 @@ class App.Controller extends Spine.Controller
|
||||||
delay: 100
|
delay: 100
|
||||||
placement: "auto #{position}"
|
placement: "auto #{position}"
|
||||||
title: ->
|
title: ->
|
||||||
user_id = $(@).data('id')
|
userId = $(@).data('id')
|
||||||
user = App.User.fullLocal(user_id)
|
user = App.User.find(userId)
|
||||||
App.Utils.htmlEscape(user.displayName())
|
App.Utils.htmlEscape(user.displayName())
|
||||||
content: ->
|
content: ->
|
||||||
user_id = $(@).data('id')
|
userId = $(@).data('id')
|
||||||
user = App.User.fullLocal(user_id)
|
user = App.User.fullLocal(userId)
|
||||||
|
|
||||||
# get display data
|
# get display data
|
||||||
userData = []
|
userData = []
|
||||||
|
@ -384,9 +384,9 @@ class App.Controller extends Spine.Controller
|
||||||
|
|
||||||
@$('div.organization-popover, span.organization-popover').bind('click', (e) =>
|
@$('div.organization-popover, span.organization-popover').bind('click', (e) =>
|
||||||
id = $(e.target).data('id')
|
id = $(e.target).data('id')
|
||||||
if id
|
return if !id
|
||||||
organization = App.Organization.find(id)
|
organization = App.Organization.find(id)
|
||||||
@navigate organization.uiUrl()
|
@navigate organization.uiUrl()
|
||||||
)
|
)
|
||||||
|
|
||||||
@organizationPopupsDestroy()
|
@organizationPopupsDestroy()
|
||||||
|
@ -401,7 +401,7 @@ class App.Controller extends Spine.Controller
|
||||||
placement: "auto #{position}"
|
placement: "auto #{position}"
|
||||||
title: ->
|
title: ->
|
||||||
organization_id = $(@).data('id')
|
organization_id = $(@).data('id')
|
||||||
organization = App.Organization.fullLocal(organization_id)
|
organization = App.Organization.find(organization_id)
|
||||||
App.Utils.htmlEscape(organization.name)
|
App.Utils.htmlEscape(organization.name)
|
||||||
content: ->
|
content: ->
|
||||||
organization_id = $(@).data('id')
|
organization_id = $(@).data('id')
|
||||||
|
@ -460,8 +460,8 @@ class App.Controller extends Spine.Controller
|
||||||
type = $(@).filter('[data-type]').data('type')
|
type = $(@).filter('[data-type]').data('type')
|
||||||
tickets = []
|
tickets = []
|
||||||
if ticket_list[type]
|
if ticket_list[type]
|
||||||
for ticket_id in ticket_list[type]
|
for ticketId in ticket_list[type]
|
||||||
tickets.push App.Ticket.fullLocal(ticket_id)
|
tickets.push App.Ticket.fullLocal(ticketId)
|
||||||
|
|
||||||
# insert data
|
# insert data
|
||||||
html = App.view('popover/user_ticket_list')(
|
html = App.view('popover/user_ticket_list')(
|
||||||
|
@ -525,14 +525,14 @@ class App.Controller extends Spine.Controller
|
||||||
|
|
||||||
# lookup real data
|
# lookup real data
|
||||||
if App[item.object] && App[item.object].exists(item.o_id)
|
if App[item.object] && App[item.object].exists(item.o_id)
|
||||||
object = App[item.object].find(item.o_id)
|
object = App[item.object].findNative(item.o_id)
|
||||||
item.objectNative = object
|
item.objectNative = object
|
||||||
item.link = object.uiUrl()
|
item.link = object.uiUrl()
|
||||||
item.title = object.displayName()
|
item.title = object.displayName()
|
||||||
item.object_name = object.objectDisplayName()
|
item.object_name = object.objectDisplayName()
|
||||||
item.cssIcon = object.iconActivity(@Session.get())
|
item.cssIcon = object.iconActivity(@Session.get())
|
||||||
|
|
||||||
item.created_by = App.User.find(item.created_by_id)
|
item.created_by = App.User.findNative(item.created_by_id)
|
||||||
item
|
item
|
||||||
|
|
||||||
# central method, is getting called on every ticket form change
|
# central method, is getting called on every ticket form change
|
||||||
|
|
|
@ -28,6 +28,11 @@ class App.Event
|
||||||
_instance ?= new _eventSingleton
|
_instance ?= new _eventSingleton
|
||||||
_instance.unbindLevel(level)
|
_instance.unbindLevel(level)
|
||||||
|
|
||||||
|
@count: ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _eventSingleton
|
||||||
|
_instance.count()
|
||||||
|
|
||||||
@_allBindings: ->
|
@_allBindings: ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _eventSingleton
|
_instance ?= new _eventSingleton
|
||||||
|
@ -67,10 +72,8 @@ class _eventSingleton extends Spine.Module
|
||||||
# bind
|
# bind
|
||||||
if one
|
if one
|
||||||
@log 'debug', 'one', event, callback
|
@log 'debug', 'one', event, callback
|
||||||
Spine.one(event, callback)
|
|
||||||
else
|
else
|
||||||
@log 'debug', 'bind', event, callback
|
@log 'debug', 'bind', event, callback
|
||||||
Spine.bind(event, callback)
|
|
||||||
|
|
||||||
unbind: (events, callback, level) ->
|
unbind: (events, callback, level) ->
|
||||||
|
|
||||||
|
@ -91,13 +94,24 @@ class _eventSingleton extends Spine.Module
|
||||||
return item if item.event isnt event
|
return item if item.event isnt event
|
||||||
)
|
)
|
||||||
@log 'debug', 'unbind', event, callback
|
@log 'debug', 'unbind', event, callback
|
||||||
Spine.unbind(event, callback)
|
|
||||||
|
|
||||||
trigger: (events, data) ->
|
trigger: (events, data) ->
|
||||||
eventList = events.split(' ')
|
eventList = events.split(' ')
|
||||||
for event in eventList
|
|
||||||
@log 'debug', 'trigger', event, data
|
for level, bindLevel of @eventCurrent
|
||||||
Spine.trigger event, data
|
for key, bindMeta of bindLevel
|
||||||
|
for event in eventList
|
||||||
|
if bindMeta.event is event
|
||||||
|
bindMeta.callback(data)
|
||||||
|
if bindMeta.one is true
|
||||||
|
@unbind(event, bindMeta.callback, level)
|
||||||
|
|
||||||
|
count: ->
|
||||||
|
return 0 if !@eventCurrent
|
||||||
|
count = 0
|
||||||
|
for levelName, levelValue of @eventCurrent
|
||||||
|
count += Object.keys(levelValue).length
|
||||||
|
count
|
||||||
|
|
||||||
_allBindings: ->
|
_allBindings: ->
|
||||||
@eventCurrent
|
@eventCurrent
|
||||||
|
|
Loading…
Reference in a new issue