Removed App.Collection.all and App.Collection.find, use module methods now.
This commit is contained in:
parent
950375005e
commit
ffb8d460a9
28 changed files with 231 additions and 299 deletions
|
@ -261,11 +261,11 @@ class App.Controller extends Spine.Controller
|
||||||
placement: position
|
placement: position
|
||||||
title: ->
|
title: ->
|
||||||
ticket_id = $(@).data('id')
|
ticket_id = $(@).data('id')
|
||||||
ticket = App.Collection.find( 'Ticket', ticket_id )
|
ticket = App.Ticket.find( ticket_id )
|
||||||
ticket.title
|
ticket.title
|
||||||
content: ->
|
content: ->
|
||||||
ticket_id = $(@).data('id')
|
ticket_id = $(@).data('id')
|
||||||
ticket = App.Collection.find( 'Ticket', ticket_id )
|
ticket = App.Ticket.find( ticket_id )
|
||||||
ticket.humanTime = ui.humanTime(ticket.created_at)
|
ticket.humanTime = ui.humanTime(ticket.created_at)
|
||||||
# insert data
|
# insert data
|
||||||
App.view('ticket_info_small')(
|
App.view('ticket_info_small')(
|
||||||
|
@ -287,11 +287,11 @@ class App.Controller extends Spine.Controller
|
||||||
placement: position
|
placement: position
|
||||||
title: ->
|
title: ->
|
||||||
user_id = $(@).data('id')
|
user_id = $(@).data('id')
|
||||||
user = App.Collection.find( 'User', user_id )
|
user = App.User.find( user_id )
|
||||||
user.displayName()
|
user.displayName()
|
||||||
content: ->
|
content: ->
|
||||||
user_id = $(@).data('id')
|
user_id = $(@).data('id')
|
||||||
user = App.Collection.find( 'User', user_id )
|
user = App.User.find( user_id )
|
||||||
|
|
||||||
# get display data
|
# get display data
|
||||||
data = []
|
data = []
|
||||||
|
@ -333,11 +333,11 @@ class App.Controller extends Spine.Controller
|
||||||
placement: position
|
placement: position
|
||||||
title: ->
|
title: ->
|
||||||
organization_id = $(@).data('id')
|
organization_id = $(@).data('id')
|
||||||
organization = App.Collection.find( 'Organization', organization_id )
|
organization = App.Organization.find( organization_id )
|
||||||
organization.name
|
organization.name
|
||||||
content: ->
|
content: ->
|
||||||
organization_id = $(@).data('id')
|
organization_id = $(@).data('id')
|
||||||
organization = App.Collection.find( 'Organization', organization_id )
|
organization = App.Organization.find( organization_id )
|
||||||
# insert data
|
# insert data
|
||||||
App.view('organization_info_small')(
|
App.view('organization_info_small')(
|
||||||
organization: organization,
|
organization: organization,
|
||||||
|
|
|
@ -1124,7 +1124,7 @@ class App.ControllerForm extends App.Controller
|
||||||
if typeof attribute.filter is 'function'
|
if typeof attribute.filter is 'function'
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-function'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-function'
|
||||||
|
|
||||||
all = App.Collection.all( type: attribute.relation, sortBy: attribute.sortBy || 'name' )
|
all = App[ attribute.relation ].search( sortBy: attribute.sortBy || 'name' )
|
||||||
|
|
||||||
list = attribute.filter( all, 'collection' )
|
list = attribute.filter( all, 'collection' )
|
||||||
|
|
||||||
|
@ -1135,7 +1135,7 @@ class App.ControllerForm extends App.Controller
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data', filter
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data', filter
|
||||||
|
|
||||||
# check all records
|
# check all records
|
||||||
for record in App.Collection.all( type: attribute.relation, sortBy: attribute.sortBy || 'name' )
|
for record in App[ attribute.relation ].search( sortBy: attribute.sortBy || 'name' )
|
||||||
|
|
||||||
# check all filter attributes
|
# check all filter attributes
|
||||||
for key in filter
|
for key in filter
|
||||||
|
@ -1148,10 +1148,10 @@ class App.ControllerForm extends App.Controller
|
||||||
# no data filter matched
|
# no data filter matched
|
||||||
else
|
else
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data no filter matched'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data no filter matched'
|
||||||
list = App.Collection.all( type: attribute.relation, sortBy: attribute.sortBy || 'name' )
|
list = App[ attribute.relation ].search( sortBy: attribute.sortBy || 'name' )
|
||||||
else
|
else
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-no filter defined'
|
App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-no filter defined'
|
||||||
list = App.Collection.all( type: attribute.relation, sortBy: attribute.sortBy || 'name' )
|
list = App[ attribute.relation ].search( sortBy: attribute.sortBy || 'name' )
|
||||||
|
|
||||||
App.Log.debug 'ControllerForm', '_getRelationOptionList', attribute, list
|
App.Log.debug 'ControllerForm', '_getRelationOptionList', attribute, list
|
||||||
|
|
||||||
|
|
|
@ -133,10 +133,7 @@ class App.ControllerGenericIndex extends App.ControllerContent
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
|
|
||||||
objects = App.Collection.all(
|
objects = App[@genericObject].search( sortBy: @defaultSortBy || 'name' )
|
||||||
type: @genericObject,
|
|
||||||
sortBy: @defaultSortBy || 'name',
|
|
||||||
)
|
|
||||||
|
|
||||||
# remove ignored items from collection
|
# remove ignored items from collection
|
||||||
if @ignoreObjectIDs
|
if @ignoreObjectIDs
|
||||||
|
|
|
@ -107,7 +107,7 @@ class App.ControllerTable extends App.Controller
|
||||||
for attribute in attributes
|
for attribute in attributes
|
||||||
if rowWithoutId is attribute.name
|
if rowWithoutId is attribute.name
|
||||||
if attribute.relation && App[ attribute.relation ]
|
if attribute.relation && App[ attribute.relation ]
|
||||||
record = App.Collection.find( attribute.relation, object[rowWithoutId] )
|
record = App[ attribute.relation ].find( object[rowWithoutId] )
|
||||||
object[row.name] = record.name
|
object[row.name] = record.name
|
||||||
|
|
||||||
@log 'debug', 'table', 'header', header, 'overview', dataTypesForCols, 'objects', data.objects
|
@log 'debug', 'table', 'header', header, 'overview', dataTypesForCols, 'objects', data.objects
|
||||||
|
|
|
@ -51,15 +51,15 @@ class App.DashboardActivityStream extends App.Controller
|
||||||
|
|
||||||
# load user data
|
# load user data
|
||||||
for item in items
|
for item in items
|
||||||
item.created_by = App.Collection.find( 'User', item.created_by_id )
|
item.created_by = App.User.find( item.created_by_id )
|
||||||
|
|
||||||
# load ticket data
|
# load ticket data
|
||||||
for item in items
|
for item in items
|
||||||
item.data = {}
|
item.data = {}
|
||||||
if item.history_object is 'Ticket'
|
if item.history_object is 'Ticket'
|
||||||
item.data.title = App.Collection.find( 'Ticket', item.o_id ).title
|
item.data.title = App.Ticket.find( item.o_id ).title
|
||||||
if item.history_object is 'Ticket::Article'
|
if item.history_object is 'Ticket::Article'
|
||||||
article = App.Collection.find( 'TicketArticle', item.o_id )
|
article = App.TicketArticle.find( item.o_id )
|
||||||
item.history_object = 'Article'
|
item.history_object = 'Article'
|
||||||
item.sub_o_id = article.id
|
item.sub_o_id = article.id
|
||||||
item.o_id = article.ticket_id
|
item.o_id = article.ticket_id
|
||||||
|
|
|
@ -33,11 +33,11 @@ class App.DashboardRecentViewed extends App.Controller
|
||||||
|
|
||||||
# load user data
|
# load user data
|
||||||
for item in @items
|
for item in @items
|
||||||
item.created_by = App.Collection.find( 'User', item.created_by_id )
|
item.created_by = App.User.find( item.created_by_id )
|
||||||
|
|
||||||
# load ticket data
|
# load ticket data
|
||||||
for item in @items
|
for item in @items
|
||||||
item.ticket = App.Collection.find( 'User', item.o_id )
|
item.ticket = App.User.find( item.o_id )
|
||||||
|
|
||||||
html = App.view('dashboard/recent_viewed')(
|
html = App.view('dashboard/recent_viewed')(
|
||||||
head: 'Recent Viewed',
|
head: 'Recent Viewed',
|
||||||
|
|
|
@ -95,7 +95,7 @@ class App.DashboardTicket extends App.Controller
|
||||||
while i < end
|
while i < end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if @ticket_list[ i - 1 ]
|
if @ticket_list[ i - 1 ]
|
||||||
@tickets_in_table.push App.Collection.find( 'Ticket', @ticket_list[ i - 1 ] )
|
@tickets_in_table.push App.Ticket.retrieve( @ticket_list[ i - 1 ] )
|
||||||
|
|
||||||
shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d )
|
shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d )
|
||||||
new App.ControllerTable(
|
new App.ControllerTable(
|
||||||
|
|
|
@ -45,8 +45,7 @@ class App.ProfileLanguage extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
App.Collection.find(
|
App.User.retrieve(
|
||||||
'User',
|
|
||||||
App.Session.get( 'id' ),
|
App.Session.get( 'id' ),
|
||||||
=>
|
=>
|
||||||
App.i18n.set( @locale )
|
App.i18n.set( @locale )
|
||||||
|
@ -57,7 +56,7 @@ class App.ProfileLanguage extends App.Controller
|
||||||
msg: App.i18n.translateContent( 'Successfully!' )
|
msg: App.i18n.translateContent( 'Successfully!' )
|
||||||
)
|
)
|
||||||
,
|
,
|
||||||
true,
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
error: (xhr, status, error) =>
|
error: (xhr, status, error) =>
|
||||||
|
|
|
@ -136,8 +136,8 @@ class App.TicketCreate extends App.Controller
|
||||||
App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
|
App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
|
||||||
|
|
||||||
# render page
|
# render page
|
||||||
t = App.Collection.find( 'Ticket', params.ticket_id ).attributes()
|
t = App.Ticket.find( params.ticket_id ).attributes()
|
||||||
a = App.Collection.find( 'TicketArticle', params.article_id )
|
a = App.TicketArticle.find( params.article_id )
|
||||||
|
|
||||||
# reset owner
|
# reset owner
|
||||||
t.owner_id = 0
|
t.owner_id = 0
|
||||||
|
@ -151,8 +151,8 @@ class App.TicketCreate extends App.Controller
|
||||||
|
|
||||||
# set defaults
|
# set defaults
|
||||||
defaults =
|
defaults =
|
||||||
ticket_state_id: App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
|
ticket_state_id: App.TicketState.findByAttribute( 'name', 'open' ).id
|
||||||
ticket_priority_id: App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id
|
ticket_priority_id: App.TicketPriority.findByAttribute( 'name', '2 normal' ).id
|
||||||
|
|
||||||
# generate form
|
# generate form
|
||||||
configure_attributes = [
|
configure_attributes = [
|
||||||
|
@ -250,11 +250,11 @@ class App.TicketCreate extends App.Controller
|
||||||
object = new App.Ticket
|
object = new App.Ticket
|
||||||
|
|
||||||
# find sender_id
|
# find sender_id
|
||||||
sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', @article_attributes['sender'] )
|
sender = App.TicketArticleSender.findByAttribute( 'name', @article_attributes['sender'] )
|
||||||
type = App.Collection.findByAttribute( 'TicketArticleType', 'name', @article_attributes['article'] )
|
type = App.TicketArticleType.findByAttribute( 'name', @article_attributes['article'] )
|
||||||
|
|
||||||
if params.group_id
|
if params.group_id
|
||||||
group = App.Collection.find( 'Group', params.group_id )
|
group = App.Group.find( params.group_id )
|
||||||
|
|
||||||
# create article
|
# create article
|
||||||
if sender.name is 'Customer'
|
if sender.name is 'Customer'
|
||||||
|
@ -356,7 +356,7 @@ class UserNew extends App.ControllerModal
|
||||||
user = new App.User
|
user = new App.User
|
||||||
|
|
||||||
# find role_id
|
# find role_id
|
||||||
role = App.Collection.findByAttribute( 'Role', 'name', 'Customer' )
|
role = App.Role.findByAttribute( 'name', 'Customer' )
|
||||||
params.role_ids = role.id
|
params.role_ids = role.id
|
||||||
@log 'notice', 'updateAttributes', params
|
@log 'notice', 'updateAttributes', params
|
||||||
user.load(params)
|
user.load(params)
|
||||||
|
@ -381,7 +381,7 @@ class UserNew extends App.ControllerModal
|
||||||
# start customer info controller
|
# start customer info controller
|
||||||
ui.userInfo( user_id: user.id )
|
ui.userInfo( user_id: user.id )
|
||||||
ui.modalHide()
|
ui.modalHide()
|
||||||
App.Collection.find( 'User', @id, callbackReload , true )
|
App.User.retrieve( @id, callbackReload , true )
|
||||||
|
|
||||||
error: ->
|
error: ->
|
||||||
ui.modalHide()
|
ui.modalHide()
|
||||||
|
|
|
@ -44,7 +44,7 @@ class App.TicketHistory extends App.ControllerModal
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
@html App.view('agent_ticket_history')(
|
@html App.view('agent_ticket_history')(
|
||||||
objects: App.Collection.all( type: 'History' ),
|
objects: App.History.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@modalShow()
|
@modalShow()
|
||||||
|
@ -62,13 +62,13 @@ class App.TicketHistory extends App.ControllerModal
|
||||||
if isSorted.length
|
if isSorted.length
|
||||||
@sortstate = 'notsorted'
|
@sortstate = 'notsorted'
|
||||||
@html App.view('agent_ticket_history')(
|
@html App.view('agent_ticket_history')(
|
||||||
objects: App.Collection.all( type: 'History' ),
|
objects: App.History.all()
|
||||||
state: @sortstate
|
state: @sortstate
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
@sortstate = 'sorted'
|
@sortstate = 'sorted'
|
||||||
@html App.view('agent_ticket_history')(
|
@html App.view('agent_ticket_history')(
|
||||||
objects: App.Collection.all( type: 'History' ).reverse(),
|
objects: App.History.all().reverse()
|
||||||
state: @sortstate
|
state: @sortstate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class App.TicketMerge extends App.ControllerModal
|
||||||
list = []
|
list = []
|
||||||
for t in data.customer.tickets
|
for t in data.customer.tickets
|
||||||
if t.id isnt @ticket_id
|
if t.id isnt @ticket_id
|
||||||
ticketItem = App.Collection.find( 'Ticket', t.id )
|
ticketItem = App.Ticket.retrieve( t.id )
|
||||||
list.push ticketItem
|
list.push ticketItem
|
||||||
new App.ControllerTable(
|
new App.ControllerTable(
|
||||||
el: @el.find('#ticket-merge-customer-tickets'),
|
el: @el.find('#ticket-merge-customer-tickets'),
|
||||||
|
@ -61,7 +61,7 @@ class App.TicketMerge extends App.ControllerModal
|
||||||
list = []
|
list = []
|
||||||
for t in data.recent.tickets
|
for t in data.recent.tickets
|
||||||
if t.id isnt @ticket_id
|
if t.id isnt @ticket_id
|
||||||
ticketItem = App.Collection.find( 'Ticket', t.id )
|
ticketItem = App.Ticket.retrieve( t.id )
|
||||||
list.push ticketItem
|
list.push ticketItem
|
||||||
new App.ControllerTable(
|
new App.ControllerTable(
|
||||||
el: @el.find('#ticket-merge-recent-tickets'),
|
el: @el.find('#ticket-merge-recent-tickets'),
|
||||||
|
@ -92,7 +92,7 @@ class App.TicketMerge extends App.ControllerModal
|
||||||
@el.delegate('[name="radio"]', 'click', (e) ->
|
@el.delegate('[name="radio"]', 'click', (e) ->
|
||||||
if $(e.target).prop('checked')
|
if $(e.target).prop('checked')
|
||||||
ticket_id = $(e.target).val()
|
ticket_id = $(e.target).val()
|
||||||
ticket = App.Collection.find( 'Ticket', ticket_id )
|
ticket = App.Ticket.retrieve( ticket_id )
|
||||||
$(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number )
|
$(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ class App.TicketMerge extends App.ControllerModal
|
||||||
@modalHide()
|
@modalHide()
|
||||||
|
|
||||||
# view ticket
|
# view ticket
|
||||||
@log 'notice', 'nav...', App.Collection.find( 'Ticket', data.master_ticket['id'] )
|
@log 'notice', 'nav...', App.Ticket.find( data.master_ticket['id'] )
|
||||||
@navigate '#ticket/zoom/' + data.master_ticket['id']
|
@navigate '#ticket/zoom/' + data.master_ticket['id']
|
||||||
|
|
||||||
# notify UI
|
# notify UI
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Index extends App.ControllerContent
|
||||||
|
|
||||||
@ticket_list_show = []
|
@ticket_list_show = []
|
||||||
for ticket_id in @ticket_list
|
for ticket_id in @ticket_list
|
||||||
@ticket_list_show.push App.Collection.find( 'Ticket', ticket_id )
|
@ticket_list_show.push App.Ticket.retrieve( ticket_id )
|
||||||
|
|
||||||
# remeber bulk attributes
|
# remeber bulk attributes
|
||||||
@bulk = data.bulk
|
@bulk = data.bulk
|
||||||
|
|
|
@ -62,8 +62,8 @@ class Index extends App.ControllerContent
|
||||||
App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
|
App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
|
||||||
|
|
||||||
# render page
|
# render page
|
||||||
t = App.Collection.find( 'Ticket', params.ticket_id ).attributes()
|
t = App.Ticket.find( params.ticket_id ).attributes()
|
||||||
a = App.Collection.find( 'TicketArticle', params.article_id )
|
a = App.TicketArticle.find( params.article_id )
|
||||||
|
|
||||||
# reset owner
|
# reset owner
|
||||||
t.owner_id = 0
|
t.owner_id = 0
|
||||||
|
@ -79,9 +79,9 @@ class Index extends App.ControllerContent
|
||||||
# set defaults
|
# set defaults
|
||||||
defaults = template['options'] || {}
|
defaults = template['options'] || {}
|
||||||
if !( 'ticket_state_id' of defaults )
|
if !( 'ticket_state_id' of defaults )
|
||||||
defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'new' )
|
defaults['ticket_state_id'] = App.TicketState.findByAttribute( 'name', 'new' )
|
||||||
if !( 'ticket_priority_id' of defaults )
|
if !( 'ticket_priority_id' of defaults )
|
||||||
defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
|
defaults['ticket_priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' )
|
||||||
|
|
||||||
groupFilter = (collection, type) =>
|
groupFilter = (collection, type) =>
|
||||||
|
|
||||||
|
@ -148,11 +148,11 @@ class Index extends App.ControllerContent
|
||||||
params.customer_id = @Session.get('id')
|
params.customer_id = @Session.get('id')
|
||||||
|
|
||||||
# set prio
|
# set prio
|
||||||
priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
|
priority = App.TicketPriority.findByAttribute( 'name', '2 normal' )
|
||||||
params.ticket_priority_id = priority.id
|
params.ticket_priority_id = priority.id
|
||||||
|
|
||||||
# set state
|
# set state
|
||||||
state = App.Collection.findByAttribute( 'TicketState', 'name', 'new' )
|
state = App.TicketState.findByAttribute( 'name', 'new' )
|
||||||
params.ticket_state_id = state.id
|
params.ticket_state_id = state.id
|
||||||
|
|
||||||
# fillup params
|
# fillup params
|
||||||
|
@ -164,10 +164,10 @@ class Index extends App.ControllerContent
|
||||||
@log 'CustomerTicketCreate', 'notice', 'updateAttributes', params
|
@log 'CustomerTicketCreate', 'notice', 'updateAttributes', params
|
||||||
|
|
||||||
# find sender_id
|
# find sender_id
|
||||||
sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' )
|
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
|
||||||
type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' )
|
type = App.TicketArticleType.findByAttribute( 'name', 'web' )
|
||||||
if params.group_id
|
if params.group_id
|
||||||
group = App.Collection.find( 'Group', params.group_id )
|
group = App.Group.find( params.group_id )
|
||||||
|
|
||||||
# create article
|
# create article
|
||||||
params['article'] = {
|
params['article'] = {
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Index extends App.ControllerContent
|
||||||
@params.invite = true
|
@params.invite = true
|
||||||
|
|
||||||
# find agent role
|
# find agent role
|
||||||
role = App.Collection.findByAttribute( 'Role', 'name', 'Agent' )
|
role = App.Role.findByAttribute( 'name', 'Agent' )
|
||||||
if role
|
if role
|
||||||
@params.role_ids = role.id
|
@params.role_ids = role.id
|
||||||
else
|
else
|
||||||
|
|
|
@ -40,7 +40,7 @@ class App.LinkInfo extends App.Controller
|
||||||
list[ item['link_type'] ] = []
|
list[ item['link_type'] ] = []
|
||||||
|
|
||||||
if item['link_object'] is 'Ticket'
|
if item['link_object'] is 'Ticket'
|
||||||
ticket = App.Collection.find( 'Ticket', item['link_object_value'] )
|
ticket = App.Ticket.retrieve( item['link_object_value'] )
|
||||||
if ticket.ticket_state.name is 'merged'
|
if ticket.ticket_state.name is 'merged'
|
||||||
ticket.css = 'merged'
|
ticket.css = 'merged'
|
||||||
list[ item['link_type'] ].push ticket
|
list[ item['link_type'] ].push ticket
|
||||||
|
|
|
@ -102,7 +102,7 @@ class App.Navigation extends App.Controller
|
||||||
if organization.user_ids
|
if organization.user_ids
|
||||||
organization.users = []
|
organization.users = []
|
||||||
for user_id in organization.user_ids
|
for user_id in organization.user_ids
|
||||||
user = App.Collection.find( 'User', user_id )
|
user = App.User.find( user_id )
|
||||||
organization.users.push user
|
organization.users.push user
|
||||||
App.Collection.load( type: 'Organization', data: data.load.organizations )
|
App.Collection.load( type: 'Organization', data: data.load.organizations )
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class App.Navigation extends App.Controller
|
||||||
if area.name is 'Ticket'
|
if area.name is 'Ticket'
|
||||||
area.result = []
|
area.result = []
|
||||||
for id in area.ids
|
for id in area.ids
|
||||||
ticket = App.Collection.find( 'Ticket', id )
|
ticket = App.Ticket.find( id )
|
||||||
ticket.humanTime = @humanTime(ticket.created_at)
|
ticket.humanTime = @humanTime(ticket.created_at)
|
||||||
data =
|
data =
|
||||||
display: "##{ticket.number} - #{ticket.title} - #{ticket.humanTime}"
|
display: "##{ticket.number} - #{ticket.title} - #{ticket.humanTime}"
|
||||||
|
@ -127,7 +127,7 @@ class App.Navigation extends App.Controller
|
||||||
else if area.name is 'User'
|
else if area.name is 'User'
|
||||||
area.result = []
|
area.result = []
|
||||||
for id in area.ids
|
for id in area.ids
|
||||||
user = App.Collection.find( 'User', id )
|
user = App.User.find( id )
|
||||||
data =
|
data =
|
||||||
display: "#{user.displayName()}"
|
display: "#{user.displayName()}"
|
||||||
id: user.id
|
id: user.id
|
||||||
|
@ -137,7 +137,7 @@ class App.Navigation extends App.Controller
|
||||||
else if area.name is 'Organization'
|
else if area.name is 'Organization'
|
||||||
area.result = []
|
area.result = []
|
||||||
for id in area.ids
|
for id in area.ids
|
||||||
organization = App.Collection.find( 'Organization', id )
|
organization = App.Organization.find( id )
|
||||||
data =
|
data =
|
||||||
display: "#{organization.displayName()}"
|
display: "#{organization.displayName()}"
|
||||||
id: organization.id
|
id: organization.id
|
||||||
|
@ -329,7 +329,7 @@ class App.Navigation extends App.Controller
|
||||||
if prio is 8000
|
if prio is 8000
|
||||||
divider = true
|
divider = true
|
||||||
navheader = 'Recent Viewed'
|
navheader = 'Recent Viewed'
|
||||||
ticket = App.Collection.find( 'Ticket', item.o_id )
|
ticket = App.Ticket.find( item.o_id )
|
||||||
prio++
|
prio++
|
||||||
NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = {
|
NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = {
|
||||||
prio: prio,
|
prio: prio,
|
||||||
|
|
|
@ -58,7 +58,7 @@ class App.TemplateUI extends App.Controller
|
||||||
name = params['template_name']
|
name = params['template_name']
|
||||||
# delete params['template_name']
|
# delete params['template_name']
|
||||||
|
|
||||||
template = App.Collection.findByAttribute( 'Template', 'name', name )
|
template = App.Template.findByAttribute( 'name', name )
|
||||||
if !template
|
if !template
|
||||||
template = new App.Template
|
template = new App.Template
|
||||||
|
|
||||||
|
|
|
@ -201,8 +201,7 @@ class App.TextModuleUIOld extends App.Controller
|
||||||
@renderTable('')
|
@renderTable('')
|
||||||
|
|
||||||
objectSearch: (search) =>
|
objectSearch: (search) =>
|
||||||
objects = App.Collection.all(
|
objects = App.TextModule.search(
|
||||||
type: 'TextModule',
|
|
||||||
sortBy: 'name',
|
sortBy: 'name',
|
||||||
filter: { active: true },
|
filter: { active: true },
|
||||||
filterExtended: [ { name: "^#{search}" }, { content: search }, { keywords: search } ],
|
filterExtended: [ { name: "^#{search}" }, { content: search }, { keywords: search } ],
|
||||||
|
@ -235,18 +234,18 @@ class App.TextModuleUIOld extends App.Controller
|
||||||
placement: 'right'
|
placement: 'right'
|
||||||
title: ->
|
title: ->
|
||||||
id = $(@).data('id')
|
id = $(@).data('id')
|
||||||
text_module = App.Collection.find( 'TextModule', id )
|
text_module = App.TextModule.find( id )
|
||||||
text_module.name
|
text_module.name
|
||||||
content: ->
|
content: ->
|
||||||
id = $(@).data('id')
|
id = $(@).data('id')
|
||||||
text_module = App.Collection.find( 'TextModule', id )
|
text_module = App.TextModule.find( id )
|
||||||
text_module.content
|
text_module.content
|
||||||
)
|
)
|
||||||
|
|
||||||
paste: (e) =>
|
paste: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
id = $(e.target).parents('tr').data('id')
|
id = $(e.target).parents('tr').data('id')
|
||||||
text_module = App.Collection.find( 'TextModule', id )
|
text_module = App.TextModule.find( id )
|
||||||
@_insert( text_module.content, @ )
|
@_insert( text_module.content, @ )
|
||||||
|
|
||||||
delete: (e) =>
|
delete: (e) =>
|
||||||
|
@ -254,7 +253,7 @@ class App.TextModuleUIOld extends App.Controller
|
||||||
|
|
||||||
# get params
|
# get params
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
text_module = App.Collection.find( 'TextModule', params['text_module_id'] )
|
text_module = App.TextModule.find( params['text_module_id'] )
|
||||||
if confirm('Sure?')
|
if confirm('Sure?')
|
||||||
text_module.destroy()
|
text_module.destroy()
|
||||||
@render()
|
@render()
|
||||||
|
@ -262,7 +261,7 @@ class App.TextModuleUIOld extends App.Controller
|
||||||
select: (e) =>
|
select: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
id = $(e.target).parents('tr').data('id')
|
id = $(e.target).parents('tr').data('id')
|
||||||
text_module = App.Collection.find( 'TextModule', id )
|
text_module = App.TextModule.find( id )
|
||||||
@el.find('#text-module-preview-content').val( text_module.content )
|
@el.find('#text-module-preview-content').val( text_module.content )
|
||||||
@el.find('#text_module_name').val( text_module.name )
|
@el.find('#text_module_name').val( text_module.name )
|
||||||
|
|
||||||
|
@ -274,7 +273,7 @@ class App.TextModuleUIOld extends App.Controller
|
||||||
name = params['name']
|
name = params['name']
|
||||||
# delete params['text_module_name']
|
# delete params['text_module_name']
|
||||||
|
|
||||||
text_module = App.Collection.findByAttribute( 'TextModule', 'name', name )
|
text_module = App.TextModule.findByAttribute( 'name', name )
|
||||||
if !text_module
|
if !text_module
|
||||||
text_module = new App.TextModule
|
text_module = new App.TextModule
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,4 @@ class App.TicketCustomer extends App.ControllerModal
|
||||||
@zoom.render()
|
@zoom.render()
|
||||||
|
|
||||||
# load user if not already exists
|
# load user if not already exists
|
||||||
App.Collection.find( 'User', params['customer_id'], callback )
|
App.User.retrieve( params['customer_id'], callback )
|
||||||
|
|
|
@ -27,7 +27,7 @@ class App.TicketZoom extends App.Controller
|
||||||
(data) =>
|
(data) =>
|
||||||
update = =>
|
update = =>
|
||||||
if data.id.toString() is @ticket_id.toString()
|
if data.id.toString() is @ticket_id.toString()
|
||||||
ticket = App.Collection.find( 'Ticket', @ticket_id )
|
ticket = App.Ticket.retrieve( @ticket_id )
|
||||||
@log 'notice', 'TRY', data.updated_at, ticket.updated_at
|
@log 'notice', 'TRY', data.updated_at, ticket.updated_at
|
||||||
if data.updated_at isnt ticket.updated_at
|
if data.updated_at isnt ticket.updated_at
|
||||||
@fetch( @ticket_id, false )
|
@fetch( @ticket_id, false )
|
||||||
|
@ -37,7 +37,7 @@ class App.TicketZoom extends App.Controller
|
||||||
|
|
||||||
meta: =>
|
meta: =>
|
||||||
return if !@ticket
|
return if !@ticket
|
||||||
ticket = App.Collection.find( 'Ticket', @ticket.id )
|
ticket = App.Ticket.retrieve( @ticket.id )
|
||||||
meta =
|
meta =
|
||||||
url: @url()
|
url: @url()
|
||||||
head: ticket.title
|
head: ticket.title
|
||||||
|
@ -135,7 +135,7 @@ class App.TicketZoom extends App.Controller
|
||||||
render: (force) =>
|
render: (force) =>
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
@ticket = App.Collection.find( 'Ticket', @ticket_id )
|
@ticket = App.Ticket.retrieve( @ticket_id )
|
||||||
|
|
||||||
# update taskbar with new meta data
|
# update taskbar with new meta data
|
||||||
App.Event.trigger 'task:render'
|
App.Event.trigger 'task:render'
|
||||||
|
@ -249,7 +249,7 @@ class TicketTitle extends App.Controller
|
||||||
title = ''
|
title = ''
|
||||||
|
|
||||||
# update title
|
# update title
|
||||||
ticket = App.Collection.find( 'Ticket', @ticket.id )
|
ticket = App.Ticket.retrieve( @ticket.id )
|
||||||
ticket.title = title
|
ticket.title = title
|
||||||
ticket.load( title: title )
|
ticket.load( title: title )
|
||||||
ticket.save()
|
ticket.save()
|
||||||
|
@ -325,7 +325,7 @@ class Edit extends App.Controller
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
ticket = App.Collection.find( 'Ticket', @ticket.id )
|
ticket = App.Ticket.retrieve( @ticket.id )
|
||||||
|
|
||||||
@html App.view('ticket_zoom/edit')(
|
@html App.view('ticket_zoom/edit')(
|
||||||
ticket: ticket
|
ticket: ticket
|
||||||
|
@ -445,10 +445,10 @@ class Edit extends App.Controller
|
||||||
@autosaveStop()
|
@autosaveStop()
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
|
|
||||||
ticket = App.Collection.find( 'Ticket', @ticket.id )
|
ticket = App.Ticket.retrieve( @ticket.id )
|
||||||
|
|
||||||
@log 'notice', 'update', params, ticket
|
@log 'notice', 'update', params, ticket
|
||||||
article_type = App.Collection.find( 'TicketArticleType', params['ticket_article_type_id'] )
|
article_type = App.TicketArticleType.find( params['ticket_article_type_id'] )
|
||||||
|
|
||||||
# update ticket
|
# update ticket
|
||||||
ticket_update = {}
|
ticket_update = {}
|
||||||
|
@ -514,11 +514,11 @@ class Edit extends App.Controller
|
||||||
|
|
||||||
# find sender_id
|
# find sender_id
|
||||||
if @isRole('Customer')
|
if @isRole('Customer')
|
||||||
sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' )
|
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
|
||||||
type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' )
|
type = App.TicketArticleType.findByAttribute( 'name', 'web' )
|
||||||
params['ticket_article_type_id'] = type.id
|
params['ticket_article_type_id'] = type.id
|
||||||
else
|
else
|
||||||
sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Agent' )
|
sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' )
|
||||||
params.ticket_article_sender_id = sender.id
|
params.ticket_article_sender_id = sender.id
|
||||||
@log 'notice', 'update article', params, sender
|
@log 'notice', 'update article', params, sender
|
||||||
article.load(params)
|
article.load(params)
|
||||||
|
@ -570,7 +570,7 @@ class ArticleView extends App.Controller
|
||||||
# get all articles
|
# get all articles
|
||||||
@articles = []
|
@articles = []
|
||||||
for article_id in @ticket.article_ids
|
for article_id in @ticket.article_ids
|
||||||
article = App.Collection.find( 'TicketArticle', article_id )
|
article = App.TicketArticle.retrieve( article_id )
|
||||||
@articles.push article
|
@articles.push article
|
||||||
|
|
||||||
# rework articles
|
# rework articles
|
||||||
|
@ -633,9 +633,9 @@ class ArticleView extends App.Controller
|
||||||
reply: (e) =>
|
reply: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
article_id = $(e.target).parents('[data-id]').data('id')
|
article_id = $(e.target).parents('[data-id]').data('id')
|
||||||
article = App.Collection.find( 'TicketArticle', article_id )
|
article = App.TicketArticle.find( article_id )
|
||||||
article_type = App.Collection.find( 'TicketArticleType', article.ticket_article_type_id )
|
article_type = App.TicketArticleType.find( article.ticket_article_type_id )
|
||||||
customer = App.Collection.find( 'User', article.created_by_id )
|
customer = App.User.find( article.created_by_id )
|
||||||
|
|
||||||
# update form
|
# update form
|
||||||
@checkIfSignatureIsNeeded(article_type)
|
@checkIfSignatureIsNeeded(article_type)
|
||||||
|
|
|
@ -57,7 +57,7 @@ class App.UserInfo extends App.Controller
|
||||||
# update changes
|
# update changes
|
||||||
update: (e) =>
|
update: (e) =>
|
||||||
note = $(e.target).parent().find('[data-type=update]').val()
|
note = $(e.target).parent().find('[data-type=update]').val()
|
||||||
user = App.Collection.find( 'User', @user_id )
|
user = App.User.find( @user_id )
|
||||||
if user.note isnt note
|
if user.note isnt note
|
||||||
user.updateAttributes( note: note )
|
user.updateAttributes( note: note )
|
||||||
@log 'notice', 'update', e, note, user
|
@log 'notice', 'update', e, note, user
|
||||||
|
|
|
@ -14,21 +14,6 @@ class App.Collection
|
||||||
_instance ?= new _collectionSingleton
|
_instance ?= new _collectionSingleton
|
||||||
_instance.reset( args )
|
_instance.reset( args )
|
||||||
|
|
||||||
@find: ( type, id, callback, force ) ->
|
|
||||||
if _instance == undefined
|
|
||||||
_instance ?= new _collectionSingleton
|
|
||||||
_instance.find( type, id, callback, force )
|
|
||||||
|
|
||||||
@all: ( args ) ->
|
|
||||||
if _instance == undefined
|
|
||||||
_instance ?= new _collectionSingleton
|
|
||||||
_instance.all( args )
|
|
||||||
|
|
||||||
@findByAttribute: ( type, key, value ) ->
|
|
||||||
if _instance == undefined
|
|
||||||
_instance ?= new _collectionSingleton
|
|
||||||
_instance.findByAttribute( type, key, value )
|
|
||||||
|
|
||||||
class _collectionSingleton extends Spine.Module
|
class _collectionSingleton extends Spine.Module
|
||||||
@include App.LogInclude
|
@include App.LogInclude
|
||||||
|
|
||||||
|
@ -114,196 +99,3 @@ class _collectionSingleton extends Spine.Module
|
||||||
if !localStorage
|
if !localStorage
|
||||||
App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } )
|
App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } )
|
||||||
|
|
||||||
find: ( type, id, callback, force ) ->
|
|
||||||
|
|
||||||
# if App[type].exists( id ) && !callback
|
|
||||||
if !force && App[type].exists( id )
|
|
||||||
data = App[type].find( id )
|
|
||||||
data = @_fillUp( type, data )
|
|
||||||
if callback
|
|
||||||
callback( data )
|
|
||||||
return data
|
|
||||||
else
|
|
||||||
if force
|
|
||||||
@log 'debug', 'find forced to load!', type, id
|
|
||||||
else
|
|
||||||
@log 'debug', 'find not loaded!', type, id
|
|
||||||
if callback
|
|
||||||
|
|
||||||
# execute callback if record got loaded
|
|
||||||
col = @
|
|
||||||
App[type].one 'refresh', (record) ->
|
|
||||||
data = App.Collection.find( type, id )
|
|
||||||
|
|
||||||
# load update to local storage
|
|
||||||
clone = {}
|
|
||||||
for key, value of data
|
|
||||||
if typeof value isnt 'function'
|
|
||||||
clone[key] = value
|
|
||||||
col.load( localStorage: false, type: type, data: [ clone ], refresh: true )
|
|
||||||
|
|
||||||
callback( data )
|
|
||||||
|
|
||||||
# fetch object
|
|
||||||
@log 'debug', 'loading..' + type + '..', id
|
|
||||||
App[type].fetch( id: id )
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
_fillUp: ( type, data ) ->
|
|
||||||
|
|
||||||
# users
|
|
||||||
if type == 'User'
|
|
||||||
|
|
||||||
# set socal media links
|
|
||||||
if data['accounts']
|
|
||||||
for account of data['accounts']
|
|
||||||
if account == 'twitter'
|
|
||||||
data['accounts'][account]['link'] = 'http://twitter.com/' + data['accounts'][account]['username']
|
|
||||||
if account == 'facebook'
|
|
||||||
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
|
|
||||||
|
|
||||||
# set image url
|
|
||||||
if data && !data.image
|
|
||||||
data.image = 'http://placehold.it/48x48'
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
# tickets
|
|
||||||
else if type == 'Ticket'
|
|
||||||
|
|
||||||
# priority
|
|
||||||
data.ticket_priority = @find( 'TicketPriority', data.ticket_priority_id )
|
|
||||||
|
|
||||||
# state
|
|
||||||
data.ticket_state = @find( 'TicketState', data.ticket_state_id )
|
|
||||||
|
|
||||||
# group
|
|
||||||
data.group = @find( 'Group', data.group_id )
|
|
||||||
|
|
||||||
# customer
|
|
||||||
if data.customer_id
|
|
||||||
data.customer = @find( 'User', data.customer_id )
|
|
||||||
|
|
||||||
# owner
|
|
||||||
if data.owner_id
|
|
||||||
data.owner = @find( 'User', data.owner_id )
|
|
||||||
|
|
||||||
# add created & updated
|
|
||||||
if data.created_by_id
|
|
||||||
data.created_by = @find( 'User', data.created_by_id )
|
|
||||||
if data.updated_by_id
|
|
||||||
data.updated_by = @find( 'User', data.updated_by_id )
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
# articles
|
|
||||||
else if type == 'TicketArticle'
|
|
||||||
|
|
||||||
# add created & updated
|
|
||||||
data.created_by = @find( 'User', data.created_by_id )
|
|
||||||
|
|
||||||
# add possible actions
|
|
||||||
data.article_type = @find( 'TicketArticleType', data.ticket_article_type_id )
|
|
||||||
data.article_sender = @find( 'TicketArticleSender', data.ticket_article_sender_id )
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
# history
|
|
||||||
else if type == 'History'
|
|
||||||
|
|
||||||
# add user
|
|
||||||
data.created_by = @find( 'User', data.created_by_id )
|
|
||||||
|
|
||||||
# add possible actions
|
|
||||||
if data.history_attribute_id
|
|
||||||
data.attribute = @find( 'HistoryAttribute', data.history_attribute_id )
|
|
||||||
if data.history_type_id
|
|
||||||
data.type = @find( 'HistoryType', data.history_type_id )
|
|
||||||
if data.history_object_id
|
|
||||||
data.object = @find( 'HistoryObject', data.history_object_id )
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
else
|
|
||||||
return data
|
|
||||||
|
|
||||||
all: (params) ->
|
|
||||||
if !App[ params.type ]
|
|
||||||
@log 'error', 'all', 'no such collection', params
|
|
||||||
return
|
|
||||||
|
|
||||||
all = App[ params.type ].all()
|
|
||||||
all_complied = []
|
|
||||||
for item in all
|
|
||||||
item_new = @find( params.type, item.id )
|
|
||||||
all_complied.push item_new
|
|
||||||
|
|
||||||
if params.filter
|
|
||||||
all_complied = @_filter( all_complied, params.filter )
|
|
||||||
|
|
||||||
if params.filterExtended
|
|
||||||
all_complied = @_filterExtended( all_complied, params.filterExtended )
|
|
||||||
|
|
||||||
if params.sortBy
|
|
||||||
all_complied = @_sortBy( all_complied, params.sortBy )
|
|
||||||
|
|
||||||
if params.order
|
|
||||||
all_complied = @_order( all_complied, params.order )
|
|
||||||
|
|
||||||
return all_complied
|
|
||||||
|
|
||||||
findByAttribute: ( type, key, value ) ->
|
|
||||||
if !App[type]
|
|
||||||
@log 'error', 'findByAttribute', 'no such collection', type, key, value
|
|
||||||
return
|
|
||||||
item = App[type].findByAttribute( key, value )
|
|
||||||
if !item
|
|
||||||
@log 'error', 'findByAttribute', 'no such item in collection', type, key, value
|
|
||||||
return
|
|
||||||
item
|
|
||||||
|
|
||||||
_sortBy: ( collection, attribute ) ->
|
|
||||||
_.sortBy( collection, (item) ->
|
|
||||||
return '' if item[ attribute ] is undefined || item[ attribute ] is null
|
|
||||||
return item[ attribute ].toLowerCase()
|
|
||||||
)
|
|
||||||
|
|
||||||
_order: ( collection, attribute ) ->
|
|
||||||
if attribute is 'DESC'
|
|
||||||
return collection.reverse()
|
|
||||||
return collection
|
|
||||||
|
|
||||||
_filter: ( collection, filter ) ->
|
|
||||||
for key, value of filter
|
|
||||||
collection = _.filter( collection, (item) ->
|
|
||||||
if item[ key ] is value
|
|
||||||
return item
|
|
||||||
)
|
|
||||||
return collection
|
|
||||||
|
|
||||||
_filterExtended: ( collection, filters ) ->
|
|
||||||
collection = _.filter( collection, (item) ->
|
|
||||||
|
|
||||||
# check all filters
|
|
||||||
for filter in filters
|
|
||||||
|
|
||||||
# all conditions need match
|
|
||||||
matchInner = undefined
|
|
||||||
for key, value of filter
|
|
||||||
|
|
||||||
if matchInner isnt false
|
|
||||||
reg = new RegExp( value, 'i' )
|
|
||||||
if item[ key ] isnt undefined && item[ key ] isnt null && item[ key ].match( reg )
|
|
||||||
matchInner = true
|
|
||||||
else
|
|
||||||
matchInner = false
|
|
||||||
|
|
||||||
# if all matched, add item to new collection
|
|
||||||
if matchInner is true
|
|
||||||
return item
|
|
||||||
|
|
||||||
return
|
|
||||||
)
|
|
||||||
return collection
|
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ class _i18nSingleton extends Spine.Module
|
||||||
$(".translation[data-text='#{source}']").html( translation_new )
|
$(".translation[data-text='#{source}']").html( translation_new )
|
||||||
|
|
||||||
# update permanent translation map
|
# update permanent translation map
|
||||||
translation = App.Collection.findByAttribute( 'Translation', 'source', source )
|
translation = App.Translation.findByAttribute( 'source', source )
|
||||||
if translation
|
if translation
|
||||||
translation.updateAttribute( 'target', translation_new )
|
translation.updateAttribute( 'target', translation_new )
|
||||||
else
|
else
|
||||||
|
|
|
@ -91,7 +91,7 @@ class App.Model extends Spine.Model
|
||||||
@retrieve: ( id, callback, force ) ->
|
@retrieve: ( id, callback, force ) ->
|
||||||
if !force && App[ @className ].exists( id )
|
if !force && App[ @className ].exists( id )
|
||||||
data = App[ @className ].find( id )
|
data = App[ @className ].find( id )
|
||||||
# data = @_fillUp( @className, data )
|
data = @_fillUp( data )
|
||||||
if callback
|
if callback
|
||||||
callback( data )
|
callback( data )
|
||||||
return data
|
return data
|
||||||
|
@ -189,3 +189,73 @@ class App.Model extends Spine.Model
|
||||||
if @SUBSCRIPTION_COLLECTION
|
if @SUBSCRIPTION_COLLECTION
|
||||||
if @SUBSCRIPTION_COLLECTION[data]
|
if @SUBSCRIPTION_COLLECTION[data]
|
||||||
delete @SUBSCRIPTION_COLLECTION[data]
|
delete @SUBSCRIPTION_COLLECTION[data]
|
||||||
|
|
||||||
|
@_fillUp: (data) ->
|
||||||
|
# nothing
|
||||||
|
data
|
||||||
|
|
||||||
|
@search: (params) ->
|
||||||
|
all = @all()
|
||||||
|
all_complied = []
|
||||||
|
for item in all
|
||||||
|
item_new = @find( item.id )
|
||||||
|
all_complied.push item_new
|
||||||
|
|
||||||
|
if params.filter
|
||||||
|
all_complied = @_filter( all_complied, params.filter )
|
||||||
|
|
||||||
|
if params.filterExtended
|
||||||
|
all_complied = @_filterExtended( all_complied, params.filterExtended )
|
||||||
|
|
||||||
|
if params.sortBy
|
||||||
|
all_complied = @_sortBy( all_complied, params.sortBy )
|
||||||
|
|
||||||
|
if params.order
|
||||||
|
all_complied = @_order( all_complied, params.order )
|
||||||
|
|
||||||
|
return all_complied
|
||||||
|
|
||||||
|
@_sortBy: ( collection, attribute ) ->
|
||||||
|
_.sortBy( collection, (item) ->
|
||||||
|
return '' if item[ attribute ] is undefined || item[ attribute ] is null
|
||||||
|
return item[ attribute ].toLowerCase()
|
||||||
|
)
|
||||||
|
|
||||||
|
@_order: ( collection, attribute ) ->
|
||||||
|
if attribute is 'DESC'
|
||||||
|
return collection.reverse()
|
||||||
|
return collection
|
||||||
|
|
||||||
|
@_filter: ( collection, filter ) ->
|
||||||
|
for key, value of filter
|
||||||
|
collection = _.filter( collection, (item) ->
|
||||||
|
if item[ key ] is value
|
||||||
|
return item
|
||||||
|
)
|
||||||
|
return collection
|
||||||
|
|
||||||
|
@_filterExtended: ( collection, filters ) ->
|
||||||
|
collection = _.filter( collection, (item) ->
|
||||||
|
|
||||||
|
# check all filters
|
||||||
|
for filter in filters
|
||||||
|
|
||||||
|
# all conditions need match
|
||||||
|
matchInner = undefined
|
||||||
|
for key, value of filter
|
||||||
|
|
||||||
|
if matchInner isnt false
|
||||||
|
reg = new RegExp( value, 'i' )
|
||||||
|
if item[ key ] isnt undefined && item[ key ] isnt null && item[ key ].match( reg )
|
||||||
|
matchInner = true
|
||||||
|
else
|
||||||
|
matchInner = false
|
||||||
|
|
||||||
|
# if all matched, add item to new collection
|
||||||
|
if matchInner is true
|
||||||
|
return item
|
||||||
|
|
||||||
|
return
|
||||||
|
)
|
||||||
|
return collection
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,18 @@ class App.History extends App.Model
|
||||||
@configure 'History', 'name'
|
@configure 'History', 'name'
|
||||||
@extend Spine.Model.Ajax
|
@extend Spine.Model.Ajax
|
||||||
@url: '/histories'
|
@url: '/histories'
|
||||||
|
|
||||||
|
@_fillUp: (data) ->
|
||||||
|
|
||||||
|
# add user
|
||||||
|
data.created_by = App.User.find( data.created_by_id )
|
||||||
|
|
||||||
|
# add possible actions
|
||||||
|
if data.history_attribute_id
|
||||||
|
data.attribute = App.HistoryAttribute.find( data.history_attribute_id )
|
||||||
|
if data.history_type_id
|
||||||
|
data.type = App.HistoryType.find( data.history_type_id )
|
||||||
|
if data.history_object_id
|
||||||
|
data.object = App.HistoryObject.find( data.history_object_id )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,3 +19,31 @@ class App.Ticket extends App.Model
|
||||||
{ name: 'escalation_time', display: 'Escalation in', tag: 'time', null: true, style: 'width: 12%' },
|
{ name: 'escalation_time', display: 'Escalation in', tag: 'time', null: true, style: 'width: 12%' },
|
||||||
{ name: 'article_count', display: 'Article#', style: 'width: 12%' },
|
{ name: 'article_count', display: 'Article#', style: 'width: 12%' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@_fillUp: (data) ->
|
||||||
|
|
||||||
|
# priority
|
||||||
|
data.ticket_priority = App.TicketPriority.find( data.ticket_priority_id )
|
||||||
|
|
||||||
|
# state
|
||||||
|
data.ticket_state = App.TicketState.find( data.ticket_state_id )
|
||||||
|
|
||||||
|
# group
|
||||||
|
data.group = App.Group.find( data.group_id )
|
||||||
|
|
||||||
|
# customer
|
||||||
|
if data.customer_id
|
||||||
|
data.customer = App.User.find( data.customer_id )
|
||||||
|
|
||||||
|
# owner
|
||||||
|
if data.owner_id
|
||||||
|
data.owner = App.User.find( data.owner_id )
|
||||||
|
|
||||||
|
# add created & updated
|
||||||
|
if data.created_by_id
|
||||||
|
data.created_by = App.User.find( data.created_by_id )
|
||||||
|
if data.updated_by_id
|
||||||
|
data.updated_by = App.User.find( data.updated_by_id )
|
||||||
|
|
||||||
|
data
|
||||||
|
|
||||||
|
|
|
@ -13,3 +13,18 @@ class App.TicketArticle extends App.Model
|
||||||
{ name: 'ticket_article_sender_id', display: 'Sender', tag: 'select', multiple: false, null: false, relation: 'TicketArticleSender', default: '', class: 'medium' },
|
{ name: 'ticket_article_sender_id', display: 'Sender', tag: 'select', multiple: false, null: false, relation: 'TicketArticleSender', default: '', class: 'medium' },
|
||||||
{ name: 'internal', display: 'Visability', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium' },
|
{ name: 'internal', display: 'Visability', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@_fillUp: (data) ->
|
||||||
|
|
||||||
|
# add created & updated
|
||||||
|
if data.created_by_id
|
||||||
|
data.created_by = App.User.find( data.created_by_id )
|
||||||
|
if data.updated_by_id
|
||||||
|
data.updated_by = App.User.find( data.updated_by_id )
|
||||||
|
|
||||||
|
# add relations
|
||||||
|
data.article_type = App.TicketArticleType.find( data.ticket_article_type_id )
|
||||||
|
data.article_sender = App.TicketArticleSender.find( data.ticket_article_sender_id )
|
||||||
|
|
||||||
|
data
|
||||||
|
|
||||||
|
|
|
@ -29,3 +29,20 @@ class App.User extends App.Model
|
||||||
# 'login', 'firstname', 'lastname', 'email', 'updated_at',
|
# 'login', 'firstname', 'lastname', 'email', 'updated_at',
|
||||||
'login', 'firstname', 'lastname',
|
'login', 'firstname', 'lastname',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@_fillUp: (data) ->
|
||||||
|
|
||||||
|
# set socal media links
|
||||||
|
if data['accounts']
|
||||||
|
for account of data['accounts']
|
||||||
|
if account == 'twitter'
|
||||||
|
data['accounts'][account]['link'] = 'http://twitter.com/' + data['accounts'][account]['username']
|
||||||
|
if account == 'facebook'
|
||||||
|
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
|
||||||
|
|
||||||
|
# set image url
|
||||||
|
if !data.image
|
||||||
|
data.image = 'http://placehold.it/48x48'
|
||||||
|
|
||||||
|
data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue