From 261c9e3214e15de7107c3e01660c39f3c6f56c40 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 13 Aug 2014 10:31:50 +0200 Subject: [PATCH] Added new Model.fullLocal() to get local full data of object. --- .../_application_controller.js.coffee | 40 ++++++++++++++++--- .../_application_controller_generic.js.coffee | 4 +- .../controllers/_dashboard/ticket.js.coffee | 4 +- .../controllers/_profile/language.js.coffee | 2 +- .../controllers/agent_ticket_create.js.coffee | 2 +- .../controllers/agent_ticket_merge.js.coffee | 6 +-- .../controllers/organization_zoom.js.coffee | 33 ++++++++------- .../app/controllers/ticket_customer.js.coffee | 2 +- .../app/controllers/ticket_overview.js.coffee | 4 +- .../app/controllers/ticket_zoom.js.coffee | 12 +++--- .../app/controllers/user_zoom.js.coffee | 35 ++++++++-------- .../app/controllers/widget/link.js.coffee | 2 +- .../app/lib/app_post/auth.js.coffee | 2 +- .../app/models/_application_model.js.coffee | 26 ++++++++---- .../javascripts/app/models/user.js.coffee | 2 +- .../views/agent_ticket_view/detail.jst.eco | 2 +- .../app/views/organization_zoom.jst.eco | 2 +- .../views/ticket_zoom/article_view.jst.eco | 2 +- .../app/views/ticket_zoom/edit.jst.eco | 2 +- .../javascripts/app/views/user_zoom.jst.eco | 2 +- .../javascripts/app/views/widget/user.jst.eco | 4 +- 21 files changed, 116 insertions(+), 74 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 81c9b28af..839b34075 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -294,11 +294,11 @@ class App.Controller extends Spine.Controller placement: position title: -> ticket_id = $(@).data('id') - ticket = App.Ticket.retrieve( ticket_id ) + ticket = App.Ticket.fullLocal( ticket_id ) App.i18n.escape( ticket.title ) content: -> ticket_id = $(@).data('id') - ticket = App.Ticket.retrieve( ticket_id ) + ticket = App.Ticket.fullLocal( ticket_id ) ticket.humanTime = ui.humanTime(ticket.created_at) # insert data App.view('popover/ticket')( @@ -328,11 +328,11 @@ class App.Controller extends Spine.Controller placement: position title: -> user_id = $(@).data('id') - user = App.User.find( user_id ) + user = App.User.fullLocal( user_id ) App.i18n.escape( user.displayName() ) content: -> user_id = $(@).data('id') - user = App.User.retrieve( user_id ) + user = App.User.fullLocal( user_id ) # get display data data = [] @@ -374,11 +374,11 @@ class App.Controller extends Spine.Controller placement: position title: -> organization_id = $(@).data('id') - organization = App.Organization.find( organization_id ) + organization = App.Organization.fullLocal( organization_id ) App.i18n.escape( organization.name ) content: -> organization_id = $(@).data('id') - organization = App.Organization.retrieve( organization_id ) + organization = App.Organization.fullLocal( organization_id ) # insert data App.view('popover/organization')( organization: organization, @@ -593,3 +593,31 @@ class App.SessionMessage extends App.ControllerModal throw "Cant reload page!" +class App.UpdateHeader extends App.Controller + constructor: -> + super + + # subscribe and reload data / fetch new data if triggered + @subscribeId = @genericObject.subscribe( @render ) + + release: => + App[ @genericObject.constructor.className ].unsubscribe(@subscribeId) + + render: (genericObject) => + @el.find( '.page-header h1' ).html( genericObject.displayName() ) + + +class App.UpdateTastbar extends App.Controller + constructor: -> + super + + # subscribe and reload data / fetch new data if triggered + @subscribeId = @genericObject.subscribe( @update ) + + release: => + App[ @genericObject.constructor.className ].unsubscribe(@subscribeId) + + update: (genericObject) => + + # update taskbar with new meta data + App.Event.trigger 'task:render' \ No newline at end of file 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 e6a8d492d..784fefe1f 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -37,7 +37,7 @@ class App.ControllerGenericNew extends App.ControllerModal object.save( done: -> if ui.callback - item = App[ ui.genericObject ].retrieve(@id) + item = App[ ui.genericObject ].fullLocal(@id) ui.callback( item ) ui.modalHide() @@ -84,7 +84,7 @@ class App.ControllerGenericEdit extends App.ControllerModal @item.save( done: -> if ui.callback - item = App[ ui.genericObject ].retrieve(@id) + item = App[ ui.genericObject ].fullLocal(@id) ui.callback( item ) ui.modalHide() diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index 81d9580cb..fd05fa6d3 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -90,10 +90,10 @@ class App.DashboardTicket extends App.Controller while i < end i = i + 1 if @ticket_ids[ i - 1 ] - @tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] ) + @tickets_in_table.push App.Ticket.fullLocal( @ticket_ids[ i - 1 ] ) openTicket = (id,e) => - ticket = App.Ticket.retrieve(id) + ticket = App.Ticket.fullLocal(id) @navigate ticket.uiUrl() callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) => attribute.title = object.title diff --git a/app/assets/javascripts/app/controllers/_profile/language.js.coffee b/app/assets/javascripts/app/controllers/_profile/language.js.coffee index ee378377f..3cc8ede1c 100644 --- a/app/assets/javascripts/app/controllers/_profile/language.js.coffee +++ b/app/assets/javascripts/app/controllers/_profile/language.js.coffee @@ -45,7 +45,7 @@ class Index extends App.Controller ) success: (data, status, xhr) => - App.User.retrieve( + App.User.full( App.Session.get( 'id' ), => App.i18n.set( @locale ) 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 27e59a410..5bb518847 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -369,7 +369,7 @@ class UserNew extends App.ControllerModal # start customer info controller ui.userInfo( user_id: user.id ) ui.modalHide() - App.User.retrieve( @id, callbackReload , true ) + App.User.full( @id, callbackReload , true ) fail: -> ui.modalHide() 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 cf5c3e263..af8a1dd63 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -29,7 +29,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for ticket_id in @ticket_ids_by_customer if ticket_id isnt @ticket.id - ticketItem = App.Ticket.retrieve( ticket_id ) + ticketItem = App.Ticket.fullLocal( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-customer-tickets'), @@ -42,7 +42,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for ticket_id in @ticket_ids_recent_viewed if ticket_id isnt @ticket.id - ticketItem = App.Ticket.retrieve( ticket_id ) + ticketItem = App.Ticket.fullLocal( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-recent-tickets'), @@ -59,7 +59,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.Ticket.retrieve( ticket_id ) + ticket = App.Ticket.fullLocal( ticket_id ) $(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number ) ) diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index a10da40a2..f1f50a851 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -7,19 +7,17 @@ class App.OrganizationZoom extends App.Controller @navupdate '#' - # subscribe and reload data / fetch new data if triggered - @subscribeId = App.Organization.full( @organization_id, @render, false, true ) - - release: => - App.Organization.unsubscribe(@subscribeId) + App.Organization.full( @organization_id, @render ) meta: => meta = url: @url() id: @organization_id - if @organization - meta.head = @organization.displayName() - meta.title = @organization.displayName() + + organization = App.Organization.find( @organization_id ) + if organization + meta.head = organization.displayName() + meta.title = organization.displayName() meta url: => @@ -35,25 +33,30 @@ class App.OrganizationZoom extends App.Controller return true render: (organization) => - @organization = organization - - # update taskbar with new meta data - App.Event.trigger 'task:render' @html App.view('organization_zoom')( - organization: @organization + organization: organization + ) + + new App.UpdateTastbar( + genericObject: organization + ) + + new App.UpdateHeader( + el: @el + genericObject: organization ) # start action controller new ActionRow( el: @el.find('.action') - organization: @organization + organization: organization ui: @ ) new Widgets( el: @el.find('.widgets') - organization: @organization + organization: organization ui: @ ) diff --git a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee index 2f827f489..1841b9f88 100644 --- a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee @@ -38,4 +38,4 @@ class App.TicketCustomer extends App.ControllerModal ) # load user if not already exists - App.User.retrieve( @customer_id, callback ) + App.User.full( @customer_id, callback ) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee index a8e093367..489ed3fbc 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee @@ -109,7 +109,7 @@ class Table extends App.ControllerContent @ticket_list_show = [] for ticket_id in @ticket_ids - @ticket_list_show.push App.Ticket.retrieve( ticket_id ) + @ticket_list_show.push App.Ticket.fullLocal( ticket_id ) # remeber bulk attributes @bulk = data.bulk @@ -185,7 +185,7 @@ class Table extends App.ControllerContent @el.find('.table-overview').append(table) else openTicket = (id,e) => - ticket = App.Ticket.retrieve(id) + ticket = App.Ticket.fullLocal(id) @navigate ticket.uiUrl() callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) => attribute.title = object.title diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index dd652b8e8..c6f6f9e88 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -38,7 +38,7 @@ class App.TicketZoom extends App.Controller url: @url() id: @ticket_id if @ticket - @ticket = App.Ticket.retrieve( @ticket.id ) + @ticket = App.Ticket.fullLocal( @ticket.id ) meta.head = @ticket.title meta.title = '#' + @ticket.number + ' - ' + @ticket.title meta @@ -118,7 +118,7 @@ class App.TicketZoom extends App.Controller App.Collection.loadAssets( data.assets ) # get data - @ticket = App.Ticket.retrieve( @ticket_id ) + @ticket = App.Ticket.fullLocal( @ticket_id ) # render page @render(force) @@ -217,7 +217,7 @@ class TicketTitle extends App.Controller constructor: -> super - @ticket = App.Ticket.retrieve( @ticket.id ) + @ticket = App.Ticket.fullLocal( @ticket.id ) @subscribeId = @ticket.subscribe(@render) @render(@ticket) @@ -327,7 +327,7 @@ class Edit extends App.Controller render: -> - ticket = App.Ticket.retrieve( @ticket.id ) + ticket = App.Ticket.fullLocal( @ticket.id ) @html App.view('ticket_zoom/edit')( ticket: ticket @@ -444,7 +444,7 @@ class Edit extends App.Controller @autosaveStop() params = @formParam(e.target) - ticket = App.Ticket.retrieve( @ticket.id ) + ticket = App.Ticket.fullLocal( @ticket.id ) @log 'notice', 'update', params, ticket @@ -574,7 +574,7 @@ class ArticleView extends App.Controller # get all articles @articles = [] for article_id in @ticket_article_ids - article = App.TicketArticle.retrieve( article_id ) + article = App.TicketArticle.fullLocal( article_id ) @articles.push article # rework articles diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 8cb8bef6d..d5360887c 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -7,20 +7,17 @@ class App.UserZoom extends App.Controller @navupdate '#' - # subscribe and reload data / fetch new data if triggered - @subscribeId = App.User.full( @user_id, @render, false, true ) - - - release: => - App.User.unsubscribe(@subscribeId) + App.User.full( @user_id, @render ) meta: => meta = url: @url() id: @user_id - if @user - meta.head = @user.displayName() - meta.title = @user.displayName() + + user = App.User.find( @user_id ) + if user + meta.head = user.displayName() + meta.title = user.displayName() meta url: => @@ -36,29 +33,33 @@ class App.UserZoom extends App.Controller return true render: (user) => - @user = user - - # update taskbar with new meta data - App.Event.trigger 'task:render' @html App.view('user_zoom')( - user: @user + user: user + ) + + new App.UpdateTastbar( + genericObject: user + ) + + new App.UpdateHeader( + el: @el + genericObject: user ) # start action controller new ActionRow( el: @el.find('.action') - user: @user + user: user ui: @ ) new Widgets( el: @el.find('.widgets') - user: @user + user: user ui: @ ) - class Widgets extends App.Controller constructor: -> super diff --git a/app/assets/javascripts/app/controllers/widget/link.js.coffee b/app/assets/javascripts/app/controllers/widget/link.js.coffee index 3136828ec..5169c696a 100644 --- a/app/assets/javascripts/app/controllers/widget/link.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.js.coffee @@ -40,7 +40,7 @@ class App.WidgetLink extends App.ControllerDrox list[ item['link_type'] ] = [] if item['link_object'] is 'Ticket' - ticket = App.Ticket.retrieve( item['link_object_value'] ) + ticket = App.Ticket.fullLocal( item['link_object_value'] ) if ticket.state.name is 'merged' ticket.css = 'merged' list[ item['link_type'] ].push ticket diff --git a/app/assets/javascripts/app/lib/app_post/auth.js.coffee b/app/assets/javascripts/app/lib/app_post/auth.js.coffee index 7921030b2..20e1bf495 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.js.coffee @@ -88,7 +88,7 @@ class App.Auth App.Collection.loadAssets( data.assets ) # store user data - session = App.User.retrieve(data.session.id) + session = App.User.fullLocal(data.session.id) for key, value of session App.Session.set( key, value ) diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 9406a7ce7..8568a4ba6 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -117,6 +117,9 @@ class App.Model extends Spine.Model return true if @id[0] isnt 'c' return false + @fullLocal: (id) -> + @_fillUp( App[ @className ].find( id ) ) + @full: (id, callback = false, force = false, bind = false) -> url = "#{@url}/#{id}?full=true" console.log('FULL', id, url, bind) @@ -282,9 +285,11 @@ class App.Model extends Spine.Model # remember record id and callback App[ @constructor.className ].subscribe_item(@id, callback) - @_subscribe_bind: -> - if !@_bindDone - @_bindDone = true + @subscribe_item: (id, callback) -> + + # init bind + if !@_subscribe_item_bindDone + @_subscribe_item_bindDone = true # subscribe and render data after local change @bind( @@ -307,14 +312,19 @@ class App.Model extends Spine.Model events (item) => if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ] - @full( item.id, false, true ) + genericObject = undefined + if App[ @className ].exists( item.id ) + genericObject = App[ @className ].find( item.id ) + + callback = => + if !genericObject || ( new Date(item.updated_at).toString() isnt new Date(genericObject.updated_at).toString() ) + @full( item.id, false, true ) + + App.Delay.set(callback, 800, item.id, "full-#{@className}") + 'Item::Subscribe::' + @className ) - @subscribe_item: (id, callback) -> - # init bind - @_subscribe_bind() - # remember item callback if !@SUBSCRIPTION_ITEM @SUBSCRIPTION_ITEM = {} diff --git a/app/assets/javascripts/app/models/user.js.coffee b/app/assets/javascripts/app/models/user.js.coffee index c04e544f1..1f93d32c9 100644 --- a/app/assets/javascripts/app/models/user.js.coffee +++ b/app/assets/javascripts/app/models/user.js.coffee @@ -44,7 +44,7 @@ class App.User extends App.Model data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid'] # set image url - data.image = @apiPath + '/users/image/' + data.image + data.imageUrl = @apiPath + '/users/image/' + data.image if data.organization_id data.organization = App.Organization.find(data.organization_id) diff --git a/app/assets/javascripts/app/views/agent_ticket_view/detail.jst.eco b/app/assets/javascripts/app/views/agent_ticket_view/detail.jst.eco index 9d6af49b8..b370be5f8 100644 --- a/app/assets/javascripts/app/views/agent_ticket_view/detail.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_view/detail.jst.eco @@ -11,7 +11,7 @@ - +

<%= ticket.title %> <%= ticket.number %> ?

diff --git a/app/assets/javascripts/app/views/organization_zoom.jst.eco b/app/assets/javascripts/app/views/organization_zoom.jst.eco index ffa1a0d7e..36e2ee833 100644 --- a/app/assets/javascripts/app/views/organization_zoom.jst.eco +++ b/app/assets/javascripts/app/views/organization_zoom.jst.eco @@ -6,7 +6,7 @@
diff --git a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco index b2530ecf7..51421793d 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco @@ -2,7 +2,7 @@ <% for article in @articles: %>
- +
  • <%- @T(article.type.name) %>
  • <% if article.type.name is 'email': %>
  • <%- @T( 'raw' ) %>
  • <% end %> diff --git a/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco index 67cf27af3..43e64f3fe 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco @@ -1,7 +1,7 @@
    - +
    diff --git a/app/assets/javascripts/app/views/user_zoom.jst.eco b/app/assets/javascripts/app/views/user_zoom.jst.eco index c369d5943..36e2ee833 100644 --- a/app/assets/javascripts/app/views/user_zoom.jst.eco +++ b/app/assets/javascripts/app/views/user_zoom.jst.eco @@ -6,7 +6,7 @@
    diff --git a/app/assets/javascripts/app/views/widget/user.jst.eco b/app/assets/javascripts/app/views/widget/user.jst.eco index 825ad26d8..f9ba2c070 100644 --- a/app/assets/javascripts/app/views/widget/user.jst.eco +++ b/app/assets/javascripts/app/views/widget/user.jst.eco @@ -1,7 +1,7 @@