1 | import $ from './jquery';
|
2 | import '../../js-vendor/jquery/jquery.tablesorter';
|
3 | import globalize from './internal/globalize';
|
4 |
|
5 | const DEFAULT_SORT_OPTIONS = {
|
6 | sortMultiSortKey: '',
|
7 | headers: {},
|
8 | debug: false,
|
9 | tabIndex: false
|
10 | };
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function sortTable($table, extraOptions) {
|
17 | let options = Object.assign({}, DEFAULT_SORT_OPTIONS, extraOptions);
|
18 | $table.find('th').each(function (index, header) {
|
19 | const $header = $(header);
|
20 | options.headers[index] = {};
|
21 | if ($header.hasClass('aui-table-column-unsortable')) {
|
22 | options.headers[index].sorter = false;
|
23 | } else {
|
24 | $header.attr('tabindex', '0');
|
25 | $header.wrapInner("<span class='aui-table-header-content'/>");
|
26 | if ($header.hasClass('aui-table-column-issue-key')) {
|
27 | options.headers[index].sorter = 'issue-key';
|
28 | }
|
29 | }
|
30 | });
|
31 | return $table.tablesorter(options);
|
32 | }
|
33 |
|
34 | let tablessortable = {
|
35 | setup: function () {
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | $.tablesorter.addParser({
|
46 | id: 'issue-key',
|
47 | is: function () {
|
48 | return false;
|
49 | },
|
50 |
|
51 | format: function (s) {
|
52 | const keyComponents = s.split('-');
|
53 | const projectKey = keyComponents[0];
|
54 | const issueNumber = keyComponents[1];
|
55 |
|
56 | const PROJECT_KEY_TEMPLATE = '..........';
|
57 | const ISSUE_NUMBER_TEMPLATE = '000000';
|
58 | let stringRepresentation = (projectKey + PROJECT_KEY_TEMPLATE).slice(0, PROJECT_KEY_TEMPLATE.length);
|
59 | stringRepresentation += (ISSUE_NUMBER_TEMPLATE + issueNumber).slice(-ISSUE_NUMBER_TEMPLATE.length);
|
60 |
|
61 | return stringRepresentation;
|
62 | },
|
63 |
|
64 | type: 'text'
|
65 | });
|
66 |
|
67 | |
68 |
|
69 |
|
70 |
|
71 | $.tablesorter.addParser({
|
72 | id: 'textSortAttributeParser',
|
73 | is: function (nodeValue, table, node) {
|
74 | return node.hasAttribute('data-sort-value') && (!node.hasAttribute('data-sort-type') || node.getAttribute('data-sort-type') === 'text');
|
75 | },
|
76 | format: function (nodeValue, table, node) {
|
77 | return node.getAttribute('data-sort-value');
|
78 | },
|
79 | type: 'text'
|
80 | });
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 | $.tablesorter.addParser({
|
87 | id: 'numericSortAttributeParser',
|
88 | is: function (nodeValue, table, node) {
|
89 | return node.getAttribute('data-sort-type') === 'numeric' && node.hasAttribute('data-sort-value');
|
90 | },
|
91 | format: function (nodeValue, table, node) {
|
92 | return node.getAttribute('data-sort-value');
|
93 | },
|
94 | type: 'numeric'
|
95 | });
|
96 |
|
97 | $('.aui-table-sortable').each(function () {
|
98 | sortTable($(this));
|
99 | });
|
100 | },
|
101 | |
102 |
|
103 |
|
104 |
|
105 | setTableSortable: function ($table, options) {
|
106 | return sortTable($table, options);
|
107 | }
|
108 | };
|
109 |
|
110 | $(tablessortable.setup);
|
111 |
|
112 | globalize('tablessortable', tablessortable);
|
113 |
|
114 | export default tablessortable;
|