forked from angular-ui/ui-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-grid-1.2.1.debug.js
2485 lines (2315 loc) · 95.4 KB
/
ng-grid-1.2.1.debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************
* ng-grid JavaScript Library
* Authors: https://github.com/Crash8308/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 11/20/2012 01:31:27
***********************************************/
(function(window, undefined){
/***********************************************
* FILE: ..\src\namespace.js
***********************************************/
window.ng = {};
var ngGridServices = angular.module('ngGrid.services', []);
var ngGridDirectives = angular.module('ngGrid.directives', []);
var ngGridFilters = angular.module('ngGrid.filters', []);
// Declare app level module which depends on filters, and services
/***********************************************
* FILE: ..\src\constants.js
***********************************************/
var ROW_KEY = '__ng_rowIndex__';
var SELECTED_PROP = '__ng_selected__';
var GRID_KEY = '__koGrid__';
// the # of rows we want to add to the top and bottom of the rendered grid rows
var EXCESS_ROWS = 8;
var ASC = "asc"; // constant for sorting direction
var DESC = "desc"; // constant for sorting direction
var NG_FIELD = '_ng_field_';
var NG_DEPTH = '_ng_depth_';
var NG_HIDDEN = '_ng_hidden_';
var NG_COLUMN = '_ng_column_';
var CUSTOM_FILTERS = /CUSTOM_FILTERS/g;
/***********************************************
* FILE: ..\src\navigation.js
***********************************************/
//set event binding on the grid so we can select using the up/down keys
ng.moveSelectionHandler = function ($scope, grid, evt) {
// null checks
if (grid === null || grid === undefined) return true;
if (grid.config.selectedItems === undefined) return true;
var offset,
charCode = (evt.which) ? evt.which : event.keyCode;
// detect which direction for arrow keys to navigate the grid
switch (charCode) {
case 38:
// up - select previous
offset = -1;
break;
case 40:
// down - select next
offset = 1;
break;
default:
return true;
}
var items = grid.sortedData,
n = items.length,
index = ng.utils.arrayIndexOf(items, grid.selectionService.lastClickedRow.entity) + offset,
rowCache = grid.rowFactory.rowCache,
selected,
itemToView;
// now find the item we arrowed to, and select it
if (index >= 0 && index < n) {
selected = items[index];
var row = rowCache[selected[ROW_KEY]];
if (row) {
row.toggleSelected(evt);
itemToView = ng.utils.getElementsByClassName("selected");
// finally scroll it into view as we arrow through
if (itemToView && itemToView[0]) {
if (!Element.prototype.scrollIntoViewIfNeeded) {
itemToView[0].scrollIntoView(false);
grid.$viewport.focus();
} else {
itemToView[0].scrollIntoViewIfNeeded();
}
}
}
if (!$scope.$$phase) {
$scope.$apply();
}
// fire the selection
return false;
}
return false;
};
/***********************************************
* FILE: ..\src\utils.js
***********************************************/
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/){
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) from += len;
for (; from < len; from++){
if (from in this && this[from] === elt) return from;
}
return -1;
};
}
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp */)
{
"use strict";
if (this === void 0 || this === null) throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
{
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t))
res.push(val);
}
}
return res;
};
}
ng.utils = {
visualLength: function (node) {
var elem = document.getElementById('testDataLength');
if (!elem) {
elem = document.createElement('SPAN');
elem.id = "testDataLength";
elem.style.visibility = "hidden";
document.body.appendChild(elem);
}
var font = $(node).css('font');
$(elem).css('font', font);
elem.innerHTML = $(node).text();
return elem.offsetWidth;
},
arrayIndexOf: function (array, item) {
if (typeof Array.prototype.indexOf == "function")
return Array.prototype.indexOf.call(array, item);
for (var i = 0, j = array.length; i < j; i++)
if (array[i] === item)
return i;
return -1;
},
arrayFilter: function (array, predicate) {
array = array || [];
var result = [];
for (var i = 0, j = array.length; i < j; i++)
if (predicate(array[i]))
result.push(array[i]);
return result;
},
forIn: function (obj, action) {
var prop;
for (prop in obj) {
if(obj.hasOwnProperty(prop)){
action(obj[prop], prop);
}
}
},
evalProperty: function (entity, path) {
var propPath = path.split('.');
var tempProp = entity[propPath[0]];
for (var j = 1; j < propPath.length; j++) {
if (tempProp) {
tempProp = tempProp[propPath[j]];
} else {
break;
}
}
return tempProp;
},
endsWith: function (str, suffix) {
if (!str || !suffix || typeof str != "string") return false;
return str.indexOf(suffix, str.length - suffix.length) !== -1;
},
isNullOrUndefined: function (obj){
if (obj == null || obj == undefined) return true;
return false;
},
StringBuilder: function () {
var strArr = [];
this.append = function (str, data) {
var len = arguments.length,
intMatch = 0,
strMatch = '{0}',
i = 1;
if (len > 1) { // they provided data
while (i < len) {
//apparently string.replace only works on one match at a time
//so, loop through the string and hit all matches
while (str.indexOf(strMatch) !== -1) {
str = str.replace(strMatch, arguments[i]);
}
i++;
intMatch = i - 1;
strMatch = "{" + intMatch.toString() + "}";
}
}
strArr.push(str);
};
this.toString = function () {
var separator = arguments[0];
if (separator !== null && separator !== undefined) {
return strArr.join(separator);
} else {
return strArr.join("");
}
};
},
getElementsByClassName: function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
},
newId: (function () {
var seedId = new Date().getTime();
return function () {
return seedId += 1;
};
})(),
// we copy KO's ie detection here bc it isn't exported in the min versions of KO
// Detect IE versions for workarounds (uses IE conditionals, not UA string, for robustness)
ieVersion: (function () {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
// Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
while (
div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',
iElems[0]
);
return version > 4 ? version : undefined;
})()
};
$.extend(ng.utils, {
isIe6: (function(){
return ng.utils.ieVersion === 6;
})(),
isIe7: (function(){
return ng.utils.ieVersion === 7;
} )(),
isIe: (function () {
return ng.utils.ieVersion !== undefined;
})()
});
/***********************************************
* FILE: ..\src\filters\ngColumns.js
***********************************************/
ngGridFilters.filter('ngColumns', function () {
return function (input) {
return input.filter(function(col) {
return !col.isAggCol;
});
};
});
/***********************************************
* FILE: ..\src\filters\checkmark.js
***********************************************/
ngGridFilters.filter('checkmark', function () {
return function (input) {
return input ? '\u2714' : '\u2718';
};
});
/***********************************************
* FILE: ..\src\services\GridService.js
***********************************************/
ngGridServices.factory('GridService', function () {
var gridService = {};
gridService.gridCache = {};
gridService.eventStorage = {};
gridService.getIndexOfCache = function() {
var indx = -1;
for (var grid in gridService.gridCache) {
indx++;
if (!gridService.gridCache.hasOwnProperty(grid)) continue;
return indx;
}
return indx;
};
gridService.StoreGrid = function (element, grid) {
gridService.gridCache[grid.gridId] = grid;
element[GRID_KEY] = grid.gridId;
};
gridService.RemoveGrid = function(gridId) {
delete gridService.gridCache[gridId];
};
gridService.GetGrid = function (element) {
var grid;
if (element[GRID_KEY]) {
grid = gridService.gridCache[element[GRID_KEY]];
return grid;
}
return false;
};
gridService.ClearGridCache = function () {
gridService.gridCache = {};
};
gridService.AssignGridEventHandlers = function ($scope, grid) {
grid.$viewport.scroll(function (e) {
var scrollLeft = e.target.scrollLeft,
scrollTop = e.target.scrollTop;
grid.adjustScrollLeft(scrollLeft);
grid.adjustScrollTop(scrollTop);
});
grid.$viewport.off('keydown');
grid.$viewport.on('keydown', function (e) {
return ng.moveSelectionHandler($scope, grid, e);
});
//Chrome and firefox both need a tab index so the grid can recieve focus.
//need to give the grid a tabindex if it doesn't already have one so
//we'll just give it a tab index of the corresponding gridcache index
//that way we'll get the same result every time it is run.
//configurable within the options.
if (grid.config.tabIndex === -1){
grid.$viewport.attr('tabIndex', gridService.getIndexOfCache(grid.gridId));
} else {
grid.$viewport.attr('tabIndex', grid.config.tabIndex);
}
$(window).resize(function () {
var prevSizes = {
rootMaxH: grid.elementDims.rootMaxH,
rootMaxW: grid.elementDims.rootMaxW,
rootMinH: grid.elementDims.rootMinH,
rootMinW: grid.elementDims.rootMinW
},
scrollTop,
isDifferent;
// first check to see if the grid is hidden... if it is, we will screw a bunch of things up by re-sizing
var $hiddens = grid.$root.parents(":hidden");
if ($hiddens.length > 0) {
return;
}
//catch this so we can return the viewer to their original scroll after the resize!
scrollTop = grid.$viewport.scrollTop();
ng.domUtility.measureGrid(grid.$root, grid);
//check to see if anything has changed
if (prevSizes.rootMaxH !== grid.elementDims.rootMaxH && grid.elementDims.rootMaxH !== 0) { // if display: none is set, then these come back as zeros
isDifferent = true;
} else if (prevSizes.rootMaxW !== grid.elementDims.rootMaxW && grid.elementDims.rootMaxW !== 0) {
isDifferent = true;
} else if (prevSizes.rootMinH !== grid.elementDims.rootMinH) {
isDifferent = true;
} else if (prevSizes.rootMinW !== grid.elementDims.rootMinW) {
isDifferent = true;
} else {
return;
}
if (isDifferent) {
grid.refreshDomSizes();
grid.adjustScrollTop(scrollTop, true); //ensure that the user stays scrolled where they were
}
});
};
return gridService;
});
/***********************************************
* FILE: ..\src\services\SortService.js
***********************************************/
ngGridServices.factory('SortService', function () {
var sortService = { };
sortService.colSortFnCache = { }; // cache of sorting functions. Once we create them, we don't want to keep re-doing it
sortService.dateRE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; // nasty regex for date parsing
// utility function for null checking
sortService.isEmpty = function(val) {
return (val === null || val === undefined || val === '');
};
// this takes an piece of data from the cell and tries to determine its type and what sorting
// function to use for it
// @item - the cell data
sortService.guessSortFn = function(item) {
var sortFn, // sorting function that is guessed
itemType, // the typeof item
dateParts, // for date parsing
month, // for date parsing
day; // for date parsing
if (item === undefined || item === null || item === '') return null;
itemType = typeof(item);
//check for numbers and booleans
switch (itemType) {
case "number":
sortFn = sortService.sortNumber;
break;
case "boolean":
sortFn = sortService.sortBool;
break;
}
//if we found one, return it
if (sortFn) return sortFn;
//check if the item is a valid Date
if (Object.prototype.toString.call(item) === '[object Date]') return sortService.sortDate;
// if we aren't left with a string, return a basic sorting function...
if (itemType !== "string") return sortService.basicSort;
// now lets string check..
//check if the item data is a valid number
if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) return sortService.sortNumberStr;
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
dateParts = item.match(sortService.dateRE);
if (dateParts) {
// looks like a date
month = parseInt(dateParts[1]);
day = parseInt(dateParts[2]);
if (month > 12) {
// definitely dd/mm
return sortService.sortDDMMStr;
} else if (day > 12) {
return sortService.sortMMDDStr;
} else {
// looks like a date, but we can't tell which, so assume that it's MM/DD
return sortService.sortMMDDStr;
}
}
//finally just sort the normal string...
return sortService.sortAlpha;
};
sortService.basicSort = function(a, b) {
if (a == b) return 0;
if (a < b) return -1;
return 1;
};
//#region Sorting Functions
sortService.sortNumber = function(a, b) {
return a - b;
};
sortService.sortNumberStr = function(a, b) {
var numA, numB, badA = false, badB = false;
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
if (isNaN(numA)) badA = true;
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
if (isNaN(numB)) badB = true;
// we want bad ones to get pushed to the bottom... which effectively is "greater than"
if (badA && badB) return 0;
if (badA) return 1;
if (badB) return -1;
return numA - numB;
};
sortService.sortAlpha = function(a, b) {
var strA = a.toUpperCase(),
strB = b.toUpperCase();
return strA == strB ? 0 : (strA < strB ? -1 : 1);
};
sortService.sortDate = function(a, b) {
var timeA = a.getTime(),
timeB = b.getTime();
return timeA == timeB ? 0 : (timeA < timeB ? -1 : 1);
};
sortService.sortBool = function(a, b) {
if (a && b) {
return 0;
}
if (!a && !b) {
return 0;
} else {
return a ? 1 : -1;
}
};
sortService.sortDDMMStr = function(a, b) {
var dateA, dateB, mtch, m, d, y;
mtch = a.match(sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
if (m.length == 1) m = '0' + m;
if (d.length == 1) d = '0' + d;
dateA = y + m + d;
mtch = b.match(sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
if (m.length == 1) m = '0' + m;
if (d.length == 1) d = '0' + d;
dateB = y + m + d;
if (dateA == dateB) return 0;
if (dateA < dateB) return -1;
return 1;
};
sortService.sortMMDDStr = function(a, b) {
var dateA, dateB, mtch, m, d, y;
mtch = a.match(sortService.dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
if (m.length == 1) m = '0' + m;
if (d.length == 1) d = '0' + d;
dateA = y + m + d;
mtch = b.match(dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
if (m.length == 1) m = '0' + m;
if (d.length == 1) d = '0' + d;
dateB = y + m + d;
if (dateA == dateB) return 0;
if (dateA < dateB) return -1;
return 1;
};
//#endregion
// the core sorting logic trigger
sortService.sortData = function(data /*datasource*/, sortInfo) {
// first make sure we are even supposed to do work
if (!data || !sortInfo) {
return;
}
// grab the metadata for the rest of the logic
var col = sortInfo.column,
direction = sortInfo.direction,
sortFn,
item;
//see if we already figured out what to use to sort the column
if (sortService.colSortFnCache[col.field]) {
sortFn = sortService.colSortFnCache[col.field];
} else if (col.sortingAlgorithm != undefined) {
sortFn = col.sortingAlgorithm;
sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
} else { // try and guess what sort function to use
item = data[0];
sortFn = sortService.guessSortFn(item[col.field]);
//cache it
if (sortFn) {
sortService.colSortFnCache[col.field] = sortFn;
} else {
// we assign the alpha sort because anything that is null/undefined will never get passed to
// the actual sorting function. It will get caught in our null check and returned to be sorted
// down to the bottom
sortFn = sortService.sortAlpha;
}
}
//now actually sort the data
data.sort(function(itemA, itemB) {
var propA = itemA,
propB = itemB,
propAEmpty,
propBEmpty,
propPath,
i;
propPath = col.field.split(".");
for (i = 0; i < propPath.length; i++) {
if (propA !== undefined && propA !== null) {
propA = propA[propPath[i]];
}
if (propB !== undefined && propB !== null) {
propB = propB[propPath[i]];
}
}
propAEmpty = sortService.isEmpty(propA);
propBEmpty = sortService.isEmpty(propB);
// we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
if (propAEmpty && propBEmpty) {
return 0;
} else if (propAEmpty) {
return 1;
} else if (propBEmpty) {
return -1;
}
//made it this far, we don't have to worry about null & undefined
if (direction === ASC) {
return sortFn(propA, propB);
} else {
return 0 - sortFn(propA, propB);
}
});
return;
};
sortService.Sort = function (sortInfo, data) {
if (sortService.isSorting) return;
sortService.isSorting = true;
sortService.sortData(data, sortInfo);
sortService.isSorting = false;
};
return sortService;
});
/***********************************************
* FILE: ..\src\templates\gridTemplate.js
***********************************************/
ng.defaultGridTemplate = function () {
var b = new ng.utils.StringBuilder();
b.append('<div ng-class="{\'ui-widget\': jqueryUITheme}">');
b.append(' <div class="ngTopPanel" ng-class="{\'ui-widget-header\':jqueryUITheme, \'ui-corner-top\': jqueryUITheme}" ng-style="topPanelStyle()">');
b.append(' <div class="ngGroupPanel" ng-show="showGroupPanel()" ng-style="headerStyle()">');
b.append(' <div class="ngGroupPanelDescription" ng-show="configGroups.length == 0">Drag a column header here and drop it to group by that column</div>');
b.append(' <ul ng-show="configGroups.length > 0" class="ngGroupList">');
b.append(' <li class="ngGroupItem" ng-repeat="group in configGroups"><span class="ngGroupElement"><span class="ngGroupName">{{group.displayName}}<span ng-click="removeGroup($index)" class="ngRemoveGroup">x</span></span><span ng-hide="$last" class="ngGroupArrow"></span></span></li>');
b.append(' </ul>');
b.append(' </div>');
b.append(' <div class="ngHeaderContainer" ng-style="headerStyle()">');
b.append(' <div class="ngHeaderScroller" ng-style="headerScrollerStyle()" ng-header-row></div>');
b.append(' </div>');
b.append(' <div class="ngHeaderButton" ng-show="showColumnMenu" ng-click="toggleShowMenu()"><div class="ngHeaderButtonArrow" ng-click=""></div></div>');
b.append(' <div ng-show="showMenu" class="ngColMenu"><span class="ngMenuText">Choose Columns:</span><ul class="ngColList"><li class="ngColListItem" ng-repeat="col in columns | ngColumns"><label><input type="checkbox" class="ngColListCheckbox" ng-model="col.visible"/> {{col.displayName}}</label></li></ul></div>');
b.append(' </div>');
b.append(' <div class="ngViewport" ng-class="{\'ui-widget-content\': jqueryUITheme}" ng-style="viewportStyle()">');
b.append(' <div class="ngCanvas" ng-style="canvasStyle()">');
b.append(' <div ng-style="rowStyle(row)" ng-repeat="row in renderedRows" ng-click="row.toggleSelected($event)" class="ngRow" ng-class="{\'selected\': row.selected}" ng-class-odd="row.alternatingRowClass()" ng-class-even="row.alternatingRowClass()" ng-row></div>');
b.append(' </div>');
b.append(' </div>');
b.append(' <div class="ngFooterPanel" ng-class="{\'ui-widget-content\': jqueryUITheme, \'ui-corner-bottom\': jqueryUITheme}" ng-style="footerStyle()">');
b.append(' <div class="ngTotalSelectContainer" ng-show="footerVisible">');
b.append(' <div class="ngFooterTotalItems" ng-class="{\'ngNoMultiSelect\': !multiSelect}" >');
b.append(' <span class="ngLabel">Total Items: {{totalItemsLength()}}</span>');
b.append(' </div>');
b.append(' <div class="ngFooterSelectedItems" ng-show="multiSelect">');
b.append(' <span class="ngLabel">Selected Items: {{selectedItems.length}}</span>');
b.append(' </div>');
b.append(' </div>');
b.append(' <div class="ngPagerContainer" style="float: right; margin-top: 10px;" ng-show="footerVisible && enablePaging" ng-class="{\'ngNoMultiSelect\': !multiSelect}">');
b.append(' <div style="float:left; margin-right: 10px;" class="ngRowCountPicker">');
b.append(' <span style="float: left; margin-top: 3px;" class="ngLabel">Page Size:</span>');
b.append(' <select style="float: left;height: 27px; width: 100px" ng-model="pagingOptions.pageSize" >');
b.append(' <option ng-repeat="size in pagingOptions.pageSizes">{{size}}</option>');
b.append(' </select>');
b.append(' </div>');
b.append(' <div style="float:left; margin-right: 10px; line-height:25px;" class="ngPagerControl" style="float: left; min-width: 135px;">');
b.append(' <button class="ngPagerButton" ng-click="pageToFirst()" ng-disabled="cantPageBackward()" title="First Page"><div class="ngPagerFirstTriangle"><div class="ngPagerFirstBar"></div></div></button>');
b.append(' <button class="ngPagerButton" ng-click="pageBackward()" ng-disabled="cantPageBackward()" title="Previous Page"><div class="ngPagerFirstTriangle ngPagerPrevTriangle"></div></button>');
b.append(' <input class="ngPagerCurrent" type="text" style="width:50px; height: 24px; margin-top: 1px; padding: 0px 4px;" ng-model="pagingOptions.currentPage"/>');
b.append(' <button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="Next Page"><div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button>');
b.append(' <button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageForward()" title="Last Page"><div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button>');
b.append(' </div>');
b.append(' </div>');
b.append(' </div>');
b.append('</div>');
return b.toString();
};
/***********************************************
* FILE: ..\src\templates\rowTemplate.js
***********************************************/
ng.defaultRowTemplate = function () {
return '<div ng-repeat="col in visibleColumns()" class="ngCell col{{$index}} {{col.cellClass}}" ng-class="{\'ui-widget-content\':jqueryUITheme}" ng-cell></div>';
};
/***********************************************
* FILE: ..\src\templates\aggregateTemplate.js
***********************************************/
ng.aggregateTemplate = function () {
return '<div ng-click="row.toggleExpand()" ng-style="{ \'left\': row.offsetleft}" class="ngAggregate"><span class="ngAggregateText">{{row.label CUSTOM_FILTERS}} ({{row.totalChildren()}} items)</span><div class="{{row.aggClass()}}"></div></div>';
};
/***********************************************
* FILE: ..\src\templates\headerRowTemplate.js
***********************************************/
ng.defaultHeaderRowTemplate = function () {
return '<div ng-repeat="col in visibleColumns()" class="ngHeaderCell col{{$index}}" ng-header-cell><div>';
};
/***********************************************
* FILE: ..\src\templates\headerCellTemplate.js
***********************************************/
ng.defaultHeaderCellTemplate = function () {
var b = new ng.utils.StringBuilder();
b.append('<div ng-click="col.sort()" class="ngHeaderSortColumn" ng-class="{ \'ngSorted\': !noSortVisible }">');
b.append(' <div class="ngHeaderText colt{{$index}}">{{col.displayName}}</div>');
b.append(' <div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>');
b.append(' <div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>');
b.append('</div>');
b.append('<div ng-show="col.allowResize" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>');
return b.toString();
};
/***********************************************
* FILE: ..\src\classes\aggregate.js
***********************************************/
ng.Aggregate = function (aggEntity, rowFactory) {
var self = this;
self.index = 0;
self.offsetTop = 0;
self.entity = aggEntity;
self.label = aggEntity.gLabel;
self.field = aggEntity.gField;
self.depth = aggEntity.gDepth;
self.parent = aggEntity.parent;
self.children = aggEntity.children;
self.aggChildren = aggEntity.aggChildren;
self.aggIndex = aggEntity.aggIndex;
self.collapsed = true;
self.isAggRow = true;
self.offsetleft = aggEntity.gDepth * 25;
self.aggLabelFilter = aggEntity.aggLabelFilter;
self.toggleExpand = function() {
self.collapsed = self.collapsed ? false : true;
self.notifyChildren();
};
self.setExpand = function (state) {
self.collapsed = state;
self.notifyChildren();
};
self.notifyChildren = function() {
angular.forEach(self.aggChildren, function(child) {
child.entity[NG_HIDDEN] = self.collapsed;
if (self.collapsed) {
child.setExpand(self.collapsed);
}
});
angular.forEach(self.children, function(child) {
child[NG_HIDDEN] = self.collapsed;
});
rowFactory.rowCache = [];
var foundMyself = false;
angular.forEach(rowFactory.aggCache, function(agg, i) {
if (foundMyself) {
var offset = (30 * self.children.length);
agg.offsetTop = self.collapsed ? agg.offsetTop - offset : agg.offsetTop + offset;
} else {
if (i == self.aggIndex) {
foundMyself = true;
}
}
});
rowFactory.renderedChange();
};
self.aggClass = function() {
return self.collapsed ? "ngAggArrowCollapsed" : "ngAggArrowExpanded";
};
self.totalChildren = function() {
if (self.aggChildren.length > 0) {
var i = 0;
var recurse = function (cur) {
if (cur.aggChildren.length > 0) {
angular.forEach(cur.aggChildren, function (a) {
recurse(a);
});
} else {
i += cur.children.length;
}
};
recurse(self);
return i;
} else {
return self.children.length;
}
};
};
/***********************************************
* FILE: ..\src\classes\aggregateProvider.js
***********************************************/
ng.AggregateProvider = function (grid, $scope, gridService) {
var self = this;
// The init method gets called during the ng-grid directive execution.
self.colToMove = undefined;
self.groupToMove = undefined;
self.assignEvents = function () {
// Here we set the onmousedown event handler to the header container.
if(grid.config.jqueryUIDraggable){
grid.$groupPanel.droppable({
addClasses: false,
drop: function(event) {
self.onGroupDrop(event);
}
});
$(document).ready(self.setDraggables);
} else {
grid.$groupPanel.on('mousedown', self.onGroupMouseDown).on('dragover', self.dragOver).on('drop', self.onGroupDrop);
grid.$headerScroller.on('mousedown', self.onHeaderMouseDown).on('dragover', self.dragOver).on('drop', self.onHeaderDrop);
if (grid.config.enableRowRerodering) {
grid.$viewport.on('mousedown', self.onRowMouseDown).on('dragover', self.dragOver).on('drop', self.onRowDrop);
}
}
$scope.$watch('columns', self.setDraggables, true);
};
self.dragOver = function(evt) {
evt.preventDefault();
};
//For JQueryUI
self.setDraggables = function(){
if(!grid.config.jqueryUIDraggable){
$('.ngHeaderSortColumn').attr('draggable', 'true').on('dragstart', self.onHeaderDragStart).on('dragend', self.onHeaderDragStop);
} else {
$('.ngHeaderSortColumn').draggable({
helper: "clone",
appendTo: 'body',
addClasses: false,
start: function(event){
self.onHeaderMouseDown(event);
}
}).droppable({
drop: function(event) {
self.onHeaderDrop(event);
}
});
}
};
self.onGroupDragStart = function () {
// color the header so we know what we are moving
if (self.groupToMove) {
self.groupToMove.header.css('background-color', 'rgb(255, 255, 204)');
}
};
self.onGroupDragStop = function () {
// Set the column to move header color back to normal
if (self.groupToMove) {
self.groupToMove.header.css('background-color', 'rgb(247,247,247)');
}
};
self.onGroupMouseDown = function(event) {
var groupItem = $(event.target);
// Get the scope from the header container
if(groupItem[0].className != 'ngRemoveGroup'){
var groupItemScope = angular.element(groupItem).scope();
if (groupItemScope) {
// set draggable events
if(!grid.config.jqueryUIDraggable){
groupItem.attr('draggable', 'true');
groupItem.on('dragstart', self.onGroupDragStart).on('dragend', self.onGroupDragStop);
}
// Save the column for later.
self.groupToMove = { header: groupItem, groupName: groupItemScope.group, index: groupItemScope.$index };
}
} else {
self.groupToMove = undefined;
}
};
self.onGroupDrop = function(event) {
// clear out the colToMove object
var groupContainer;
var groupScope;
if (self.groupToMove) {
self.onGroupDragStop();
// Get the closest header to where we dropped
groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
if (groupContainer.context.className == 'ngGroupPanel') {
$scope.configGroups.splice(self.groupToMove.index, 1);
$scope.configGroups.push(self.groupToMove.groupName);
} else {
groupScope = angular.element(groupContainer).scope();
if (groupScope) {
// If we have the same column, do nothing.
if (self.groupToMove.index != groupScope.$index){
// Splice the columns
$scope.configGroups.splice(self.groupToMove.index, 1);
$scope.configGroups.splice(groupScope.$index, 0, self.groupToMove.groupName);
}
}
}
self.groupToMove = undefined;
} else {
self.onHeaderDragStop();
if ($scope.configGroups.indexOf(self.colToMove.col) == -1) {
groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
if (groupContainer.context.className == 'ngGroupPanel' || groupContainer.context.className == 'ngGroupPanelDescription') {
$scope.configGroups.push(self.colToMove.col);
} else {
groupScope = angular.element(groupContainer).scope();
if (groupScope) {
// Splice the columns
$scope.configGroups.splice(groupScope.$index + 1, 0, self.colToMove.col);
}
}
}
self.colToMove = undefined;
}
$scope.$apply();
};
//Header functions
self.onHeaderMouseDown = function (event) {
// Get the closest header container from where we clicked.
var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
// Get the scope from the header container
var headerScope = angular.element(headerContainer).scope();
if (headerScope) {
// Save the column for later.
self.colToMove = { header: headerContainer, col: headerScope.col };
}
};
self.onHeaderDragStart = function () {
// color the header so we know what we are moving
if (self.colToMove) {
self.colToMove.header.css('background-color', 'rgb(255, 255, 204)');
}
};
self.onHeaderDragStop = function () {
// Set the column to move header color back to normal
if (self.colToMove) {
self.colToMove.header.css('background-color', 'rgb(234, 234, 234)');
}
};
self.onHeaderDrop = function (event) {
if (!self.colToMove) return;
self.onHeaderDragStop();
// Get the closest header to where we dropped
var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
// Get the scope from the header.
var headerScope = angular.element(headerContainer).scope();
if (headerScope) {
// If we have the same column, do nothing.
if (self.colToMove.col == headerScope.col) return;
// Splice the columns
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
// Finally, rebuild the CSS styles.
grid.cssBuilder.buildStyles(true);
// clear out the colToMove object
self.colToMove = undefined;
}
};
// Row functions
self.onRowMouseDown = function (event) {
// Get the closest row element from where we clicked.
var targetRow = $(event.target).closest('.ngRow');
// Get the scope from the row element
var rowScope = angular.element(targetRow).scope();
if (rowScope) {
// set draggable events
targetRow.attr('draggable', 'true');
// Save the row for later.
gridService.eventStorage.rowToMove = { targetRow: targetRow, scope: rowScope };
}
};
self.onRowDrop = function (event) {
// Get the closest row to where we dropped
var targetRow = $(event.target).closest('.ngRow');
// Get the scope from the row element.