From 62733c0f589c229b2328789beab9a82ef817858d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 4 Jul 2012 23:36:39 +0200 Subject: [PATCH] Moved history and merge into extra files. --- .../agent_ticket_history.js.coffee | 69 ++++++++++++++++ .../controllers/agent_ticket_merge.js.coffee | 55 +++++++++++++ .../controllers/agent_ticket_zoom.js.coffee | 82 ++----------------- .../app/views/agent_ticket_history.jst.eco | 2 +- .../ticket_overviews_controller.rb | 48 +++++++++++ config/routes/ticket.rb | 2 + 6 files changed, 184 insertions(+), 74 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee create mode 100644 app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee diff --git a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee new file mode 100644 index 000000000..e8276edf3 --- /dev/null +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -0,0 +1,69 @@ +class App.TicketHistory extends App.ControllerModal + constructor: -> + super + @fetch(@ticket_id) + + fetch: (@ticket_id) -> + # get data + @ajax = new App.Ajax + @ajax.ajax( + type: 'GET', + url: '/ticket_history/' + ticket_id, + data: { +# view: @view + } +# processData: true, + success: (data, status, xhr) => + # remember ticket + @ticket = data.ticket + + # load user collection + @loadCollection( type: 'User', data: data.users ) + + # load ticket collection + @loadCollection( type: 'Ticket', data: [data.ticket] ) + + # load history_type collections + @loadCollection( type: 'HistoryType', data: data.history_types ) + + # load history_object collections + @loadCollection( type: 'HistoryObject', data: data.history_objects ) + + # load history_attributes collections + @loadCollection( type: 'HistoryAttribute', data: data.history_attributes ) + + # load history collections + App.History.deleteAll() + @loadCollection( type: 'History', data: data.history ) + + # render page + @render() + ) + + render: -> + + + # create table/overview + table = @table( + overview_extended: [ + { name: 'type', }, + { name: 'attribute', }, + { name: 'value_from', }, + { name: 'value_to', }, + { name: 'created_by', class: 'user-data', data: { id: 1 } }, + { name: 'created_at', callback: @humanTime }, + ], + model: App.History, + objects: App.History.all(), + ) + + + @html App.view('agent_ticket_history')( +# head: 'New User', +# form: @formGen( model: App.User, required: 'quick' ), + ) + @el.find('.table_history').append(table) + + @modalShow() + + @userPopups() diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee new file mode 100644 index 000000000..b08495c3c --- /dev/null +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -0,0 +1,55 @@ +class App.TicketMerge extends App.ControllerModal + constructor: -> + super + @render() + + render: -> + @html App.view('agent_ticket_merge')( +# head: 'New User', +# form: @formGen( model: App.User, required: 'quick' ), + ) + @log '123123123' + @modalShow() + + submit: (e) => + e.preventDefault() + + params = @formParam(e.target) + + # merge tickets + @ajax = new App.Ajax + @ajax.ajax( + type: 'GET', + url: '/ticket_merge/' + @ticket_id + '/' + params['master_ticket_number'], + data: { +# view: @view + } + processData: true, + success: (data, status, xhr) => + + if data['result'] is 'success' + @loadCollection( type: 'Ticket', data: [data.master_ticket] ) + @loadCollection( type: 'Ticket', data: [data.slave_ticket] ) + + @modalHide() + + # view ticket + @log 'nav...', App.Ticket.find( data.master_ticket['id'] ) + @navigate '#ticket/zoom/' + data.master_ticket['id'] + + # notify UI + @notify + type: 'success', + msg: T( 'Ticket %s merged!', data.slave_ticket['number'] ), + timeout: 6000, + + else + + # notify UI + @notify + type: 'error', + msg: T( data['message'] ), + timeout: 6000, +# error: => + ) + diff --git a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee index 2bbe14ecc..b18a00c52 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee @@ -7,7 +7,8 @@ class Index extends App.Controller # 'click [data-type=reply-all]': 'replyall', 'click [data-type=public]': 'public_internal', 'click [data-type=internal]': 'public_internal', - 'click [data-type=history]': 'history_view', + 'click [data-type=history]': 'history_dialog', + 'click [data-type=merge]': 'merge_dialog', 'change [name="ticket_article_type_id"]': 'form_update', 'click .show_toogle': 'show_toogle', @@ -26,6 +27,7 @@ class Index extends App.Controller @fetch(@ticket_id) fetch: (ticket_id) -> + # get data @ajax = new App.Ajax @ajax.ajax( @@ -208,9 +210,13 @@ class Index extends App.Controller else $(e.target).parent().next('div').show() - history_view: (e) -> + history_dialog: (e) -> e.preventDefault() - new History( ticket_id: @ticket_id ) + new App.TicketHistory( ticket_id: @ticket_id ) + + merge_dialog: (e) -> + e.preventDefault() + new App.TicketMerge( ticket_id: @ticket_id ) public_internal: (e) -> e.preventDefault() @@ -370,75 +376,5 @@ class Index extends App.Controller return false -class History extends App.ControllerModal - constructor: -> - super - @fetch(@ticket_id) - - fetch: (@ticket_id) -> - # get data - @ajax = new App.Ajax - @ajax.ajax( - type: 'GET', - url: '/ticket_history/' + ticket_id, - data: { -# view: @view - } -# processData: true, - success: (data, status, xhr) => - # remember ticket - @ticket = data.ticket - - # load user collection - @loadCollection( type: 'User', data: data.users ) - - # load ticket collection - @loadCollection( type: 'Ticket', data: [data.ticket] ) - - # load history_type collections - @loadCollection( type: 'HistoryType', data: data.history_types ) - - # load history_object collections - @loadCollection( type: 'HistoryObject', data: data.history_objects ) - - # load history_attributes collections - @loadCollection( type: 'HistoryAttribute', data: data.history_attributes ) - - # load history collections - App.History.deleteAll() - @loadCollection( type: 'History', data: data.history ) - - # render page - @render() - ) - - render: -> - - - # create table/overview - table = @table( - overview_extended: [ - { name: 'type', }, - { name: 'attribute', }, - { name: 'value_from', }, - { name: 'value_to', }, - { name: 'created_by', class: 'user-data', data: { id: 1 } }, - { name: 'created_at', callback: @humanTime }, - ], - model: App.History, - objects: App.History.all(), - ) - - - @html App.view('agent_ticket_history')( -# head: 'New User', -# form: @formGen( model: App.User, required: 'quick' ), - ) - @el.find('.table_history').append(table) - - @modalShow() - - @userPopups() - Config.Routes['ticket/zoom/:ticket_id'] = Index Config.Routes['ticket/zoom/:ticket_id/:article_id'] = Index \ No newline at end of file diff --git a/app/assets/javascripts/app/views/agent_ticket_history.jst.eco b/app/assets/javascripts/app/views/agent_ticket_history.jst.eco index 4c933e373..40e4b28cd 100644 --- a/app/assets/javascripts/app/views/agent_ticket_history.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_history.jst.eco @@ -1,6 +1,6 @@