From e947d4262f2dd75af233405daa7268e3525ae29d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 17 Sep 2015 00:02:11 +0200 Subject: [PATCH] Use new widget for small ticket lists. Reduced tags in tables. --- .../controllers/agent_ticket_merge.js.coffee | 35 +++------- .../controllers/widget/ticket_list.js.coffee | 68 +++++++++++++++++++ .../javascripts/app/models/ticket.js.coffee | 2 +- .../app/views/generic/table.jst.eco | 10 ++- 4 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/widget/ticket_list.js.coffee 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 81edb37df..526f0dc9a 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -16,7 +16,6 @@ class App.TicketMerge extends App.ControllerModal processData: true, success: (data, status, xhr) => - # load assets App.Collection.loadAssets( data.assets ) @ticket_ids_by_customer = data.ticket_ids_by_customer @@ -26,36 +25,22 @@ class App.TicketMerge extends App.ControllerModal render: -> - @content = $ App.view('agent_ticket_merge')() + @content = $App.view('agent_ticket_merge')() - 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: @content.find('#ticket-merge-customer-tickets'), - overview: [ 'number', 'title', 'state', 'group', 'created_at' ] - model: App.Ticket, - objects: list, - radio: true, + new App.TicketList( + el: @content.find('#ticket-merge-customer-tickets') + ticket_ids: @ticket_ids_by_customer + 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: @content.find('#ticket-merge-recent-tickets'), - overview: [ 'number', 'title', 'state', 'group', 'created_at' ] - model: App.Ticket, - objects: list, - radio: true, + new App.TicketList( + el: @content.find('#ticket-merge-recent-tickets'), + ticket_ids: @ticket_ids_recent_viewed + radio: true ) @content.delegate('[name="master_ticket_number"]', 'focus', (e) -> - $(e.target).parents().find('[name="radio"]').prop( 'checked', false ) + $(e.target).parents().find('[name="radio"]').prop('checked', false) ) @content.delegate('[name="radio"]', 'click', (e) -> diff --git a/app/assets/javascripts/app/controllers/widget/ticket_list.js.coffee b/app/assets/javascripts/app/controllers/widget/ticket_list.js.coffee new file mode 100644 index 000000000..123a6d3c7 --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/ticket_list.js.coffee @@ -0,0 +1,68 @@ +class App.TicketList extends App.Controller + constructor: -> + super + + @render() + + render: => + + callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) => + attribute.title = object.title + value + callbackUserPopover = (value, object, attribute, attributes, refObject) => + attribute.class = 'user-popover' + attribute.data = + id: refObject.id + value + callbackOrganizationPopover = (value, object, attribute, attributes, refObject) => + attribute.class = 'organization-popover' + attribute.data = + id: refObject.id + value + + callbackIconHeader = (header) -> + attribute = + name: 'icon' + display: '' + translation: false + style: 'width: 28px' + header.unshift(0) + header[0] = attribute + header + callbackIcon = (value, object, attribute, header, refObject) -> + value = ' ' + attribute.class = object.icon() + attribute.link = '' + attribute.title = App.i18n.translateInline( object.iconTitle() ) + value + + list = [] + for ticket_id in @ticket_ids + ticketItem = App.Ticket.fullLocal( ticket_id ) + list.push ticketItem + @el.html('') + new App.ControllerTable( + el: @el + overview: [ 'number', 'title', 'customer', 'group', 'created_at' ] + model: App.Ticket + objects: list + callbackHeader: callbackIconHeader + callbackAttributes: + icon: + [ callbackIcon ] + customer_id: + [ callbackUserPopover ] + organization_id: + [ callbackOrganizationPopover ] + owner_id: + [ callbackUserPopover ] + title: + [ callbackTicketTitleAdd ] + radio: @radio + ) + + # start user popups + @userPopups() + + # start organization popups + @organizationPopups() diff --git a/app/assets/javascripts/app/models/ticket.js.coffee b/app/assets/javascripts/app/models/ticket.js.coffee index c816cf275..587e913e9 100644 --- a/app/assets/javascripts/app/models/ticket.js.coffee +++ b/app/assets/javascripts/app/models/ticket.js.coffee @@ -3,7 +3,7 @@ class App.Ticket extends App.Model @extend Spine.Model.Ajax @url: @apiPath + '/tickets' @configure_attributes = [ - { name: 'number', display: '#', tag: 'input', type: 'text', limit: 100, null: true, read_only: true, style: 'width: 60px' }, + { name: 'number', display: '#', tag: 'input', type: 'text', limit: 100, null: true, read_only: true, style: 'width: 68px' }, { name: 'customer_id', display: 'Customer', tag: 'input', type: 'text', limit: 100, null: false, autocapitalize: false, relation: 'User' }, { name: 'organization_id', display: 'Organization', tag: 'select', relation: 'Organization', tagreadonly: 1 }, { name: 'group_id', display: 'Group', tag: 'select', multiple: false, limit: 100, null: false, relation: 'Group', style: 'width: 10%', edit: true }, diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index bce56fd7a..503c5bae1 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -71,7 +71,7 @@ <% end %> <% end %> - class="<%= item.parentClass %>"<% end %>> + class="<%= item.parentClass %>"<% end %> <% if item.title: %>title="<%= item.title %>"<% end %>> <% if item.name is 'icon': %> <%- @Icon('priority', item.class) %> <% else: %> @@ -81,9 +81,13 @@ <% if item.raw: %> <%- item.raw %> <% else: %> - class="<%= item.class %>"<% end %> <% if item.title: %>title="<%= item.title %>"<% end %> <% if item.data: %><% for data_key, data_item of item.data: %>data-<%- data_key %>="<%= data_item %>" <% end %><% end %>> + <% if item.class || item.data: %> + class="<%= item.class %>"<% end %> <% if item.data: %><% for data_key, data_item of item.data: %>data-<%- data_key %>="<%= data_item %>" <% end %><% end %>> + <% end %> <%- value %> - + <% if item.class || item.data: %> + + <% end %> <% end %> <% if item.link: %><% end %> <% end %>