From 24ef928c9675a35a588237084a1a4d36721297a6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 29 Sep 2015 22:07:50 +0200 Subject: [PATCH] Add order direction to table overview. --- .../_application_controller_table.coffee | 5 ++-- .../app/controllers/ticket_overview.coffee | 23 +++++++++++++++---- .../javascripts/app/controllers/users.coffee | 2 +- .../app/controllers/widget/ticket_list.coffee | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index c26a157f4..865360e04 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -72,7 +72,7 @@ class App.ControllerTable extends App.Controller 'mouseover': rowMouseover 'mouseout': rowMouseout 'dblclick': rowDblClick - callbackHeader: callbackHeader + callbackHeader: [callbackHeader] callbackAttributes: attributeName: [ callbackAttributes @@ -161,7 +161,8 @@ class App.ControllerTable extends App.Controller # execute header callback if data.callbackHeader - header = data.callbackHeader(header) + for callback in data.callbackHeader + header = callback(header) # get content @log 'debug', 'table', 'header', header, 'overview', 'objects', data.objects diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index 8e3ddc051..dcd2d3b47 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -264,15 +264,28 @@ class Table extends App.Controller @el.find('.bulkAction').addClass('hide') else @el.find('.bulkAction').removeClass('hide') - callbackIconHeader = (header) -> + callbackIconHeader = (headers) -> attribute = name: 'icon' display: '' translation: false style: 'width: 28px' - header.unshift(0) - header[0] = attribute - header + headers.unshift(0) + headers[0] = attribute + headers + callbackSortOrderHeader = (headers) => + return headers if !@overview + return headers if !@overview.order + return headers if !@overview.order.by + for header in headers + if header.name is @overview.order.by + if @overview.order.direction is 'DESC' + header.sortOrderIcon = ['arrow-down', 'table-sort-arrow'] + else + header.sortOrderIcon = ['arrow-up', 'table-sort-arrow'] + else + header.sortOrderIcon = undefined + headers callbackIcon = (value, object, attribute, header, refObject) -> value = ' ' attribute.class = object.iconClass() @@ -294,7 +307,7 @@ class Table extends App.Controller # customer_id: # events: # 'mouseover': popOver - callbackHeader: callbackIconHeader + callbackHeader: [ callbackIconHeader, callbackSortOrderHeader ] callbackAttributes: icon: [ callbackIcon ] diff --git a/app/assets/javascripts/app/controllers/users.coffee b/app/assets/javascripts/app/controllers/users.coffee index 62ab5be40..4cec8dd03 100644 --- a/app/assets/javascripts/app/controllers/users.coffee +++ b/app/assets/javascripts/app/controllers/users.coffee @@ -107,7 +107,7 @@ class Index extends App.Controller model: App.User objects: users class: 'user-list' - callbackHeader: callbackHeader + callbackHeader: [callbackHeader] callbackAttributes: switch_to: [ callbackAttributes diff --git a/app/assets/javascripts/app/controllers/widget/ticket_list.coffee b/app/assets/javascripts/app/controllers/widget/ticket_list.coffee index 3ef107f66..fd524888b 100644 --- a/app/assets/javascripts/app/controllers/widget/ticket_list.coffee +++ b/app/assets/javascripts/app/controllers/widget/ticket_list.coffee @@ -46,7 +46,7 @@ class App.TicketList extends App.Controller overview: [ 'number', 'title', 'customer', 'group', 'created_at' ] model: App.Ticket objects: list - callbackHeader: callbackIconHeader + callbackHeader: [ callbackIconHeader ] callbackAttributes: icon: [ callbackIcon ]