angular-pack 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3613 @@
1
+ /***********************************************
2
+ * ng-grid JavaScript Library
3
+ * Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
4
+ * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
+ * Compiled At: 07/06/2013 13:50
6
+ ***********************************************/
7
+ (function(window, $) {
8
+ 'use strict';
9
+ // the # of rows we want to add to the top and bottom of the rendered grid rows
10
+ var EXCESS_ROWS = 6;
11
+ var SCROLL_THRESHOLD = 4;
12
+ var ASC = "asc";
13
+ // constant for sorting direction
14
+ var DESC = "desc";
15
+ // constant for sorting direction
16
+ var NG_FIELD = '_ng_field_';
17
+ var NG_DEPTH = '_ng_depth_';
18
+ var NG_HIDDEN = '_ng_hidden_';
19
+ var NG_COLUMN = '_ng_column_';
20
+ var CUSTOM_FILTERS = /CUSTOM_FILTERS/g;
21
+ var COL_FIELD = /COL_FIELD/g;
22
+ var DISPLAY_CELL_TEMPLATE = /DISPLAY_CELL_TEMPLATE/g;
23
+ var EDITABLE_CELL_TEMPLATE = /EDITABLE_CELL_TEMPLATE/g;
24
+ var TEMPLATE_REGEXP = /<.+>/;
25
+ window.ngGrid = {};
26
+ window.ngGrid.i18n = {};
27
+
28
+ // Declare app level module which depends on filters, and services
29
+ var ngGridServices = angular.module('ngGrid.services', []);
30
+ var ngGridDirectives = angular.module('ngGrid.directives', []);
31
+ var ngGridFilters = angular.module('ngGrid.filters', []);
32
+ // initialization of services into the main module
33
+ angular.module('ngGrid', ['ngGrid.services', 'ngGrid.directives', 'ngGrid.filters']);
34
+ //set event binding on the grid so we can select using the up/down keys
35
+ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
36
+ if ($scope.selectionProvider.selectedItems === undefined) {
37
+ return true;
38
+ }
39
+
40
+ var charCode = evt.which || evt.keyCode,
41
+ newColumnIndex,
42
+ lastInRow = false,
43
+ firstInRow = false,
44
+ rowIndex = $scope.selectionProvider.lastClickedRow === undefined ? 1 : $scope.selectionProvider.lastClickedRow.rowIndex,
45
+ visibleCols = $scope.columns.filter(function(c) { return c.visible; }),
46
+ pinnedCols = $scope.columns.filter(function(c) { return c.pinned; });
47
+
48
+ if ($scope.col) {
49
+ newColumnIndex = visibleCols.indexOf($scope.col);
50
+ }
51
+
52
+ if (charCode !== 37 && charCode !== 38 && charCode !== 39 && charCode !== 40 && charCode !== 9 && charCode !== 13) {
53
+ return true;
54
+ }
55
+
56
+ if ($scope.enableCellSelection) {
57
+ if (charCode === 9) { //tab key
58
+ evt.preventDefault();
59
+ }
60
+
61
+ var focusedOnFirstColumn = $scope.showSelectionCheckbox ? $scope.col.index === 1 : $scope.col.index === 0;
62
+ var focusedOnFirstVisibleColumns = $scope.$index === 1 || $scope.$index === 0;
63
+ var focusedOnLastVisibleColumns = $scope.$index === ($scope.renderedColumns.length - 1) || $scope.$index === ($scope.renderedColumns.length - 2);
64
+ var focusedOnLastColumn = visibleCols.indexOf($scope.col) === (visibleCols.length - 1);
65
+ var focusedOnLastPinnedColumn = pinnedCols.indexOf($scope.col) === (pinnedCols.length - 1);
66
+
67
+ if (charCode === 37 || charCode === 9 && evt.shiftKey) {
68
+ var scrollTo = 0;
69
+
70
+ if (!focusedOnFirstColumn) {
71
+ newColumnIndex -= 1;
72
+ }
73
+
74
+ if (focusedOnFirstVisibleColumns) {
75
+ if (focusedOnFirstColumn && charCode === 9 && evt.shiftKey){
76
+ scrollTo = grid.$canvas.width();
77
+ newColumnIndex = visibleCols.length - 1;
78
+ firstInRow = true;
79
+ }
80
+ else {
81
+ scrollTo = grid.$viewport.scrollLeft() - $scope.col.width;
82
+ }
83
+ }
84
+ else if (pinnedCols.length > 0) {
85
+ scrollTo = grid.$viewport.scrollLeft() - visibleCols[newColumnIndex].width;
86
+ }
87
+
88
+ grid.$viewport.scrollLeft(scrollTo);
89
+
90
+ }
91
+ else if (charCode === 39 || charCode === 9 && !evt.shiftKey) {
92
+ if (focusedOnLastVisibleColumns) {
93
+ if (focusedOnLastColumn && charCode === 9 && !evt.shiftKey) {
94
+ grid.$viewport.scrollLeft(0);
95
+ newColumnIndex = $scope.showSelectionCheckbox ? 1 : 0;
96
+ lastInRow = true;
97
+ }
98
+ else {
99
+ grid.$viewport.scrollLeft(grid.$viewport.scrollLeft() + $scope.col.width);
100
+ }
101
+ }
102
+ else if (focusedOnLastPinnedColumn) {
103
+ grid.$viewport.scrollLeft(0);
104
+ }
105
+
106
+ if (!focusedOnLastColumn) {
107
+ newColumnIndex += 1;
108
+ }
109
+ }
110
+ }
111
+
112
+ var items;
113
+ if ($scope.configGroups.length > 0) {
114
+ items = grid.rowFactory.parsedData.filter(function (row) {
115
+ return !row.isAggRow;
116
+ });
117
+ }
118
+ else {
119
+ items = grid.filteredRows;
120
+ }
121
+
122
+ var offset = 0;
123
+ if (rowIndex !== 0 && (charCode === 38 || charCode === 13 && evt.shiftKey || charCode === 9 && evt.shiftKey && firstInRow)) { //arrow key up or shift enter or tab key and first item in row
124
+ offset = -1;
125
+ }
126
+ else if (rowIndex !== items.length - 1 && (charCode === 40 || charCode === 13 && !evt.shiftKey || charCode === 9 && lastInRow)) {//arrow key down, enter, or tab key and last item in row?
127
+ offset = 1;
128
+ }
129
+
130
+ if (offset) {
131
+ var r = items[rowIndex + offset];
132
+ if (r.beforeSelectionChange(r, evt)) {
133
+ r.continueSelection(evt);
134
+ $scope.$emit('ngGridEventDigestGridParent');
135
+
136
+ if ($scope.selectionProvider.lastClickedRow.renderedRowIndex >= $scope.renderedRows.length - EXCESS_ROWS - 2) {
137
+ grid.$viewport.scrollTop(grid.$viewport.scrollTop() + $scope.rowHeight);
138
+ }
139
+ else if ($scope.selectionProvider.lastClickedRow.renderedRowIndex <= EXCESS_ROWS + 2) {
140
+ grid.$viewport.scrollTop(grid.$viewport.scrollTop() - $scope.rowHeight);
141
+ }
142
+ }
143
+ }
144
+
145
+ if ($scope.enableCellSelection) {
146
+ setTimeout(function(){
147
+ $scope.domAccessProvider.focusCellElement($scope, $scope.renderedColumns.indexOf(visibleCols[newColumnIndex]));
148
+ }, 3);
149
+ }
150
+
151
+ return false;
152
+ };
153
+
154
+ if (!String.prototype.trim) {
155
+ String.prototype.trim = function() {
156
+ return this.replace(/^\s+|\s+$/g, '');
157
+ };
158
+ }
159
+ if (!Array.prototype.indexOf) {
160
+ Array.prototype.indexOf = function(elt /*, from*/) {
161
+ var len = this.length >>> 0;
162
+ var from = Number(arguments[1]) || 0;
163
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
164
+ if (from < 0) {
165
+ from += len;
166
+ }
167
+ for (; from < len; from++) {
168
+ if (from in this && this[from] === elt) {
169
+ return from;
170
+ }
171
+ }
172
+ return -1;
173
+ };
174
+ }
175
+ if (!Array.prototype.filter) {
176
+ Array.prototype.filter = function(fun /*, thisp */) {
177
+ "use strict";
178
+ var t = Object(this);
179
+ var len = t.length >>> 0;
180
+ if (typeof fun !== "function") {
181
+ throw new TypeError();
182
+ }
183
+ var res = [];
184
+ var thisp = arguments[1];
185
+ for (var i = 0; i < len; i++) {
186
+ if (i in t) {
187
+ var val = t[i]; // in case fun mutates this
188
+ if (fun.call(thisp, val, i, t)) {
189
+ res.push(val);
190
+ }
191
+ }
192
+ }
193
+ return res;
194
+ };
195
+ }
196
+ ngGridFilters.filter('checkmark', function() {
197
+ return function(input) {
198
+ return input ? '\u2714' : '\u2718';
199
+ };
200
+ });
201
+ ngGridFilters.filter('ngColumns', function() {
202
+ return function(input) {
203
+ return input.filter(function(col) {
204
+ return !col.isAggCol;
205
+ });
206
+ };
207
+ });
208
+ angular.module('ngGrid.services').factory('$domUtilityService',['$utilityService', function($utils) {
209
+ var domUtilityService = {};
210
+ var regexCache = {};
211
+ var getWidths = function() {
212
+ var $testContainer = $('<div></div>');
213
+ $testContainer.appendTo('body');
214
+ // 1. Run all the following measurements on startup!
215
+ //measure Scroll Bars
216
+ $testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
217
+ $testContainer.append('<div style="height: 400px; width: 400px;"></div>');
218
+ domUtilityService.ScrollH = ($testContainer.height() - $testContainer[0].clientHeight);
219
+ domUtilityService.ScrollW = ($testContainer.width() - $testContainer[0].clientWidth);
220
+ $testContainer.empty();
221
+ //clear styles
222
+ $testContainer.attr('style', '');
223
+ //measure letter sizes using a pretty typical font size and fat font-family
224
+ $testContainer.append('<span style="font-family: Verdana, Helvetica, Sans-Serif; font-size: 14px;"><strong>M</strong></span>');
225
+ domUtilityService.LetterW = $testContainer.children().first().width();
226
+ $testContainer.remove();
227
+ };
228
+ domUtilityService.eventStorage = {};
229
+ domUtilityService.AssignGridContainers = function($scope, rootEl, grid) {
230
+ grid.$root = $(rootEl);
231
+ //Headers
232
+ grid.$topPanel = grid.$root.find(".ngTopPanel");
233
+ grid.$groupPanel = grid.$root.find(".ngGroupPanel");
234
+ grid.$headerContainer = grid.$topPanel.find(".ngHeaderContainer");
235
+ $scope.$headerContainer = grid.$headerContainer;
236
+
237
+ grid.$headerScroller = grid.$topPanel.find(".ngHeaderScroller");
238
+ grid.$headers = grid.$headerScroller.children();
239
+ //Viewport
240
+ grid.$viewport = grid.$root.find(".ngViewport");
241
+ //Canvas
242
+ grid.$canvas = grid.$viewport.find(".ngCanvas");
243
+ //Footers
244
+ grid.$footerPanel = grid.$root.find(".ngFooterPanel");
245
+
246
+ $scope.$watch(function () {
247
+ return grid.$viewport.scrollLeft();
248
+ }, function (newLeft) {
249
+ return grid.$headerContainer.scrollLeft(newLeft);
250
+ });
251
+ domUtilityService.UpdateGridLayout($scope, grid);
252
+ };
253
+ domUtilityService.getRealWidth = function (obj) {
254
+ var width = 0;
255
+ var props = { visibility: "hidden", display: "block" };
256
+ var hiddenParents = obj.parents().andSelf().not(':visible');
257
+ $.swap(hiddenParents[0], props, function () {
258
+ width = obj.outerWidth();
259
+ });
260
+ return width;
261
+ };
262
+ domUtilityService.UpdateGridLayout = function($scope, grid) {
263
+ //catch this so we can return the viewer to their original scroll after the resize!
264
+ var scrollTop = grid.$viewport.scrollTop();
265
+ grid.elementDims.rootMaxW = grid.$root.width();
266
+ if (grid.$root.is(':hidden')) {
267
+ grid.elementDims.rootMaxW = domUtilityService.getRealWidth(grid.$root);
268
+ }
269
+ grid.elementDims.rootMaxH = grid.$root.height();
270
+ //check to see if anything has changed
271
+ grid.refreshDomSizes();
272
+ $scope.adjustScrollTop(scrollTop, true); //ensure that the user stays scrolled where they were
273
+ };
274
+ domUtilityService.numberOfGrids = 0;
275
+ domUtilityService.BuildStyles = function($scope, grid, digest) {
276
+ var rowHeight = grid.config.rowHeight,
277
+ $style = grid.$styleSheet,
278
+ gridId = grid.gridId,
279
+ css,
280
+ cols = $scope.columns,
281
+ sumWidth = 0;
282
+
283
+ if (!$style) {
284
+ $style = $('#' + gridId);
285
+ if (!$style[0]) {
286
+ $style = $("<style id='" + gridId + "' type='text/css' rel='stylesheet' />").appendTo(grid.$root);
287
+ }
288
+ }
289
+ $style.empty();
290
+ var trw = $scope.totalRowWidth();
291
+ css = "." + gridId + " .ngCanvas { width: " + trw + "px; }" +
292
+ "." + gridId + " .ngRow { width: " + trw + "px; }" +
293
+ "." + gridId + " .ngCanvas { width: " + trw + "px; }" +
294
+ "." + gridId + " .ngHeaderScroller { width: " + (trw + domUtilityService.ScrollH) + "px}";
295
+
296
+ for (var i = 0; i < cols.length; i++) {
297
+ var col = cols[i];
298
+ if (col.visible !== false) {
299
+ css += "." + gridId + " .col" + i + " { width: " + col.width + "px; left: " + sumWidth + "px; height: " + rowHeight + "px }" +
300
+ "." + gridId + " .colt" + i + " { width: " + col.width + "px; }";
301
+ sumWidth += col.width;
302
+ }
303
+ }
304
+
305
+ if ($utils.isIe) { // IE
306
+ $style[0].styleSheet.cssText = css;
307
+ }
308
+
309
+ else {
310
+ $style[0].appendChild(document.createTextNode(css));
311
+ }
312
+
313
+ grid.$styleSheet = $style;
314
+
315
+ $scope.adjustScrollLeft(grid.$viewport.scrollLeft());
316
+ if (digest) {
317
+ domUtilityService.digest($scope);
318
+ }
319
+ };
320
+ domUtilityService.setColLeft = function(col, colLeft, grid) {
321
+ if (grid.$styleSheet) {
322
+ var regex = regexCache[col.index];
323
+ if (!regex) {
324
+ regex = regexCache[col.index] = new RegExp(".col" + col.index + " { width: [0-9]+px; left: [0-9]+px");
325
+ }
326
+ var str = grid.$styleSheet.html();
327
+ var newStr = str.replace(regex, ".col" + col.index + " { width: " + col.width + "px; left: " + colLeft + "px");
328
+ if ($utils.isIe) { // IE
329
+ setTimeout(function() {
330
+ grid.$styleSheet.html(newStr);
331
+ });
332
+ }
333
+ else {
334
+ grid.$styleSheet.html(newStr);
335
+ }
336
+ }
337
+ };
338
+ domUtilityService.setColLeft.immediate = 1;
339
+ domUtilityService.RebuildGrid = function($scope, grid){
340
+ domUtilityService.UpdateGridLayout($scope, grid);
341
+ if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
342
+ grid.configureColumnWidths();
343
+ }
344
+ $scope.adjustScrollLeft(grid.$viewport.scrollLeft());
345
+ domUtilityService.BuildStyles($scope, grid, true);
346
+ };
347
+
348
+ domUtilityService.digest = function($scope) {
349
+ if (!$scope.$root.$$phase) {
350
+ $scope.$digest();
351
+ }
352
+ };
353
+ domUtilityService.ScrollH = 17; // default in IE, Chrome, & most browsers
354
+ domUtilityService.ScrollW = 17; // default in IE, Chrome, & most browsers
355
+ domUtilityService.LetterW = 10;
356
+ getWidths();
357
+ return domUtilityService;
358
+ }]);
359
+ angular.module('ngGrid.services').factory('$sortService', ['$parse', function($parse) {
360
+ var sortService = {};
361
+ sortService.colSortFnCache = {}; // cache of sorting functions. Once we create them, we don't want to keep re-doing it
362
+ // this takes an piece of data from the cell and tries to determine its type and what sorting
363
+ // function to use for it
364
+ // @item - the cell data
365
+ sortService.guessSortFn = function(item) {
366
+ var itemType = typeof(item);
367
+ //check for numbers and booleans
368
+ switch (itemType) {
369
+ case "number":
370
+ return sortService.sortNumber;
371
+ case "boolean":
372
+ return sortService.sortBool;
373
+ case "string":
374
+ // if number string return number string sort fn. else return the str
375
+ return item.match(/^[-+]?[£$¤]?[\d,.]+%?$/) ? sortService.sortNumberStr : sortService.sortAlpha;
376
+ default:
377
+ //check if the item is a valid Date
378
+ if (Object.prototype.toString.call(item) === '[object Date]') {
379
+ return sortService.sortDate;
380
+ }
381
+ else {
382
+ //finally just sort the basic sort...
383
+ return sortService.basicSort;
384
+ }
385
+ }
386
+ };
387
+ //#region Sorting Functions
388
+ sortService.basicSort = function(a, b) {
389
+ if (a === b) {
390
+ return 0;
391
+ }
392
+ if (a < b) {
393
+ return -1;
394
+ }
395
+ return 1;
396
+ };
397
+ sortService.sortNumber = function(a, b) {
398
+ return a - b;
399
+ };
400
+ sortService.sortNumberStr = function(a, b) {
401
+ var numA, numB, badA = false, badB = false;
402
+ numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
403
+ if (isNaN(numA)) {
404
+ badA = true;
405
+ }
406
+ numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
407
+ if (isNaN(numB)) {
408
+ badB = true;
409
+ }
410
+ // we want bad ones to get pushed to the bottom... which effectively is "greater than"
411
+ if (badA && badB) {
412
+ return 0;
413
+ }
414
+ if (badA) {
415
+ return 1;
416
+ }
417
+ if (badB) {
418
+ return -1;
419
+ }
420
+ return numA - numB;
421
+ };
422
+ sortService.sortAlpha = function(a, b) {
423
+ var strA = a.toLowerCase(),
424
+ strB = b.toLowerCase();
425
+ return strA === strB ? 0 : (strA < strB ? -1 : 1);
426
+ };
427
+ sortService.sortDate = function(a, b) {
428
+ var timeA = a.getTime(),
429
+ timeB = b.getTime();
430
+ return timeA === timeB ? 0 : (timeA < timeB ? -1 : 1);
431
+ };
432
+ sortService.sortBool = function(a, b) {
433
+ if (a && b) {
434
+ return 0;
435
+ }
436
+ if (!a && !b) {
437
+ return 0;
438
+ } else {
439
+ return a ? 1 : -1;
440
+ }
441
+ };
442
+ //#endregion
443
+ // the core sorting logic trigger
444
+ sortService.sortData = function(sortInfo, data /*datasource*/) {
445
+ // first make sure we are even supposed to do work
446
+ if (!data || !sortInfo) {
447
+ return;
448
+ }
449
+ var l = sortInfo.fields.length,
450
+ order = sortInfo.fields,
451
+ col,
452
+ direction,
453
+ // IE9 HACK.... omg, I can't reference data array within the sort fn below. has to be a separate reference....!!!!
454
+ d = data.slice(0);
455
+ //now actually sort the data
456
+ data.sort(function (itemA, itemB) {
457
+ var tem = 0,
458
+ indx = 0,
459
+ sortFn;
460
+ while (tem === 0 && indx < l) {
461
+ // grab the metadata for the rest of the logic
462
+ col = sortInfo.columns[indx];
463
+ direction = sortInfo.directions[indx];
464
+ sortFn = sortService.getSortFn(col, d);
465
+
466
+ var propA = $parse(order[indx])(itemA);
467
+ var propB = $parse(order[indx])(itemB);
468
+ // we want to allow zero values to be evaluated in the sort function
469
+ if ((!propA && propA !== 0) || (!propB && propB !== 0)) {
470
+ // we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
471
+ if (!propB && !propA) {
472
+ tem = 0;
473
+ }
474
+ else if (!propA) {
475
+ tem = 1;
476
+ }
477
+ else if (!propB) {
478
+ tem = -1;
479
+ }
480
+ }
481
+ else {
482
+ tem = sortFn(propA, propB);
483
+ }
484
+ indx++;
485
+ }
486
+ //made it this far, we don't have to worry about null & undefined
487
+ if (direction === ASC) {
488
+ return tem;
489
+ } else {
490
+ return 0 - tem;
491
+ }
492
+ });
493
+ };
494
+ sortService.Sort = function(sortInfo, data) {
495
+ if (sortService.isSorting) {
496
+ return;
497
+ }
498
+ sortService.isSorting = true;
499
+ sortService.sortData(sortInfo, data);
500
+ sortService.isSorting = false;
501
+ };
502
+ sortService.getSortFn = function(col, data) {
503
+ var sortFn, item;
504
+ //see if we already figured out what to use to sort the column
505
+ if (sortService.colSortFnCache[col.field]) {
506
+ sortFn = sortService.colSortFnCache[col.field];
507
+ }
508
+ else if (col.sortingAlgorithm !== undefined) {
509
+ sortFn = col.sortingAlgorithm;
510
+ sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
511
+ }
512
+ else { // try and guess what sort function to use
513
+ item = data[0];
514
+ if (!item) {
515
+ return sortFn;
516
+ }
517
+ sortFn = sortService.guessSortFn($parse(col.field)(item));
518
+ //cache it
519
+ if (sortFn) {
520
+ sortService.colSortFnCache[col.field] = sortFn;
521
+ } else {
522
+ // we assign the alpha sort because anything that is null/undefined will never get passed to
523
+ // the actual sorting function. It will get caught in our null check and returned to be sorted
524
+ // down to the bottom
525
+ sortFn = sortService.sortAlpha;
526
+ }
527
+ }
528
+ return sortFn;
529
+ };
530
+ return sortService;
531
+ }]);
532
+
533
+ angular.module('ngGrid.services').factory('$utilityService', ['$parse', function ($parse) {
534
+ var funcNameRegex = /function (.{1,})\(/;
535
+ var utils = {
536
+ visualLength: function(node) {
537
+ var elem = document.getElementById('testDataLength');
538
+ if (!elem) {
539
+ elem = document.createElement('SPAN');
540
+ elem.id = "testDataLength";
541
+ elem.style.visibility = "hidden";
542
+ document.body.appendChild(elem);
543
+ }
544
+ $(elem).css('font', $(node).css('font'));
545
+ $(elem).css('font-size', $(node).css('font-size'));
546
+ $(elem).css('font-family', $(node).css('font-family'));
547
+ elem.innerHTML = $(node).text();
548
+ return elem.offsetWidth;
549
+ },
550
+ forIn: function(obj, action) {
551
+ for (var prop in obj) {
552
+ if (obj.hasOwnProperty(prop)) {
553
+ action(obj[prop], prop);
554
+ }
555
+ }
556
+ },
557
+ evalProperty: function (entity, path) {
558
+ return $parse(path)(entity);
559
+ },
560
+ endsWith: function(str, suffix) {
561
+ if (!str || !suffix || typeof str !== "string") {
562
+ return false;
563
+ }
564
+ return str.indexOf(suffix, str.length - suffix.length) !== -1;
565
+ },
566
+ isNullOrUndefined: function(obj) {
567
+ if (obj === undefined || obj === null) {
568
+ return true;
569
+ }
570
+ return false;
571
+ },
572
+ getElementsByClassName: function(cl) {
573
+ var retnode = [];
574
+ var myclass = new RegExp('\\b' + cl + '\\b');
575
+ var elem = document.getElementsByTagName('*');
576
+ for (var i = 0; i < elem.length; i++) {
577
+ var classes = elem[i].className;
578
+ if (myclass.test(classes)) {
579
+ retnode.push(elem[i]);
580
+ }
581
+ }
582
+ return retnode;
583
+ },
584
+ newId: (function() {
585
+ var seedId = new Date().getTime();
586
+ return function() {
587
+ return seedId += 1;
588
+ };
589
+ })(),
590
+ seti18n: function($scope, language) {
591
+ var $langPack = window.ngGrid.i18n[language];
592
+ for (var label in $langPack) {
593
+ $scope.i18n[label] = $langPack[label];
594
+ }
595
+ },
596
+ getInstanceType: function (o) {
597
+ var results = (funcNameRegex).exec(o.constructor.toString());
598
+ if (results && results.length > 1) {
599
+ var instanceType = results[1].replace(/^\s+|\s+$/g, ""); // Trim surrounding whitespace; IE appears to add a space at the end
600
+ return instanceType;
601
+ }
602
+ else {
603
+ return "";
604
+ }
605
+ },
606
+ // Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)
607
+ // Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
608
+ // Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
609
+ // If there is a future need to detect specific versions of IE10+, we will amend this.
610
+ ieVersion: (function() {
611
+ var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
612
+
613
+ // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
614
+ do{
615
+ div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->';
616
+ }while(iElems[0]);
617
+ return version > 4 ? version : undefined;
618
+ })()
619
+ };
620
+
621
+ $.extend(utils, {
622
+ isIe: (function() {
623
+ return utils.ieVersion !== undefined;
624
+ })()
625
+ });
626
+ return utils;
627
+ }]);
628
+
629
+ var ngAggregate = function (aggEntity, rowFactory, rowHeight, groupInitState) {
630
+ this.rowIndex = 0;
631
+ this.offsetTop = this.rowIndex * rowHeight;
632
+ this.entity = aggEntity;
633
+ this.label = aggEntity.gLabel;
634
+ this.field = aggEntity.gField;
635
+ this.depth = aggEntity.gDepth;
636
+ this.parent = aggEntity.parent;
637
+ this.children = aggEntity.children;
638
+ this.aggChildren = aggEntity.aggChildren;
639
+ this.aggIndex = aggEntity.aggIndex;
640
+ this.collapsed = groupInitState;
641
+ this.groupInitState = groupInitState;
642
+ this.rowFactory = rowFactory;
643
+ this.rowHeight = rowHeight;
644
+ this.isAggRow = true;
645
+ this.offsetLeft = aggEntity.gDepth * 25;
646
+ this.aggLabelFilter = aggEntity.aggLabelFilter;
647
+ };
648
+
649
+ ngAggregate.prototype.toggleExpand = function () {
650
+ this.collapsed = this.collapsed ? false : true;
651
+ if (this.orig) {
652
+ this.orig.collapsed = this.collapsed;
653
+ }
654
+ this.notifyChildren();
655
+ };
656
+ ngAggregate.prototype.setExpand = function (state) {
657
+ this.collapsed = state;
658
+ this.notifyChildren();
659
+ };
660
+ ngAggregate.prototype.notifyChildren = function () {
661
+ var longest = Math.max(this.rowFactory.aggCache.length, this.children.length);
662
+ for (var i = 0; i < longest; i++) {
663
+ if (this.aggChildren[i]) {
664
+ this.aggChildren[i].entity[NG_HIDDEN] = this.collapsed;
665
+ if (this.collapsed) {
666
+ this.aggChildren[i].setExpand(this.collapsed);
667
+ }
668
+ }
669
+ if (this.children[i]) {
670
+ this.children[i][NG_HIDDEN] = this.collapsed;
671
+ }
672
+ if (i > this.aggIndex && this.rowFactory.aggCache[i]) {
673
+ var agg = this.rowFactory.aggCache[i];
674
+ var offset = (30 * this.children.length);
675
+ agg.offsetTop = this.collapsed ? agg.offsetTop - offset : agg.offsetTop + offset;
676
+ }
677
+ }
678
+ this.rowFactory.renderedChange();
679
+ };
680
+ ngAggregate.prototype.aggClass = function () {
681
+ return this.collapsed ? "ngAggArrowCollapsed" : "ngAggArrowExpanded";
682
+ };
683
+ ngAggregate.prototype.totalChildren = function () {
684
+ if (this.aggChildren.length > 0) {
685
+ var i = 0;
686
+ var recurse = function (cur) {
687
+ if (cur.aggChildren.length > 0) {
688
+ angular.forEach(cur.aggChildren, function (a) {
689
+ recurse(a);
690
+ });
691
+ } else {
692
+ i += cur.children.length;
693
+ }
694
+ };
695
+ recurse(this);
696
+ return i;
697
+ } else {
698
+ return this.children.length;
699
+ }
700
+ };
701
+ ngAggregate.prototype.copy = function () {
702
+ var ret = new ngAggregate(this.entity, this.rowFactory, this.rowHeight, this.groupInitState);
703
+ ret.orig = this;
704
+ return ret;
705
+ };
706
+ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache, $utils) {
707
+ var self = this,
708
+ colDef = config.colDef,
709
+ delay = 500,
710
+ clicks = 0,
711
+ timer = null;
712
+ self.colDef = config.colDef;
713
+ self.width = colDef.width;
714
+ self.groupIndex = 0;
715
+ self.isGroupedBy = false;
716
+ self.minWidth = !colDef.minWidth ? 50 : colDef.minWidth;
717
+ self.maxWidth = !colDef.maxWidth ? 9000 : colDef.maxWidth;
718
+
719
+ // TODO: Use the column's definition for enabling cell editing
720
+ // self.enableCellEdit = config.enableCellEdit || colDef.enableCellEdit;
721
+ self.enableCellEdit = colDef.enableCellEdit !== undefined ? colDef.enableCellEdit : (config.enableCellEdit || config.enableCellEditOnFocus);
722
+
723
+ self.headerRowHeight = config.headerRowHeight;
724
+
725
+ // Use colDef.displayName as long as it's not undefined, otherwise default to the field name
726
+ self.displayName = (colDef.displayName === undefined) ? colDef.field : colDef.displayName;
727
+
728
+ self.index = config.index;
729
+ self.isAggCol = config.isAggCol;
730
+ self.cellClass = colDef.cellClass;
731
+ self.sortPriority = undefined;
732
+ self.cellFilter = colDef.cellFilter ? colDef.cellFilter : "";
733
+ self.field = colDef.field;
734
+ self.aggLabelFilter = colDef.cellFilter || colDef.aggLabelFilter;
735
+ self.visible = $utils.isNullOrUndefined(colDef.visible) || colDef.visible;
736
+ self.sortable = false;
737
+ self.resizable = false;
738
+ self.pinnable = false;
739
+ self.pinned = (config.enablePinning && colDef.pinned);
740
+ self.originalIndex = config.originalIndex == null ? self.index : config.originalIndex;
741
+ self.groupable = $utils.isNullOrUndefined(colDef.groupable) || colDef.groupable;
742
+ if (config.enableSort) {
743
+ self.sortable = $utils.isNullOrUndefined(colDef.sortable) || colDef.sortable;
744
+ }
745
+ if (config.enableResize) {
746
+ self.resizable = $utils.isNullOrUndefined(colDef.resizable) || colDef.resizable;
747
+ }
748
+ if (config.enablePinning) {
749
+ self.pinnable = $utils.isNullOrUndefined(colDef.pinnable) || colDef.pinnable;
750
+ }
751
+ self.sortDirection = undefined;
752
+ self.sortingAlgorithm = colDef.sortFn;
753
+ self.headerClass = colDef.headerClass;
754
+ self.cursor = self.sortable ? 'pointer' : 'default';
755
+ self.headerCellTemplate = colDef.headerCellTemplate || $templateCache.get('headerCellTemplate.html');
756
+ self.cellTemplate = colDef.cellTemplate || $templateCache.get('cellTemplate.html').replace(CUSTOM_FILTERS, self.cellFilter ? "|" + self.cellFilter : "");
757
+ if(self.enableCellEdit) {
758
+ self.cellEditTemplate = $templateCache.get('cellEditTemplate.html');
759
+ self.editableCellTemplate = colDef.editableCellTemplate || $templateCache.get('editableCellTemplate.html');
760
+ }
761
+ if (colDef.cellTemplate && !TEMPLATE_REGEXP.test(colDef.cellTemplate)) {
762
+ self.cellTemplate = $.ajax({
763
+ type: "GET",
764
+ url: colDef.cellTemplate,
765
+ async: false
766
+ }).responseText;
767
+ }
768
+ if (self.enableCellEdit && colDef.editableCellTemplate && !TEMPLATE_REGEXP.test(colDef.editableCellTemplate)) {
769
+ self.editableCellTemplate = $.ajax({
770
+ type: "GET",
771
+ url: colDef.editableCellTemplate,
772
+ async: false
773
+ }).responseText;
774
+ }
775
+ if (colDef.headerCellTemplate && !TEMPLATE_REGEXP.test(colDef.headerCellTemplate)) {
776
+ self.headerCellTemplate = $.ajax({
777
+ type: "GET",
778
+ url: colDef.headerCellTemplate,
779
+ async: false
780
+ }).responseText;
781
+ }
782
+ self.colIndex = function () {
783
+ var classes = self.pinned ? "pinned " : "";
784
+ classes += "col" + self.index + " colt" + self.index;
785
+ if (self.cellClass) {
786
+ classes += " " + self.cellClass;
787
+ }
788
+ return classes;
789
+ };
790
+ self.groupedByClass = function() {
791
+ return self.isGroupedBy ? "ngGroupedByIcon" : "ngGroupIcon";
792
+ };
793
+ self.toggleVisible = function() {
794
+ self.visible = !self.visible;
795
+ };
796
+ self.showSortButtonUp = function() {
797
+ return self.sortable ? self.sortDirection === DESC : self.sortable;
798
+ };
799
+ self.showSortButtonDown = function() {
800
+ return self.sortable ? self.sortDirection === ASC : self.sortable;
801
+ };
802
+ self.noSortVisible = function() {
803
+ return !self.sortDirection;
804
+ };
805
+ self.sort = function(evt) {
806
+ if (!self.sortable) {
807
+ return true; // column sorting is disabled, do nothing
808
+ }
809
+ var dir = self.sortDirection === ASC ? DESC : ASC;
810
+ self.sortDirection = dir;
811
+ config.sortCallback(self, evt);
812
+ return false;
813
+ };
814
+ self.gripClick = function() {
815
+ clicks++; //count clicks
816
+ if (clicks === 1) {
817
+ timer = setTimeout(function() {
818
+ //Here you can add a single click action.
819
+ clicks = 0; //after action performed, reset counter
820
+ }, delay);
821
+ } else {
822
+ clearTimeout(timer); //prevent single-click action
823
+ config.resizeOnDataCallback(self); //perform double-click action
824
+ clicks = 0; //after action performed, reset counter
825
+ }
826
+ };
827
+ self.gripOnMouseDown = function(event) {
828
+ $scope.isColumnResizing = true;
829
+ if (event.ctrlKey && !self.pinned) {
830
+ self.toggleVisible();
831
+ domUtilityService.BuildStyles($scope, grid);
832
+ return true;
833
+ }
834
+ event.target.parentElement.style.cursor = 'col-resize';
835
+ self.startMousePosition = event.clientX;
836
+ self.origWidth = self.width;
837
+ $(document).mousemove(self.onMouseMove);
838
+ $(document).mouseup(self.gripOnMouseUp);
839
+ return false;
840
+ };
841
+ self.onMouseMove = function(event) {
842
+ var diff = event.clientX - self.startMousePosition;
843
+ var newWidth = diff + self.origWidth;
844
+ self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
845
+ $scope.hasUserChangedGridColumnWidths = true;
846
+ domUtilityService.BuildStyles($scope, grid);
847
+ return false;
848
+ };
849
+ self.gripOnMouseUp = function (event) {
850
+ $(document).off('mousemove', self.onMouseMove);
851
+ $(document).off('mouseup', self.gripOnMouseUp);
852
+ event.target.parentElement.style.cursor = 'default';
853
+ domUtilityService.digest($scope);
854
+ $scope.isColumnResizing = false;
855
+ return false;
856
+ };
857
+ self.copy = function() {
858
+ var ret = new ngColumn(config, $scope, grid, domUtilityService, $templateCache);
859
+ ret.isClone = true;
860
+ ret.orig = self;
861
+ return ret;
862
+ };
863
+ self.setVars = function (fromCol) {
864
+ self.orig = fromCol;
865
+ self.width = fromCol.width;
866
+ self.groupIndex = fromCol.groupIndex;
867
+ self.isGroupedBy = fromCol.isGroupedBy;
868
+ self.displayName = fromCol.displayName;
869
+ self.index = fromCol.index;
870
+ self.isAggCol = fromCol.isAggCol;
871
+ self.cellClass = fromCol.cellClass;
872
+ self.cellFilter = fromCol.cellFilter;
873
+ self.field = fromCol.field;
874
+ self.aggLabelFilter = fromCol.aggLabelFilter;
875
+ self.visible = fromCol.visible;
876
+ self.sortable = fromCol.sortable;
877
+ self.resizable = fromCol.resizable;
878
+ self.pinnable = fromCol.pinnable;
879
+ self.pinned = fromCol.pinned;
880
+ self.originalIndex = fromCol.originalIndex;
881
+ self.sortDirection = fromCol.sortDirection;
882
+ self.sortingAlgorithm = fromCol.sortingAlgorithm;
883
+ self.headerClass = fromCol.headerClass;
884
+ self.headerCellTemplate = fromCol.headerCellTemplate;
885
+ self.cellTemplate = fromCol.cellTemplate;
886
+ self.cellEditTemplate = fromCol.cellEditTemplate;
887
+ };
888
+ };
889
+
890
+ var ngDimension = function (options) {
891
+ this.outerHeight = null;
892
+ this.outerWidth = null;
893
+ $.extend(this, options);
894
+ };
895
+ var ngDomAccessProvider = function (grid) {
896
+ this.previousColumn = null;
897
+ this.grid = grid;
898
+
899
+ };
900
+
901
+ ngDomAccessProvider.prototype.changeUserSelect = function (elm, value) {
902
+ elm.css({
903
+ '-webkit-touch-callout': value,
904
+ '-webkit-user-select': value,
905
+ '-khtml-user-select': value,
906
+ '-moz-user-select': value === 'none' ? '-moz-none' : value,
907
+ '-ms-user-select': value,
908
+ 'user-select': value
909
+ });
910
+ };
911
+ ngDomAccessProvider.prototype.focusCellElement = function ($scope, index) {
912
+ if ($scope.selectionProvider.lastClickedRow) {
913
+ var columnIndex = index !== undefined ? index : this.previousColumn;
914
+ var elm = $scope.selectionProvider.lastClickedRow.clone ? $scope.selectionProvider.lastClickedRow.clone.elm : $scope.selectionProvider.lastClickedRow.elm;
915
+ if (columnIndex !== undefined && elm) {
916
+ var columns = angular.element(elm[0].children).filter(function () { return this.nodeType !== 8; }); //Remove html comments for IE8
917
+ var i = Math.max(Math.min($scope.renderedColumns.length - 1, columnIndex), 0);
918
+ if (this.grid.config.showSelectionCheckbox && angular.element(columns[i]).scope() && angular.element(columns[i]).scope().col.index === 0) {
919
+ i = 1; //don't want to focus on checkbox
920
+ }
921
+ if (columns[i]) {
922
+ columns[i].children[1].children[0].focus();
923
+ }
924
+ this.previousColumn = columnIndex;
925
+ }
926
+ }
927
+ };
928
+ ngDomAccessProvider.prototype.selectionHandlers = function ($scope, elm) {
929
+ var doingKeyDown = false;
930
+ var self = this;
931
+ elm.bind('keydown', function (evt) {
932
+ if (evt.keyCode === 16) { //shift key
933
+ self.changeUserSelect(elm, 'none', evt);
934
+ return true;
935
+ } else if (!doingKeyDown) {
936
+ doingKeyDown = true;
937
+ var ret = ngMoveSelectionHandler($scope, elm, evt, self.grid);
938
+ doingKeyDown = false;
939
+ return ret;
940
+ }
941
+ return true;
942
+ });
943
+ elm.bind('keyup', function (evt) {
944
+ if (evt.keyCode === 16) { //shift key
945
+ self.changeUserSelect(elm, 'text', evt);
946
+ }
947
+ return true;
948
+ });
949
+ };
950
+ var ngEventProvider = function (grid, $scope, domUtilityService, $timeout) {
951
+ var self = this;
952
+ // The init method gets called during the ng-grid directive execution.
953
+ self.colToMove = undefined;
954
+ self.groupToMove = undefined;
955
+ self.assignEvents = function() {
956
+ // Here we set the onmousedown event handler to the header container.
957
+ if (grid.config.jqueryUIDraggable && !grid.config.enablePinning) {
958
+ grid.$groupPanel.droppable({
959
+ addClasses: false,
960
+ drop: function(event) {
961
+ self.onGroupDrop(event);
962
+ }
963
+ });
964
+ } else {
965
+ grid.$groupPanel.on('mousedown', self.onGroupMouseDown).on('dragover', self.dragOver).on('drop', self.onGroupDrop);
966
+ grid.$headerScroller.on('mousedown', self.onHeaderMouseDown).on('dragover', self.dragOver);
967
+ if (grid.config.enableColumnReordering && !grid.config.enablePinning) {
968
+ grid.$headerScroller.on('drop', self.onHeaderDrop);
969
+ }
970
+ }
971
+ $scope.$watch('renderedColumns', function() {
972
+ $timeout(self.setDraggables);
973
+ });
974
+ };
975
+ self.dragStart = function(evt){
976
+ //FireFox requires there to be dataTransfer if you want to drag and drop.
977
+ evt.dataTransfer.setData('text', ''); //cannot be empty string
978
+ };
979
+ self.dragOver = function(evt) {
980
+ evt.preventDefault();
981
+ };
982
+ //For JQueryUI
983
+ self.setDraggables = function() {
984
+ if (!grid.config.jqueryUIDraggable) {
985
+ //Fix for FireFox. Instead of using jQuery on('dragstart', function) on find, we have to use addEventListeners for each column.
986
+ var columns = grid.$root.find('.ngHeaderSortColumn'); //have to iterate if using addEventListener
987
+ angular.forEach(columns, function(col){
988
+ if(col.className && col.className.indexOf("ngHeaderSortColumn") !== -1){
989
+ col.setAttribute('draggable', 'true');
990
+ //jQuery 'on' function doesn't have dataTransfer as part of event in handler unless added to event props, which is not recommended
991
+ //See more here: http://api.jquery.com/category/events/event-object/
992
+ if (col.addEventListener) { //IE8 doesn't have drag drop or event listeners
993
+ col.addEventListener('dragstart', self.dragStart);
994
+ }
995
+ }
996
+ });
997
+ if (navigator.userAgent.indexOf("MSIE") !== -1){
998
+ //call native IE dragDrop() to start dragging
999
+ grid.$root.find('.ngHeaderSortColumn').bind('selectstart', function () {
1000
+ this.dragDrop();
1001
+ return false;
1002
+ });
1003
+ }
1004
+ } else {
1005
+ grid.$root.find('.ngHeaderSortColumn').draggable({
1006
+ helper: 'clone',
1007
+ appendTo: 'body',
1008
+ stack: 'div',
1009
+ addClasses: false,
1010
+ start: function(event) {
1011
+ self.onHeaderMouseDown(event);
1012
+ }
1013
+ }).droppable({
1014
+ drop: function(event) {
1015
+ self.onHeaderDrop(event);
1016
+ }
1017
+ });
1018
+ }
1019
+ };
1020
+ self.onGroupMouseDown = function(event) {
1021
+ var groupItem = $(event.target);
1022
+ // Get the scope from the header container
1023
+ if (groupItem[0].className !== 'ngRemoveGroup') {
1024
+ var groupItemScope = angular.element(groupItem).scope();
1025
+ if (groupItemScope) {
1026
+ // set draggable events
1027
+ if (!grid.config.jqueryUIDraggable) {
1028
+ groupItem.attr('draggable', 'true');
1029
+ if(this.addEventListener){//IE8 doesn't have drag drop or event listeners
1030
+ this.addEventListener('dragstart', self.dragStart);
1031
+ }
1032
+ if (navigator.userAgent.indexOf("MSIE") !== -1){
1033
+ //call native IE dragDrop() to start dragging
1034
+ groupItem.bind('selectstart', function () {
1035
+ this.dragDrop();
1036
+ return false;
1037
+ });
1038
+ }
1039
+ }
1040
+ // Save the column for later.
1041
+ self.groupToMove = { header: groupItem, groupName: groupItemScope.group, index: groupItemScope.$index };
1042
+ }
1043
+ } else {
1044
+ self.groupToMove = undefined;
1045
+ }
1046
+ };
1047
+ self.onGroupDrop = function(event) {
1048
+ event.stopPropagation();
1049
+ // clear out the colToMove object
1050
+ var groupContainer;
1051
+ var groupScope;
1052
+ if (self.groupToMove) {
1053
+ // Get the closest header to where we dropped
1054
+ groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
1055
+ if (groupContainer.context.className === 'ngGroupPanel') {
1056
+ $scope.configGroups.splice(self.groupToMove.index, 1);
1057
+ $scope.configGroups.push(self.groupToMove.groupName);
1058
+ } else {
1059
+ groupScope = angular.element(groupContainer).scope();
1060
+ if (groupScope) {
1061
+ // If we have the same column, do nothing.
1062
+ if (self.groupToMove.index !== groupScope.$index) {
1063
+ // Splice the columns
1064
+ $scope.configGroups.splice(self.groupToMove.index, 1);
1065
+ $scope.configGroups.splice(groupScope.$index, 0, self.groupToMove.groupName);
1066
+ }
1067
+ }
1068
+ }
1069
+ self.groupToMove = undefined;
1070
+ grid.fixGroupIndexes();
1071
+ } else if (self.colToMove) {
1072
+ if ($scope.configGroups.indexOf(self.colToMove.col) === -1) {
1073
+ groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
1074
+ if (groupContainer.context.className === 'ngGroupPanel' || groupContainer.context.className === 'ngGroupPanelDescription ng-binding') {
1075
+ $scope.groupBy(self.colToMove.col);
1076
+ } else {
1077
+ groupScope = angular.element(groupContainer).scope();
1078
+ if (groupScope) {
1079
+ // Splice the columns
1080
+ $scope.removeGroup(groupScope.$index);
1081
+ }
1082
+ }
1083
+ }
1084
+ self.colToMove = undefined;
1085
+ }
1086
+ if (!$scope.$$phase) {
1087
+ $scope.$apply();
1088
+ }
1089
+ };
1090
+ //Header functions
1091
+ self.onHeaderMouseDown = function(event) {
1092
+ // Get the closest header container from where we clicked.
1093
+ var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
1094
+ // Get the scope from the header container
1095
+ var headerScope = angular.element(headerContainer).scope();
1096
+ if (headerScope) {
1097
+ // Save the column for later.
1098
+ self.colToMove = { header: headerContainer, col: headerScope.col };
1099
+ }
1100
+ };
1101
+ self.onHeaderDrop = function(event) {
1102
+ if (!self.colToMove || self.colToMove.col.pinned) {
1103
+ return;
1104
+ }
1105
+ // Get the closest header to where we dropped
1106
+ var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
1107
+ // Get the scope from the header.
1108
+ var headerScope = angular.element(headerContainer).scope();
1109
+ if (headerScope) {
1110
+ // If we have the same column, do nothing.
1111
+ if (self.colToMove.col === headerScope.col) {
1112
+ return;
1113
+ }
1114
+ // Splice the columns
1115
+ $scope.columns.splice(self.colToMove.col.index, 1);
1116
+ $scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
1117
+ grid.fixColumnIndexes();
1118
+ // clear out the colToMove object
1119
+ self.colToMove = undefined;
1120
+ domUtilityService.digest($scope);
1121
+ }
1122
+ };
1123
+
1124
+ self.assignGridEventHandlers = function() {
1125
+ //Chrome and firefox both need a tab index so the grid can recieve focus.
1126
+ //need to give the grid a tabindex if it doesn't already have one so
1127
+ //we'll just give it a tab index of the corresponding gridcache index
1128
+ //that way we'll get the same result every time it is run.
1129
+ //configurable within the options.
1130
+ if (grid.config.tabIndex === -1) {
1131
+ grid.$viewport.attr('tabIndex', domUtilityService.numberOfGrids);
1132
+ domUtilityService.numberOfGrids++;
1133
+ } else {
1134
+ grid.$viewport.attr('tabIndex', grid.config.tabIndex);
1135
+ }
1136
+ // resize on window resize
1137
+ var windowThrottle;
1138
+ $(window).resize(function(){
1139
+ clearTimeout(windowThrottle);
1140
+ windowThrottle = setTimeout(function() {
1141
+ //in function for IE8 compatibility
1142
+ domUtilityService.RebuildGrid($scope,grid);
1143
+ }, 100);
1144
+ });
1145
+ // resize on parent resize as well.
1146
+ var parentThrottle;
1147
+ $(grid.$root.parent()).on('resize', function() {
1148
+ clearTimeout(parentThrottle);
1149
+ parentThrottle = setTimeout(function() {
1150
+ //in function for IE8 compatibility
1151
+ domUtilityService.RebuildGrid($scope,grid);
1152
+ }, 100);
1153
+ });
1154
+ };
1155
+ // In this example we want to assign grid events.
1156
+ self.assignGridEventHandlers();
1157
+ self.assignEvents();
1158
+ };
1159
+
1160
+ var ngFooter = function ($scope, grid) {
1161
+ $scope.maxRows = function () {
1162
+ var ret = Math.max($scope.totalServerItems, grid.data.length);
1163
+ return ret;
1164
+ };
1165
+
1166
+ $scope.multiSelect = (grid.config.enableRowSelection && grid.config.multiSelect);
1167
+ $scope.selectedItemCount = grid.selectedItemCount;
1168
+ $scope.maxPages = function () {
1169
+ return Math.ceil($scope.maxRows() / $scope.pagingOptions.pageSize);
1170
+ };
1171
+
1172
+ $scope.pageForward = function() {
1173
+ var page = $scope.pagingOptions.currentPage;
1174
+ if ($scope.totalServerItems > 0) {
1175
+ $scope.pagingOptions.currentPage = Math.min(page + 1, $scope.maxPages());
1176
+ } else {
1177
+ $scope.pagingOptions.currentPage++;
1178
+ }
1179
+ };
1180
+
1181
+ $scope.pageBackward = function() {
1182
+ var page = $scope.pagingOptions.currentPage;
1183
+ $scope.pagingOptions.currentPage = Math.max(page - 1, 1);
1184
+ };
1185
+
1186
+ $scope.pageToFirst = function() {
1187
+ $scope.pagingOptions.currentPage = 1;
1188
+ };
1189
+
1190
+ $scope.pageToLast = function() {
1191
+ var maxPages = $scope.maxPages();
1192
+ $scope.pagingOptions.currentPage = maxPages;
1193
+ };
1194
+
1195
+ $scope.cantPageForward = function() {
1196
+ var curPage = $scope.pagingOptions.currentPage;
1197
+ var maxPages = $scope.maxPages();
1198
+ if ($scope.totalServerItems > 0) {
1199
+ return curPage >= maxPages;
1200
+ } else {
1201
+ return grid.data.length < 1;
1202
+ }
1203
+
1204
+ };
1205
+ $scope.cantPageToLast = function() {
1206
+ if ($scope.totalServerItems > 0) {
1207
+ return $scope.cantPageForward();
1208
+ } else {
1209
+ return true;
1210
+ }
1211
+ };
1212
+
1213
+ $scope.cantPageBackward = function() {
1214
+ var curPage = $scope.pagingOptions.currentPage;
1215
+ return curPage <= 1;
1216
+ };
1217
+ };
1218
+ /// <reference path="footer.js" />
1219
+ /// <reference path="../services/SortService.js" />
1220
+ /// <reference path="../../lib/jquery-1.8.2.min" />
1221
+ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter, $templateCache, $utils, $timeout, $parse, $http, $q) {
1222
+ var defaults = {
1223
+ //Define an aggregate template to customize the rows when grouped. See github wiki for more details.
1224
+ aggregateTemplate: undefined,
1225
+
1226
+ //Callback for when you want to validate something after selection.
1227
+ afterSelectionChange: function() {
1228
+ },
1229
+
1230
+ /* Callback if you want to inspect something before selection,
1231
+ return false if you want to cancel the selection. return true otherwise.
1232
+ If you need to wait for an async call to proceed with selection you can
1233
+ use rowItem.changeSelection(event) method after returning false initially.
1234
+ Note: when shift+ Selecting multiple items in the grid this will only get called
1235
+ once and the rowItem will be an array of items that are queued to be selected. */
1236
+ beforeSelectionChange: function() {
1237
+ return true;
1238
+ },
1239
+
1240
+ //checkbox templates.
1241
+ checkboxCellTemplate: undefined,
1242
+ checkboxHeaderTemplate: undefined,
1243
+
1244
+ //definitions of columns as an array [], if not defines columns are auto-generated. See github wiki for more details.
1245
+ columnDefs: undefined,
1246
+
1247
+ //*Data being displayed in the grid. Each item in the array is mapped to a row being displayed.
1248
+ data: [],
1249
+
1250
+ //Data updated callback, fires every time the data is modified from outside the grid.
1251
+ dataUpdated: function() {
1252
+ },
1253
+
1254
+ //Enables cell editing.
1255
+ enableCellEdit: false,
1256
+
1257
+ //Enables cell editing on focus
1258
+ enableCellEditOnFocus: false,
1259
+
1260
+ //Enables cell selection.
1261
+ enableCellSelection: false,
1262
+
1263
+ //Enable or disable resizing of columns
1264
+ enableColumnResize: false,
1265
+
1266
+ //Enable or disable reordering of columns
1267
+ enableColumnReordering: false,
1268
+
1269
+ //Enable or disable HEAVY column virtualization. This turns off selection checkboxes and column pinning and is designed for spreadsheet-like data.
1270
+ enableColumnHeavyVirt: false,
1271
+
1272
+ //Enables the server-side paging feature
1273
+ enablePaging: false,
1274
+
1275
+ //Enable column pinning
1276
+ enablePinning: false,
1277
+
1278
+ //To be able to have selectable rows in grid.
1279
+ enableRowSelection: true,
1280
+
1281
+ //Enables or disables sorting in grid.
1282
+ enableSorting: true,
1283
+
1284
+ //Enables or disables text highlighting in grid by adding the "unselectable" class (See CSS file)
1285
+ enableHighlighting: false,
1286
+
1287
+ // string list of properties to exclude when auto-generating columns.
1288
+ excludeProperties: [],
1289
+
1290
+ /* filterOptions -
1291
+ filterText: The text bound to the built-in search box.
1292
+ useExternalFilter: Bypass internal filtering if you want to roll your own filtering mechanism but want to use builtin search box.
1293
+ */
1294
+ filterOptions: {
1295
+ filterText: "",
1296
+ useExternalFilter: false
1297
+ },
1298
+
1299
+ //Defining the height of the footer in pixels.
1300
+ footerRowHeight: 55,
1301
+
1302
+ // the template for the column menu and filter, including the button.
1303
+ footerTemplate: undefined,
1304
+
1305
+ //Initial fields to group data by. Array of field names, not displayName.
1306
+ groups: [],
1307
+
1308
+ // set the initial state of aggreagate grouping. "true" means they will be collapsed when grouping changes, "false" means they will be expanded by default.
1309
+ groupsCollapsedByDefault: true,
1310
+
1311
+ //The height of the header row in pixels.
1312
+ headerRowHeight: 30,
1313
+
1314
+ //Define a header row template for further customization. See github wiki for more details.
1315
+ headerRowTemplate: undefined,
1316
+
1317
+ /*Enables the use of jquery UI reaggable/droppable plugin. requires jqueryUI to work if enabled.
1318
+ Useful if you want drag + drop but your users insist on crappy browsers. */
1319
+ jqueryUIDraggable: false,
1320
+
1321
+ //Enable the use jqueryUIThemes
1322
+ jqueryUITheme: false,
1323
+
1324
+ //Prevent unselections when in single selection mode.
1325
+ keepLastSelected: true,
1326
+
1327
+ /*Maintains the column widths while resizing.
1328
+ Defaults to true when using *'s or undefined widths. Can be ovverriden by setting to false.*/
1329
+ maintainColumnRatios: undefined,
1330
+
1331
+ // the template for the column menu and filter, including the button.
1332
+ menuTemplate: undefined,
1333
+
1334
+ //Set this to false if you only want one item selected at a time
1335
+ multiSelect: true,
1336
+
1337
+ // pagingOptions -
1338
+ pagingOptions: {
1339
+ // pageSizes: list of available page sizes.
1340
+ pageSizes: [250, 500, 1000],
1341
+ //pageSize: currently selected page size.
1342
+ pageSize: 250,
1343
+ //currentPage: the uhm... current page.
1344
+ currentPage: 1
1345
+ },
1346
+
1347
+ //the selection checkbox is pinned to the left side of the viewport or not.
1348
+ pinSelectionCheckbox: false,
1349
+
1350
+ //Array of plugin functions to register in ng-grid
1351
+ plugins: [],
1352
+
1353
+ //User defined unique ID field that allows for better handling of selections and for server-side paging
1354
+ primaryKey: undefined,
1355
+
1356
+ //Row height of rows in grid.
1357
+ rowHeight: 30,
1358
+
1359
+ //Define a row template to customize output. See github wiki for more details.
1360
+ rowTemplate: undefined,
1361
+
1362
+ //all of the items selected in the grid. In single select mode there will only be one item in the array.
1363
+ selectedItems: [],
1364
+
1365
+ //Disable row selections by clicking on the row and only when the checkbox is clicked.
1366
+ selectWithCheckboxOnly: false,
1367
+
1368
+ /*Enables menu to choose which columns to display and group by.
1369
+ If both showColumnMenu and showFilter are false the menu button will not display.*/
1370
+ showColumnMenu: false,
1371
+
1372
+ /*Enables display of the filterbox in the column menu.
1373
+ If both showColumnMenu and showFilter are false the menu button will not display.*/
1374
+ showFilter: false,
1375
+
1376
+ //Show or hide the footer alltogether the footer is enabled by default
1377
+ showFooter: false,
1378
+
1379
+ //Show the dropzone for drag and drop grouping
1380
+ showGroupPanel: false,
1381
+
1382
+ //Row selection check boxes appear as the first column.
1383
+ showSelectionCheckbox: false,
1384
+
1385
+ /*Define a sortInfo object to specify a default sorting state.
1386
+ You can also observe this variable to utilize server-side sorting (see useExternalSorting).
1387
+ Syntax is sortinfo: { fields: ['fieldName1',' fieldName2'], direction: 'ASC'/'asc' || 'desc'/'DESC'}*/
1388
+ sortInfo: {fields: [], columns: [], directions: [] },
1389
+
1390
+ //Set the tab index of the Vieport.
1391
+ tabIndex: -1,
1392
+
1393
+ //totalServerItems: Total items are on the server.
1394
+ totalServerItems: 0,
1395
+
1396
+ /*Prevents the internal sorting from executing.
1397
+ The sortInfo object will be updated with the sorting information so you can handle sorting (see sortInfo)*/
1398
+ useExternalSorting: false,
1399
+
1400
+ /*i18n language support. choose from the installed or included languages, en, fr, sp, etc...*/
1401
+ i18n: 'en',
1402
+
1403
+ //the threshold in rows to force virtualization on
1404
+ virtualizationThreshold: 50
1405
+ },
1406
+ self = this;
1407
+ self.maxCanvasHt = 0;
1408
+ //self vars
1409
+ self.config = $.extend(defaults, window.ngGrid.config, options);
1410
+
1411
+ // override conflicting settings
1412
+ self.config.showSelectionCheckbox = (self.config.showSelectionCheckbox && self.config.enableColumnHeavyVirt === false);
1413
+ self.config.enablePinning = (self.config.enablePinning && self.config.enableColumnHeavyVirt === false);
1414
+ self.config.selectWithCheckboxOnly = (self.config.selectWithCheckboxOnly && self.config.showSelectionCheckbox !== false);
1415
+ self.config.pinSelectionCheckbox = self.config.enablePinning;
1416
+
1417
+ if (typeof options.columnDefs === "string") {
1418
+ self.config.columnDefs = $scope.$eval(options.columnDefs);
1419
+ }
1420
+ self.rowCache = [];
1421
+ self.rowMap = [];
1422
+ self.gridId = "ng" + $utils.newId();
1423
+ self.$root = null; //this is the root element that is passed in with the binding handler
1424
+ self.$groupPanel = null;
1425
+ self.$topPanel = null;
1426
+ self.$headerContainer = null;
1427
+ self.$headerScroller = null;
1428
+ self.$headers = null;
1429
+ self.$viewport = null;
1430
+ self.$canvas = null;
1431
+ self.rootDim = self.config.gridDim;
1432
+ self.data = [];
1433
+ self.lateBindColumns = false;
1434
+ self.filteredRows = [];
1435
+
1436
+ self.initTemplates = function() {
1437
+ var templates = ['rowTemplate', 'aggregateTemplate', 'headerRowTemplate', 'checkboxCellTemplate', 'checkboxHeaderTemplate', 'menuTemplate', 'footerTemplate'];
1438
+
1439
+ var promises = [];
1440
+ angular.forEach(templates, function(template) {
1441
+ promises.push( self.getTemplate(template) );
1442
+ });
1443
+
1444
+ return $q.all(promises);
1445
+ };
1446
+
1447
+ //Templates
1448
+ // test templates for urls and get the tempaltes via synchronous ajax calls
1449
+ self.getTemplate = function (key) {
1450
+ var t = self.config[key];
1451
+ var uKey = self.gridId + key + ".html";
1452
+ var p = $q.defer();
1453
+ if (t && !TEMPLATE_REGEXP.test(t)) {
1454
+ $http.get(t, {
1455
+ cache: $templateCache
1456
+ })
1457
+ .success(function(data){
1458
+ $templateCache.put(uKey, data);
1459
+ p.resolve();
1460
+ })
1461
+ .error(function(err){
1462
+ p.reject("Could not load template: " + t);
1463
+ });
1464
+ } else if (t) {
1465
+ $templateCache.put(uKey, t);
1466
+ p.resolve();
1467
+ } else {
1468
+ var dKey = key + ".html";
1469
+ $templateCache.put(uKey, $templateCache.get(dKey));
1470
+ p.resolve();
1471
+ }
1472
+
1473
+ return p.promise;
1474
+ };
1475
+
1476
+ if (typeof self.config.data === "object") {
1477
+ self.data = self.config.data; // we cannot watch for updates if you don't pass the string name
1478
+ }
1479
+ self.calcMaxCanvasHeight = function() {
1480
+ var calculatedHeight;
1481
+ if(self.config.groups.length > 0){
1482
+ calculatedHeight = self.rowFactory.parsedData.filter(function(e) {
1483
+ return !e[NG_HIDDEN];
1484
+ }).length * self.config.rowHeight;
1485
+ } else {
1486
+ calculatedHeight = self.filteredRows.length * self.config.rowHeight;
1487
+ }
1488
+ return calculatedHeight;
1489
+ };
1490
+ self.elementDims = {
1491
+ scrollW: 0,
1492
+ scrollH: 0,
1493
+ rowIndexCellW: 25,
1494
+ rowSelectedCellW: 25,
1495
+ rootMaxW: 0,
1496
+ rootMaxH: 0
1497
+ };
1498
+ //self funcs
1499
+ self.setRenderedRows = function (newRows) {
1500
+ $scope.renderedRows.length = newRows.length;
1501
+ for (var i = 0; i < newRows.length; i++) {
1502
+ if (!$scope.renderedRows[i] || (newRows[i].isAggRow || $scope.renderedRows[i].isAggRow)) {
1503
+ $scope.renderedRows[i] = newRows[i].copy();
1504
+ $scope.renderedRows[i].collapsed = newRows[i].collapsed;
1505
+ if (!newRows[i].isAggRow) {
1506
+ $scope.renderedRows[i].setVars(newRows[i]);
1507
+ }
1508
+ } else {
1509
+ $scope.renderedRows[i].setVars(newRows[i]);
1510
+ }
1511
+ $scope.renderedRows[i].rowIndex = newRows[i].rowIndex;
1512
+ $scope.renderedRows[i].offsetTop = newRows[i].offsetTop;
1513
+ $scope.renderedRows[i].selected = newRows[i].selected;
1514
+ newRows[i].renderedRowIndex = i;
1515
+ }
1516
+ self.refreshDomSizes();
1517
+ $scope.$emit('ngGridEventRows', newRows);
1518
+ };
1519
+ self.minRowsToRender = function() {
1520
+ var viewportH = $scope.viewportDimHeight() || 1;
1521
+ return Math.floor(viewportH / self.config.rowHeight);
1522
+ };
1523
+ self.refreshDomSizes = function() {
1524
+ var dim = new ngDimension();
1525
+ dim.outerWidth = self.elementDims.rootMaxW;
1526
+ dim.outerHeight = self.elementDims.rootMaxH;
1527
+ self.rootDim = dim;
1528
+ self.maxCanvasHt = self.calcMaxCanvasHeight();
1529
+ };
1530
+ self.buildColumnDefsFromData = function () {
1531
+ self.config.columnDefs = [];
1532
+ var item = self.data[0];
1533
+ if (!item) {
1534
+ self.lateBoundColumns = true;
1535
+ return;
1536
+ }
1537
+ $utils.forIn(item, function (prop, propName) {
1538
+ if (self.config.excludeProperties.indexOf(propName) === -1) {
1539
+ self.config.columnDefs.push({
1540
+ field: propName
1541
+ });
1542
+ }
1543
+ });
1544
+ };
1545
+ self.buildColumns = function() {
1546
+ var columnDefs = self.config.columnDefs,
1547
+ cols = [];
1548
+ if (!columnDefs) {
1549
+ self.buildColumnDefsFromData();
1550
+ columnDefs = self.config.columnDefs;
1551
+ }
1552
+ if (self.config.showSelectionCheckbox) {
1553
+ cols.push(new ngColumn({
1554
+ colDef: {
1555
+ field: '\u2714',
1556
+ width: self.elementDims.rowSelectedCellW,
1557
+ sortable: false,
1558
+ resizable: false,
1559
+ groupable: false,
1560
+ headerCellTemplate: $templateCache.get($scope.gridId + 'checkboxHeaderTemplate.html'),
1561
+ cellTemplate: $templateCache.get($scope.gridId + 'checkboxCellTemplate.html'),
1562
+ pinned: self.config.pinSelectionCheckbox
1563
+ },
1564
+ index: 0,
1565
+ headerRowHeight: self.config.headerRowHeight,
1566
+ sortCallback: self.sortData,
1567
+ resizeOnDataCallback: self.resizeOnData,
1568
+ enableResize: self.config.enableColumnResize,
1569
+ enableSort: self.config.enableSorting,
1570
+ enablePinning: self.config.enablePinning
1571
+ }, $scope, self, domUtilityService, $templateCache, $utils));
1572
+ }
1573
+ if (columnDefs.length > 0) {
1574
+ var checkboxOffset = self.config.showSelectionCheckbox ? 1 : 0;
1575
+ var groupOffset = $scope.configGroups.length;
1576
+ $scope.configGroups.length = 0;
1577
+ angular.forEach(columnDefs, function(colDef, i) {
1578
+ i += checkboxOffset;
1579
+ var column = new ngColumn({
1580
+ colDef: colDef,
1581
+ index: i + groupOffset,
1582
+ originalIndex: i,
1583
+ headerRowHeight: self.config.headerRowHeight,
1584
+ sortCallback: self.sortData,
1585
+ resizeOnDataCallback: self.resizeOnData,
1586
+ enableResize: self.config.enableColumnResize,
1587
+ enableSort: self.config.enableSorting,
1588
+ enablePinning: self.config.enablePinning,
1589
+ enableCellEdit: self.config.enableCellEdit || self.config.enableCellEditOnFocus
1590
+ }, $scope, self, domUtilityService, $templateCache, $utils);
1591
+ var indx = self.config.groups.indexOf(colDef.field);
1592
+ if (indx !== -1) {
1593
+ column.isGroupedBy = true;
1594
+ $scope.configGroups.splice(indx, 0, column);
1595
+ column.groupIndex = $scope.configGroups.length;
1596
+ }
1597
+ cols.push(column);
1598
+ });
1599
+ $scope.columns = cols;
1600
+ if (self.config.groups.length > 0) {
1601
+ self.rowFactory.getGrouping(self.config.groups);
1602
+ }
1603
+ }
1604
+ };
1605
+ self.configureColumnWidths = function() {
1606
+ var asterisksArray = [],
1607
+ percentArray = [],
1608
+ asteriskNum = 0,
1609
+ totalWidth = 0;
1610
+
1611
+ // When rearranging columns, their index in $scope.columns will no longer match the original column order from columnDefs causing
1612
+ // their width config to be out of sync. We can use "originalIndex" on the ngColumns to get hold of the correct setup from columnDefs, but to
1613
+ // avoid O(n) lookups in $scope.columns per column we setup a map.
1614
+ var indexMap = {};
1615
+ // Build a map of columnDefs column indices -> ngColumn indices (via the "originalIndex" property on ngColumns).
1616
+ angular.forEach($scope.columns, function(ngCol, i) {
1617
+ // Disregard columns created by grouping (the grouping columns don't match a column from columnDefs)
1618
+ if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
1619
+ var origIndex = ngCol.originalIndex;
1620
+ if (self.config.showSelectionCheckbox) {
1621
+ //if visible, takes up 25 pixels
1622
+ if(ngCol.originalIndex === 0 && ngCol.visible){
1623
+ totalWidth += 25;
1624
+ }
1625
+ // The originalIndex will be offset 1 when including the selection column
1626
+ origIndex--;
1627
+ }
1628
+ indexMap[origIndex] = i;
1629
+ }
1630
+ });
1631
+
1632
+ angular.forEach(self.config.columnDefs, function(colDef, i) {
1633
+ // Get the ngColumn that matches the current column from columnDefs
1634
+ var ngColumn = $scope.columns[indexMap[i]];
1635
+
1636
+ colDef.index = i;
1637
+
1638
+ var isPercent = false, t;
1639
+ //if width is not defined, set it to a single star
1640
+ if ($utils.isNullOrUndefined(colDef.width)) {
1641
+ colDef.width = "*";
1642
+ } else { // get column width
1643
+ isPercent = isNaN(colDef.width) ? $utils.endsWith(colDef.width, "%") : false;
1644
+ t = isPercent ? colDef.width : parseInt(colDef.width, 10);
1645
+ }
1646
+
1647
+ // check if it is a number
1648
+ if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
1649
+ t = colDef.width;
1650
+ // figure out if the width is defined or if we need to calculate it
1651
+ if (t === 'auto') { // set it for now until we have data and subscribe when it changes so we can set the width.
1652
+ ngColumn.width = ngColumn.minWidth;
1653
+ totalWidth += ngColumn.width;
1654
+ var temp = ngColumn;
1655
+
1656
+ $scope.$on("ngGridEventData", function () {
1657
+ self.resizeOnData(temp);
1658
+ });
1659
+ return;
1660
+ } else if (t.indexOf("*") !== -1) { // we need to save it until the end to do the calulations on the remaining width.
1661
+ if (ngColumn.visible !== false) {
1662
+ asteriskNum += t.length;
1663
+ }
1664
+ asterisksArray.push(colDef);
1665
+ return;
1666
+ } else if (isPercent) { // If the width is a percentage, save it until the very last.
1667
+ percentArray.push(colDef);
1668
+ return;
1669
+ } else { // we can't parse the width so lets throw an error.
1670
+ throw "unable to parse column width, use percentage (\"10%\",\"20%\", etc...) or \"*\" to use remaining width of grid";
1671
+ }
1672
+ } else if (ngColumn.visible !== false) {
1673
+ totalWidth += ngColumn.width = parseInt(ngColumn.width, 10);
1674
+ }
1675
+ });
1676
+
1677
+ // Now we check if we saved any percentage columns for calculating last
1678
+ if (percentArray.length > 0) {
1679
+ //If they specificy for maintain column ratios to be false in grid config, then it will remain false. If not specifiied or true, will be true.
1680
+ self.config.maintainColumnRatios = self.config.maintainColumnRatios !== false;
1681
+ // If any columns with % widths have been hidden, then let other % based columns use their width
1682
+ var percentWidth = 0; // The total % value for all columns setting their width using % (will e.g. be 40 for 2 columns with 20% each)
1683
+ var hiddenPercent = 0; // The total % value for all columns setting their width using %, but which have been hidden
1684
+ angular.forEach(percentArray, function(colDef) {
1685
+ // Get the ngColumn that matches the current column from columnDefs
1686
+ var ngColumn = $scope.columns[indexMap[colDef.index]];
1687
+ var t = colDef.width;
1688
+ var percent = parseInt(t.slice(0, -1), 10) / 100;
1689
+ percentWidth += percent;
1690
+
1691
+ if (!ngColumn.visible) {
1692
+ hiddenPercent += percent;
1693
+ }
1694
+ });
1695
+ var percentWidthUsed = percentWidth - hiddenPercent;
1696
+
1697
+ // do the math
1698
+ angular.forEach(percentArray, function(colDef) {
1699
+ // Get the ngColumn that matches the current column from columnDefs
1700
+ var ngColumn = $scope.columns[indexMap[colDef.index]];
1701
+
1702
+ // Calc the % relative to the amount of % reserved for the visible columns (that use % based widths)
1703
+ var t = colDef.width;
1704
+ var percent = parseInt(t.slice(0, -1), 10) / 100;
1705
+ if (hiddenPercent > 0) {
1706
+ percent = percent / percentWidthUsed;
1707
+ }
1708
+ else {
1709
+ percent = percent / percentWidth;
1710
+ }
1711
+
1712
+ var pixelsForPercentBasedWidth = self.rootDim.outerWidth * percentWidth;
1713
+ ngColumn.width = Math.floor(pixelsForPercentBasedWidth * percent);
1714
+ totalWidth += ngColumn.width;
1715
+ });
1716
+ }
1717
+
1718
+ // check if we saved any asterisk columns for calculating later
1719
+ if (asterisksArray.length > 0) {
1720
+ //If they specificy for maintain column ratios to be false in grid config, then it will remain false. If not specifiied or true, will be true.
1721
+ self.config.maintainColumnRatios = self.config.maintainColumnRatios !== false;
1722
+ // get the remaining width
1723
+ var remainingWidth = self.rootDim.outerWidth - totalWidth;
1724
+ // are we overflowing vertically?
1725
+ if (self.maxCanvasHt > $scope.viewportDimHeight()) {
1726
+ //compensate for scrollbar
1727
+ remainingWidth -= domUtilityService.ScrollW;
1728
+ }
1729
+ // calculate the weight of each asterisk rounded down
1730
+ var asteriskVal = Math.floor(remainingWidth / asteriskNum);
1731
+
1732
+ // set the width of each column based on the number of stars
1733
+ angular.forEach(asterisksArray, function(colDef, i) {
1734
+ // Get the ngColumn that matches the current column from columnDefs
1735
+ var ngColumn = $scope.columns[indexMap[colDef.index]];
1736
+ ngColumn.width = asteriskVal * colDef.width.length;
1737
+ if (ngColumn.visible !== false) {
1738
+ totalWidth += ngColumn.width;
1739
+ }
1740
+
1741
+ var isLast = (i === (asterisksArray.length - 1));
1742
+ //if last asterisk and doesn't fill width of grid, add the difference
1743
+ if(isLast && totalWidth < self.rootDim.outerWidth){
1744
+ var gridWidthDifference = self.rootDim.outerWidth - totalWidth;
1745
+ if(self.maxCanvasHt > $scope.viewportDimHeight()){
1746
+ gridWidthDifference -= domUtilityService.ScrollW;
1747
+ }
1748
+ ngColumn.width += gridWidthDifference;
1749
+ }
1750
+ });
1751
+ }
1752
+ };
1753
+ self.init = function() {
1754
+ return self.initTemplates().then(function(){
1755
+ //factories and services
1756
+ $scope.selectionProvider = new ngSelectionProvider(self, $scope, $parse);
1757
+ $scope.domAccessProvider = new ngDomAccessProvider(self);
1758
+ self.rowFactory = new ngRowFactory(self, $scope, domUtilityService, $templateCache, $utils);
1759
+ self.searchProvider = new ngSearchProvider($scope, self, $filter);
1760
+ self.styleProvider = new ngStyleProvider($scope, self);
1761
+ $scope.$watch('configGroups', function(a) {
1762
+ var tempArr = [];
1763
+ angular.forEach(a, function(item) {
1764
+ tempArr.push(item.field || item);
1765
+ });
1766
+ self.config.groups = tempArr;
1767
+ self.rowFactory.filteredRowsChanged();
1768
+ $scope.$emit('ngGridEventGroups', a);
1769
+ }, true);
1770
+ $scope.$watch('columns', function (a) {
1771
+ if(!$scope.isColumnResizing){
1772
+ domUtilityService.RebuildGrid($scope, self);
1773
+ }
1774
+ $scope.$emit('ngGridEventColumns', a);
1775
+ }, true);
1776
+ $scope.$watch(function() {
1777
+ return options.i18n;
1778
+ }, function(newLang) {
1779
+ $utils.seti18n($scope, newLang);
1780
+ });
1781
+ self.maxCanvasHt = self.calcMaxCanvasHeight();
1782
+
1783
+ if (self.config.sortInfo.fields && self.config.sortInfo.fields.length > 0) {
1784
+ $scope.$watch(function() {
1785
+ return self.config.sortInfo;
1786
+ }, function(sortInfo){
1787
+ if (!sortService.isSorting) {
1788
+ self.sortColumnsInit();
1789
+ $scope.$emit('ngGridEventSorted', self.config.sortInfo);
1790
+ }
1791
+ },true);
1792
+ }
1793
+ });
1794
+
1795
+ // var p = $q.defer();
1796
+ // p.resolve();
1797
+ // return p.promise;
1798
+ };
1799
+
1800
+ self.resizeOnData = function(col) {
1801
+ // we calculate the longest data.
1802
+ var longest = col.minWidth;
1803
+ var arr = $utils.getElementsByClassName('col' + col.index);
1804
+ angular.forEach(arr, function(elem, index) {
1805
+ var i;
1806
+ if (index === 0) {
1807
+ var kgHeaderText = $(elem).find('.ngHeaderText');
1808
+ i = $utils.visualLength(kgHeaderText) + 10; // +10 some margin
1809
+ } else {
1810
+ var ngCellText = $(elem).find('.ngCellText');
1811
+ i = $utils.visualLength(ngCellText) + 10; // +10 some margin
1812
+ }
1813
+ if (i > longest) {
1814
+ longest = i;
1815
+ }
1816
+ });
1817
+ col.width = col.longest = Math.min(col.maxWidth, longest + 7); // + 7 px to make it look decent.
1818
+ domUtilityService.BuildStyles($scope, self, true);
1819
+ };
1820
+ self.lastSortedColumns = [];
1821
+ self.sortData = function(col, evt) {
1822
+ if (evt && evt.shiftKey && self.config.sortInfo) {
1823
+ var indx = self.config.sortInfo.columns.indexOf(col);
1824
+ if (indx === -1) {
1825
+ if (self.config.sortInfo.columns.length === 1) {
1826
+ self.config.sortInfo.columns[0].sortPriority = 1;
1827
+ }
1828
+ self.config.sortInfo.columns.push(col);
1829
+ col.sortPriority = self.config.sortInfo.columns.length;
1830
+ self.config.sortInfo.fields.push(col.field);
1831
+ self.config.sortInfo.directions.push(col.sortDirection);
1832
+ self.lastSortedColumns.push(col);
1833
+ } else {
1834
+ self.config.sortInfo.directions[indx] = col.sortDirection;
1835
+ }
1836
+ } else {
1837
+ var isArr = $.isArray(col);
1838
+ self.config.sortInfo.columns.length = 0;
1839
+ self.config.sortInfo.fields.length = 0;
1840
+ self.config.sortInfo.directions.length = 0;
1841
+ var push = function (c) {
1842
+ self.config.sortInfo.columns.push(c);
1843
+ self.config.sortInfo.fields.push(c.field);
1844
+ self.config.sortInfo.directions.push(c.sortDirection);
1845
+ self.lastSortedColumns.push(c);
1846
+ };
1847
+ if (isArr) {
1848
+ self.clearSortingData();
1849
+ angular.forEach(col, function (c, i) {
1850
+ c.sortPriority = i + 1;
1851
+ push(c);
1852
+ });
1853
+ } else {
1854
+ self.clearSortingData(col);
1855
+ col.sortPriority = undefined;
1856
+ push(col);
1857
+ }
1858
+ }
1859
+ self.sortActual();
1860
+ self.searchProvider.evalFilter();
1861
+ $scope.$emit('ngGridEventSorted', self.config.sortInfo);
1862
+ };
1863
+ self.sortColumnsInit = function() {
1864
+ if (self.config.sortInfo.columns) {
1865
+ self.config.sortInfo.columns.length = 0;
1866
+ } else {
1867
+ self.config.sortInfo.columns = [];
1868
+ }
1869
+ angular.forEach($scope.columns, function(c) {
1870
+ var i = self.config.sortInfo.fields.indexOf(c.field);
1871
+ if (i !== -1) {
1872
+ c.sortDirection = self.config.sortInfo.directions[i] || 'asc';
1873
+ self.config.sortInfo.columns[i] = c;
1874
+ }
1875
+ });
1876
+ angular.forEach(self.config.sortInfo.columns, function(c){
1877
+ self.sortData(c);
1878
+ });
1879
+ };
1880
+ self.sortActual = function() {
1881
+ if (!self.config.useExternalSorting) {
1882
+ var tempData = self.data.slice(0);
1883
+ angular.forEach(tempData, function(item, i) {
1884
+ var e = self.rowMap[i];
1885
+ if (e !== undefined) {
1886
+ var v = self.rowCache[e];
1887
+ if (v !== undefined) {
1888
+ item.preSortSelected = v.selected;
1889
+ item.preSortIndex = i;
1890
+ }
1891
+ }
1892
+ });
1893
+ sortService.Sort(self.config.sortInfo, tempData);
1894
+ angular.forEach(tempData, function(item, i) {
1895
+ self.rowCache[i].entity = item;
1896
+ self.rowCache[i].selected = item.preSortSelected;
1897
+ self.rowMap[item.preSortIndex] = i;
1898
+ delete item.preSortSelected;
1899
+ delete item.preSortIndex;
1900
+ });
1901
+ }
1902
+ };
1903
+
1904
+ self.clearSortingData = function (col) {
1905
+ if (!col) {
1906
+ angular.forEach(self.lastSortedColumns, function (c) {
1907
+ c.sortDirection = "";
1908
+ c.sortPriority = null;
1909
+ });
1910
+ self.lastSortedColumns = [];
1911
+ } else {
1912
+ angular.forEach(self.lastSortedColumns, function (c) {
1913
+ if (col.index !== c.index) {
1914
+ c.sortDirection = "";
1915
+ c.sortPriority = null;
1916
+ }
1917
+ });
1918
+ self.lastSortedColumns[0] = col;
1919
+ self.lastSortedColumns.length = 1;
1920
+ }
1921
+ };
1922
+ self.fixColumnIndexes = function() {
1923
+ //fix column indexes
1924
+ for (var i = 0; i < $scope.columns.length; i++) {
1925
+ $scope.columns[i].index = i;
1926
+ }
1927
+ };
1928
+ self.fixGroupIndexes = function() {
1929
+ angular.forEach($scope.configGroups, function(item, i) {
1930
+ item.groupIndex = i + 1;
1931
+ });
1932
+ };
1933
+ //$scope vars
1934
+ $scope.elementsNeedMeasuring = true;
1935
+ $scope.columns = [];
1936
+ $scope.renderedRows = [];
1937
+ $scope.renderedColumns = [];
1938
+ $scope.headerRow = null;
1939
+ $scope.rowHeight = self.config.rowHeight;
1940
+ $scope.jqueryUITheme = self.config.jqueryUITheme;
1941
+ $scope.showSelectionCheckbox = self.config.showSelectionCheckbox;
1942
+ $scope.enableCellSelection = self.config.enableCellSelection;
1943
+ $scope.enableCellEditOnFocus = self.config.enableCellEditOnFocus;
1944
+ $scope.footer = null;
1945
+ $scope.selectedItems = self.config.selectedItems;
1946
+ $scope.multiSelect = self.config.multiSelect;
1947
+ $scope.showFooter = self.config.showFooter;
1948
+ $scope.footerRowHeight = $scope.showFooter ? self.config.footerRowHeight : 0;
1949
+ $scope.showColumnMenu = self.config.showColumnMenu;
1950
+ $scope.showMenu = false;
1951
+ $scope.configGroups = [];
1952
+ $scope.gridId = self.gridId;
1953
+ //Paging
1954
+ $scope.enablePaging = self.config.enablePaging;
1955
+ $scope.pagingOptions = self.config.pagingOptions;
1956
+
1957
+ //i18n support
1958
+ $scope.i18n = {};
1959
+ $utils.seti18n($scope, self.config.i18n);
1960
+ $scope.adjustScrollLeft = function (scrollLeft) {
1961
+ var colwidths = 0,
1962
+ totalLeft = 0,
1963
+ x = $scope.columns.length,
1964
+ newCols = [],
1965
+ dcv = !self.config.enableColumnHeavyVirt;
1966
+ var r = 0;
1967
+ var addCol = function (c) {
1968
+ if (dcv) {
1969
+ newCols.push(c);
1970
+ } else {
1971
+ if (!$scope.renderedColumns[r]) {
1972
+ $scope.renderedColumns[r] = c.copy();
1973
+ } else {
1974
+ $scope.renderedColumns[r].setVars(c);
1975
+ }
1976
+ }
1977
+ r++;
1978
+ };
1979
+ for (var i = 0; i < x; i++) {
1980
+ var col = $scope.columns[i];
1981
+ if (col.visible !== false) {
1982
+ var w = col.width + colwidths;
1983
+ if (col.pinned) {
1984
+ addCol(col);
1985
+ var newLeft = i > 0 ? (scrollLeft + totalLeft) : scrollLeft;
1986
+ domUtilityService.setColLeft(col, newLeft, self);
1987
+ totalLeft += col.width;
1988
+ } else {
1989
+ if (w >= scrollLeft) {
1990
+ if (colwidths <= scrollLeft + self.rootDim.outerWidth) {
1991
+ addCol(col);
1992
+ }
1993
+ }
1994
+ }
1995
+ colwidths += col.width;
1996
+ }
1997
+ }
1998
+ if (dcv) {
1999
+ $scope.renderedColumns = newCols;
2000
+ }
2001
+ };
2002
+ self.prevScrollTop = 0;
2003
+ self.prevScrollIndex = 0;
2004
+ $scope.adjustScrollTop = function(scrollTop, force) {
2005
+ if (self.prevScrollTop === scrollTop && !force) {
2006
+ return;
2007
+ }
2008
+ if (scrollTop > 0 && self.$viewport[0].scrollHeight - scrollTop <= self.$viewport.outerHeight()) {
2009
+ $scope.$emit('ngGridEventScroll');
2010
+ }
2011
+ var rowIndex = Math.floor(scrollTop / self.config.rowHeight);
2012
+ var newRange;
2013
+ if (self.filteredRows.length > self.config.virtualizationThreshold) {
2014
+ // Have we hit the threshold going down?
2015
+ if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) {
2016
+ return;
2017
+ }
2018
+ //Have we hit the threshold going up?
2019
+ if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) {
2020
+ return;
2021
+ }
2022
+ newRange = new ngRange(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS);
2023
+ } else {
2024
+ var maxLen = $scope.configGroups.length > 0 ? self.rowFactory.parsedData.length : self.data.length;
2025
+ newRange = new ngRange(0, Math.max(maxLen, self.minRowsToRender() + EXCESS_ROWS));
2026
+ }
2027
+ self.prevScrollTop = scrollTop;
2028
+ self.rowFactory.UpdateViewableRange(newRange);
2029
+ self.prevScrollIndex = rowIndex;
2030
+ };
2031
+
2032
+ //scope funcs
2033
+ $scope.toggleShowMenu = function() {
2034
+ $scope.showMenu = !$scope.showMenu;
2035
+ };
2036
+ $scope.toggleSelectAll = function(state, selectOnlyVisible) {
2037
+ $scope.selectionProvider.toggleSelectAll(state, false, selectOnlyVisible);
2038
+ };
2039
+ $scope.totalFilteredItemsLength = function() {
2040
+ return self.filteredRows.length;
2041
+ };
2042
+ $scope.showGroupPanel = function() {
2043
+ return self.config.showGroupPanel;
2044
+ };
2045
+ $scope.topPanelHeight = function() {
2046
+ return self.config.showGroupPanel === true ? self.config.headerRowHeight + 32 : self.config.headerRowHeight;
2047
+ };
2048
+
2049
+ $scope.viewportDimHeight = function() {
2050
+ return Math.max(0, self.rootDim.outerHeight - $scope.topPanelHeight() - $scope.footerRowHeight - 2);
2051
+ };
2052
+ $scope.groupBy = function (col) {
2053
+ if (self.data.length < 1 || !col.groupable || !col.field) {
2054
+ return;
2055
+ }
2056
+ //first sort the column
2057
+ if (!col.sortDirection) {
2058
+ col.sort({ shiftKey: $scope.configGroups.length > 0 ? true : false });
2059
+ }
2060
+
2061
+ var indx = $scope.configGroups.indexOf(col);
2062
+ if (indx === -1) {
2063
+ col.isGroupedBy = true;
2064
+ $scope.configGroups.push(col);
2065
+ col.groupIndex = $scope.configGroups.length;
2066
+ } else {
2067
+ $scope.removeGroup(indx);
2068
+ }
2069
+ self.$viewport.scrollTop(0);
2070
+ domUtilityService.digest($scope);
2071
+ };
2072
+ $scope.removeGroup = function(index) {
2073
+ var col = $scope.columns.filter(function(item) {
2074
+ return item.groupIndex === (index + 1);
2075
+ })[0];
2076
+ col.isGroupedBy = false;
2077
+ col.groupIndex = 0;
2078
+ if ($scope.columns[index].isAggCol) {
2079
+ $scope.columns.splice(index, 1);
2080
+ $scope.configGroups.splice(index, 1);
2081
+ self.fixGroupIndexes();
2082
+ }
2083
+ if ($scope.configGroups.length === 0) {
2084
+ self.fixColumnIndexes();
2085
+ domUtilityService.digest($scope);
2086
+ }
2087
+ $scope.adjustScrollLeft(0);
2088
+ };
2089
+ $scope.togglePin = function (col) {
2090
+ var indexFrom = col.index;
2091
+ var indexTo = 0;
2092
+ for (var i = 0; i < $scope.columns.length; i++) {
2093
+ if (!$scope.columns[i].pinned) {
2094
+ break;
2095
+ }
2096
+ indexTo++;
2097
+ }
2098
+ if (col.pinned) {
2099
+ indexTo = Math.max(col.originalIndex, indexTo - 1);
2100
+ }
2101
+ col.pinned = !col.pinned;
2102
+ // Splice the columns
2103
+ $scope.columns.splice(indexFrom, 1);
2104
+ $scope.columns.splice(indexTo, 0, col);
2105
+ self.fixColumnIndexes();
2106
+ // Finally, rebuild the CSS styles.
2107
+ domUtilityService.BuildStyles($scope, self, true);
2108
+ self.$viewport.scrollLeft(self.$viewport.scrollLeft() - col.width);
2109
+ };
2110
+ $scope.totalRowWidth = function() {
2111
+ var totalWidth = 0,
2112
+ cols = $scope.columns;
2113
+ for (var i = 0; i < cols.length; i++) {
2114
+ if (cols[i].visible !== false) {
2115
+ totalWidth += cols[i].width;
2116
+ }
2117
+ }
2118
+ return totalWidth;
2119
+ };
2120
+ $scope.headerScrollerDim = function() {
2121
+ var viewportH = $scope.viewportDimHeight(),
2122
+ maxHeight = self.maxCanvasHt,
2123
+ vScrollBarIsOpen = (maxHeight > viewportH),
2124
+ newDim = new ngDimension();
2125
+
2126
+ newDim.autoFitHeight = true;
2127
+ newDim.outerWidth = $scope.totalRowWidth();
2128
+ if (vScrollBarIsOpen) {
2129
+ newDim.outerWidth += self.elementDims.scrollW;
2130
+ } else if ((maxHeight - viewportH) <= self.elementDims.scrollH) { //if the horizontal scroll is open it forces the viewport to be smaller
2131
+ newDim.outerWidth += self.elementDims.scrollW;
2132
+ }
2133
+ return newDim;
2134
+ };
2135
+ };
2136
+
2137
+ var ngRange = function (top, bottom) {
2138
+ this.topRow = top;
2139
+ this.bottomRow = bottom;
2140
+ };
2141
+ var ngRow = function (entity, config, selectionProvider, rowIndex, $utils) {
2142
+ this.entity = entity;
2143
+ this.config = config;
2144
+ this.selectionProvider = selectionProvider;
2145
+ this.rowIndex = rowIndex;
2146
+ this.utils = $utils;
2147
+ this.selected = selectionProvider.getSelection(entity);
2148
+ this.cursor = this.config.enableRowSelection ? 'pointer' : 'default';
2149
+ this.beforeSelectionChange = config.beforeSelectionChangeCallback;
2150
+ this.afterSelectionChange = config.afterSelectionChangeCallback;
2151
+ this.offsetTop = this.rowIndex * config.rowHeight;
2152
+ this.rowDisplayIndex = 0;
2153
+ };
2154
+
2155
+ ngRow.prototype.setSelection = function (isSelected) {
2156
+ this.selectionProvider.setSelection(this, isSelected);
2157
+ this.selectionProvider.lastClickedRow = this;
2158
+ };
2159
+ ngRow.prototype.continueSelection = function (event) {
2160
+ this.selectionProvider.ChangeSelection(this, event);
2161
+ };
2162
+ ngRow.prototype.ensureEntity = function (expected) {
2163
+ if (this.entity !== expected) {
2164
+ // Update the entity and determine our selected property
2165
+ this.entity = expected;
2166
+ this.selected = this.selectionProvider.getSelection(this.entity);
2167
+ }
2168
+ };
2169
+ ngRow.prototype.toggleSelected = function (event) {
2170
+ if (!this.config.enableRowSelection && !this.config.enableCellSelection) {
2171
+ return true;
2172
+ }
2173
+ var element = event.target || event;
2174
+ //check and make sure its not the bubbling up of our checked 'click' event
2175
+ if (element.type === "checkbox" && element.parentElement.className !== "ngSelectionCell ng-scope") {
2176
+ return true;
2177
+ }
2178
+ if (this.config.selectWithCheckboxOnly && element.type !== "checkbox") {
2179
+ this.selectionProvider.lastClickedRow = this;
2180
+ return true;
2181
+ }
2182
+ if (this.beforeSelectionChange(this, event)) {
2183
+ this.continueSelection(event);
2184
+ }
2185
+ return false;
2186
+ };
2187
+ ngRow.prototype.alternatingRowClass = function () {
2188
+ var isEven = (this.rowIndex % 2) === 0;
2189
+ var classes = {
2190
+ 'ngRow' : true,
2191
+ 'selected': this.selected,
2192
+ 'even': isEven,
2193
+ 'odd': !isEven,
2194
+ 'ui-state-default': this.config.jqueryUITheme && isEven,
2195
+ 'ui-state-active': this.config.jqueryUITheme && !isEven
2196
+ };
2197
+ return classes;
2198
+ };
2199
+ ngRow.prototype.getProperty = function (path) {
2200
+ return this.utils.evalProperty(this.entity, path);
2201
+ };
2202
+ ngRow.prototype.copy = function () {
2203
+ this.clone = new ngRow(this.entity, this.config, this.selectionProvider, this.rowIndex, this.utils);
2204
+ this.clone.isClone = true;
2205
+ this.clone.elm = this.elm;
2206
+ this.clone.orig = this;
2207
+ return this.clone;
2208
+ };
2209
+ ngRow.prototype.setVars = function (fromRow) {
2210
+ fromRow.clone = this;
2211
+ this.entity = fromRow.entity;
2212
+ this.selected = fromRow.selected;
2213
+ this.orig = fromRow;
2214
+ };
2215
+ var ngRowFactory = function (grid, $scope, domUtilityService, $templateCache, $utils) {
2216
+ var self = this;
2217
+ // we cache rows when they are built, and then blow the cache away when sorting
2218
+ self.aggCache = {};
2219
+ self.parentCache = []; // Used for grouping and is cleared each time groups are calulated.
2220
+ self.dataChanged = true;
2221
+ self.parsedData = [];
2222
+ self.rowConfig = {};
2223
+ self.selectionProvider = $scope.selectionProvider;
2224
+ self.rowHeight = 30;
2225
+ self.numberOfAggregates = 0;
2226
+ self.groupedData = undefined;
2227
+ self.rowHeight = grid.config.rowHeight;
2228
+ self.rowConfig = {
2229
+ enableRowSelection: grid.config.enableRowSelection,
2230
+ rowClasses: grid.config.rowClasses,
2231
+ selectedItems: $scope.selectedItems,
2232
+ selectWithCheckboxOnly: grid.config.selectWithCheckboxOnly,
2233
+ beforeSelectionChangeCallback: grid.config.beforeSelectionChange,
2234
+ afterSelectionChangeCallback: grid.config.afterSelectionChange,
2235
+ jqueryUITheme: grid.config.jqueryUITheme,
2236
+ enableCellSelection: grid.config.enableCellSelection,
2237
+ rowHeight: grid.config.rowHeight
2238
+ };
2239
+
2240
+ self.renderedRange = new ngRange(0, grid.minRowsToRender() + EXCESS_ROWS);
2241
+
2242
+ // @entity - the data item
2243
+ // @rowIndex - the index of the row
2244
+ self.buildEntityRow = function(entity, rowIndex) {
2245
+ // build the row
2246
+ return new ngRow(entity, self.rowConfig, self.selectionProvider, rowIndex, $utils);
2247
+ };
2248
+
2249
+ self.buildAggregateRow = function(aggEntity, rowIndex) {
2250
+ var agg = self.aggCache[aggEntity.aggIndex]; // first check to see if we've already built it
2251
+ if (!agg) {
2252
+ // build the row
2253
+ agg = new ngAggregate(aggEntity, self, self.rowConfig.rowHeight, grid.config.groupsCollapsedByDefault);
2254
+ self.aggCache[aggEntity.aggIndex] = agg;
2255
+ }
2256
+ agg.rowIndex = rowIndex;
2257
+ agg.offsetTop = rowIndex * self.rowConfig.rowHeight;
2258
+ return agg;
2259
+ };
2260
+ self.UpdateViewableRange = function(newRange) {
2261
+ self.renderedRange = newRange;
2262
+ self.renderedChange();
2263
+ };
2264
+ self.filteredRowsChanged = function() {
2265
+ // check for latebound autogenerated columns
2266
+ if (grid.lateBoundColumns && grid.filteredRows.length > 0) {
2267
+ grid.config.columnDefs = undefined;
2268
+ grid.buildColumns();
2269
+ grid.lateBoundColumns = false;
2270
+ $scope.$evalAsync(function() {
2271
+ $scope.adjustScrollLeft(0);
2272
+ });
2273
+ }
2274
+ self.dataChanged = true;
2275
+ if (grid.config.groups.length > 0) {
2276
+ self.getGrouping(grid.config.groups);
2277
+ }
2278
+ self.UpdateViewableRange(self.renderedRange);
2279
+ };
2280
+
2281
+ self.renderedChange = function() {
2282
+ if (!self.groupedData || grid.config.groups.length < 1) {
2283
+ self.renderedChangeNoGroups();
2284
+ grid.refreshDomSizes();
2285
+ return;
2286
+ }
2287
+ self.wasGrouped = true;
2288
+ self.parentCache = [];
2289
+ var x = 0;
2290
+ var temp = self.parsedData.filter(function (e) {
2291
+ if (e.isAggRow) {
2292
+ if (e.parent && e.parent.collapsed) {
2293
+ return false;
2294
+ }
2295
+ return true;
2296
+ }
2297
+ if (!e[NG_HIDDEN]) {
2298
+ e.rowIndex = x++;
2299
+ }
2300
+ return !e[NG_HIDDEN];
2301
+ });
2302
+ self.totalRows = temp.length;
2303
+ var rowArr = [];
2304
+ for (var i = self.renderedRange.topRow; i < self.renderedRange.bottomRow; i++) {
2305
+ if (temp[i]) {
2306
+ temp[i].offsetTop = i * grid.config.rowHeight;
2307
+ rowArr.push(temp[i]);
2308
+ }
2309
+ }
2310
+ grid.setRenderedRows(rowArr);
2311
+ };
2312
+
2313
+ self.renderedChangeNoGroups = function () {
2314
+ var rowArr = [];
2315
+ for (var i = self.renderedRange.topRow; i < self.renderedRange.bottomRow; i++) {
2316
+ if (grid.filteredRows[i]) {
2317
+ grid.filteredRows[i].rowIndex = i;
2318
+ grid.filteredRows[i].offsetTop = i * grid.config.rowHeight;
2319
+ rowArr.push(grid.filteredRows[i]);
2320
+ }
2321
+ }
2322
+ grid.setRenderedRows(rowArr);
2323
+ };
2324
+
2325
+ self.fixRowCache = function () {
2326
+ var newLen = grid.data.length;
2327
+ var diff = newLen - grid.rowCache.length;
2328
+ if (diff < 0) {
2329
+ grid.rowCache.length = grid.rowMap.length = newLen;
2330
+ } else {
2331
+ for (var i = grid.rowCache.length; i < newLen; i++) {
2332
+ grid.rowCache[i] = grid.rowFactory.buildEntityRow(grid.data[i], i);
2333
+ }
2334
+ }
2335
+ };
2336
+
2337
+ //magical recursion. it works. I swear it. I figured it out in the shower one day.
2338
+ self.parseGroupData = function(g) {
2339
+ if (g.values) {
2340
+ for (var x = 0; x < g.values.length; x++){
2341
+ // get the last parent in the array because that's where our children want to be
2342
+ self.parentCache[self.parentCache.length - 1].children.push(g.values[x]);
2343
+ //add the row to our return array
2344
+ self.parsedData.push(g.values[x]);
2345
+ }
2346
+ } else {
2347
+ for (var prop in g) {
2348
+ // exclude the meta properties.
2349
+ if (prop === NG_FIELD || prop === NG_DEPTH || prop === NG_COLUMN) {
2350
+ continue;
2351
+ } else if (g.hasOwnProperty(prop)) {
2352
+ //build the aggregate row
2353
+ var agg = self.buildAggregateRow({
2354
+ gField: g[NG_FIELD],
2355
+ gLabel: prop,
2356
+ gDepth: g[NG_DEPTH],
2357
+ isAggRow: true,
2358
+ '_ng_hidden_': false,
2359
+ children: [],
2360
+ aggChildren: [],
2361
+ aggIndex: self.numberOfAggregates,
2362
+ aggLabelFilter: g[NG_COLUMN].aggLabelFilter
2363
+ }, 0);
2364
+ self.numberOfAggregates++;
2365
+ //set the aggregate parent to the parent in the array that is one less deep.
2366
+ agg.parent = self.parentCache[agg.depth - 1];
2367
+ // if we have a parent, set the parent to not be collapsed and append the current agg to its children
2368
+ if (agg.parent) {
2369
+ agg.parent.collapsed = false;
2370
+ agg.parent.aggChildren.push(agg);
2371
+ }
2372
+ // add the aggregate row to the parsed data.
2373
+ self.parsedData.push(agg);
2374
+ // the current aggregate now the parent of the current depth
2375
+ self.parentCache[agg.depth] = agg;
2376
+ // dig deeper for more aggregates or children.
2377
+ self.parseGroupData(g[prop]);
2378
+ }
2379
+ }
2380
+ }
2381
+ };
2382
+ //Shuffle the data into their respective groupings.
2383
+ self.getGrouping = function(groups) {
2384
+ self.aggCache = [];
2385
+ self.numberOfAggregates = 0;
2386
+ self.groupedData = {};
2387
+ // Here we set the onmousedown event handler to the header container.
2388
+ var rows = grid.filteredRows,
2389
+ maxDepth = groups.length,
2390
+ cols = $scope.columns;
2391
+
2392
+ function filterCols(cols, group) {
2393
+ return cols.filter(function(c) {
2394
+ return c.field === group;
2395
+ });
2396
+ }
2397
+
2398
+ for (var x = 0; x < rows.length; x++) {
2399
+ var model = rows[x].entity;
2400
+ if (!model) {
2401
+ return;
2402
+ }
2403
+ rows[x][NG_HIDDEN] = grid.config.groupsCollapsedByDefault;
2404
+ var ptr = self.groupedData;
2405
+
2406
+ for (var y = 0; y < groups.length; y++) {
2407
+ var group = groups[y];
2408
+
2409
+ var col = filterCols(cols, group)[0];
2410
+
2411
+ var val = $utils.evalProperty(model, group);
2412
+ val = val ? val.toString() : 'null';
2413
+ if (!ptr[val]) {
2414
+ ptr[val] = {};
2415
+ }
2416
+ if (!ptr[NG_FIELD]) {
2417
+ ptr[NG_FIELD] = group;
2418
+ }
2419
+ if (!ptr[NG_DEPTH]) {
2420
+ ptr[NG_DEPTH] = y;
2421
+ }
2422
+ if (!ptr[NG_COLUMN]) {
2423
+ ptr[NG_COLUMN] = col;
2424
+ }
2425
+ ptr = ptr[val];
2426
+ }
2427
+ if (!ptr.values) {
2428
+ ptr.values = [];
2429
+ }
2430
+ ptr.values.push(rows[x]);
2431
+ }
2432
+
2433
+ //moved out of above loops due to if no data initially, but has initial grouping, columns won't be added
2434
+ if(cols.length > 0) {
2435
+ for (var z = 0; z < groups.length; z++) {
2436
+ if (!cols[z].isAggCol && z <= maxDepth) {
2437
+ cols.splice(0, 0, new ngColumn({
2438
+ colDef: {
2439
+ field: '',
2440
+ width: 25,
2441
+ sortable: false,
2442
+ resizable: false,
2443
+ headerCellTemplate: '<div class="ngAggHeader"></div>',
2444
+ pinned: grid.config.pinSelectionCheckbox
2445
+
2446
+ },
2447
+ enablePinning: grid.config.enablePinning,
2448
+ isAggCol: true,
2449
+ headerRowHeight: grid.config.headerRowHeight
2450
+
2451
+ }, $scope, grid, domUtilityService, $templateCache, $utils));
2452
+ }
2453
+ }
2454
+ }
2455
+
2456
+ grid.fixColumnIndexes();
2457
+ $scope.adjustScrollLeft(0);
2458
+ self.parsedData.length = 0;
2459
+ self.parseGroupData(self.groupedData);
2460
+ self.fixRowCache();
2461
+ };
2462
+
2463
+ if (grid.config.groups.length > 0 && grid.filteredRows.length > 0) {
2464
+ self.getGrouping(grid.config.groups);
2465
+ }
2466
+ };
2467
+ var ngSearchProvider = function ($scope, grid, $filter) {
2468
+ var self = this,
2469
+ searchConditions = [];
2470
+
2471
+ self.extFilter = grid.config.filterOptions.useExternalFilter;
2472
+ $scope.showFilter = grid.config.showFilter;
2473
+ $scope.filterText = '';
2474
+
2475
+ self.fieldMap = {};
2476
+
2477
+ var searchEntireRow = function(condition, item, fieldMap){
2478
+ var result;
2479
+ for (var prop in item) {
2480
+ if (item.hasOwnProperty(prop)) {
2481
+ var c = fieldMap[prop.toLowerCase()];
2482
+ if (!c) {
2483
+ continue;
2484
+ }
2485
+ var pVal = item[prop];
2486
+ if(typeof pVal === 'object'){
2487
+ return searchEntireRow(condition, pVal, c);
2488
+ } else {
2489
+ var f = null,
2490
+ s = null;
2491
+ if (c && c.cellFilter) {
2492
+ s = c.cellFilter.split(':');
2493
+ f = $filter(s[0]);
2494
+ }
2495
+ if (pVal !== null && pVal !== undefined) {
2496
+ if (typeof f === "function") {
2497
+ var filterRes = f(pVal, s[1]).toString();
2498
+ result = condition.regex.test(filterRes);
2499
+ } else {
2500
+ result = condition.regex.test(pVal.toString());
2501
+ }
2502
+ if (result) {
2503
+ return true;
2504
+ }
2505
+ }
2506
+ }
2507
+ }
2508
+ }
2509
+ return false;
2510
+ };
2511
+
2512
+ var searchColumn = function(condition, item){
2513
+ var result;
2514
+ var col = self.fieldMap[condition.columnDisplay];
2515
+ if (!col) {
2516
+ return false;
2517
+ }
2518
+ var sp = col.cellFilter.split(':');
2519
+ var filter = col.cellFilter ? $filter(sp[0]) : null;
2520
+ var value = item[condition.column] || item[col.field.split('.')[0]];
2521
+ if (value === null || value === undefined) {
2522
+ return false;
2523
+ }
2524
+ if (typeof filter === "function") {
2525
+ var filterResults = filter(typeof value === "object" ? evalObject(value, col.field) : value, sp[1]).toString();
2526
+ result = condition.regex.test(filterResults);
2527
+ }
2528
+ else {
2529
+ result = condition.regex.test(typeof value === "object" ? evalObject(value, col.field).toString() : value.toString());
2530
+ }
2531
+ if (result) {
2532
+ return true;
2533
+ }
2534
+ return false;
2535
+ };
2536
+
2537
+ var filterFunc = function(item) {
2538
+ for (var x = 0, len = searchConditions.length; x < len; x++) {
2539
+ var condition = searchConditions[x];
2540
+ var result;
2541
+ if (!condition.column) {
2542
+ result = searchEntireRow(condition, item, self.fieldMap);
2543
+ } else {
2544
+ result = searchColumn(condition, item);
2545
+ }
2546
+ if(!result) {
2547
+ return false;
2548
+ }
2549
+ }
2550
+ return true;
2551
+ };
2552
+
2553
+ self.evalFilter = function () {
2554
+ if (searchConditions.length === 0) {
2555
+ grid.filteredRows = grid.rowCache;
2556
+ } else {
2557
+ grid.filteredRows = grid.rowCache.filter(function(row) {
2558
+ return filterFunc(row.entity);
2559
+ });
2560
+ }
2561
+ for (var i = 0; i < grid.filteredRows.length; i++)
2562
+ {
2563
+ grid.filteredRows[i].rowIndex = i;
2564
+
2565
+ }
2566
+ grid.rowFactory.filteredRowsChanged();
2567
+ };
2568
+
2569
+ //Traversing through the object to find the value that we want. If fail, then return the original object.
2570
+ var evalObject = function (obj, columnName) {
2571
+ if (typeof obj !== "object" || typeof columnName !== "string") {
2572
+ return obj;
2573
+ }
2574
+ var args = columnName.split('.');
2575
+ var cObj = obj;
2576
+ if (args.length > 1) {
2577
+ for (var i = 1, len = args.length; i < len; i++) {
2578
+ cObj = cObj[args[i]];
2579
+ if (!cObj) {
2580
+ return obj;
2581
+ }
2582
+ }
2583
+ return cObj;
2584
+ }
2585
+ return obj;
2586
+ };
2587
+ var getRegExp = function (str, modifiers) {
2588
+ try {
2589
+ return new RegExp(str, modifiers);
2590
+ } catch (err) {
2591
+ //Escape all RegExp metacharacters.
2592
+ return new RegExp(str.replace(/(\^|\$|\(|\)|<|>|\[|\]|\{|\}|\\|\||\.|\*|\+|\?)/g, '\\$1'));
2593
+ }
2594
+ };
2595
+ var buildSearchConditions = function (a) {
2596
+ //reset.
2597
+ searchConditions = [];
2598
+ var qStr;
2599
+ if (!(qStr = $.trim(a))) {
2600
+ return;
2601
+ }
2602
+ var columnFilters = qStr.split(";");
2603
+ for (var i = 0; i < columnFilters.length; i++) {
2604
+ var args = columnFilters[i].split(':');
2605
+ if (args.length > 1) {
2606
+ var columnName = $.trim(args[0]);
2607
+ var columnValue = $.trim(args[1]);
2608
+ if (columnName && columnValue) {
2609
+ searchConditions.push({
2610
+ column: columnName,
2611
+ columnDisplay: columnName.replace(/\s+/g, '').toLowerCase(),
2612
+ regex: getRegExp(columnValue, 'i')
2613
+ });
2614
+ }
2615
+ } else {
2616
+ var val = $.trim(args[0]);
2617
+ if (val) {
2618
+ searchConditions.push({
2619
+ column: '',
2620
+ regex: getRegExp(val, 'i')
2621
+ });
2622
+ }
2623
+ }
2624
+ }
2625
+ };
2626
+
2627
+ if (!self.extFilter) {
2628
+ $scope.$watch('columns', function (cs) {
2629
+ for (var i = 0; i < cs.length; i++) {
2630
+ var col = cs[i];
2631
+ if (col.field) {
2632
+ if(col.field.match(/\./g)){
2633
+ var properties = col.field.split('.');
2634
+ var currentProperty = self.fieldMap;
2635
+ for(var j = 0; j < properties.length - 1; j++) {
2636
+ currentProperty[ properties[j] ] = currentProperty[ properties[j] ] || {};
2637
+ currentProperty = currentProperty[properties[j]];
2638
+ }
2639
+ currentProperty[ properties[properties.length - 1] ] = col;
2640
+ } else {
2641
+ self.fieldMap[col.field.toLowerCase()] = col;
2642
+ }
2643
+ }
2644
+ if (col.displayName) {
2645
+ self.fieldMap[col.displayName.toLowerCase().replace(/\s+/g, '')] = col;
2646
+ }
2647
+ }
2648
+ });
2649
+ }
2650
+
2651
+ $scope.$watch(
2652
+ function () {
2653
+ return grid.config.filterOptions.filterText;
2654
+ },
2655
+ function (a) {
2656
+ $scope.filterText = a;
2657
+ }
2658
+ );
2659
+
2660
+ $scope.$watch('filterText', function(a){
2661
+ if (!self.extFilter) {
2662
+ $scope.$emit('ngGridEventFilter', a);
2663
+ buildSearchConditions(a);
2664
+ self.evalFilter();
2665
+ }
2666
+ });
2667
+ };
2668
+ var ngSelectionProvider = function (grid, $scope, $parse) {
2669
+ var self = this;
2670
+ self.multi = grid.config.multiSelect;
2671
+ self.selectedItems = grid.config.selectedItems;
2672
+ self.selectedIndex = grid.config.selectedIndex;
2673
+ self.lastClickedRow = undefined;
2674
+ self.ignoreSelectedItemChanges = false; // flag to prevent circular event loops keeping single-select var in sync
2675
+ self.pKeyParser = $parse(grid.config.primaryKey);
2676
+
2677
+ // function to manage the selection action of a data item (entity)
2678
+ self.ChangeSelection = function (rowItem, evt) {
2679
+ // ctrl-click + shift-click multi-selections
2680
+ // up/down key navigation in multi-selections
2681
+ var charCode = evt.which || evt.keyCode;
2682
+ var isUpDownKeyPress = (charCode === 40 || charCode === 38);
2683
+
2684
+ if (evt && evt.shiftKey && !evt.keyCode && self.multi && grid.config.enableRowSelection) {
2685
+ if (self.lastClickedRow) {
2686
+ var rowsArr;
2687
+ if ($scope.configGroups.length > 0) {
2688
+ rowsArr = grid.rowFactory.parsedData.filter(function(row) {
2689
+ return !row.isAggRow;
2690
+ });
2691
+ }
2692
+ else {
2693
+ rowsArr = grid.filteredRows;
2694
+ }
2695
+
2696
+ var thisIndx = rowItem.rowIndex;
2697
+ var prevIndx = self.lastClickedRowIndex;
2698
+
2699
+ if (thisIndx === prevIndx) {
2700
+ return false;
2701
+ }
2702
+
2703
+ if (thisIndx < prevIndx) {
2704
+ thisIndx = thisIndx ^ prevIndx;
2705
+ prevIndx = thisIndx ^ prevIndx;
2706
+ thisIndx = thisIndx ^ prevIndx;
2707
+ thisIndx--;
2708
+ }
2709
+ else {
2710
+ prevIndx++;
2711
+ }
2712
+
2713
+ var rows = [];
2714
+ for (; prevIndx <= thisIndx; prevIndx++) {
2715
+ rows.push(rowsArr[prevIndx]);
2716
+ }
2717
+
2718
+ if (rows[rows.length - 1].beforeSelectionChange(rows, evt)) {
2719
+ for (var i = 0; i < rows.length; i++) {
2720
+ var ri = rows[i];
2721
+ var selectionState = ri.selected;
2722
+ ri.selected = !selectionState;
2723
+ if (ri.clone) {
2724
+ ri.clone.selected = ri.selected;
2725
+ }
2726
+ var index = self.selectedItems.indexOf(ri.entity);
2727
+ if (index === -1) {
2728
+ self.selectedItems.push(ri.entity);
2729
+ }
2730
+ else {
2731
+ self.selectedItems.splice(index, 1);
2732
+ }
2733
+ }
2734
+ rows[rows.length - 1].afterSelectionChange(rows, evt);
2735
+ }
2736
+ self.lastClickedRow = rowItem;
2737
+ self.lastClickedRowIndex = rowItem.rowIndex;
2738
+
2739
+ return true;
2740
+ }
2741
+ }
2742
+ else if (!self.multi) {
2743
+ if (self.lastClickedRow === rowItem) {
2744
+ self.setSelection(self.lastClickedRow, grid.config.keepLastSelected ? true : !rowItem.selected);
2745
+ } else {
2746
+ if (self.lastClickedRow) {
2747
+ self.setSelection(self.lastClickedRow, false);
2748
+ }
2749
+ self.setSelection(rowItem, !rowItem.selected);
2750
+ }
2751
+ }
2752
+ else if (!evt.keyCode || isUpDownKeyPress && !grid.config.selectWithCheckboxOnly) {
2753
+ self.setSelection(rowItem, !rowItem.selected);
2754
+ }
2755
+ self.lastClickedRow = rowItem;
2756
+ self.lastClickedRowIndex = rowItem.rowIndex;
2757
+ return true;
2758
+ };
2759
+
2760
+ self.getSelection = function (entity) {
2761
+ var isSelected = false;
2762
+ if (grid.config.primaryKey) {
2763
+ var val = self.pKeyParser(entity);
2764
+ angular.forEach(self.selectedItems, function (c) {
2765
+ if (val === self.pKeyParser(c)) {
2766
+ isSelected = true;
2767
+ }
2768
+ });
2769
+ }
2770
+ else {
2771
+ isSelected = self.selectedItems.indexOf(entity) !== -1;
2772
+ }
2773
+ return isSelected;
2774
+ };
2775
+
2776
+ // just call this func and hand it the rowItem you want to select (or de-select)
2777
+ self.setSelection = function (rowItem, isSelected) {
2778
+ if(grid.config.enableRowSelection){
2779
+ if (!isSelected) {
2780
+ var indx = self.selectedItems.indexOf(rowItem.entity);
2781
+ if (indx !== -1) {
2782
+ self.selectedItems.splice(indx, 1);
2783
+ }
2784
+ }
2785
+ else {
2786
+ if (self.selectedItems.indexOf(rowItem.entity) === -1) {
2787
+ if (!self.multi && self.selectedItems.length > 0) {
2788
+ self.toggleSelectAll(false, true);
2789
+ }
2790
+ self.selectedItems.push(rowItem.entity);
2791
+ }
2792
+ }
2793
+ rowItem.selected = isSelected;
2794
+ if (rowItem.orig) {
2795
+ rowItem.orig.selected = isSelected;
2796
+ }
2797
+ if (rowItem.clone) {
2798
+ rowItem.clone.selected = isSelected;
2799
+ }
2800
+ rowItem.afterSelectionChange(rowItem);
2801
+ }
2802
+ };
2803
+
2804
+ // @return - boolean indicating if all items are selected or not
2805
+ // @val - boolean indicating whether to select all/de-select all
2806
+ self.toggleSelectAll = function (checkAll, bypass, selectFiltered) {
2807
+ var rows = selectFiltered ? grid.filteredRows : grid.rowCache;
2808
+ if (bypass || grid.config.beforeSelectionChange(rows, checkAll)) {
2809
+ var selectedlength = self.selectedItems.length;
2810
+ if (selectedlength > 0) {
2811
+ self.selectedItems.length = 0;
2812
+ }
2813
+ for (var i = 0; i < rows.length; i++) {
2814
+ rows[i].selected = checkAll;
2815
+ if (rows[i].clone) {
2816
+ rows[i].clone.selected = checkAll;
2817
+ }
2818
+ if (checkAll) {
2819
+ self.selectedItems.push(rows[i].entity);
2820
+ }
2821
+ }
2822
+ if (!bypass) {
2823
+ grid.config.afterSelectionChange(rows, checkAll);
2824
+ }
2825
+ }
2826
+ };
2827
+ };
2828
+ var ngStyleProvider = function($scope, grid) {
2829
+ $scope.headerCellStyle = function(col) {
2830
+ return { "height": col.headerRowHeight + "px" };
2831
+ };
2832
+ $scope.rowStyle = function (row) {
2833
+ var ret = { "top": row.offsetTop + "px", "height": $scope.rowHeight + "px" };
2834
+ if (row.isAggRow) {
2835
+ ret.left = row.offsetLeft;
2836
+ }
2837
+ return ret;
2838
+ };
2839
+ $scope.canvasStyle = function() {
2840
+ return { "height": grid.maxCanvasHt + "px" };
2841
+ };
2842
+ $scope.headerScrollerStyle = function() {
2843
+ return { "height": grid.config.headerRowHeight + "px" };
2844
+ };
2845
+ $scope.topPanelStyle = function() {
2846
+ return { "width": grid.rootDim.outerWidth + "px", "height": $scope.topPanelHeight() + "px" };
2847
+ };
2848
+ $scope.headerStyle = function() {
2849
+ return { "width": grid.rootDim.outerWidth + "px", "height": grid.config.headerRowHeight + "px" };
2850
+ };
2851
+ $scope.groupPanelStyle = function () {
2852
+ return { "width": grid.rootDim.outerWidth + "px", "height": "32px" };
2853
+ };
2854
+ $scope.viewportStyle = function() {
2855
+ return { "width": grid.rootDim.outerWidth + "px", "height": $scope.viewportDimHeight() + "px" };
2856
+ };
2857
+ $scope.footerStyle = function() {
2858
+ return { "width": grid.rootDim.outerWidth + "px", "height": $scope.footerRowHeight + "px" };
2859
+ };
2860
+ };
2861
+ ngGridDirectives.directive('ngCellHasFocus', ['$domUtilityService',
2862
+ function (domUtilityService) {
2863
+ var focusOnInputElement = function($scope, elm) {
2864
+ $scope.isFocused = true;
2865
+ domUtilityService.digest($scope);
2866
+
2867
+ $scope.$broadcast('ngGridEventStartCellEdit');
2868
+
2869
+ $scope.$on('ngGridEventEndCellEdit', function() {
2870
+ $scope.isFocused = false;
2871
+ domUtilityService.digest($scope);
2872
+ });
2873
+ };
2874
+
2875
+ return function($scope, elm) {
2876
+ var isFocused = false;
2877
+ var isCellEditableOnMouseDown = false;
2878
+
2879
+ $scope.editCell = function() {
2880
+ if(!$scope.enableCellEditOnFocus) {
2881
+ setTimeout(function() {
2882
+ focusOnInputElement($scope,elm);
2883
+ }, 0);
2884
+ }
2885
+ };
2886
+ elm.bind('mousedown', function(evt) {
2887
+ if($scope.enableCellEditOnFocus) {
2888
+ isCellEditableOnMouseDown = true;
2889
+ } else {
2890
+ elm.focus();
2891
+ }
2892
+ return true;
2893
+ });
2894
+ elm.bind('click', function(evt) {
2895
+ if($scope.enableCellEditOnFocus) {
2896
+ evt.preventDefault();
2897
+ isCellEditableOnMouseDown = false;
2898
+ focusOnInputElement($scope,elm);
2899
+ }
2900
+ });
2901
+ elm.bind('focus', function(evt) {
2902
+ isFocused = true;
2903
+ if($scope.enableCellEditOnFocus && !isCellEditableOnMouseDown) {
2904
+ focusOnInputElement($scope,elm);
2905
+ }
2906
+ return true;
2907
+ });
2908
+ elm.bind('blur', function() {
2909
+ isFocused = false;
2910
+ return true;
2911
+ });
2912
+ elm.bind('keydown', function(evt) {
2913
+ if(!$scope.enableCellEditOnFocus) {
2914
+ if (isFocused && evt.keyCode !== 37 && evt.keyCode !== 38 && evt.keyCode !== 39 && evt.keyCode !== 40 && evt.keyCode !== 9 && !evt.shiftKey && evt.keyCode !== 13) {
2915
+ focusOnInputElement($scope,elm);
2916
+ }
2917
+ if (isFocused && evt.shiftKey && (evt.keyCode >= 65 && evt.keyCode <= 90)) {
2918
+ focusOnInputElement($scope, elm);
2919
+ }
2920
+ if (evt.keyCode === 27) {
2921
+ elm.focus();
2922
+ }
2923
+ }
2924
+ return true;
2925
+ });
2926
+ };
2927
+ }]);
2928
+ ngGridDirectives.directive('ngCellText',
2929
+ function () {
2930
+ return function(scope, elm) {
2931
+ elm.bind('mouseover', function(evt) {
2932
+ evt.preventDefault();
2933
+ elm.css({
2934
+ 'cursor': 'text'
2935
+ });
2936
+ });
2937
+ elm.bind('mouseleave', function(evt) {
2938
+ evt.preventDefault();
2939
+ elm.css({
2940
+ 'cursor': 'default'
2941
+ });
2942
+ });
2943
+ };
2944
+ });
2945
+ ngGridDirectives.directive('ngCell', ['$compile', '$domUtilityService', function ($compile, domUtilityService) {
2946
+ var ngCell = {
2947
+ scope: false,
2948
+ compile: function() {
2949
+ return {
2950
+ pre: function($scope, iElement) {
2951
+ var html;
2952
+ var cellTemplate = $scope.col.cellTemplate.replace(COL_FIELD, 'row.entity.' + $scope.col.field);
2953
+
2954
+ if ($scope.col.enableCellEdit) {
2955
+ html = $scope.col.cellEditTemplate;
2956
+ html = html.replace(DISPLAY_CELL_TEMPLATE, cellTemplate);
2957
+ html = html.replace(EDITABLE_CELL_TEMPLATE, $scope.col.editableCellTemplate.replace(COL_FIELD, 'row.entity.' + $scope.col.field));
2958
+ } else {
2959
+ html = cellTemplate;
2960
+ }
2961
+
2962
+ var cellElement = $compile(html)($scope);
2963
+
2964
+ if ($scope.enableCellSelection && cellElement[0].className.indexOf('ngSelectionCell') === -1) {
2965
+ cellElement[0].setAttribute('tabindex', 0);
2966
+ cellElement.addClass('ngCellElement');
2967
+ }
2968
+
2969
+ iElement.append(cellElement);
2970
+ },
2971
+ post: function($scope, iElement) {
2972
+ if ($scope.enableCellSelection) {
2973
+ $scope.domAccessProvider.selectionHandlers($scope, iElement);
2974
+ }
2975
+
2976
+ $scope.$on('ngGridEventDigestCell', function() {
2977
+ domUtilityService.digest($scope);
2978
+ });
2979
+ }
2980
+ };
2981
+ }
2982
+ };
2983
+
2984
+ return ngCell;
2985
+ }]);
2986
+ /*
2987
+ * Defines the ui-if tag. This removes/adds an element from the dom depending on a condition
2988
+ * Originally created by @tigbro, for the @jquery-mobile-angular-pack-adapter
2989
+ * https://github.com/tigbro/jquery-mobile-angular-pack-adapter
2990
+ */
2991
+ ngGridDirectives.directive('ngEditCellIf', [function () {
2992
+ return {
2993
+ transclude: 'element',
2994
+ priority: 1000,
2995
+ terminal: true,
2996
+ restrict: 'A',
2997
+ compile: function (e, a, transclude) {
2998
+ return function (scope, element, attr) {
2999
+
3000
+ var childElement;
3001
+ var childScope;
3002
+
3003
+ scope.$watch(attr['ngEditCellIf'], function (newValue) {
3004
+ if (childElement) {
3005
+ childElement.remove();
3006
+ childElement = undefined;
3007
+ }
3008
+ if (childScope) {
3009
+ childScope.$destroy();
3010
+ childScope = undefined;
3011
+ }
3012
+
3013
+ if (newValue) {
3014
+ childScope = scope.$new();
3015
+ transclude(childScope, function (clone) {
3016
+ childElement = clone;
3017
+ element.after(clone);
3018
+ });
3019
+ }
3020
+ });
3021
+ };
3022
+ }
3023
+ };
3024
+ }]);
3025
+ ngGridDirectives.directive('ngGridFooter', ['$compile', '$templateCache', function ($compile, $templateCache) {
3026
+ var ngGridFooter = {
3027
+ scope: false,
3028
+ compile: function () {
3029
+ return {
3030
+ pre: function ($scope, iElement) {
3031
+ if (iElement.children().length === 0) {
3032
+ iElement.append($compile($templateCache.get($scope.gridId + 'footerTemplate.html'))($scope));
3033
+ }
3034
+ }
3035
+ };
3036
+ }
3037
+ };
3038
+ return ngGridFooter;
3039
+ }]);
3040
+ ngGridDirectives.directive('ngGridMenu', ['$compile', '$templateCache', function ($compile, $templateCache) {
3041
+ var ngGridMenu = {
3042
+ scope: false,
3043
+ compile: function () {
3044
+ return {
3045
+ pre: function ($scope, iElement) {
3046
+ if (iElement.children().length === 0) {
3047
+ iElement.append($compile($templateCache.get($scope.gridId + 'menuTemplate.html'))($scope));
3048
+ }
3049
+ }
3050
+ };
3051
+ }
3052
+ };
3053
+ return ngGridMenu;
3054
+ }]);
3055
+ ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '$sortService', '$domUtilityService', '$utilityService', '$timeout', '$parse', '$http', '$q', function ($compile, $filter, $templateCache, sortService, domUtilityService, $utils, $timeout, $parse, $http, $q) {
3056
+ var ngGridDirective = {
3057
+ scope: true,
3058
+ compile: function() {
3059
+ return {
3060
+ pre: function($scope, iElement, iAttrs) {
3061
+ var $element = $(iElement);
3062
+ var options = $scope.$eval(iAttrs.ngGrid);
3063
+ options.gridDim = new ngDimension({ outerHeight: $($element).height(), outerWidth: $($element).width() });
3064
+
3065
+ var grid = new ngGrid($scope, options, sortService, domUtilityService, $filter, $templateCache, $utils, $timeout, $parse, $http, $q);
3066
+ return grid.init().then(function() {
3067
+ // if columndefs are a string of a property ont he scope watch for changes and rebuild columns.
3068
+ if (typeof options.columnDefs === "string") {
3069
+ $scope.$parent.$watch(options.columnDefs, function (a) {
3070
+ if (!a) {
3071
+ grid.refreshDomSizes();
3072
+ grid.buildColumns();
3073
+ return;
3074
+ }
3075
+ // we have to set this to false in case we want to autogenerate columns with no initial data.
3076
+ grid.lateBoundColumns = false;
3077
+ $scope.columns = [];
3078
+ grid.config.columnDefs = a;
3079
+ grid.buildColumns();
3080
+ grid.eventProvider.assignEvents();
3081
+ domUtilityService.RebuildGrid($scope, grid);
3082
+ }, true);
3083
+ }
3084
+ else {
3085
+ grid.buildColumns();
3086
+ }
3087
+
3088
+ // Watch totalServerItems if it's a string
3089
+ if (typeof options.totalServerItems === "string") {
3090
+ $scope.$parent.$watch(options.totalServerItems, function (newTotal, oldTotal) {
3091
+ // If the newTotal is not defined (like during init, set the value to 0)
3092
+ if (!angular.isDefined(newTotal)) {
3093
+ $scope.totalServerItems = 0;
3094
+ }
3095
+ // Otherwise set the value to the new total
3096
+ else {
3097
+ $scope.totalServerItems = newTotal;
3098
+ }
3099
+ });
3100
+ }
3101
+ // If it's NOT a string, then just set totalServerItems to 0 since they should only be setting this if using a string
3102
+ else {
3103
+ $scope.totalServerItems = 0;
3104
+ }
3105
+
3106
+ // if it is a string we can watch for data changes. otherwise you won't be able to update the grid data
3107
+ if (typeof options.data === "string") {
3108
+ var dataWatcher = function (a) {
3109
+ // make a temporary copy of the data
3110
+ grid.data = $.extend([], a);
3111
+ grid.rowFactory.fixRowCache();
3112
+ angular.forEach(grid.data, function (item, j) {
3113
+ var indx = grid.rowMap[j] || j;
3114
+ if (grid.rowCache[indx]) {
3115
+ grid.rowCache[indx].ensureEntity(item);
3116
+ }
3117
+ grid.rowMap[indx] = j;
3118
+ });
3119
+ grid.searchProvider.evalFilter();
3120
+ grid.configureColumnWidths();
3121
+ grid.refreshDomSizes();
3122
+ if (grid.config.sortInfo.fields.length > 0) {
3123
+ grid.sortColumnsInit();
3124
+ $scope.$emit('ngGridEventSorted', grid.config.sortInfo);
3125
+ }
3126
+ $scope.$emit("ngGridEventData", grid.gridId);
3127
+ };
3128
+ $scope.$parent.$watch(options.data, dataWatcher);
3129
+ $scope.$parent.$watch(options.data + '.length', function() {
3130
+ dataWatcher($scope.$eval(options.data));
3131
+ });
3132
+ }
3133
+
3134
+ grid.footerController = new ngFooter($scope, grid);
3135
+ //set the right styling on the container
3136
+ iElement.addClass("ngGrid").addClass(grid.gridId.toString());
3137
+ if (!options.enableHighlighting) {
3138
+ iElement.addClass("unselectable");
3139
+ }
3140
+ if (options.jqueryUITheme) {
3141
+ iElement.addClass('ui-widget');
3142
+ }
3143
+ iElement.append($compile($templateCache.get('gridTemplate.html'))($scope)); // make sure that if any of these change, we re-fire the calc logic
3144
+ //walk the element's graph and the correct properties on the grid
3145
+ domUtilityService.AssignGridContainers($scope, iElement, grid);
3146
+ //now use the manager to assign the event handlers
3147
+ grid.eventProvider = new ngEventProvider(grid, $scope, domUtilityService, $timeout);
3148
+
3149
+ // method for user to select a specific row programatically
3150
+ options.selectRow = function (rowIndex, state) {
3151
+ if (grid.rowCache[rowIndex]) {
3152
+ if (grid.rowCache[rowIndex].clone) {
3153
+ grid.rowCache[rowIndex].clone.setSelection(state ? true : false);
3154
+ }
3155
+ grid.rowCache[rowIndex].setSelection(state ? true : false);
3156
+ }
3157
+ };
3158
+ // method for user to select the row by data item programatically
3159
+ options.selectItem = function (itemIndex, state) {
3160
+ options.selectRow(grid.rowMap[itemIndex], state);
3161
+ };
3162
+ // method for user to set the select all state.
3163
+ options.selectAll = function (state) {
3164
+ $scope.toggleSelectAll(state);
3165
+ };
3166
+ // method for user to set the select all state on visible items.
3167
+ options.selectVisible = function (state) {
3168
+ $scope.toggleSelectAll(state, true);
3169
+ };
3170
+ // method for user to set the groups programatically
3171
+ options.groupBy = function (field) {
3172
+ if (field) {
3173
+ $scope.groupBy($scope.columns.filter(function(c) {
3174
+ return c.field === field;
3175
+ })[0]);
3176
+ } else {
3177
+ var arr = $.extend(true, [], $scope.configGroups);
3178
+ angular.forEach(arr, $scope.groupBy);
3179
+ }
3180
+ };
3181
+ // method for user to set the sort field programatically
3182
+ options.sortBy = function (field) {
3183
+ var col = $scope.columns.filter(function (c) {
3184
+ return c.field === field;
3185
+ })[0];
3186
+ if (col) {
3187
+ col.sort();
3188
+ }
3189
+ };
3190
+ // the grid Id, entity, scope for convenience
3191
+ options.gridId = grid.gridId;
3192
+ options.ngGrid = grid;
3193
+ options.$gridScope = $scope;
3194
+ options.$gridServices = { SortService: sortService, DomUtilityService: domUtilityService, UtilityService: $utils };
3195
+ $scope.$on('ngGridEventDigestGrid', function(){
3196
+ domUtilityService.digest($scope.$parent);
3197
+ });
3198
+
3199
+ $scope.$on('ngGridEventDigestGridParent', function(){
3200
+ domUtilityService.digest($scope.$parent);
3201
+ });
3202
+ // set up the columns
3203
+ $scope.$evalAsync(function() {
3204
+ $scope.adjustScrollLeft(0);
3205
+ });
3206
+ //initialize plugins.
3207
+ angular.forEach(options.plugins, function (p) {
3208
+ if (typeof p === "function") {
3209
+ p = new p(); //If p is a function, then we assume it is a class.
3210
+ }
3211
+ p.init($scope.$new(), grid, options.$gridServices);
3212
+ options.plugins[$utils.getInstanceType(p)] = p;
3213
+ });
3214
+ //send initi finalize notification.
3215
+ if (typeof options.init === "function") {
3216
+ options.init(grid, $scope);
3217
+ }
3218
+ return null;
3219
+ });
3220
+ }
3221
+ };
3222
+ }
3223
+ };
3224
+ return ngGridDirective;
3225
+ }]);
3226
+
3227
+ ngGridDirectives.directive('ngHeaderCell', ['$compile', function($compile) {
3228
+ var ngHeaderCell = {
3229
+ scope: false,
3230
+ compile: function() {
3231
+ return {
3232
+ pre: function($scope, iElement) {
3233
+ iElement.append($compile($scope.col.headerCellTemplate)($scope));
3234
+ }
3235
+ };
3236
+ }
3237
+ };
3238
+ return ngHeaderCell;
3239
+ }]);
3240
+ ngGridDirectives.directive('ngInput', [function() {
3241
+ return {
3242
+ require: 'ngModel',
3243
+ link: function (scope, elm, attrs, ngModel) {
3244
+ // Store the initial cell value so we can reset to it if need be
3245
+ var oldCellValue;
3246
+ var dereg = scope.$watch('ngModel', function() {
3247
+ oldCellValue = ngModel.$modelValue;
3248
+ dereg(); // only run this watch once, we don't want to overwrite our stored value when the input changes
3249
+ });
3250
+
3251
+ elm.bind('keydown', function(evt) {
3252
+ switch (evt.keyCode) {
3253
+ case 37: // Left arrow
3254
+ case 38: // Up arrow
3255
+ case 39: // Right arrow
3256
+ case 40: // Down arrow
3257
+ evt.stopPropagation();
3258
+ break;
3259
+ case 27: // Esc (reset to old value)
3260
+ if (!scope.$$phase) {
3261
+ scope.$apply(function() {
3262
+ ngModel.$setViewValue(oldCellValue);
3263
+ elm.blur();
3264
+ });
3265
+ }
3266
+ break;
3267
+ case 13: // Enter (Leave Field)
3268
+ if(scope.enableCellEditOnFocus && scope.totalFilteredItemsLength() - 1 > scope.row.rowIndex && scope.row.rowIndex > 0 || scope.enableCellEdit) {
3269
+ elm.blur();
3270
+ }
3271
+ break;
3272
+ }
3273
+
3274
+ return true;
3275
+ });
3276
+
3277
+ elm.bind('click', function(evt) {
3278
+ evt.stopPropagation();
3279
+ });
3280
+
3281
+ elm.bind('mousedown', function(evt) {
3282
+ evt.stopPropagation();
3283
+ });
3284
+
3285
+ scope.$on('ngGridEventStartCellEdit', function () {
3286
+ elm.focus();
3287
+ elm.select();
3288
+ });
3289
+
3290
+ angular.element(elm).bind('blur', function () {
3291
+ scope.$emit('ngGridEventEndCellEdit');
3292
+ });
3293
+ }
3294
+ };
3295
+ }]);
3296
+ ngGridDirectives.directive('ngRow', ['$compile', '$domUtilityService', '$templateCache', function ($compile, domUtilityService, $templateCache) {
3297
+ var ngRow = {
3298
+ scope: false,
3299
+ compile: function() {
3300
+ return {
3301
+ pre: function($scope, iElement) {
3302
+ $scope.row.elm = iElement;
3303
+ if ($scope.row.clone) {
3304
+ $scope.row.clone.elm = iElement;
3305
+ }
3306
+ if ($scope.row.isAggRow) {
3307
+ var html = $templateCache.get($scope.gridId + 'aggregateTemplate.html');
3308
+ if ($scope.row.aggLabelFilter) {
3309
+ html = html.replace(CUSTOM_FILTERS, '| ' + $scope.row.aggLabelFilter);
3310
+ } else {
3311
+ html = html.replace(CUSTOM_FILTERS, "");
3312
+ }
3313
+ iElement.append($compile(html)($scope));
3314
+ } else {
3315
+ iElement.append($compile($templateCache.get($scope.gridId + 'rowTemplate.html'))($scope));
3316
+ }
3317
+ $scope.$on('ngGridEventDigestRow', function(){
3318
+ domUtilityService.digest($scope);
3319
+ });
3320
+ }
3321
+ };
3322
+ }
3323
+ };
3324
+ return ngRow;
3325
+ }]);
3326
+ ngGridDirectives.directive('ngViewport', [function() {
3327
+ return function($scope, elm) {
3328
+ var isMouseWheelActive;
3329
+ var prevScollLeft;
3330
+ var prevScollTop = 0;
3331
+ elm.bind('scroll', function(evt) {
3332
+ var scrollLeft = evt.target.scrollLeft,
3333
+ scrollTop = evt.target.scrollTop;
3334
+ if ($scope.$headerContainer) {
3335
+ $scope.$headerContainer.scrollLeft(scrollLeft);
3336
+ }
3337
+ $scope.adjustScrollLeft(scrollLeft);
3338
+ $scope.adjustScrollTop(scrollTop);
3339
+ if (!$scope.$root.$$phase) {
3340
+ $scope.$digest();
3341
+ }
3342
+ prevScollLeft = scrollLeft;
3343
+ prevScollTop = scrollTop;
3344
+ isMouseWheelActive = false;
3345
+ return true;
3346
+ });
3347
+ elm.bind("mousewheel DOMMouseScroll", function() {
3348
+ isMouseWheelActive = true;
3349
+ if (elm.focus) { elm.focus(); }
3350
+ return true;
3351
+ });
3352
+ if (!$scope.enableCellSelection) {
3353
+ $scope.domAccessProvider.selectionHandlers($scope, elm);
3354
+ }
3355
+ };
3356
+ }]);
3357
+ window.ngGrid.i18n['da'] = {
3358
+ ngAggregateLabel: 'artikler',
3359
+ ngGroupPanelDescription: 'Grupér rækker udfra en kolonne ved at trække dens overskift hertil.',
3360
+ ngSearchPlaceHolder: 'Søg...',
3361
+ ngMenuText: 'Vælg kolonner:',
3362
+ ngShowingItemsLabel: 'Viste rækker:',
3363
+ ngTotalItemsLabel: 'Rækker totalt:',
3364
+ ngSelectedItemsLabel: 'Valgte rækker:',
3365
+ ngPageSizeLabel: 'Side størrelse:',
3366
+ ngPagerFirstTitle: 'Første side',
3367
+ ngPagerNextTitle: 'Næste side',
3368
+ ngPagerPrevTitle: 'Forrige side',
3369
+ ngPagerLastTitle: 'Sidste side'
3370
+ };
3371
+ window.ngGrid.i18n['de'] = {
3372
+ ngAggregateLabel: 'artikel',
3373
+ ngGroupPanelDescription: 'Ziehen Sie eine Spaltenüberschrift hier und legen Sie es der Gruppe nach dieser Spalte.',
3374
+ ngSearchPlaceHolder: 'Suche...',
3375
+ ngMenuText: 'Spalten auswählen:',
3376
+ ngShowingItemsLabel: 'Zeige Artikel:',
3377
+ ngTotalItemsLabel: 'Meiste Artikel:',
3378
+ ngSelectedItemsLabel: 'Ausgewählte Artikel:',
3379
+ ngPageSizeLabel: 'Größe Seite:',
3380
+ ngPagerFirstTitle: 'Erste Page',
3381
+ ngPagerNextTitle: 'Nächste Page',
3382
+ ngPagerPrevTitle: 'Vorherige Page',
3383
+ ngPagerLastTitle: 'Letzte Page'
3384
+ };
3385
+ window.ngGrid.i18n['en'] = {
3386
+ ngAggregateLabel: 'items',
3387
+ ngGroupPanelDescription: 'Drag a column header here and drop it to group by that column.',
3388
+ ngSearchPlaceHolder: 'Search...',
3389
+ ngMenuText: 'Choose Columns:',
3390
+ ngShowingItemsLabel: 'Showing Items:',
3391
+ ngTotalItemsLabel: 'Total Items:',
3392
+ ngSelectedItemsLabel: 'Selected Items:',
3393
+ ngPageSizeLabel: 'Page Size:',
3394
+ ngPagerFirstTitle: 'First Page',
3395
+ ngPagerNextTitle: 'Next Page',
3396
+ ngPagerPrevTitle: 'Previous Page',
3397
+ ngPagerLastTitle: 'Last Page'
3398
+ };
3399
+ window.ngGrid.i18n['es'] = {
3400
+ ngAggregateLabel: 'Artículos',
3401
+ ngGroupPanelDescription: 'Arrastre un encabezado de columna aquí y soltarlo para agrupar por esa columna.',
3402
+ ngSearchPlaceHolder: 'Buscar...',
3403
+ ngMenuText: 'Elegir columnas:',
3404
+ ngShowingItemsLabel: 'Artículos Mostrando:',
3405
+ ngTotalItemsLabel: 'Artículos Totales:',
3406
+ ngSelectedItemsLabel: 'Artículos Seleccionados:',
3407
+ ngPageSizeLabel: 'Tamaño de Página:',
3408
+ ngPagerFirstTitle: 'Primera Página',
3409
+ ngPagerNextTitle: 'Página Siguiente',
3410
+ ngPagerPrevTitle: 'Página Anterior',
3411
+ ngPagerLastTitle: 'Última Página'
3412
+ };
3413
+ window.ngGrid.i18n['fr'] = {
3414
+ ngAggregateLabel: 'articles',
3415
+ ngGroupPanelDescription: 'Faites glisser un en-tête de colonne ici et déposez-le vers un groupe par cette colonne.',
3416
+ ngSearchPlaceHolder: 'Recherche...',
3417
+ ngMenuText: 'Choisir des colonnes:',
3418
+ ngShowingItemsLabel: 'Articles Affichage des:',
3419
+ ngTotalItemsLabel: 'Nombre total d\'articles:',
3420
+ ngSelectedItemsLabel: 'Éléments Articles:',
3421
+ ngPageSizeLabel: 'Taille de page:',
3422
+ ngPagerFirstTitle: 'Première page',
3423
+ ngPagerNextTitle: 'Page Suivante',
3424
+ ngPagerPrevTitle: 'Page précédente',
3425
+ ngPagerLastTitle: 'Dernière page'
3426
+ };
3427
+ window.ngGrid.i18n['pt-br'] = {
3428
+ ngAggregateLabel: 'items',
3429
+ ngGroupPanelDescription: 'Arraste e solte uma coluna aqui para agrupar por essa coluna',
3430
+ ngSearchPlaceHolder: 'Procurar...',
3431
+ ngMenuText: 'Selecione as colunas:',
3432
+ ngShowingItemsLabel: 'Mostrando os Items:',
3433
+ ngTotalItemsLabel: 'Total de Items:',
3434
+ ngSelectedItemsLabel: 'Items Selecionados:',
3435
+ ngPageSizeLabel: 'Tamanho da Página:',
3436
+ ngPagerFirstTitle: 'Primeira Página',
3437
+ ngPagerNextTitle: 'Próxima Página',
3438
+ ngPagerPrevTitle: 'Página Anterior',
3439
+ ngPagerLastTitle: 'Última Página'
3440
+ };
3441
+ window.ngGrid.i18n['zh-cn'] = {
3442
+ ngAggregateLabel: '条目',
3443
+ ngGroupPanelDescription: '拖曳表头到此处以进行分组',
3444
+ ngSearchPlaceHolder: '搜索...',
3445
+ ngMenuText: '数据分组与选择列:',
3446
+ ngShowingItemsLabel: '当前显示条目:',
3447
+ ngTotalItemsLabel: '条目总数:',
3448
+ ngSelectedItemsLabel: '选中条目:',
3449
+ ngPageSizeLabel: '每页显示数:',
3450
+ ngPagerFirstTitle: '回到首页',
3451
+ ngPagerNextTitle: '下一页',
3452
+ ngPagerPrevTitle: '上一页',
3453
+ ngPagerLastTitle: '前往尾页'
3454
+ };
3455
+
3456
+ window.ngGrid.i18n['zh-tw'] = {
3457
+ ngAggregateLabel: '筆',
3458
+ ngGroupPanelDescription: '拖拉表頭到此處以進行分組',
3459
+ ngSearchPlaceHolder: '搜尋...',
3460
+ ngMenuText: '選擇欄位:',
3461
+ ngShowingItemsLabel: '目前顯示筆數:',
3462
+ ngTotalItemsLabel: '總筆數:',
3463
+ ngSelectedItemsLabel: '選取筆數:',
3464
+ ngPageSizeLabel: '每頁顯示:',
3465
+ ngPagerFirstTitle: '第一頁',
3466
+ ngPagerNextTitle: '下一頁',
3467
+ ngPagerPrevTitle: '上一頁',
3468
+ ngPagerLastTitle: '最後頁'
3469
+ };
3470
+
3471
+ angular.module("ngGrid").run(["$templateCache", function($templateCache) {
3472
+
3473
+ $templateCache.put("aggregateTemplate.html",
3474
+ "<div ng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">" +
3475
+ " <span class=\"ngAggregateText\">{{row.label CUSTOM_FILTERS}} ({{row.totalChildren()}} {{AggItemsLabel}})</span>" +
3476
+ " <div class=\"{{row.aggClass()}}\"></div>" +
3477
+ "</div>" +
3478
+ ""
3479
+ );
3480
+
3481
+ $templateCache.put("cellEditTemplate.html",
3482
+ "<div ng-cell-has-focus ng-dblclick=\"editCell()\">" +
3483
+ " <div ng-edit-cell-if=\"!isFocused\"> " +
3484
+ " DISPLAY_CELL_TEMPLATE" +
3485
+ " </div>" +
3486
+ " <div ng-edit-cell-if=\"isFocused\">" +
3487
+ " EDITABLE_CELL_TEMPLATE" +
3488
+ " </div>" +
3489
+ "</div>"
3490
+ );
3491
+
3492
+ $templateCache.put("cellTemplate.html",
3493
+ "<div class=\"ngCellText\" ng-class=\"col.colIndex()\"><span ng-cell-text>{{COL_FIELD CUSTOM_FILTERS}}</span></div>"
3494
+ );
3495
+
3496
+ $templateCache.put("checkboxCellTemplate.html",
3497
+ "<div class=\"ngSelectionCell\"><input tabindex=\"-1\" class=\"ngSelectionCheckbox\" type=\"checkbox\" ng-checked=\"row.selected\" /></div>"
3498
+ );
3499
+
3500
+ $templateCache.put("checkboxHeaderTemplate.html",
3501
+ "<input class=\"ngSelectionHeader\" type=\"checkbox\" ng-show=\"multiSelect\" ng-model=\"allSelected\" ng-change=\"toggleSelectAll(allSelected, true)\"/>"
3502
+ );
3503
+
3504
+ $templateCache.put("editableCellTemplate.html",
3505
+ "<input ng-class=\"'colt' + col.index\" ng-input=\"COL_FIELD\" ng-model=\"COL_FIELD\" />"
3506
+ );
3507
+
3508
+ $templateCache.put("footerTemplate.html",
3509
+ "<div ng-show=\"showFooter\" class=\"ngFooterPanel\" ng-class=\"{'ui-widget-content': jqueryUITheme, 'ui-corner-bottom': jqueryUITheme}\" ng-style=\"footerStyle()\">" +
3510
+ " <div class=\"ngTotalSelectContainer\" >" +
3511
+ " <div class=\"ngFooterTotalItems\" ng-class=\"{'ngNoMultiSelect': !multiSelect}\" >" +
3512
+ " <span class=\"ngLabel\">{{i18n.ngTotalItemsLabel}} {{maxRows()}}</span><span ng-show=\"filterText.length > 0\" class=\"ngLabel\">({{i18n.ngShowingItemsLabel}} {{totalFilteredItemsLength()}})</span>" +
3513
+ " </div>" +
3514
+ " <div class=\"ngFooterSelectedItems\" ng-show=\"multiSelect\">" +
3515
+ " <span class=\"ngLabel\">{{i18n.ngSelectedItemsLabel}} {{selectedItems.length}}</span>" +
3516
+ " </div>" +
3517
+ " </div>" +
3518
+ " <div class=\"ngPagerContainer\" style=\"float: right; margin-top: 10px;\" ng-show=\"enablePaging\" ng-class=\"{'ngNoMultiSelect': !multiSelect}\">" +
3519
+ " <div style=\"float:left; margin-right: 10px;\" class=\"ngRowCountPicker\">" +
3520
+ " <span style=\"float: left; margin-top: 3px;\" class=\"ngLabel\">{{i18n.ngPageSizeLabel}}</span>" +
3521
+ " <select style=\"float: left;height: 27px; width: 100px\" ng-model=\"pagingOptions.pageSize\" >" +
3522
+ " <option ng-repeat=\"size in pagingOptions.pageSizes\">{{size}}</option>" +
3523
+ " </select>" +
3524
+ " </div>" +
3525
+ " <div style=\"float:left; margin-right: 10px; line-height:25px;\" class=\"ngPagerControl\" style=\"float: left; min-width: 135px;\">" +
3526
+ " <button class=\"ngPagerButton\" ng-click=\"pageToFirst()\" ng-disabled=\"cantPageBackward()\" title=\"{{i18n.ngPagerFirstTitle}}\"><div class=\"ngPagerFirstTriangle\"><div class=\"ngPagerFirstBar\"></div></div></button>" +
3527
+ " <button class=\"ngPagerButton\" ng-click=\"pageBackward()\" ng-disabled=\"cantPageBackward()\" title=\"{{i18n.ngPagerPrevTitle}}\"><div class=\"ngPagerFirstTriangle ngPagerPrevTriangle\"></div></button>" +
3528
+ " <input class=\"ngPagerCurrent\" min=\"1\" max=\"{{maxPages()}}\" type=\"number\" style=\"width:50px; height: 24px; margin-top: 1px; padding: 0 4px;\" ng-model=\"pagingOptions.currentPage\"/>" +
3529
+ " <button class=\"ngPagerButton\" ng-click=\"pageForward()\" ng-disabled=\"cantPageForward()\" title=\"{{i18n.ngPagerNextTitle}}\"><div class=\"ngPagerLastTriangle ngPagerNextTriangle\"></div></button>" +
3530
+ " <button class=\"ngPagerButton\" ng-click=\"pageToLast()\" ng-disabled=\"cantPageToLast()\" title=\"{{i18n.ngPagerLastTitle}}\"><div class=\"ngPagerLastTriangle\"><div class=\"ngPagerLastBar\"></div></div></button>" +
3531
+ " </div>" +
3532
+ " </div>" +
3533
+ "</div>"
3534
+ );
3535
+
3536
+ $templateCache.put("gridTemplate.html",
3537
+ "<div class=\"ngTopPanel\" ng-class=\"{'ui-widget-header':jqueryUITheme, 'ui-corner-top': jqueryUITheme}\" ng-style=\"topPanelStyle()\">" +
3538
+ " <div class=\"ngGroupPanel\" ng-show=\"showGroupPanel()\" ng-style=\"groupPanelStyle()\">" +
3539
+ " <div class=\"ngGroupPanelDescription\" ng-show=\"configGroups.length == 0\">{{i18n.ngGroupPanelDescription}}</div>" +
3540
+ " <ul ng-show=\"configGroups.length > 0\" class=\"ngGroupList\">" +
3541
+ " <li class=\"ngGroupItem\" ng-repeat=\"group in configGroups\">" +
3542
+ " <span class=\"ngGroupElement\">" +
3543
+ " <span class=\"ngGroupName\">{{group.displayName}}" +
3544
+ " <span ng-click=\"removeGroup($index)\" class=\"ngRemoveGroup\">x</span>" +
3545
+ " </span>" +
3546
+ " <span ng-hide=\"$last\" class=\"ngGroupArrow\"></span>" +
3547
+ " </span>" +
3548
+ " </li>" +
3549
+ " </ul>" +
3550
+ " </div>" +
3551
+ " <div class=\"ngHeaderContainer\" ng-style=\"headerStyle()\">" +
3552
+ " <div class=\"ngHeaderScroller\" ng-style=\"headerScrollerStyle()\" ng-include=\"gridId + 'headerRowTemplate.html'\"></div>" +
3553
+ " </div>" +
3554
+ " <div ng-grid-menu></div>" +
3555
+ "</div>" +
3556
+ "<div class=\"ngViewport\" unselectable=\"on\" ng-viewport ng-class=\"{'ui-widget-content': jqueryUITheme}\" ng-style=\"viewportStyle()\">" +
3557
+ " <div class=\"ngCanvas\" ng-style=\"canvasStyle()\">" +
3558
+ " <div ng-style=\"rowStyle(row)\" ng-repeat=\"row in renderedRows\" ng-click=\"row.toggleSelected($event)\" ng-class=\"row.alternatingRowClass()\" ng-row></div>" +
3559
+ " </div>" +
3560
+ "</div>" +
3561
+ "<div ng-grid-footer></div>" +
3562
+ ""
3563
+ );
3564
+
3565
+ $templateCache.put("headerCellTemplate.html",
3566
+ "<div class=\"ngHeaderSortColumn {{col.headerClass}}\" ng-style=\"{'cursor': col.cursor}\" ng-class=\"{ 'ngSorted': !noSortVisible }\">" +
3567
+ " <div ng-click=\"col.sort($event)\" ng-class=\"'colt' + col.index\" class=\"ngHeaderText\">{{col.displayName}}</div>" +
3568
+ " <div class=\"ngSortButtonDown\" ng-show=\"col.showSortButtonDown()\"></div>" +
3569
+ " <div class=\"ngSortButtonUp\" ng-show=\"col.showSortButtonUp()\"></div>" +
3570
+ " <div class=\"ngSortPriority\">{{col.sortPriority}}</div>" +
3571
+ " <div ng-class=\"{ ngPinnedIcon: col.pinned, ngUnPinnedIcon: !col.pinned }\" ng-click=\"togglePin(col)\" ng-show=\"col.pinnable\"></div>" +
3572
+ "</div>" +
3573
+ "<div ng-show=\"col.resizable\" class=\"ngHeaderGrip\" ng-click=\"col.gripClick($event)\" ng-mousedown=\"col.gripOnMouseDown($event)\"></div>"
3574
+ );
3575
+
3576
+ $templateCache.put("headerRowTemplate.html",
3577
+ "<div ng-style=\"{ height: col.headerRowHeight }\" ng-repeat=\"col in renderedColumns\" ng-class=\"col.colIndex()\" class=\"ngHeaderCell\">" +
3578
+ " <div class=\"ngVerticalBar\" ng-style=\"{height: col.headerRowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\">&nbsp;</div>" +
3579
+ " <div ng-header-cell></div>" +
3580
+ "</div>"
3581
+ );
3582
+
3583
+ $templateCache.put("menuTemplate.html",
3584
+ "<div ng-show=\"showColumnMenu || showFilter\" class=\"ngHeaderButton\" ng-click=\"toggleShowMenu()\">" +
3585
+ " <div class=\"ngHeaderButtonArrow\"></div>" +
3586
+ "</div>" +
3587
+ "<div ng-show=\"showMenu\" class=\"ngColMenu\">" +
3588
+ " <div ng-show=\"showFilter\">" +
3589
+ " <input placeholder=\"{{i18n.ngSearchPlaceHolder}}\" type=\"text\" ng-model=\"filterText\"/>" +
3590
+ " </div>" +
3591
+ " <div ng-show=\"showColumnMenu\">" +
3592
+ " <span class=\"ngMenuText\">{{i18n.ngMenuText}}</span>" +
3593
+ " <ul class=\"ngColList\">" +
3594
+ " <li class=\"ngColListItem\" ng-repeat=\"col in columns | ngColumns\">" +
3595
+ " <label><input ng-disabled=\"col.pinned\" type=\"checkbox\" class=\"ngColListCheckbox\" ng-model=\"col.visible\"/>{{col.displayName}}</label>" +
3596
+ " <a title=\"Group By\" ng-class=\"col.groupedByClass()\" ng-show=\"col.groupable && col.visible\" ng-click=\"groupBy(col)\"></a>" +
3597
+ " <span class=\"ngGroupingNumber\" ng-show=\"col.groupIndex > 0\">{{col.groupIndex}}</span> " +
3598
+ " </li>" +
3599
+ " </ul>" +
3600
+ " </div>" +
3601
+ "</div>"
3602
+ );
3603
+
3604
+ $templateCache.put("rowTemplate.html",
3605
+ "<div ng-style=\"{ 'cursor': row.cursor }\" ng-repeat=\"col in renderedColumns\" ng-class=\"col.colIndex()\" class=\"ngCell {{col.cellClass}}\">" +
3606
+ " <div class=\"ngVerticalBar\" ng-style=\"{height: rowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\">&nbsp;</div>" +
3607
+ " <div ng-cell></div>" +
3608
+ "</div>"
3609
+ );
3610
+
3611
+ }]);
3612
+
3613
+ }(window, jQuery));