From 6be0e97a4843c53c752f24750aab018861ba5387 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 3 Apr 2014 00:35:56 +0200 Subject: [PATCH] Improved changing customers. --- .../controllers/agent_ticket_merge.js.coffee | 8 +++--- .../app/controllers/ticket_customer.js.coffee | 14 +++++----- .../app/controllers/ticket_history.js.coffee | 2 +- .../app/controllers/ticket_zoom.js.coffee | 27 +++++++++++-------- .../app/controllers/user_zoom.js.coffee | 4 +-- 5 files changed, 29 insertions(+), 26 deletions(-) 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 b4cbafe2f..e6db3c385 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -9,7 +9,7 @@ class App.TicketMerge extends App.ControllerModal @ajax( id: 'ticket_merge_list' type: 'GET' - url: @apiPath + '/ticket_merge_list/' + @ticket_id + url: @apiPath + '/ticket_merge_list/' + @ticket.id processData: true, success: (data, status, xhr) => @@ -28,7 +28,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for ticket_id in @ticket_ids_by_customer - if ticket_id isnt @ticket_id + if ticket_id isnt @ticket.id ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( @@ -55,7 +55,7 @@ class App.TicketMerge extends App.ControllerModal list = [] for ticket_id in @ticket_ids_recent_viewed - if ticket_id isnt @ticket_id + if ticket_id isnt @ticket.id ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( @@ -105,7 +105,7 @@ class App.TicketMerge extends App.ControllerModal @ajax( id: 'ticket_merge', type: 'GET', - url: @apiPath + '/ticket_merge/' + @ticket_id + '/' + params['master_ticket_number'], + url: @apiPath + '/ticket_merge/' + @ticket.id + '/' + params['master_ticket_number'], data: { # view: @view } diff --git a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee index 2d53e8191..2f827f489 100644 --- a/app/assets/javascripts/app/controllers/ticket_customer.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_customer.js.coffee @@ -25,19 +25,17 @@ class App.TicketCustomer extends App.ControllerModal params = @formParam(e.target) - # update ticket - ticket = App.Ticket.find(@ticket_id) - ticket.updateAttributes( - customer_id: params['customer_id'] - ) + @customer_id = params['customer_id'] callback = => # close modal @modalHide() - # reload zoom view - @ui.render() + # update ticket + @ticket.updateAttributes( + customer_id: @customer_id + ) # load user if not already exists - App.User.retrieve( params['customer_id'], callback ) + App.User.retrieve( @customer_id, callback ) diff --git a/app/assets/javascripts/app/controllers/ticket_history.js.coffee b/app/assets/javascripts/app/controllers/ticket_history.js.coffee index fe3110239..1e2a5f6c7 100644 --- a/app/assets/javascripts/app/controllers/ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_history.js.coffee @@ -9,7 +9,7 @@ class App.TicketHistory extends App.GenericHistory @ajax( id: 'ticket_history', type: 'GET', - url: @apiPath + '/ticket_history/' + @ticket_id, + url: @apiPath + '/ticket_history/' + @ticket.id, success: (data, status, xhr) => # load assets diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 5cec5f3e0..383514583 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -28,8 +28,8 @@ class App.TicketZoom extends App.Controller update = => if data.id.toString() is @ticket_id.toString() ticket = App.Ticket.find( @ticket_id ) - @log 'notice', 'TRY', data.updated_at, ticket.updated_at - if data.updated_at isnt ticket.updated_at + @log 'notice', 'TRY', Date(data.updated_at), Date(ticket.updated_at) + if Date(data.updated_at) isnt Date(ticket.updated_at) @fetch( @ticket_id, false ) @delay( update, 1800, 'ticket-zoom-' + @ticket_id ) ) @@ -282,15 +282,17 @@ class TicketInfo extends App.ControllerDrox class Widgets extends App.Controller constructor: -> super - @render() - render: -> + @subscribeId = @ticket.subscribe(@render) + @render(@ticket) + + render: (ticket) => @html App.view('ticket_zoom/widgets')() # show ticket info new TicketInfo( - ticket: @ticket + ticket: ticket el: @el.find('.ticket_info') ) @@ -298,8 +300,8 @@ class Widgets extends App.Controller if !@isRole('Customer') new App.WidgetUser( el: @el.find('.customer_info') - user_id: @ticket.customer_id - ticket: @ticket + user_id: ticket.customer_id + ticket: ticket ) # start link info controller @@ -307,9 +309,12 @@ class Widgets extends App.Controller new App.WidgetLink( el: @el.find('.link_info') object_type: 'Ticket' - object: @ticket + object: ticket ) + release: => + App.Ticket.unsubscribe( @subscribeId ) + class Edit extends App.Controller events: 'click .submit': 'update' @@ -802,15 +807,15 @@ class ActionRow extends App.Controller history_dialog: (e) -> e.preventDefault() - new App.TicketHistory( ticket_id: @ticket.id ) + new App.TicketHistory( ticket: @ticket ) merge_dialog: (e) -> e.preventDefault() - new App.TicketMerge( ticket_id: @ticket.id, task_key: @ui.task_key ) + new App.TicketMerge( ticket: @ticket, task_key: @ui.task_key ) customer_dialog: (e) -> e.preventDefault() - new App.TicketCustomer( ticket_id: @ticket.id, ui: @ui ) + new App.TicketCustomer( ticket: @ticket ) class TicketZoomRouter extends App.ControllerPermanent constructor: (params) -> diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 39b40a1b7..8c4b7e249 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -92,11 +92,11 @@ class ActionRow extends App.Controller merge_dialog: (e) -> e.preventDefault() - new App.TicketMerge( ticket_id: @ticket.id, task_key: @ui.task_key ) + new App.TicketMerge( ticket: @ticket, task_key: @ui.task_key ) customer_dialog: (e) -> e.preventDefault() - new App.TicketCustomer( ticket_id: @ticket.id, ui: @ui ) + new App.TicketCustomer( ticket: @ticket, ui: @ui ) class Router extends App.ControllerPermanent