View | Details | Raw Unified | Return to bug 23493
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.rowGrouping.js (-690 lines)
Lines 1-690 Link Here
1
/*
2
* File:        jquery.dataTables.grouping.js
3
* Version:     1.2.9.
4
* Author:      Jovan Popovic
5
*
6
* Copyright 2013 Jovan Popovic, all rights reserved.
7
*
8
* This source file is free software, under either the GPL v2 license or a
9
* BSD style license, as supplied with this software.
10
*
11
* This source file is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE.
14
* Parameters:
15
* @iGroupingColumnIndex                                 Integer             Index of the column that will be used for grouping - default 0
16
* @sGroupingColumnSortDirection                         Enumeration         Sort direction of the group
17
* @iGroupingOrderByColumnIndex                          Integer             Index of the column that will be used for ordering groups
18
* @sGroupingClass                                       String              Class that will be associated to the group row. Default - "group"
19
* @sGroupItemClass                                      String              Class that will be associated to the group row of group items. Default - "group-item"
20
* @bSetGroupingClassOnTR                                Boolean             If set class will be set to the TR instead of the TD withing the grouping TR
21
* @bHideGroupingColumn                                  Boolean             Hide column used for grouping once results are grouped. Default - true
22
* @bHideGroupingOrderByColumn                           Boolean             Hide column used for ordering groups once results are grouped. Default - true
23
* @sGroupBy                                             Enumeration         Type of grouping that should be applied. Values "name"(default), "letter", "year"
24
* @sGroupLabelPrefix                                    String              Prefix that will be added to each group cell
25
* @bExpandableGrouping                                  Boolean             Attach expand/collapse handlers to the grouping rows
26
* @bExpandSingleGroup                                   Boolean             Use accordon grouping
27
* @iExpandGroupOffset                                   Integer             Number of pixels to set scroll position above the currently selected group. If -1 scroll will be alligned to the table
28
* General settings
29
* @sDateFormat: "dd/MM/yyyy"                            String              Date format used for grouping
30
* @sEmptyGroupLabel                                     String              Lable that will be placed as group if grouping cells are empty. Default "-"
31
32
* Parameters used in the second level grouping
33
* @iGroupingColumnIndex2                                Integer             Index of the secondary column that will be used for grouping - default 0
34
* @sGroupingColumnSortDirection2                        Enumeration         Sort direction of the secondary group
35
* @iGroupingOrderByColumnIndex2                         Integer             Index of the column that will be used for ordering secondary groups
36
* @sGroupingClass2                                      String              Class that will be associated to the secondary group row. Default "subgroup"
37
* @sGroupItemClass2                                     String              Class that will be associated to the secondary group row of group items. Default "subgroup-item"
38
* @bHideGroupingColumn2                                 Boolean             Hide column used for secondary grouping once results are grouped. Default - true,
39
* @bHideGroupingOrderByColumn2                          Boolean             Hide column used for ordering secondary groups once results are grouped. Default - true,
40
* @sGroupBy2                                            Enumeration         Type of grouping that should be applied to secondary column. Values "name"(default), "letter", "year",
41
* @sGroupLabelPrefix2                                   String              Prefix that will be added to each secondary group cell
42
* @fnOnGrouped                                          Function            Function that is called when grouping is finished. Function has no parameters.
43
*/
44
(function ($) {
45
46
 "use strict";
47
48
    $.fn.rowGrouping = function (options) {
49
50
        function _fnOnGrouped() {
51
52
        }
53
54
        function _fnOnGroupCreated(oGroup, sGroup, iLevel) {
55
            ///<summary>
56
            ///Function called when a new grouping row is created(it should be overriden in properties)
57
            ///</summary>
58
        }
59
60
           function _fnOnGroupCompleted(oGroup, sGroup, iLevel) {
61
            ///<summary>
62
            ///Function called when a new grouping row is created(it should be overriden in properties)
63
            ///</summary>
64
        }
65
66
        function _getMonthName(iMonth) {
67
            var asMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
68
            return asMonths[iMonth - 1];
69
        }
70
71
        var defaults = {
72
73
            iGroupingColumnIndex: 0,
74
            sGroupingColumnSortDirection: "",
75
            iGroupingOrderByColumnIndex: -1,
76
            sGroupingClass: "group",
77
                        sGroupItemClass: "group-item",
78
            bHideGroupingColumn: true,
79
            bHideGroupingOrderByColumn: true,
80
            sGroupBy: "name",
81
            sGroupLabelPrefix: "",
82
            fnGroupLabelFormat: function (label) { return label; },
83
            bExpandableGrouping: false,
84
            bExpandSingleGroup: false,
85
            iExpandGroupOffset: 100,
86
            asExpandedGroups: null,
87
88
            sDateFormat: "dd/MM/yyyy",
89
            sEmptyGroupLabel: "-",
90
            bSetGroupingClassOnTR: false,
91
92
            iGroupingColumnIndex2: -1,
93
            sGroupingColumnSortDirection2: "",
94
            iGroupingOrderByColumnIndex2: -1,
95
            sGroupingClass2: "subgroup",
96
            sGroupItemClass2: "subgroup-item",
97
            bHideGroupingColumn2: true,
98
            bHideGroupingOrderByColumn2: true,
99
            sGroupBy2: "name",
100
            sGroupLabelPrefix2: "",
101
            fnGroupLabelFormat2: function (label) { return label; },
102
            bExpandableGrouping2: false,
103
104
            fnOnGrouped: _fnOnGrouped,
105
106
            fnOnGroupCreated: _fnOnGroupCreated,
107
            fnOnGroupCompleted: _fnOnGroupCompleted,
108
109
            oHideEffect: null, // { method: "hide", duration: "fast", easing: "linear" },
110
            oShowEffect: null,//{ method: "show", duration: "slow", easing: "linear" }
111
112
                   bUseFilteringForGrouping: false // This is still work in progress option
113
        };
114
        return this.each(function (index, elem) {
115
116
            var oTable = $(elem).dataTable();
117
118
            var aoGroups = new Array();
119
            $(this).dataTableExt.aoGroups = aoGroups;
120
121
            function fnCreateGroupRow(sGroupCleaned, sGroup, iColspan) {
122
                var nGroup = document.createElement('tr');
123
                var nCell = document.createElement('td');
124
                nGroup.id = "group-id-" + oTable.attr("id") + "_" + sGroupCleaned;
125
126
                var oGroup = { id: nGroup.id, key: sGroupCleaned, text: sGroup, level: 0, groupItemClass: ".group-item-" + sGroupCleaned, dataGroup: sGroupCleaned, aoSubgroups: new Array() };
127
128
129
130
                if (properties.bSetGroupingClassOnTR) {
131
                    nGroup.className = properties.sGroupingClass + " " + sGroupCleaned;
132
                } else {
133
                    nCell.className = properties.sGroupingClass + " " + sGroupCleaned;
134
                }
135
136
                nCell.colSpan = iColspan;
137
                nCell.innerHTML = properties.sGroupLabelPrefix + properties.fnGroupLabelFormat(sGroup == "" ? properties.sEmptyGroupLabel : sGroup, oGroup );
138
                if (properties.bExpandableGrouping) {
139
140
                    if (!_fnIsGroupCollapsed(sGroupCleaned)) {
141
                        nCell.className += " expanded-group";
142
                        oGroup.state = "expanded";
143
                    } else {
144
                        nCell.className += " collapsed-group";
145
                        oGroup.state = "collapsed";
146
                    }
147
                    nCell.className += " group-item-expander";
148
                    $(nCell).attr('data-group', oGroup.dataGroup); //Fix provided by mssskhalsa (Issue 5)
149
                    $(nCell).attr("data-group-level", oGroup.level);
150
                    $(nCell).click(_fnOnGroupClick);
151
                }
152
                nGroup.appendChild(nCell);
153
                aoGroups[sGroupCleaned] = oGroup;
154
                oGroup.nGroup = nGroup;
155
                properties.fnOnGroupCreated(oGroup, sGroupCleaned, 1);
156
                return oGroup;
157
            }
158
159
            function _fnCreateGroup2Row(sGroup2, sGroupLabel, iColspan, oParentGroup) {
160
161
                var nGroup2 = document.createElement('tr');
162
                nGroup2.id = oParentGroup.id + "_" + sGroup2;
163
                var nCell2 = document.createElement('td');
164
                var dataGroup = oParentGroup.dataGroup + '_' + sGroup2;
165
166
                var oGroup = { id: nGroup2.id, key: sGroup2, text: sGroupLabel, level: oParentGroup.level + 1, groupItemClass: ".group-item-" + dataGroup,
167
                    dataGroup: dataGroup, aoSubgroups: new Array()
168
                };
169
170
                if (properties.bSetGroupingClassOnTR) {
171
                    nGroup2.className = properties.sGroupingClass2 + " " + sGroup2;
172
                } else {
173
                    nCell2.className = properties.sGroupingClass2 + " " + sGroup2;
174
                }
175
176
                nCell2.colSpan = iColspan;
177
                nCell2.innerHTML = properties.sGroupLabelPrefix2 + properties.fnGroupLabelFormat2(sGroupLabel == "" ? properties.sEmptyGroupLabel : sGroupLabel, oGroup);
178
179
                if (properties.bExpandableGrouping) {
180
181
                    nGroup2.className += " group-item-" + oParentGroup.dataGroup;
182
                }
183
184
185
                if (properties.bExpandableGrouping && properties.bExpandableGrouping2) {
186
187
                    if (!_fnIsGroupCollapsed(oGroup.dataGroup)) {
188
                        nCell2.className += " expanded-group";
189
                        oGroup.state = "expanded";
190
                    } else {
191
                        nCell2.className += " collapsed-group";
192
                        oGroup.state = "collapsed";
193
                    }
194
                    nCell2.className += " group-item-expander";
195
                    $(nCell2).attr('data-group', oGroup.dataGroup);
196
                    $(nCell2).attr("data-group-level", oGroup.level);
197
                    $(nCell2).click(_fnOnGroupClick);
198
                }
199
200
                nGroup2.appendChild(nCell2);
201
202
                oParentGroup.aoSubgroups[oGroup.dataGroup] = oGroup;
203
                aoGroups[oGroup.dataGroup] = oGroup;
204
                oGroup.nGroup = nGroup2;
205
                properties.fnOnGroupCreated(oGroup, sGroup2, 2);
206
                return oGroup;
207
            }
208
209
            function _fnIsGroupCollapsed(sGroup) {
210
                if (aoGroups[sGroup] != null)
211
                    return (aoGroups[sGroup].state == "collapsed");
212
                else
213
                    if (sGroup.indexOf("_") > -1)
214
                        true;
215
                    else
216
                                             if(bInitialGrouping && (asExpandedGroups==null || asExpandedGroups.length == 0))
217
                                                       return false;// initially if asExpandedGroups is empty - no one is collapsed
218
                                           else
219
                                                   return ($.inArray(sGroup, asExpandedGroups) == -1); //the last chance check asExpandedGroups
220
            }
221
222
            function _fnGetYear(x) {
223
                               if(x.length< (iYearIndex+iYearLength) )
224
                                        return x;
225
                              else
226
                                   return x.substr(iYearIndex, iYearLength);
227
            }
228
            function _fnGetGroupByName(x) {
229
                return x;
230
            }
231
232
            function _fnGetGroupByLetter(x) {
233
                return x.substr(0, 1);
234
            }
235
236
            function _fnGetGroupByYear(x) {
237
                return _fnGetYear(x);
238
                //return Date.parseExact(x, properties.sDateFormat).getFullYear();//slooooow
239
            }
240
241
            function _fnGetGroupByYearMonth(x) {
242
                //var date = Date.parseExact(x, "dd/MM/yyyy");
243
                //return date.getFullYear() + " / " + date.getMonthName();
244
                //return x.substr(iYearIndex, iYearLength) + '/' + x.substr(iMonthIndex, iMonthLength);
245
                return x.substr(iYearIndex, iYearLength) + ' ' + _getMonthName(x.substr(iMonthIndex, iMonthLength));
246
            }
247
248
            function _fnGetCleanedGroup(sGroup) {
249
250
                if (sGroup === "") return "-";
251
                return sGroup.toLowerCase().replace(/[^a-zA-Z0-9\u0080-\uFFFF]+/g, "-"); //fix for unicode characters (Issue 23)
252
                //return sGroup.toLowerCase().replace(/\W+/g, "-"); //Fix provided by bmathews (Issue 7)
253
            }
254
255
                       function _rowGroupingRowFilter(oSettings, aData, iDataIndex) {
256
                     ///<summary>Used to expand/collapse groups with DataTables filtering</summary>
257
                if (oSettings.nTable.id !== oTable[0].id) return true;
258
                var sColData = aData[properties.iGroupingColumnIndex];
259
                if (typeof sColData === "undefined")
260
                    sColData = aData[oSettings.aoColumns[properties.iGroupingColumnIndex].mDataProp];
261
                if (_fnIsGroupCollapsed(_fnGetCleanedGroup(sColData))) {
262
                    if (oTable.fnIsOpen(oTable.fnGetNodes(iDataIndex)))
263
                                   {
264
                                              if (properties.fnOnRowClosed != null) {
265
                            properties.fnOnRowClosed(this); //    $(this.cells[0].children[0]).attr('src', '../../Images/details.png');
266
                        }
267
                        oTable.fnClose(oTable.fnGetNodes(iDataIndex));
268
                    }
269
                    return false;
270
                };
271
                            return true;
272
            } //end of function _rowGroupingRowFilter
273
274
275
            function fnExpandGroup(sGroup) {
276
                ///<summary>Expand group if expanadable grouping is used</summary>
277
278
                      aoGroups[sGroup].state = "expanded";
279
280
                              $("td[data-group^='" + sGroup + "']").removeClass("collapsed-group");
281
                $("td[data-group^='" + sGroup + "']").addClass("expanded-group");
282
283
284
                              if(properties.bUseFilteringForGrouping)
285
                                {
286
                                      oTable.fnDraw();
287
                                       return;//Because rows are expanded with _rowGroupingRowFilter function
288
                         }
289
290
                             if (jQuery.inArray(sGroup, asExpandedGroups)==-1)
291
                    asExpandedGroups.push(sGroup);
292
293
                if (properties.oHideEffect != null)
294
                    $(".group-item-" + sGroup, oTable)
295
                                       [properties.oShowEffect.method](properties.oShowEffect.duration,
296
                                                                       properties.oShowEffect.easing,
297
                                                                 function () { });
298
                else
299
                    $(".group-item-" + sGroup, oTable).show();
300
301
302
            } //end of function fnExpandGroup
303
304
            function fnCollapseGroup(sGroup) {
305
                ///<summary>Collapse group if expanadable grouping is used</summary>
306
307
                            aoGroups[sGroup].state = "collapsed";
308
                          $("td[data-group^='" + sGroup + "']").removeClass("expanded-group");
309
                $("td[data-group^='" + sGroup + "']").addClass("collapsed-group");
310
311
                               if(properties.bUseFilteringForGrouping)
312
                                {
313
                                      oTable.fnDraw();
314
                                       return;//Because rows are expanded with _rowGroupingRowFilter function
315
                         }
316
                              //var index = $.inArray(sGroup, asExpandedGroups);
317
                //asExpandedGroups.splice(index, 1);
318
319
                $('.group-item-' + sGroup).each(function () {
320
                    //Issue 24 - Patch provided by Bob Graham
321
                    if (oTable.fnIsOpen(this)) {
322
                        if (properties.fnOnRowClosed != null) {
323
                            properties.fnOnRowClosed(this); //    $(this.cells[0].children[0]).attr('src', '../../Images/details.png');
324
                        }
325
                        oTable.fnClose(this);
326
                    }
327
                });
328
329
                if (properties.oHideEffect != null)
330
                    $(".group-item-" + sGroup, oTable)
331
                                    [properties.oHideEffect.method](properties.oHideEffect.duration,
332
                                                                       properties.oHideEffect.easing,
333
                                                                 function () { });
334
                else
335
                    $(".group-item-" + sGroup, oTable).hide();
336
337
            } //end of function fnCollapseGroup
338
339
            function _fnOnGroupClick(e) {
340
                ///<summary>
341
                ///Function that is called when user click on the group cell in order to
342
                ///expand of collapse group
343
                ///</summary>
344
345
                //var sGroup = $(this).attr("rel");
346
                var sGroup = $(this).attr("data-group");
347
                var iGroupLevel = $(this).attr("data-group-level");
348
349
                var bIsExpanded = !_fnIsGroupCollapsed(sGroup);
350
                if (properties.bExpandSingleGroup) {
351
                    if (!bIsExpanded) {
352
                        var sCurrentGroup = $("td.expanded-group").attr("data-group");
353
                        fnCollapseGroup(sCurrentGroup);
354
                        fnExpandGroup(sGroup);
355
356
                        if (properties.iExpandGroupOffset != -1) {
357
                            var position = $("#group-id-" + oTable.attr("id") + "_" + sGroup).offset().top - properties.iExpandGroupOffset;
358
                            window.scroll(0, position);
359
                        } else {
360
                            var position = oTable.offset().top;
361
                            window.scroll(0, position);
362
                        }
363
                    }
364
                } else {
365
                    if (bIsExpanded) {
366
                        fnCollapseGroup(sGroup);
367
                    } else {
368
                        fnExpandGroup(sGroup);
369
                    }
370
                }
371
                e.preventDefault();
372
373
            }; //end function _fnOnGroupClick
374
375
376
                     function _fnDrawCallBackWithGrouping (oSettings) {
377
378
                if (oTable.fnSettings().oFeatures.bServerSide)
379
                    bInitialGrouping = true;
380
                var bUseSecondaryGrouping = false;
381
382
                if (properties.iGroupingColumnIndex2 != -1)
383
                    bUseSecondaryGrouping = true;
384
385
                //-----Start grouping
386
387
                if (oSettings.aiDisplayMaster.length == 0) { //aiDisplay
388
                    return;
389
                }
390
391
                var nTrs = $('tbody tr', oTable);
392
                var iColspan = 0; //nTrs[0].getElementsByTagName('td').length;
393
                for (var iColIndex = 0; iColIndex < oSettings.aoColumns.length; iColIndex++) {
394
                    if (oSettings.aoColumns[iColIndex].bVisible)
395
                        iColspan += 1;
396
                }
397
                var sLastGroup = null;
398
                var sLastGroup2 = null;
399
                if (oSettings.aiDisplay.length > 0) {
400
                    for (var i = 0; i < nTrs.length; i++) {
401
402
403
                        var iDisplayIndex = oSettings._iDisplayStart + i;
404
                        if (oTable.fnSettings().oFeatures.bServerSide)
405
                            iDisplayIndex = i;
406
                        var sGroupData = "";
407
                        var sGroup = null;
408
                        var sGroupData2 = "";
409
                        var sGroup2 = null;
410
411
                        //Issue 31 - Start fix provided by Fabien Taysse
412
//                      sGroupData = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[properties.iGroupingColumnIndex];
413
//                      if (sGroupData == undefined)
414
//                          sGroupData = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[oSettings.aoColumns[properties.iGroupingColumnIndex].mDataProp];
415
                        sGroupData = this.fnGetData(nTrs[i], properties.iGroupingColumnIndex);
416
                        //Issue 31 - End fix provided by Fabien Taysse
417
418
                        var sGroup = sGroupData;
419
                        if (properties.sGroupBy != "year")
420
                            sGroup = fnGetGroup(sGroupData);
421
422
                        if (bUseSecondaryGrouping) {
423
                            sGroupData2 = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[properties.iGroupingColumnIndex2];
424
                            if (sGroupData2 == undefined)
425
                                sGroupData2 = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[oSettings.aoColumns[properties.iGroupingColumnIndex2].mDataProp];
426
                            if (properties.sGroupBy2 != "year")
427
                                sGroup2 = fnGetGroup(sGroupData2);
428
                        }
429
430
431
                        if (sLastGroup == null || _fnGetCleanedGroup(sGroup) != _fnGetCleanedGroup(sLastGroup)) { // new group encountered (or first of group)
432
                            var sGroupCleaned = _fnGetCleanedGroup(sGroup);
433
434
                            if(sLastGroup != null)
435
                            {
436
                              properties.fnOnGroupCompleted(aoGroups[_fnGetCleanedGroup(sLastGroup)]);
437
                            }
438
                                                   /*
439
                            if (properties.bExpandableGrouping && bInitialGrouping) {
440
                                if (properties.bExpandSingleGroup) {
441
                                    if (asExpandedGroups.length == 0)
442
                                        asExpandedGroups.push(sGroupCleaned);
443
                                } else {
444
                                    asExpandedGroups.push(sGroupCleaned);
445
                                }
446
                            }
447
                                                   */
448
                                                     if(properties.bAddAllGroupsAsExpanded && jQuery.inArray(sGroupCleaned,asExpandedGroups) == -1)
449
                                                         asExpandedGroups.push(sGroupCleaned);
450
451
                            var oGroup = fnCreateGroupRow(sGroupCleaned, sGroup, iColspan);
452
                            var nGroup = oGroup.nGroup;
453
454
                                                    if(nTrs[i].parentNode!=null)
455
                                                           nTrs[i].parentNode.insertBefore(nGroup, nTrs[i]);
456
                                                      else
457
                                                           $(nTrs[i]).before(nGroup);
458
459
                            sLastGroup = sGroup;
460
                            sLastGroup2 = null; //to reset second level grouping
461
462
463
464
465
466
                        } // end if (sLastGroup == null || sGroup != sLastGroup)
467
468
                                           $(nTrs[i]).attr("data-group", aoGroups[sGroupCleaned].dataGroup);
469
470
                        $(nTrs[i]).addClass(properties.sGroupItemClass);
471
                        $(nTrs[i]).addClass("group-item-" + sGroupCleaned);
472
                        if (properties.bExpandableGrouping) {
473
                            if (_fnIsGroupCollapsed(sGroupCleaned) && !properties.bUseFilteringForGrouping) {
474
                                $(nTrs[i]).hide();
475
                            }
476
                        }
477
478
479
                        if (bUseSecondaryGrouping) {
480
481
                            if (sLastGroup2 == null || _fnGetCleanedGroup(sGroup2) != _fnGetCleanedGroup(sLastGroup2)) {
482
                                var sGroup2Id = _fnGetCleanedGroup(sGroup) + '-' + _fnGetCleanedGroup(sGroup2);
483
                                var oGroup2 = _fnCreateGroup2Row(sGroup2Id, sGroup2, iColspan, aoGroups[sGroupCleaned])
484
                                var nGroup2 = oGroup2.nGroup;
485
                                nTrs[i].parentNode.insertBefore(nGroup2, nTrs[i]);
486
487
                                sLastGroup2 = sGroup2;
488
                            }
489
490
                            $(nTrs[i]).attr("data-group", oGroup2.dataGroup)
491
                                                                           .addClass(properties.sGroupItemClass2)
492
                                        .addClass("group-item-" + oGroup2.dataGroup);
493
                        } //end if (bUseSecondaryGrouping)
494
495
496
497
                    } // end for (var i = 0; i < nTrs.length; i++)
498
                }; // if (oSettings.aiDisplay.length > 0)
499
500
                               if(sLastGroup != null)
501
                     {
502
                                properties.fnOnGroupCompleted(aoGroups[_fnGetCleanedGroup(sLastGroup)]);
503
                         }
504
505
506
                //-----End grouping
507
                properties.fnOnGrouped(aoGroups);
508
509
                bInitialGrouping = false;
510
511
            }; // end of _fnDrawCallBackWithGrouping = function (oSettings)
512
513
514
            //var oTable = this;
515
            var iYearIndex = 6;
516
            var iYearLength = 4;
517
            var asExpandedGroups = new Array();
518
            var bInitialGrouping = true;
519
520
            var properties = $.extend(defaults, options);
521
522
            if (properties.iGroupingOrderByColumnIndex == -1) {
523
                properties.bCustomColumnOrdering = false;
524
                properties.iGroupingOrderByColumnIndex = properties.iGroupingColumnIndex;
525
            } else {
526
                properties.bCustomColumnOrdering = true;
527
            }
528
529
            if (properties.sGroupingColumnSortDirection == "") {
530
                if (properties.sGroupBy == "year")
531
                    properties.sGroupingColumnSortDirection = "desc";
532
                else
533
                    properties.sGroupingColumnSortDirection = "asc";
534
            }
535
536
537
            if (properties.iGroupingOrderByColumnIndex2 == -1) {
538
                properties.bCustomColumnOrdering2 = false;
539
                properties.iGroupingOrderByColumnIndex2 = properties.iGroupingColumnIndex2;
540
            } else {
541
                properties.bCustomColumnOrdering2 = true;
542
            }
543
544
            if (properties.sGroupingColumnSortDirection2 == "") {
545
                if (properties.sGroupBy2 == "year")
546
                    properties.sGroupingColumnSortDirection2 = "desc";
547
                else
548
                    properties.sGroupingColumnSortDirection2 = "asc";
549
            }
550
551
552
553
            iYearIndex = properties.sDateFormat.toLowerCase().indexOf('yy');
554
            iYearLength = properties.sDateFormat.toLowerCase().lastIndexOf('y') - properties.sDateFormat.toLowerCase().indexOf('y') + 1;
555
556
            var iMonthIndex = properties.sDateFormat.toLowerCase().indexOf('mm');
557
            var iMonthLength = properties.sDateFormat.toLowerCase().lastIndexOf('m') - properties.sDateFormat.toLowerCase().indexOf('m') + 1;
558
559
            var fnGetGroup = _fnGetGroupByName;
560
            switch (properties.sGroupBy) {
561
                case "letter": fnGetGroup = _fnGetGroupByLetter;
562
                    break;
563
                case "year": fnGetGroup = _fnGetGroupByYear;
564
                    break;
565
                case "month": fnGetGroup = _fnGetGroupByYearMonth;
566
                    break;
567
                default: fnGetGroup = _fnGetGroupByName;
568
                    break;
569
            }
570
571
572
            if (properties.asExpandedGroups != null) {
573
                if (properties.asExpandedGroups == "NONE") {
574
                    properties.asExpandedGroups = [];
575
                    asExpandedGroups = properties.asExpandedGroups;
576
                    bInitialGrouping = false;
577
                } else if (properties.asExpandedGroups == "ALL") {
578
                                     properties.bAddAllGroupsAsExpanded = true;
579
                } else if (properties.asExpandedGroups.constructor == String) {
580
                    var currentGroup = properties.asExpandedGroups;
581
                    properties.asExpandedGroups = new Array();
582
                    properties.asExpandedGroups.push(_fnGetCleanedGroup(currentGroup));
583
                    asExpandedGroups = properties.asExpandedGroups;
584
                    bInitialGrouping = false;
585
                } else if (properties.asExpandedGroups.constructor == Array) {
586
                    for (var i = 0; i < properties.asExpandedGroups.length; i++) {
587
                        asExpandedGroups.push(_fnGetCleanedGroup(properties.asExpandedGroups[i]));
588
                        if (properties.bExpandSingleGroup)
589
                            break;
590
                    }
591
                    bInitialGrouping = false;
592
                }
593
            }else{
594
                            properties.asExpandedGroups = new Array();
595
                             properties.bAddAllGroupsAsExpanded = true;
596
                     }
597
                      if(properties.bExpandSingleGroup){
598
                         var nTrs = $('tbody tr', oTable);
599
                          var sGroupData = oTable.fnGetData(nTrs[0], properties.iGroupingColumnIndex);
600
601
                          var sGroup = sGroupData;
602
                if (properties.sGroupBy != "year")
603
                    sGroup = fnGetGroup(sGroupData);
604
605
                              var sGroupCleaned = _fnGetCleanedGroup(sGroup);
606
                                properties.asExpandedGroups = new Array();
607
                             properties.asExpandedGroups.push(sGroupCleaned);
608
609
                      }
610
611
            oTable.fnSetColumnVis(properties.iGroupingColumnIndex, !properties.bHideGroupingColumn);
612
            if (properties.bCustomColumnOrdering) {
613
                oTable.fnSetColumnVis(properties.iGroupingOrderByColumnIndex, !properties.bHideGroupingOrderByColumn);
614
            }
615
            if (properties.iGroupingColumnIndex2 != -1) {
616
                oTable.fnSetColumnVis(properties.iGroupingColumnIndex2, !properties.bHideGroupingColumn2);
617
            }
618
            if (properties.bCustomColumnOrdering2) {
619
                oTable.fnSetColumnVis(properties.iGroupingOrderByColumnIndex2, !properties.bHideGroupingOrderByColumn2);
620
            }
621
            oTable.fnSettings().aoDrawCallback.push({
622
                "fn": _fnDrawCallBackWithGrouping,
623
                "sName": "fnRowGrouping"
624
            });
625
626
            var aaSortingFixed = new Array();
627
            aaSortingFixed.push([properties.iGroupingOrderByColumnIndex, properties.sGroupingColumnSortDirection]);
628
            if (properties.iGroupingColumnIndex2 != -1) {
629
                aaSortingFixed.push([properties.iGroupingOrderByColumnIndex2, properties.sGroupingColumnSortDirection2]);
630
            } // end of if (properties.iGroupingColumnIndex2 != -1)
631
632
            oTable.fnSettings().aaSortingFixed = aaSortingFixed;
633
            //Old way
634
            //oTable.fnSettings().aaSortingFixed = [[properties.iGroupingOrderByColumnIndex, properties.sGroupingColumnSortDirection]];
635
636
            switch (properties.sGroupBy) {
637
                case "name":
638
                    break;
639
640
641
                case "letter":
642
643
                    /* Create an array with the values of all the input boxes in a column */
644
                    oTable.fnSettings().aoColumns[properties.iGroupingOrderByColumnIndex].sSortDataType = "rg-letter";
645
                    $.fn.dataTableExt.afnSortData['rg-letter'] = function (oSettings, iColumn) {
646
                        var aData = [];
647
                        $('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
648
                            aData.push(_fnGetGroupByLetter(this.innerHTML));
649
                        });
650
                        return aData;
651
                    }
652
653
654
                    break;
655
656
657
                case "year":
658
                    /* Create an array with the values of all the input boxes in a column */
659
                    oTable.fnSettings().aoColumns[properties.iGroupingOrderByColumnIndex].sSortDataType = "rg-date";
660
                    $.fn.dataTableExt.afnSortData['rg-date'] = function (oSettings, iColumn) {
661
                        var aData = [];
662
                                              var nTrs = oSettings.oApi._fnGetTrNodes(oSettings);
663
                                            for(i = 0; i< nTrs.length; i++)
664
                                                {
665
                                                      aData.push(_fnGetYear( oTable.fnGetData( nTrs[i], iColumn) ));
666
                                         }
667
668
/*
669
                        $('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
670
                            aData.push(_fnGetYear(this.innerHTML));
671
                        });
672
*/
673
                        return aData;
674
                    }
675
                    break;
676
                default:
677
                    break;
678
679
            } // end of switch (properties.sGroupBy)
680
681
                     if(properties.bUseFilteringForGrouping)
682
                                        $.fn.dataTableExt.afnFiltering.push(_rowGroupingRowFilter);
683
684
            oTable.fnDraw();
685
686
687
688
        });
689
    };
690
})(jQuery);
(-)a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js (+25 lines)
Line 0 Link Here
1
/*!
2
   Copyright 2017-2018 SpryMedia Ltd.
3
4
 This source file is free software, available under the following license:
5
   MIT license - http://datatables.net/license/mit
6
7
 This source file is distributed in the hope that it will be useful, but
8
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9
 or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
10
11
 For details please refer to: http://www.datatables.net
12
 RowGroup 1.1.0
13
 ©2017-2018 SpryMedia Ltd - datatables.net/license
14
*/
15
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,d,c){a instanceof String&&(a=String(a));for(var e=a.length,f=0;f<e;f++){var h=a[f];if(d.call(c,h,f,a))return{i:f,v:h}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,d,c){a!=Array.prototype&&a!=Object.prototype&&(a[d]=c.value)};
16
$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,d,c,e){if(d){c=$jscomp.global;a=a.split(".");for(e=0;e<a.length-1;e++){var f=a[e];f in c||(c[f]={});c=c[f]}a=a[a.length-1];e=c[a];d=d(e);d!=e&&null!=d&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:d})}};
17
$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,c){return $jscomp.findInternal(this,a,c).v}},"es6","es3");
18
(function(a){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(d){return a(d,window,document)}):"object"===typeof exports?module.exports=function(d,c){d||(d=window);c&&c.fn.dataTable||(c=require("datatables.net")(d,c).$);return a(c,d,d.document)}:a(jQuery,window,document)})(function(a,d,c,e){var f=a.fn.dataTable,h=function(b,g){if(!f.versionCheck||!f.versionCheck("1.10.8"))throw"RowGroup requires DataTables 1.10.8 or newer";this.c=a.extend(!0,{},f.defaults.rowGroup,
19
h.defaults,g);this.s={dt:new f.Api(b)};this.dom={};b=this.s.dt.settings()[0];if(g=b.rowGroup)return g;b.rowGroup=this;this._constructor()};a.extend(h.prototype,{dataSrc:function(b){if(b===e)return this.c.dataSrc;var g=this.s.dt;this.c.dataSrc=b;a(g.table().node()).triggerHandler("rowgroup-datasrc.dt",[g,b]);return this},disable:function(){this.c.enable=!1;return this},enable:function(b){if(!1===b)return this.disable();this.c.enable=!0;return this},_constructor:function(){var b=this,a=this.s.dt;a.on("draw.dtrg",
20
function(){b.c.enable&&b._draw()});a.on("column-visibility.dt.dtrg responsive-resize.dt.dtrg",function(){b._adjustColspan()});a.on("destroy",function(){a.off(".dtrg")});a.on("responsive-resize.dt",function(){b._adjustColspan()})},_adjustColspan:function(){a("tr."+this.c.className,this.s.dt.table().body()).find("td").attr("colspan",this._colspan())},_colspan:function(){return this.s.dt.columns().visible().reduce(function(b,a){return b+a},0)},_draw:function(){var b=this._group(0,this.s.dt.rows({page:"current"}).indexes());
21
this._groupDisplay(0,b)},_group:function(b,g){for(var c=a.isArray(this.c.dataSrc)?this.c.dataSrc:[this.c.dataSrc],d=f.ext.oApi._fnGetObjectDataFn(c[b]),h=this.s.dt,l,n,m=[],k=0,p=g.length;k<p;k++){var q=g[k];l=h.row(q).data();l=d(l);if(null===l||l===e)l=that.c.emptyDataGroup;if(n===e||l!==n)m.push({dataPoint:l,rows:[]}),n=l;m[m.length-1].rows.push(q)}if(c[b+1]!==e)for(k=0,p=m.length;k<p;k++)m[k].children=this._group(b+1,m[k].rows);return m},_groupDisplay:function(b,a){for(var c=this.s.dt,g,d=0,f=
22
a.length;d<f;d++){var e=a[d],h=e.dataPoint,k=e.rows;this.c.startRender&&(g=this.c.startRender.call(this,c.rows(k),h,b),(g=this._rowWrap(g,this.c.startClassName,b))&&g.insertBefore(c.row(k[0]).node()));this.c.endRender&&(g=this.c.endRender.call(this,c.rows(k),h,b),(g=this._rowWrap(g,this.c.endClassName,b))&&g.insertAfter(c.row(k[k.length-1]).node()));e.children&&this._groupDisplay(b+1,e.children)}},_rowWrap:function(b,g,c){if(null===b||""===b)b=this.c.emptyDataGroup;return b===e?null:("object"===typeof b&&
23
b.nodeName&&"tr"===b.nodeName.toLowerCase()?a(b):b instanceof a&&b.length&&"tr"===b[0].nodeName.toLowerCase()?b:a("<tr/>").append(a("<td/>").attr("colspan",this._colspan()).append(b))).addClass(this.c.className).addClass(g).addClass("dtrg-level-"+c)}});h.defaults={className:"dtrg-group",dataSrc:0,emptyDataGroup:"No group",enable:!0,endClassName:"dtrg-end",endRender:null,startClassName:"dtrg-start",startRender:function(a,c){return c}};h.version="1.1.0";a.fn.dataTable.RowGroup=h;a.fn.DataTable.RowGroup=
24
h;f.Api.register("rowGroup()",function(){return this});f.Api.register("rowGroup().disable()",function(){return this.iterator("table",function(a){a.rowGroup&&a.rowGroup.enable(!1)})});f.Api.register("rowGroup().enable()",function(a){return this.iterator("table",function(b){b.rowGroup&&b.rowGroup.enable(a===e?!0:a)})});f.Api.register("rowGroup().dataSrc()",function(a){return a===e?this.context[0].rowGroup.dataSrc():this.iterator("table",function(b){b.rowGroup&&b.rowGroup.dataSrc(a)})});a(c).on("preInit.dt.dtrg",
25
function(b,c,d){"dt"===b.namespace&&(b=c.oInit.rowGroup,d=f.defaults.rowGroup,b||d)&&(d=a.extend({},d,b),!1!==b&&new h(c,d))});return h});
(-)a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css (+1 lines)
Line 0 Link Here
1
table.dataTable tr.dtrg-group td{background-color:#e0e0e0}table.dataTable tr.dtrg-group.dtrg-level-0 td{font-weight:bold}table.dataTable tr.dtrg-group.dtrg-level-1 td,table.dataTable tr.dtrg-group.dtrg-level-2 td{background-color:#f0f0f0;padding-top:0.25em;padding-bottom:0.25em;padding-left:2em;font-size:0.9em}table.dataTable tr.dtrg-group.dtrg-level-2 td{background-color:#f3f3f3}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +2 lines)
Lines 10-15 Link Here
10
[% USE AuthorisedValues %]
10
[% USE AuthorisedValues %]
11
[% SET footerjs = 1 %]
11
[% SET footerjs = 1 %]
12
[% INCLUDE 'doc-head-open.inc' %]
12
[% INCLUDE 'doc-head-open.inc' %]
13
[% Asset.css("lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css") | $raw %]
13
[% SET destination = "circ" %]
14
[% SET destination = "circ" %]
14
<title>
15
<title>
15
    Koha &rsaquo; Circulation
16
    Koha &rsaquo; Circulation
Lines 1014-1020 Link Here
1014
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
1015
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
1015
    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
1016
    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
1016
    [% INCLUDE 'timepicker.inc' %]
1017
    [% INCLUDE 'timepicker.inc' %]
1017
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.rowGrouping.js") | $raw %]
1018
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
1018
    <script>
1019
    <script>
1019
        /* Set some variable needed in circulation.js */
1020
        /* Set some variable needed in circulation.js */
1020
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
1021
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-1 / +2 lines)
Lines 8-13 Link Here
8
[% USE Price %]
8
[% USE Price %]
9
[% SET footerjs = 1 %]
9
[% SET footerjs = 1 %]
10
[% INCLUDE 'doc-head-open.inc' %]
10
[% INCLUDE 'doc-head-open.inc' %]
11
[% Asset.css("lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css") | $raw %]
11
<title>Koha &rsaquo; Patrons &rsaquo;
12
<title>Koha &rsaquo; Patrons &rsaquo;
12
    [% UNLESS blocking_error %]
13
    [% UNLESS blocking_error %]
13
        Patron details for [% INCLUDE 'patron-title.inc' no_html = 1 %]
14
        Patron details for [% INCLUDE 'patron-title.inc' no_html = 1 %]
Lines 845-857 Link Here
845
846
846
[% MACRO jsinclude BLOCK %]
847
[% MACRO jsinclude BLOCK %]
847
    [% INCLUDE 'datatables.inc' %]
848
    [% INCLUDE 'datatables.inc' %]
849
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
848
    [% INCLUDE 'columns_settings.inc' %]
850
    [% INCLUDE 'columns_settings.inc' %]
849
    [% INCLUDE 'strings.inc' %]
851
    [% INCLUDE 'strings.inc' %]
850
    [% INCLUDE 'calendar.inc' %]
852
    [% INCLUDE 'calendar.inc' %]
851
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
853
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
852
    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
854
    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
853
    [% INCLUDE 'timepicker.inc' %]
855
    [% INCLUDE 'timepicker.inc' %]
854
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.rowGrouping.js") | $raw %]
855
    <script>
856
    <script>
856
        /* Set some variable needed in circulation.js */
857
        /* Set some variable needed in circulation.js */
857
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
858
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
(-)a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js (-18 / +12 lines)
Lines 596-614 $(document).ready(function() { Link Here
596
                    fnCallback(json)
596
                    fnCallback(json)
597
                } );
597
                } );
598
            },
598
            },
599
            "rowGroup":{
600
                "dataSrc": "issued_today",
601
                "startRender": function ( rows, group ) {
602
                    if ( group ) {
603
                        return $('<tr/>').append("<td colspan='100%'><strong>" + TODAYS_CHECKOUTS + "</strong></td>");
604
                    } else {
605
                        return $('<tr/>').append("<td colspan='100%'><strong>" + PREVIOUS_CHECKOUTS + "</strong></td>");
606
                    }
607
                }
608
            },
599
            "fnInitComplete": function(oSettings, json) {
609
            "fnInitComplete": function(oSettings, json) {
600
                // Disable rowGrouping plugin after first use
610
                // Disable rowGrouping plugin after first use
601
                // so any sorting on the table doesn't use it
611
                // so any sorting on the table doesn't use it
602
                var oSettings = issuesTable.fnSettings();
612
                //var oSettings = issuesTable.fnSettings();
603
604
                for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
605
                    if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
606
                        oSettings.aoDrawCallback.splice(f, 1);
607
                        break;
608
                    }
609
                }
610
611
                oSettings.aaSortingFixed = null;
612
613
613
                // Build a summary of checkouts grouped by itemtype
614
                // Build a summary of checkouts grouped by itemtype
614
                var checkoutsByItype = json.aaData.reduce(function (obj, row) {
615
                var checkoutsByItype = json.aaData.reduce(function (obj, row) {
Lines 628-640 $(document).ready(function() { Link Here
628
                    .append(ul)
629
                    .append(ul)
629
                    .insertBefore(oSettings.nTableWrapper)
630
                    .insertBefore(oSettings.nTableWrapper)
630
            },
631
            },
631
        }, columns_settings_issues_table).rowGrouping(
632
        }, columns_settings_issues_table);
632
            {
633
                iGroupingColumnIndex: 1,
634
                iGroupingOrderByColumnIndex: 0,
635
                sGroupingColumnSortDirection: "asc"
636
            }
637
        );
638
633
639
        if ( $("#issues-table").length ) {
634
        if ( $("#issues-table").length ) {
640
            $("#issues-table_processing").position({
635
            $("#issues-table_processing").position({
641
- 

Return to bug 23493