Browse Source

First stage of migration to object assets for frontend.

Martin Edenhofer 11 years ago
parent
commit
ddc99ca406

+ 15 - 32
app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee

@@ -1,10 +1,6 @@
 class App.DashboardActivityStream extends App.Controller
-  events:
-    'click [data-type=edit]': 'zoom'
-
   constructor: ->
     super
-    @items = []
 
     @fetch()
 
@@ -36,34 +32,29 @@ class App.DashboardActivityStream extends App.Controller
   load: (data) =>
     items = data.activity_stream
 
-    # load user collection
-    App.Collection.load( type: 'User', data: data.users )
-
-    # load ticket collection
-    App.Collection.load( type: 'Ticket', data: data.tickets )
-
-    # load article collection
-    App.Collection.load( type: 'TicketArticle', data: data.articles )
+    # load collections
+    App.Event.trigger 'loadAssets', data.assets
 
     @render(items)
 
   render: (items) ->
 
-    # load user data
     for item in items
-      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.Ticket.find( item.o_id ).title
-      if item.history_object is 'Ticket::Article'
+        ticket = App.Ticket.find( item.o_id )
+        item.link = '#ticket_zoom/' + ticket.id
+        item.title = ticket.title
+        item.type  = item.history_object
+        item.updated_by_id = ticket.updated_by_id
+        item.updated_by = App.User.find( ticket.updated_by_id )
+      else if item.history_object is 'Ticket::Article'
         article = App.TicketArticle.find( item.o_id )
-        item.history_object = 'Article'
-        item.sub_o_id = article.id
-        item.o_id = article.ticket_id
-        item.data.title = article.subject
+        ticket  = App.Ticket.find( article.ticket_id )
+        item.link = '#ticket_zoom/' + ticket.id + '/' + article.od
+        item.title = article.subject || ticket.title
+        item.type  = item.history_object
+        item.updated_by_id = article.updated_by_id
+        item.updated_by = App.User.find( article.updated_by_id )
 
     html = App.view('dashboard/activity_stream')(
       head: 'Activity Stream',
@@ -76,11 +67,3 @@ class App.DashboardActivityStream extends App.Controller
     # start user popups
     @userPopups('left')
 
-  zoom: (e) =>
-    e.preventDefault()
-    id = $(e.target).parents('[data-id]').data('id')
-    subid = $(e.target).parents('[data-subid]').data('subid')
-    if subid
-      @navigate 'ticket/zoom/' + id + '/' + subid
-    else
-      @navigate 'ticket/zoom/' + id

+ 5 - 21
app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee

@@ -1,7 +1,4 @@
 class App.DashboardRecentViewed extends App.Controller
-  events:
-    'click [data-type=edit]': 'zoom'
-
   constructor: ->
     super
 
@@ -16,28 +13,21 @@ class App.DashboardRecentViewed extends App.Controller
         limit: 5,
       }
       processData: true,
-#      data: JSON.stringify( view: @view ),
       success: (data, status, xhr) =>
         @items = data.recent_viewed
 
-        # load user collection
-        App.Collection.load( type: 'User', data: data.users )
-
-        # load ticket collection
-        App.Collection.load( type: 'Ticket', data: data.tickets )
+        # load collections
+        App.Event.trigger 'loadAssets', data.assets
 
         @render()
     )
 
   render: ->
 
-    # load user data
-    for item in @items
-      item.created_by = App.User.find( item.created_by_id )
-
-    # load ticket data
     for item in @items
-      item.ticket = App.User.find( item.o_id )
+      item.link = '#ticket_zoom/' + item.o_id
+      item.title = App.Ticket.find( item.o_id ).title
+      item.type  = item.recent_view_object
 
     html = App.view('dashboard/recent_viewed')(
       head: 'Recent Viewed',
@@ -49,9 +39,3 @@ class App.DashboardRecentViewed extends App.Controller
 
     # start user popups
     @userPopups('left')
-
-  zoom: (e) =>
-    e.preventDefault()
-    id = $(e.target).parents('[data-id]').data('id')
-
-    @navigate 'ticket/zoom/' + id

+ 6 - 9
app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee

@@ -48,11 +48,8 @@ class App.DashboardTicket extends App.Controller
       data.ajax = false
       App.Store.write( @key, data )
 
-      # load user collection
-      App.Collection.load( type: 'User', data: data.collections.users )
-
-      # load ticket collection
-      App.Collection.load( type: 'Ticket', data: data.collections.tickets )
+      # load collections
+      App.Event.trigger 'loadAssets', data.assets
 
     # get meta data
     App.Overview.refresh( data.overview, options: { clear: true } )
@@ -71,12 +68,12 @@ class App.DashboardTicket extends App.Controller
 
   render: (data) ->
     return if !data
-    return if !data.ticket_list
+    return if !data.ticket_ids
     return if !data.overview
 
     @overview      = data.overview
     @tickets_count = data.tickets_count
-    @ticket_list   = data.ticket_list
+    @ticket_ids    = data.ticket_ids
     # FIXME 10
     pages_total =  parseInt( ( @tickets_count / 10 ) + 0.99999 ) || 1
     html = App.view('dashboard/ticket')(
@@ -94,8 +91,8 @@ class App.DashboardTicket extends App.Controller
     i = start
     while i < end
       i = i + 1
-      if @ticket_list[ i - 1 ]
-        @tickets_in_table.push App.Ticket.retrieve( @ticket_list[ i - 1 ] )
+      if @ticket_ids[ i - 1 ]
+        @tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] )
 
     shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d )
     new App.ControllerTable(

+ 27 - 18
app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee

@@ -35,12 +35,18 @@ class App.TicketCreate extends App.Controller
         title:   'Email'
     @article_attributes = article_sender_type_map[@type]
 
+    # remember split info if exists
+    split = ''
+    if @ticket_id && @article_id
+      split = "/#{@ticket_id}/#{@article_id}"
+
     # if no map entry exists, route to default
     if !@article_attributes
-      @navigate '#ticket_create/' + default_type
+      @navigate '#ticket_create/' + default_type + split
+      return
 
     # update navbar highlighting
-    @navupdate '#ticket_create/' + @type + '/id/' + @id
+    @navupdate '#ticket_create/' + @type + '/id/' + @id + split
 
     @fetch(params)
 
@@ -97,8 +103,8 @@ class App.TicketCreate extends App.Controller
       # get edit form attributes
       @edit_form = cache.edit_form
 
-      # load user collection
-      App.Collection.load( type: 'User', data: cache.users )
+      # load collections
+      App.Event.trigger 'loadAssets', cache.assets
 
       @render()
     else
@@ -118,17 +124,11 @@ class App.TicketCreate extends App.Controller
           # get edit form attributes
           @edit_form = data.edit_form
 
-          # load user collection
-          App.Collection.load( type: 'User', data: data.users )
-
-          # load ticket collection
-          if data.ticket && data.articles
-            App.Collection.load( type: 'Ticket', data: [data.ticket] )
+          # load collections
+          App.Event.trigger 'loadAssets', data.assets
 
-            # load article collections
-            App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
-
-            # render page
+          # split ticket
+          if data.split && data.split.ticket_id && data.split.article_id
             t = App.Ticket.find( params.ticket_id ).attributes()
             a = App.TicketArticle.find( params.article_id )
 
@@ -137,6 +137,8 @@ class App.TicketCreate extends App.Controller
             t.customer_id_autocompletion = a.from
             t.subject = a.subject || t.title
             t.body = a.body
+
+          # render page
           @render( options: t )
       )
 
@@ -386,8 +388,13 @@ class TicketCreateRouter extends App.ControllerPermanent
 
     # create new uniq form id
     if !params['id']
+      # remember split info if exists
+      split = ''
+      if params['ticket_id'] && params['article_id']
+        split = "/#{params['ticket_id']}/#{params['article_id']}"
+
       id = Math.floor( Math.random() * 99999 )
-      @navigate "#ticket_create/#{params['type']}/id/#{id}"
+      @navigate "#ticket_create/#{params['type']}/id/#{id}#{split}" 
       return
 
     # cleanup params
@@ -399,14 +406,16 @@ class TicketCreateRouter extends App.ControllerPermanent
 
     App.TaskManager.add( 'TicketCreateScreen-' + params['type'] + '-' + params['id'], 'TicketCreate', clean_params )
 
-# split ticket
-App.Config.set( 'ticket_create/:ticket_id/:article_id', TicketCreateRouter, 'Routes' )
-
 # create new ticket routs/controller
 App.Config.set( 'ticket_create', TicketCreateRouter, 'Routes' )
 App.Config.set( 'ticket_create/:type', TicketCreateRouter, 'Routes' )
 App.Config.set( 'ticket_create/:type/id/:id', TicketCreateRouter, 'Routes' )
 
+
+# split ticket
+App.Config.set( 'ticket_create/:type/:ticket_id/:article_id', TicketCreateRouter, 'Routes' )
+App.Config.set( 'ticket_create/:type/id/:id/:ticket_id/:article_id', TicketCreateRouter, 'Routes' )
+
 # set new task actions
 App.Config.set( 'TicketNewCallOutbound', { prio: 8001, name: 'Call Outbound', target: '#ticket_create/call_outbound', role: ['Agent'] }, 'TaskActions' )
 App.Config.set( 'TicketNewCallInbound', { prio: 8002, name: 'Call Inbound', target: '#ticket_create/call_inbound', role: ['Agent'] }, 'TaskActions' )

+ 3 - 18
app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee

@@ -15,23 +15,9 @@ class App.TicketHistory extends App.ControllerModal
       type:  'GET',
       url:   @apiPath + '/ticket_history/' + ticket_id,
       success: (data, status, xhr) =>
-        # remember ticket
-        @ticket = data.ticket
 
-        # load user collection
-        App.Collection.load( type: 'User', data: data.users )
-
-        # load ticket collection
-        App.Collection.load( type: 'Ticket', data: [data.ticket] )
-
-        # load history_type collections
-        App.Collection.load( type: 'HistoryType', data: data.history_types )
-
-        # load history_object collections
-        App.Collection.load( type: 'HistoryObject', data: data.history_objects )
-
-        # load history_attributes collections
-        App.Collection.load( type: 'HistoryAttribute', data: data.history_attributes )
+        # load collections
+        App.Event.trigger 'loadAssets', data.assets
 
         # load history collections
         App.History.deleteAll()
@@ -53,7 +39,7 @@ class App.TicketHistory extends App.ControllerModal
     @userPopups()
 
     # show frontend times
-    @delay( @frontendTimeUpdate, 200, 'ui-time-update' )
+    @delay( @frontendTimeUpdate, 300, 'ui-time-update' )
 
   sortorder: (e) ->
     e.preventDefault()
@@ -72,7 +58,6 @@ class App.TicketHistory extends App.ControllerModal
         state:   @sortstate
       )
 
-
     @modalShow()
 
     # enable user popups

+ 6 - 27
app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee

@@ -24,13 +24,13 @@ class Index extends App.ControllerContent
     # use cache
     cache = App.Store.get( 'ticket_create_attributes' )
 
-    if cache && !params.ticket_id && !params.article_id
+    if cache
 
       # get edit form attributes
       @edit_form = cache.edit_form
 
-      # load user collection
-      App.Collection.load( type: 'User', data: cache.users )
+      # load collections
+      App.Event.trigger 'loadAssets', cache.assets
 
       @render()
     else
@@ -38,10 +38,6 @@ class Index extends App.ControllerContent
         id:    'ticket_create',
         type:  'GET',
         url:   @apiPath + '/ticket_create',
-        data:  {
-          ticket_id: params.ticket_id,
-          article_id: params.article_id,
-        },
         processData: true,
         success: (data, status, xhr) =>
 
@@ -51,27 +47,10 @@ class Index extends App.ControllerContent
           # get edit form attributes
           @edit_form = data.edit_form
 
-          # load user collection
-          App.Collection.load( type: 'User', data: data.users )
+          # load collections
+          App.Event.trigger 'loadAssets', data.assets
 
-          # load ticket collection
-          if data.ticket && data.articles
-            App.Collection.load( type: 'Ticket', data: [data.ticket] )
-
-            # load article collections
-            App.Collection.load( type: 'TicketArticle', data: data.articles || [] )
-
-            # render page
-            t = App.Ticket.find( params.ticket_id ).attributes()
-            a = App.TicketArticle.find( params.article_id )
-
-            # reset owner
-            t.owner_id = 0
-            t.customer_id_autocompletion = a.from
-            t.subject = a.subject || t.title
-            t.body = a.body
-            @log 'CustomerTicketCreate', 'notice', 'created', t
-          @render( options: t )
+          @render()
       )
 
   render: (template = {}) ->

+ 3 - 3
app/assets/javascripts/app/controllers/dashboard.js.coffee

@@ -53,9 +53,9 @@ class Index extends App.ControllerContent
 #          },
 #        },
 
-#        recent_viewed: {
-#          controller: App.DashboardRecentViewed,
-#        }
+        recent_viewed: {
+          controller: App.DashboardRecentViewed,
+        }
       }
     }
 

+ 2 - 5
app/assets/javascripts/app/controllers/link_info_widget.js.coffee

@@ -23,11 +23,8 @@ class App.LinkInfo extends App.Controller
       success: (data, status, xhr) =>
         @links = data.links
 
-        # load user collection
-        App.Collection.load( type: 'User', data: data.users )
-
-        # load ticket collection
-        App.Collection.load( type: 'Ticket', data: data.tickets )
+        # load collections
+        App.Event.trigger 'loadAssets', data.assets
 
         @render()
     )

+ 23 - 23
app/assets/javascripts/app/controllers/ticket_zoom.js.coffee

@@ -82,7 +82,7 @@ class App.TicketZoom extends App.Controller
           @log 'diff', diff
 
           # notify if ticket changed not by my self
-          if !_.isEmpty(diff) && data.ticket.updated_by_id isnt @Session.all().id
+          if !_.isEmpty(diff) && data.asset.ticket[0].updated_by_id isnt @Session.all().id
             App.TaskManager.notify( @task_key )
 
           # rerender edit box
@@ -112,20 +112,19 @@ class App.TicketZoom extends App.Controller
     # reset old indexes
     @ticket = undefined
 
+
+    # remember article ids
+    @ticket_article_ids = data.ticket_article_ids
+
+
     # get edit form attributes
     @edit_form = data.edit_form
 
     # get signature
     @signature = data.signature
 
-    # load user collection
-    App.Collection.load( type: 'User', data: data.users )
-
-    # load ticket collection
-    App.Collection.load( type: 'Ticket', data: [data.ticket] )
-
-    # load article collections
-    App.Collection.load( type: 'TicketArticle', data: data.articles )
+    # load collections
+    App.Event.trigger 'loadAssets', data.assets
 
     # render page
     @render(force)
@@ -196,9 +195,10 @@ class App.TicketZoom extends App.Controller
   ArticleView: =>
     # show article
     new ArticleView(
-      ticket:   @ticket
-      el:       @el.find('.article-view')
-      ui:       @
+      ticket:             @ticket
+      ticket_article_ids: @ticket_article_ids
+      el:                 @el.find('.article-view')
+      ui:                 @
     )
 
   Edit: =>
@@ -570,7 +570,7 @@ class ArticleView extends App.Controller
 
     # get all articles
     @articles = []
-    for article_id in @ticket.article_ids
+    for article_id in @ticket_article_ids
       article = App.TicketArticle.retrieve( article_id )
       @articles.push article
 
@@ -620,16 +620,16 @@ class ArticleView extends App.Controller
 
   checkIfSignatureIsNeeded: (article_type) =>
 
-      # add signature
-      if @ui.signature && @ui.signature.body && article_type.name is 'email'
-        body   = @ui.el.find('[name="body"]').val() || ''
-        regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i')
-        if !body.match(regexp)
-          body = body + "\n" + @ui.signature.body
-          @ui.el.find('[name="body"]').val( body )
+    # add signature
+    if @ui.signature && @ui.signature.body && article_type.name is 'email'
+      body   = @ui.el.find('[name="body"]').val() || ''
+      regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i')
+      if !body.match(regexp)
+        body = body + "\n" + @ui.signature.body
+        @ui.el.find('[name="body"]').val( body )
 
-          # update textarea size
-          @ui.el.find('[name="body"]').trigger('change')
+        # update textarea size
+        @ui.el.find('[name="body"]').trigger('change')
 
   reply: (e) =>
     e.preventDefault()
@@ -774,7 +774,7 @@ class Article extends App.Controller
         actions.push {
           name: 'split'
           type: 'split'
-          href: '#ticket_create/' + @article.ticket_id + '/' + @article.id
+          href: '#ticket_create/call_inbound/' + @article.ticket_id + '/' + @article.id
         }
     @article.actions = actions
 

+ 22 - 0
app/assets/javascripts/app/lib/app_post/collection.js.coffee

@@ -19,6 +19,28 @@ class _collectionSingleton extends Spine.Module
 
   constructor: (@args) ->
 
+    # add trigger - bind new events
+    App.Event.bind 'loadAssets', (data) =>
+      if data
+        for type, collections of data
+          if type is 'users'
+            type = 'User'
+          if type is 'tickets'
+            type = 'Ticket'
+          if type is 'ticket_article'
+            type = 'TicketArticle'
+          if type is 'organization'
+            type = 'Organization'
+          if type is 'history_object'
+            type = 'HistoryObject'
+          if type is 'history_type'
+            type = 'HistoryType'
+          if type is 'history_attribute'
+            type = 'HistoryAttribute'
+
+          @log 'debug', 'loadCollection:trigger', type, collections
+          @load( localStorage: data.localStorage, type: type, data: collections )
+
     # add trigger - bind new events
     App.Event.bind 'loadCollection', (data) =>
 

Some files were not shown because too many files changed in this diff