diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 0b3762346..648f222e5 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -456,7 +456,6 @@ class App.ControllerModal extends App.Controller @show() show: -> - console.log('M', @message, @el.length) if @button is true @button = 'Submit' 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 fed8e74cc..51ad826d9 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -359,41 +359,21 @@ class App.GenericHistory extends App.ControllerModal @head = 'History' @close = true - render: ( items, orderClass = '' ) -> + render: -> - for item in items - - item.link = '' - item.title = '???' - - if item.object is 'Ticket::Article' - item.object = 'Article' - article = App.TicketArticle.find( item.o_id ) - ticket = App.Ticket.find( article.ticket_id ) - item.title = article.subject || ticket.title - item.link = article.uiUrl() - - if App[item.object] - object = App[item.object].find( item.o_id ) - item.link = object.uiUrl() - item.title = object.displayName() - - item.created_by = App.User.find( item.created_by_id ) - - # set cache - @historyListCache = items + localItem = @reworkItems( @items ) @html App.view('generic/history')( - items: items - orderClass: orderClass - - @historyListCache + items: localItem ) + + @onShow() + @el.find('a[data-type="sortorder"]').bind( 'click', (e) => e.preventDefault() - @sortorder(e) + @sortorder() ) if !@isShown @isShown = true @@ -404,16 +384,95 @@ class App.GenericHistory extends App.ControllerModal @userPopups() # show frontend times - @delay( @frontendTimeUpdate, 100, 'ui-time-update' ) + @delay( @frontendTimeUpdate, 800, 'ui-time-update' ) - sortorder: (e) -> - e.preventDefault() - isDown = @el.find('[data-type="sortorder"]').hasClass('down') + sortorder: => + @items = @items.reverse() - if isDown - @render( @historyListCache, 'up' ) - else - @render( @historyListCache.reverse(), 'down' ) + @render() + + T: (name) -> + App.i18n.translateInline(name) + + reworkItems: (items) -> + newItems = [] + newItem = {} + lastUserId = undefined + lastTime = undefined + items = clone(items) + for item in items + + if item.object is 'Ticket::Article' + item.object = 'Article' + + data = item + data.created_by = App.User.find( item.created_by_id ) + + currentItemTime = new Date( item.created_at ) + lastItemTime = new Date( new Date( lastTime ).getTime() + (15 * 1000) ) + + # start new section if user or time has changed + if lastUserId isnt item.created_by_id || currentItemTime > lastItemTime + lastTime = item.created_at + lastUserId = item.created_by_id + if !_.isEmpty(newItem) + newItems.push newItem + newItem = + created_at: item.created_at + created_by: App.User.find( item.created_by_id ) + records: [] + + # build content + content = '' + if item.type is 'notification' || item.type is 'email' + content = "#{ @T( item.type ) } #{ @T( 'sent to' ) } #{ item.value_to }" + else + content = "#{ @T( item.type ) } #{ @T(item.object) } " + if item.attribute + content += "#{ @T(item.attribute) }" + + # convert time stamps + if item.object is 'User' && item.attribute is 'last_login' + if item.value_from + item.value_from = App.i18n.translateTimestamp( item.value_from ) + if item.value_to + item.value_to = App.i18n.translateTimestamp( item.value_to ) + + if item.value_from + if item.value_to + content += " #{ @T( 'from' ) }" + content += " '#{ item.value_from }'" + + if item.value_to + if item.value_from + content += " #{ @T( 'to' ) }" + content += " '#{ item.value_to }'" + + newItem.records.push content + + if !_.isEmpty(newItem) + newItems.push newItem + + newItems + +class App.ActionRow extends App.Controller + constructor: -> + super + @render() + + render: -> + @html App.view('generic/actions')( + items: @items + ) + + for item in @items + do (item) => + @el.find('[data-type="' + item.name + '"]').on( + 'click', + (e) => + e.preventDefault() + item.callback() + ) class App.Sidebar extends App.Controller events: 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 09d4e9038..cdb748b58 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -1,15 +1,18 @@ class App.TicketMerge extends App.ControllerModal constructor: -> super + @head = 'Merge' + @button = true + @cancel = true @fetch() fetch: -> # merge tickets @ajax( - id: 'ticket_merge_list' + id: 'ticket_related' type: 'GET' - url: @apiPath + '/ticket_merge_list/' + @ticket.id + url: @apiPath + '/ticket_related/' + @ticket.id processData: true, success: (data, status, xhr) => @@ -18,7 +21,6 @@ class App.TicketMerge extends App.ControllerModal @ticket_ids_by_customer = data.ticket_ids_by_customer @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed - @render() ) diff --git a/app/assets/javascripts/app/controllers/organization_history.js.coffee b/app/assets/javascripts/app/controllers/organization_history.js.coffee index 0504a0718..a88953a15 100644 --- a/app/assets/javascripts/app/controllers/organization_history.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_history.js.coffee @@ -15,6 +15,8 @@ class App.OrganizationHistory extends App.GenericHistory # load assets App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) - ) + @render() + ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index 025bf41fa..f7c0647ee 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -64,10 +64,19 @@ class App.OrganizationZoom extends App.Controller ) # start action controller - new ActionRow( - el: @el.find('.action') - organization: organization - ui: @ + showHistory = => + new App.OrganizationHistory( organization_id: organization.id ) + + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + } + ] + new App.ActionRow( + el: @el.find('.action') + items: actions ) new Sidebar( @@ -168,21 +177,6 @@ class Sidebar extends App.Controller items: items ) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('user_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.OrganizationHistory( organization_id: @organization.id ) - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/ticket_history.js.coffee b/app/assets/javascripts/app/controllers/ticket_history.js.coffee index 1e2a5f6c7..2cd33cc60 100644 --- a/app/assets/javascripts/app/controllers/ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_history.js.coffee @@ -9,12 +9,14 @@ 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 App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) - ) + @render() + ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 3c7f76773..c7617aba9 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -162,6 +162,28 @@ class App.TicketZoom extends App.Controller object_type: 'Ticket' object: @ticket ) + el.append('
') + showHistory = => + new App.TicketHistory( ticket_id: @ticket.id ) + showMerge = => + new App.TicketMerge( ticket: @ticket, task_key: @task_key ) + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + }, + { + name: 'merge' + title: 'Merge' + callback: showMerge + }, + ] + new App.ActionRow( + el: @el.find('.action') + items: actions + ) + items = [ { head: 'Ticket Settings' @@ -275,7 +297,6 @@ class App.TicketZoom extends App.Controller ) ### - @TicketAction() @ArticleView() if force || !@editDone @@ -323,18 +344,6 @@ class App.TicketZoom extends App.Controller ui: @ ) - TicketAction: => - # start action controller - if !@isRole('Customer') - new ActionRow( - el: @el.find('.action') - ticket: @ticket - ui: @ - ) - - # enable user popups - @userPopups() - class TicketTitle extends App.Controller events: 'blur .ticket-title-update': 'update' @@ -1212,26 +1221,6 @@ class Article extends App.Controller for attachment in @article.attachments attachment.size = @humanFileSize(attachment.size) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - 'click [data-type=merge]': 'merge_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('ticket_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.TicketHistory( ticket: @ticket ) - - merge_dialog: (e) -> - e.preventDefault() - new App.TicketMerge( ticket: @ticket, task_key: @ui.task_key ) - class TicketZoomRouter extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/user_history.js.coffee b/app/assets/javascripts/app/controllers/user_history.js.coffee index 6083dd746..5890082ce 100644 --- a/app/assets/javascripts/app/controllers/user_history.js.coffee +++ b/app/assets/javascripts/app/controllers/user_history.js.coffee @@ -15,6 +15,8 @@ class App.UserHistory extends App.GenericHistory # load assets App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) + @render() ) diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 166e2072f..74c2b485a 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -63,10 +63,19 @@ class App.UserZoom extends App.Controller ) # start action controller - new ActionRow( - el: @el.find('.action') - user: user - ui: @ + showHistory = => + new App.UserHistory( user_id: user.id ) + + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + } + ] + new App.ActionRow( + el: @el.find('.action') + items: actions ) new Sidebar( @@ -218,22 +227,6 @@ class Sidebar extends App.Controller items: items ) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('user_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.UserHistory( user_id: @user.id ) - - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/widget/link.js.coffee b/app/assets/javascripts/app/controllers/widget/link.js.coffee index 645cd27ac..9840f1d28 100644 --- a/app/assets/javascripts/app/controllers/widget/link.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.js.coffee @@ -74,10 +74,10 @@ class App.WidgetLink extends App.Controller add: (e) => e.preventDefault() new App.LinkAdd( - link_object: @object_type, - link_object_id: @object.id, - object: @object, - parent: @, + link_object: @object_type + link_object_id: @object.id + object: @object + parent: @ ) class App.LinkAdd extends App.ControllerModal @@ -87,17 +87,86 @@ class App.LinkAdd extends App.ControllerModal @button = true @cancel = true + @ticket = @object + + @fetch() + + fetch: -> + + # merge tickets + @ajax( + id: 'ticket_related' + type: 'GET' + url: @apiPath + '/ticket_related/' + @ticket.id + processData: true, + success: (data, status, xhr) => + + # load assets + App.Collection.loadAssets( data.assets ) + + @ticket_ids_by_customer = data.ticket_ids_by_customer + @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed + @render() + ) + + + render: -> @html App.view('link/add')( link_object: @link_object, link_object_id: @link_object_id, object: @object, ) + + list = [] + for ticket_id in @ticket_ids_by_customer + if ticket_id isnt @ticket.id + ticketItem = App.Ticket.fullLocal( ticket_id ) + list.push ticketItem + new App.ControllerTable( + el: @el.find('#ticket-merge-customer-tickets'), + overview: [ 'number', 'title', 'state', 'group', 'created_at' ] + model: App.Ticket, + objects: list, + radio: true, + ) + + list = [] + for ticket_id in @ticket_ids_recent_viewed + if ticket_id isnt @ticket.id + ticketItem = App.Ticket.fullLocal( ticket_id ) + list.push ticketItem + new App.ControllerTable( + el: @el.find('#ticket-merge-recent-tickets'), + overview: [ 'number', 'title', 'state', 'group', 'created_at' ] + model: App.Ticket, + objects: list, + radio: true, + ) + + @el.delegate('[name="ticket_number"]', 'focus', (e) -> + $(e.target).parents().find('[name="radio"]').prop( 'checked', false ) + ) + + @el.delegate('[name="radio"]', 'click', (e) -> + if $(e.target).prop('checked') + ticket_id = $(e.target).val() + ticket = App.Ticket.fullLocal( ticket_id ) + $(e.target).parents().find('[name="ticket_number"]').val( ticket.number ) + ) + @show() onSubmit: (e) => e.preventDefault() params = @formParam(e.target) + if !params['ticket_number'] + alert('Ticket# is needed!') + return + if !params['link_type'] + alert('Link type is needed!') + return + # get data @ajax( id: 'links_add_' + @object.id + '_' + @object_type, diff --git a/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco b/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco index ce11d67c8..fb77665ac 100644 --- a/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco @@ -1,26 +1,10 @@ - +