diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 7f7afbfa4..c73bb3750 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -261,11 +261,11 @@ class App.Controller extends Spine.Controller placement: position title: -> ticket_id = $(@).data('id') - ticket = App.Collection.find( 'Ticket', ticket_id ) + ticket = App.Ticket.find( ticket_id ) ticket.title content: -> ticket_id = $(@).data('id') - ticket = App.Collection.find( 'Ticket', ticket_id ) + ticket = App.Ticket.find( ticket_id ) ticket.humanTime = ui.humanTime(ticket.created_at) # insert data App.view('ticket_info_small')( @@ -287,11 +287,11 @@ class App.Controller extends Spine.Controller placement: position title: -> user_id = $(@).data('id') - user = App.Collection.find( 'User', user_id ) + user = App.User.find( user_id ) user.displayName() content: -> user_id = $(@).data('id') - user = App.Collection.find( 'User', user_id ) + user = App.User.find( user_id ) # get display data data = [] @@ -333,11 +333,11 @@ class App.Controller extends Spine.Controller placement: position title: -> organization_id = $(@).data('id') - organization = App.Collection.find( 'Organization', organization_id ) + organization = App.Organization.find( organization_id ) organization.name content: -> organization_id = $(@).data('id') - organization = App.Collection.find( 'Organization', organization_id ) + organization = App.Organization.find( organization_id ) # insert data App.view('organization_info_small')( organization: organization, diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index 248c073ee..f4b6cbb1e 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -1124,7 +1124,7 @@ class App.ControllerForm extends App.Controller if typeof attribute.filter is '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' ) @@ -1135,7 +1135,7 @@ class App.ControllerForm extends App.Controller App.Log.debug 'ControllerForm', '_getRelationOptionList:filter-data', filter # 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 for key in filter @@ -1148,10 +1148,10 @@ class App.ControllerForm extends App.Controller # no data filter matched else 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 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 diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index 13085a58e..530565c56 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -133,10 +133,7 @@ class App.ControllerGenericIndex extends App.ControllerContent render: => - objects = App.Collection.all( - type: @genericObject, - sortBy: @defaultSortBy || 'name', - ) + objects = App[@genericObject].search( sortBy: @defaultSortBy || 'name' ) # remove ignored items from collection if @ignoreObjectIDs diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee index 90fd597b4..b9e4dc504 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.js.coffee @@ -106,8 +106,8 @@ class App.ControllerTable extends App.Controller rowWithoutId = row.name + '_id' for attribute in attributes if rowWithoutId is attribute.name - if attribute.relation && App[attribute.relation] - record = App.Collection.find( attribute.relation, object[rowWithoutId] ) + if attribute.relation && App[ attribute.relation ] + record = App[ attribute.relation ].find( object[rowWithoutId] ) object[row.name] = record.name @log 'debug', 'table', 'header', header, 'overview', dataTypesForCols, 'objects', data.objects diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index d799d68d3..d5cc0ea1c 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -51,15 +51,15 @@ class App.DashboardActivityStream extends App.Controller # load user data 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 for item in items item.data = {} 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' - article = App.Collection.find( 'TicketArticle', item.o_id ) + article = App.TicketArticle.find( item.o_id ) item.history_object = 'Article' item.sub_o_id = article.id item.o_id = article.ticket_id diff --git a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee index 149509389..dfca5830c 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -33,11 +33,11 @@ class App.DashboardRecentViewed extends App.Controller # load user data 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 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')( head: 'Recent Viewed', diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index d64404a97..5f433d4e8 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -50,7 +50,7 @@ class App.DashboardTicket extends App.Controller # load user collection App.Collection.load( type: 'User', data: data.collections.users ) - + # load ticket collection App.Collection.load( type: 'Ticket', data: data.collections.tickets ) @@ -95,7 +95,7 @@ class App.DashboardTicket extends App.Controller while i < end i = 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 ) new App.ControllerTable( diff --git a/app/assets/javascripts/app/controllers/_profile/language.js.coffee b/app/assets/javascripts/app/controllers/_profile/language.js.coffee index 8759a9d1c..a86a78ba2 100644 --- a/app/assets/javascripts/app/controllers/_profile/language.js.coffee +++ b/app/assets/javascripts/app/controllers/_profile/language.js.coffee @@ -45,8 +45,7 @@ class App.ProfileLanguage extends App.Controller ) success: (data, status, xhr) => - App.Collection.find( - 'User', + App.User.retrieve( App.Session.get( 'id' ), => App.i18n.set( @locale ) @@ -57,7 +56,7 @@ class App.ProfileLanguage extends App.Controller msg: App.i18n.translateContent( 'Successfully!' ) ) , - true, + true ) error: (xhr, status, error) => diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index 7fd940994..349678c02 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -136,8 +136,8 @@ class App.TicketCreate extends App.Controller App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) # render page - t = App.Collection.find( 'Ticket', params.ticket_id ).attributes() - a = App.Collection.find( 'TicketArticle', params.article_id ) + t = App.Ticket.find( params.ticket_id ).attributes() + a = App.TicketArticle.find( params.article_id ) # reset owner t.owner_id = 0 @@ -151,8 +151,8 @@ class App.TicketCreate extends App.Controller # set defaults defaults = - ticket_state_id: App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id - ticket_priority_id: App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id + ticket_state_id: App.TicketState.findByAttribute( 'name', 'open' ).id + ticket_priority_id: App.TicketPriority.findByAttribute( 'name', '2 normal' ).id # generate form configure_attributes = [ @@ -250,11 +250,11 @@ class App.TicketCreate extends App.Controller object = new App.Ticket # find sender_id - sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', @article_attributes['sender'] ) - type = App.Collection.findByAttribute( 'TicketArticleType', 'name', @article_attributes['article'] ) + sender = App.TicketArticleSender.findByAttribute( 'name', @article_attributes['sender'] ) + type = App.TicketArticleType.findByAttribute( 'name', @article_attributes['article'] ) if params.group_id - group = App.Collection.find( 'Group', params.group_id ) + group = App.Group.find( params.group_id ) # create article if sender.name is 'Customer' @@ -356,7 +356,7 @@ class UserNew extends App.ControllerModal user = new App.User # find role_id - role = App.Collection.findByAttribute( 'Role', 'name', 'Customer' ) + role = App.Role.findByAttribute( 'name', 'Customer' ) params.role_ids = role.id @log 'notice', 'updateAttributes', params user.load(params) @@ -381,7 +381,7 @@ class UserNew extends App.ControllerModal # start customer info controller ui.userInfo( user_id: user.id ) ui.modalHide() - App.Collection.find( 'User', @id, callbackReload , true ) + App.User.retrieve( @id, callbackReload , true ) error: -> ui.modalHide() diff --git a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee index 81e254dc9..4e0c25691 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -44,7 +44,7 @@ class App.TicketHistory extends App.ControllerModal render: -> @html App.view('agent_ticket_history')( - objects: App.Collection.all( type: 'History' ), + objects: App.History.all() ) @modalShow() @@ -62,14 +62,14 @@ class App.TicketHistory extends App.ControllerModal if isSorted.length @sortstate = 'notsorted' @html App.view('agent_ticket_history')( - objects: App.Collection.all( type: 'History' ), - state: @sortstate + objects: App.History.all() + state: @sortstate ) else @sortstate = 'sorted' @html App.view('agent_ticket_history')( - objects: App.Collection.all( type: 'History' ).reverse(), - state: @sortstate + objects: App.History.all().reverse() + state: @sortstate ) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index e95dfc545..ab46ca86a 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -34,7 +34,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for t in data.customer.tickets if t.id isnt @ticket_id - ticketItem = App.Collection.find( 'Ticket', t.id ) + ticketItem = App.Ticket.retrieve( t.id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-customer-tickets'), @@ -61,7 +61,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for t in data.recent.tickets if t.id isnt @ticket_id - ticketItem = App.Collection.find( 'Ticket', t.id ) + ticketItem = App.Ticket.retrieve( t.id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-recent-tickets'), @@ -92,7 +92,7 @@ class App.TicketMerge extends App.ControllerModal @el.delegate('[name="radio"]', 'click', (e) -> if $(e.target).prop('checked') 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 ) ) @@ -124,7 +124,7 @@ class App.TicketMerge extends App.ControllerModal @modalHide() # 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'] # notify UI diff --git a/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee index 9196fac7b..a80578648 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_view.js.coffee @@ -68,7 +68,7 @@ class Index extends App.ControllerContent # load user collection App.Collection.load( type: 'User', data: data.collections.users ) - + # load ticket collection App.Collection.load( type: 'Ticket', data: data.collections.tickets ) @@ -88,7 +88,7 @@ class Index extends App.ControllerContent @ticket_list_show = [] 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 @bulk = data.bulk diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee index ad2e0afb4..f0275f221 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee @@ -62,8 +62,8 @@ class Index extends App.ControllerContent App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) # render page - t = App.Collection.find( 'Ticket', params.ticket_id ).attributes() - a = App.Collection.find( 'TicketArticle', params.article_id ) + t = App.Ticket.find( params.ticket_id ).attributes() + a = App.TicketArticle.find( params.article_id ) # reset owner t.owner_id = 0 @@ -79,9 +79,9 @@ class Index extends App.ControllerContent # set defaults defaults = template['options'] || {} 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 ) - defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) + defaults['ticket_priority_id'] = App.TicketPriority.findByAttribute( 'name', '2 normal' ) groupFilter = (collection, type) => @@ -148,11 +148,11 @@ class Index extends App.ControllerContent params.customer_id = @Session.get('id') # set prio - priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) + priority = App.TicketPriority.findByAttribute( 'name', '2 normal' ) params.ticket_priority_id = priority.id # set state - state = App.Collection.findByAttribute( 'TicketState', 'name', 'new' ) + state = App.TicketState.findByAttribute( 'name', 'new' ) params.ticket_state_id = state.id # fillup params @@ -164,10 +164,10 @@ class Index extends App.ControllerContent @log 'CustomerTicketCreate', 'notice', 'updateAttributes', params # find sender_id - sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' ) - type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' ) + sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) + type = App.TicketArticleType.findByAttribute( 'name', 'web' ) if params.group_id - group = App.Collection.find( 'Group', params.group_id ) + group = App.Group.find( params.group_id ) # create article params['article'] = { diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index 638fb796a..2325f73e0 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -76,7 +76,7 @@ class Index extends App.ControllerContent @params.invite = true # find agent role - role = App.Collection.findByAttribute( 'Role', 'name', 'Agent' ) + role = App.Role.findByAttribute( 'name', 'Agent' ) if role @params.role_ids = role.id else diff --git a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee index bd2b23ebe..ac7730bbf 100644 --- a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee @@ -40,7 +40,7 @@ class App.LinkInfo extends App.Controller list[ item['link_type'] ] = [] 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' ticket.css = 'merged' list[ item['link_type'] ].push ticket diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index c7fbe4a5d..71cda4b4c 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -102,7 +102,7 @@ class App.Navigation extends App.Controller if organization.user_ids organization.users = [] for user_id in organization.user_ids - user = App.Collection.find( 'User', user_id ) + user = App.User.find( user_id ) organization.users.push user App.Collection.load( type: 'Organization', data: data.load.organizations ) @@ -116,7 +116,7 @@ class App.Navigation extends App.Controller if area.name is 'Ticket' area.result = [] for id in area.ids - ticket = App.Collection.find( 'Ticket', id ) + ticket = App.Ticket.find( id ) ticket.humanTime = @humanTime(ticket.created_at) data = display: "##{ticket.number} - #{ticket.title} - #{ticket.humanTime}" @@ -127,7 +127,7 @@ class App.Navigation extends App.Controller else if area.name is 'User' area.result = [] for id in area.ids - user = App.Collection.find( 'User', id ) + user = App.User.find( id ) data = display: "#{user.displayName()}" id: user.id @@ -137,7 +137,7 @@ class App.Navigation extends App.Controller else if area.name is 'Organization' area.result = [] for id in area.ids - organization = App.Collection.find( 'Organization', id ) + organization = App.Organization.find( id ) data = display: "#{organization.displayName()}" id: organization.id @@ -329,7 +329,7 @@ class App.Navigation extends App.Controller if prio is 8000 divider = true navheader = 'Recent Viewed' - ticket = App.Collection.find( 'Ticket', item.o_id ) + ticket = App.Ticket.find( item.o_id ) prio++ NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = { prio: prio, diff --git a/app/assets/javascripts/app/controllers/template_widget.js.coffee b/app/assets/javascripts/app/controllers/template_widget.js.coffee index 6ff904477..c24661ba1 100644 --- a/app/assets/javascripts/app/controllers/template_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/template_widget.js.coffee @@ -58,7 +58,7 @@ class App.TemplateUI extends App.Controller name = params['template_name'] # delete params['template_name'] - template = App.Collection.findByAttribute( 'Template', 'name', name ) + template = App.Template.findByAttribute( 'name', name ) if !template template = new App.Template diff --git a/app/assets/javascripts/app/controllers/text_module_widget.js.coffee b/app/assets/javascripts/app/controllers/text_module_widget.js.coffee index 7681e1541..4af73778a 100644 --- a/app/assets/javascripts/app/controllers/text_module_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/text_module_widget.js.coffee @@ -201,8 +201,7 @@ class App.TextModuleUIOld extends App.Controller @renderTable('') objectSearch: (search) => - objects = App.Collection.all( - type: 'TextModule', + objects = App.TextModule.search( sortBy: 'name', filter: { active: true }, filterExtended: [ { name: "^#{search}" }, { content: search }, { keywords: search } ], @@ -226,7 +225,7 @@ class App.TextModuleUIOld extends App.Controller # @el.find('.popover-inner').parent().remove() $('.popover').remove() - # show user popup + # show user popup @el.find('#form-text-module').find('.item').popover( trigger: 'hover' html: true @@ -235,18 +234,18 @@ class App.TextModuleUIOld extends App.Controller placement: 'right' title: -> id = $(@).data('id') - text_module = App.Collection.find( 'TextModule', id ) + text_module = App.TextModule.find( id ) text_module.name content: -> id = $(@).data('id') - text_module = App.Collection.find( 'TextModule', id ) + text_module = App.TextModule.find( id ) text_module.content ) paste: (e) => e.preventDefault() id = $(e.target).parents('tr').data('id') - text_module = App.Collection.find( 'TextModule', id ) + text_module = App.TextModule.find( id ) @_insert( text_module.content, @ ) delete: (e) => @@ -254,15 +253,15 @@ class App.TextModuleUIOld extends App.Controller # get params 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?') - text_module.destroy() + text_module.destroy() @render() select: (e) => e.preventDefault() 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_name').val( text_module.name ) @@ -274,7 +273,7 @@ class App.TextModuleUIOld extends App.Controller name = params['name'] # delete params['text_module_name'] - text_module = App.Collection.findByAttribute( 'TextModule', 'name', name ) + text_module = App.TextModule.findByAttribute( 'name', name ) if !text_module text_module = new App.TextModule diff --git a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee index a39ab8bbc..8fc9ae6eb 100644 --- a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee @@ -40,4 +40,4 @@ class App.TicketCustomer extends App.ControllerModal @zoom.render() # load user if not already exists - App.Collection.find( 'User', params['customer_id'], callback ) + App.User.retrieve( params['customer_id'], callback ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index f54d537a2..d4486e604 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -27,7 +27,7 @@ class App.TicketZoom extends App.Controller (data) => update = => 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 if data.updated_at isnt ticket.updated_at @fetch( @ticket_id, false ) @@ -37,7 +37,7 @@ class App.TicketZoom extends App.Controller meta: => return if !@ticket - ticket = App.Collection.find( 'Ticket', @ticket.id ) + ticket = App.Ticket.retrieve( @ticket.id ) meta = url: @url() head: ticket.title @@ -135,7 +135,7 @@ class App.TicketZoom extends App.Controller render: (force) => # get data - @ticket = App.Collection.find( 'Ticket', @ticket_id ) + @ticket = App.Ticket.retrieve( @ticket_id ) # update taskbar with new meta data App.Event.trigger 'task:render' @@ -249,7 +249,7 @@ class TicketTitle extends App.Controller title = '' # update title - ticket = App.Collection.find( 'Ticket', @ticket.id ) + ticket = App.Ticket.retrieve( @ticket.id ) ticket.title = title ticket.load( title: title ) ticket.save() @@ -325,7 +325,7 @@ class Edit extends App.Controller render: -> - ticket = App.Collection.find( 'Ticket', @ticket.id ) + ticket = App.Ticket.retrieve( @ticket.id ) @html App.view('ticket_zoom/edit')( ticket: ticket @@ -445,10 +445,10 @@ class Edit extends App.Controller @autosaveStop() params = @formParam(e.target) - ticket = App.Collection.find( 'Ticket', @ticket.id ) + ticket = App.Ticket.retrieve( @ticket.id ) @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 ticket_update = {} @@ -514,11 +514,11 @@ class Edit extends App.Controller # find sender_id if @isRole('Customer') - sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Customer' ) - type = App.Collection.findByAttribute( 'TicketArticleType', 'name', 'web' ) + sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' ) + type = App.TicketArticleType.findByAttribute( 'name', 'web' ) params['ticket_article_type_id'] = type.id else - sender = App.Collection.findByAttribute( 'TicketArticleSender', 'name', 'Agent' ) + sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' ) params.ticket_article_sender_id = sender.id @log 'notice', 'update article', params, sender article.load(params) @@ -570,7 +570,7 @@ class ArticleView extends App.Controller # get all articles @articles = [] for article_id in @ticket.article_ids - article = App.Collection.find( 'TicketArticle', article_id ) + article = App.TicketArticle.retrieve( article_id ) @articles.push article # rework articles @@ -633,9 +633,9 @@ class ArticleView extends App.Controller reply: (e) => e.preventDefault() article_id = $(e.target).parents('[data-id]').data('id') - article = App.Collection.find( 'TicketArticle', article_id ) - article_type = App.Collection.find( 'TicketArticleType', article.ticket_article_type_id ) - customer = App.Collection.find( 'User', article.created_by_id ) + article = App.TicketArticle.find( article_id ) + article_type = App.TicketArticleType.find( article.ticket_article_type_id ) + customer = App.User.find( article.created_by_id ) # update form @checkIfSignatureIsNeeded(article_type) diff --git a/app/assets/javascripts/app/controllers/user_info_widget.js.coffee b/app/assets/javascripts/app/controllers/user_info_widget.js.coffee index 998fbb6f8..326da3233 100644 --- a/app/assets/javascripts/app/controllers/user_info_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/user_info_widget.js.coffee @@ -57,7 +57,7 @@ class App.UserInfo extends App.Controller # update changes update: (e) => 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 user.updateAttributes( note: note ) @log 'notice', 'update', e, note, user diff --git a/app/assets/javascripts/app/lib/app_post/collection.js.coffee b/app/assets/javascripts/app/lib/app_post/collection.js.coffee index b66793d95..63476a2cc 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.js.coffee @@ -14,21 +14,6 @@ class App.Collection _instance ?= new _collectionSingleton _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 @include App.LogInclude @@ -114,196 +99,3 @@ class _collectionSingleton extends Spine.Module if !localStorage 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 - diff --git a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee index 27ddbad71..8edf82ed2 100644 --- a/app/assets/javascripts/app/lib/app_post/i18n.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/i18n.js.coffee @@ -77,7 +77,7 @@ class _i18nSingleton extends Spine.Module $(".translation[data-text='#{source}']").html( translation_new ) # update permanent translation map - translation = App.Collection.findByAttribute( 'Translation', 'source', source ) + translation = App.Translation.findByAttribute( 'source', source ) if translation translation.updateAttribute( 'target', translation_new ) else diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 73a73c545..b972686f2 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -91,7 +91,7 @@ class App.Model extends Spine.Model @retrieve: ( id, callback, force ) -> if !force && App[ @className ].exists( id ) data = App[ @className ].find( id ) -# data = @_fillUp( @className, data ) + data = @_fillUp( data ) if callback callback( data ) return data @@ -189,3 +189,73 @@ class App.Model extends Spine.Model if @SUBSCRIPTION_COLLECTION if @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 + diff --git a/app/assets/javascripts/app/models/history.js.coffee b/app/assets/javascripts/app/models/history.js.coffee index 2c4b2cc17..51d34727d 100644 --- a/app/assets/javascripts/app/models/history.js.coffee +++ b/app/assets/javascripts/app/models/history.js.coffee @@ -2,3 +2,18 @@ class App.History extends App.Model @configure 'History', 'name' @extend Spine.Model.Ajax @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 ) + + diff --git a/app/assets/javascripts/app/models/ticket.js.coffee b/app/assets/javascripts/app/models/ticket.js.coffee index ad53ee2f8..6c296cde0 100644 --- a/app/assets/javascripts/app/models/ticket.js.coffee +++ b/app/assets/javascripts/app/models/ticket.js.coffee @@ -19,3 +19,31 @@ class App.Ticket extends App.Model { name: 'escalation_time', display: 'Escalation in', tag: 'time', null: true, 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 + diff --git a/app/assets/javascripts/app/models/ticket_article.js.coffee b/app/assets/javascripts/app/models/ticket_article.js.coffee index 9d6df962a..b7f9379fd 100644 --- a/app/assets/javascripts/app/models/ticket_article.js.coffee +++ b/app/assets/javascripts/app/models/ticket_article.js.coffee @@ -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: '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 + diff --git a/app/assets/javascripts/app/models/user.js.coffee b/app/assets/javascripts/app/models/user.js.coffee index f0bea6b88..0f7461ea4 100644 --- a/app/assets/javascripts/app/models/user.js.coffee +++ b/app/assets/javascripts/app/models/user.js.coffee @@ -29,3 +29,20 @@ class App.User extends App.Model # 'login', 'firstname', 'lastname', 'email', 'updated_at', '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 +