-
Notifications
You must be signed in to change notification settings - Fork 350
/
ember-table.js
2889 lines (2632 loc) · 109 KB
/
ember-table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* ember-table v0.9.2
* Copyright 2012-2015 Addepar Inc.
* See LICENSE.md
*/
(function(){;
var define, requireModule, require, requirejs;
(function() {
var _isArray;
if (!Array.isArray) {
_isArray = function (x) {
return Object.prototype.toString.call(x) === "[object Array]";
};
} else {
_isArray = Array.isArray;
}
var registry = {}, seen = {};
var FAILED = false;
var uuid = 0;
function tryFinally(tryable, finalizer) {
try {
return tryable();
} finally {
finalizer();
}
}
function unsupportedModule(length) {
throw new Error("an unsupported module was defined, expected `define(name, deps, module)` instead got: `" + length + "` arguments to define`");
}
var defaultDeps = ['require', 'exports', 'module'];
function Module(name, deps, callback, exports) {
this.id = uuid++;
this.name = name;
this.deps = !deps.length && callback.length ? defaultDeps : deps;
this.exports = exports || { };
this.callback = callback;
this.state = undefined;
this._require = undefined;
}
Module.prototype.makeRequire = function() {
var name = this.name;
return this._require || (this._require = function(dep) {
return require(resolve(dep, name));
});
}
define = function(name, deps, callback) {
if (arguments.length < 2) {
unsupportedModule(arguments.length);
}
if (!_isArray(deps)) {
callback = deps;
deps = [];
}
registry[name] = new Module(name, deps, callback);
};
// we don't support all of AMD
// define.amd = {};
// we will support petals...
define.petal = { };
function Alias(path) {
this.name = path;
}
define.alias = function(path) {
return new Alias(path);
};
function reify(mod, name, seen) {
var deps = mod.deps;
var length = deps.length;
var reified = new Array(length);
var dep;
// TODO: new Module
// TODO: seen refactor
var module = { };
for (var i = 0, l = length; i < l; i++) {
dep = deps[i];
if (dep === 'exports') {
module.exports = reified[i] = seen;
} else if (dep === 'require') {
reified[i] = mod.makeRequire();
} else if (dep === 'module') {
mod.exports = seen;
module = reified[i] = mod;
} else {
reified[i] = requireFrom(resolve(dep, name), name);
}
}
return {
deps: reified,
module: module
};
}
function requireFrom(name, origin) {
var mod = registry[name];
if (!mod) {
throw new Error('Could not find module `' + name + '` imported from `' + origin + '`');
}
return require(name);
}
function missingModule(name) {
throw new Error('Could not find module ' + name);
}
requirejs = require = requireModule = function(name) {
var mod = registry[name];
if (mod && mod.callback instanceof Alias) {
mod = registry[mod.callback.name];
}
if (!mod) { missingModule(name); }
if (mod.state !== FAILED &&
seen.hasOwnProperty(name)) {
return seen[name];
}
var reified;
var module;
var loaded = false;
seen[name] = { }; // placeholder for run-time cycles
tryFinally(function() {
reified = reify(mod, name, seen[name]);
module = mod.callback.apply(this, reified.deps);
loaded = true;
}, function() {
if (!loaded) {
mod.state = FAILED;
}
});
var obj;
if (module === undefined && reified.module.exports) {
obj = reified.module.exports;
} else {
obj = seen[name] = module;
}
if (obj !== null &&
(typeof obj === 'object' || typeof obj === 'function') &&
obj['default'] === undefined) {
obj['default'] = obj;
}
return (seen[name] = obj);
};
function resolve(child, name) {
if (child.charAt(0) !== '.') { return child; }
var parts = child.split('/');
var nameParts = name.split('/');
var parentBase = nameParts.slice(0, -1);
for (var i = 0, l = parts.length; i < l; i++) {
var part = parts[i];
if (part === '..') {
if (parentBase.length === 0) {
throw new Error('Cannot access parent module of root');
}
parentBase.pop();
} else if (part === '.') { continue; }
else { parentBase.push(part); }
}
return parentBase.join('/');
}
requirejs.entries = requirejs._eak_seen = registry;
requirejs.clear = function(){
requirejs.entries = requirejs._eak_seen = registry = {};
seen = state = {};
};
})();
;define("ember-table/components/ember-table",
["ember","ember-table/mixins/style-bindings","ember-table/mixins/resize-handler","ember-table/controllers/row-array","ember-table/controllers/row","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __exports__) {
"use strict";
var Ember = __dependency1__["default"];
var StyleBindingsMixin = __dependency2__["default"];
var ResizeHandlerMixin = __dependency3__["default"];
var RowArrayController = __dependency4__["default"];
var Row = __dependency5__["default"];
__exports__["default"] = Ember.Component.extend(
StyleBindingsMixin, ResizeHandlerMixin, {
classNames: ['ember-table-tables-container'],
classNameBindings: ['enableContentSelection:ember-table-content-selectable'],
// ---------------------------------------------------------------------------
// API - Inputs
// ---------------------------------------------------------------------------
// Values which are bound to the table's style attr. See
// `Ember.StyleBindingsMixin` documentation for more details.
styleBindings: ['height'],
// An array of row objects. Usually a hash where the keys are column names
// and the values are the rows's values. However, could be any object, since
// each column can define a function to return the column value given the row
// object. See `Ember.Table.ColumnDefinition.getCellContent`.
content: [],
// An array of column definitions: see `Ember.Table.ColumnDefinition`. Allows
// each column to have its own configuration.
// TODO(new-api): Rename to `data`
columns: null,
// The number of fixed columns on the left side of the table. Fixed columns
// are always visible, even when the table is scrolled horizontally.
numFixedColumns: 0,
// The number of footer rows in the table. Footer rows appear at the bottom of
// the table and are always visible.
// TODO(new-api): Rename to `numFooterRows`
numFooterRow: 0,
// The row height in pixels. A consistent row height is necessary to calculate
// which rows are being shown, to enable lazy rendering.
// TODO: Currently must be kept in sync with the LESS file.
rowHeight: 30,
// The minimum header height in pixels. Headers will grow in height if given
// more content than they can display.
// TODO: Currently must be kept in sync with the LESS file.
minHeaderHeight: 30,
// The footer height in pixels.
// TODO: Currently must be kept in sync with the LESS file.
footerHeight: 30,
// Enables or disables the header block.
hasHeader: true,
// Enables or disables the footer block.
// TODO(new-api): Control this via `numFooterRows` and remove from API
hasFooter: true,
enableColumnReorder: true,
// Allow users to select the content of table cells.
enableContentSelection: false,
// Sets which column resizing behavior to use. Possible values are
// <code>'standard'</code> (resizing a column pushes or pulls all other
// columns) and <code>'fluid'</code> (resizing a column steals width from
// neighboring columns).
columnMode: 'standard',
// Sets which row selection behavior to follow. Possible values are 'none'
// (clicking on a row does nothing), 'single' (clicking on a row selects it
// and deselects other rows), and 'multiple' (multiple rows can be selected
// through ctrl/cmd-click or shift-click).
selectionMode: 'single',
// ---------------------------------------------------------------------------
// API - Outputs
// ---------------------------------------------------------------------------
// An array of the rows currently selected. If `selectionMode` is set to
// 'single', the array will contain either one or zero elements.
selection: Ember.computed(function(key, val) {
var selectionMode = this.get('selectionMode');
if (arguments.length > 1 && val) {
this.get('persistedSelection').clear();
this.get('rangeSelection').clear();
switch (selectionMode) {
case 'single':
this.get('persistedSelection').addObject(val);
break;
case 'multiple':
this.get('persistedSelection').addObjects(val);
}
}
var selection = this.get('persistedSelection').copy().addObjects(this.get('rangeSelection'));
switch (selectionMode) {
case 'none':
return null;
case 'single':
return selection[0] || null;
case 'multiple':
return selection;
}
}).property('persistedSelection.[]', 'rangeSelection.[]', 'selectionMode'),
// ---------------------------------------------------------------------------
// Internal properties
// ---------------------------------------------------------------------------
// Special flag used by child views to look up this component using
// nearestWithProperty()
isEmberTable: true,
columnsFillTable: true,
// _resolvedContent is an intermediate property between content and rows
// This allows content to be a plain array or a promise resolving to an array
_resolvedContent: function(key, value) {
if (arguments.length > 1) {
return value;
} else {
var _this = this;
value = [];
var content = this.get('content');
if (content.then)
{
// content is a promise
content.then(function(resolvedContent) {
// when the promise resolves, set this property so it gets cached
_this.set('_resolvedContent', resolvedContent);
// if the promise resolves immediately, set `value` so we return
// the resolved value and not []
value = resolvedContent;
});
// returns [] if the promise doesn't resolve immediately, or
// the resolved value if it's ready
return value;
}
else
{
// content is not a promise
return content;
}
}
}.property('content'),
init: function() {
this._super();
if (!Ember.$.ui) {
throw 'Missing dependency: jquery-ui';
}
if (!Ember.$().mousewheel) {
throw 'Missing dependency: jquery-mousewheel';
}
if (!Ember.$().antiscroll) {
throw 'Missing dependency: antiscroll.js';
}
this.prepareTableColumns();
},
height: Ember.computed.alias('_tablesContainerHeight'),
// TODO(new-api): eliminate view alias
// specify the view class to use for rendering the table rows
tableRowView: 'table-row',
tableRowViewClass: Ember.computed.alias('tableRowView'),
onColumnSort: function(column, newIndex) {
// Fixed columns are not affected by column reordering
var numFixedColumns = this.get('fixedColumns.length');
var columns = this.get('columns');
columns.removeObject(column);
columns.insertAt(numFixedColumns + newIndex, column);
this.prepareTableColumns();
this.sendAction('onColumnReordered', columns, column, newIndex);
},
// An array of Ember.Table.Row computed based on `content`
bodyContent: Ember.computed(function() {
return RowArrayController.create({
target: this,
parentController: this,
container: this.get('container'),
itemController: Row,
content: this.get('_resolvedContent')
});
}).property('_resolvedContent.[]'),
// An array of Ember.Table.Row
footerContent: Ember.computed(function(key, value) {
if (value) {
return value;
} else {
return Ember.A();
}
}).property(),
fixedColumns: Ember.computed(function() {
var columns = this.get('columns');
if (!columns) {
return Ember.A();
}
var numFixedColumns = this.get('numFixedColumns') || 0;
return columns.slice(0, numFixedColumns) || [];
}).property('columns.[]', 'numFixedColumns'),
tableColumns: Ember.computed(function() {
var columns = this.get('columns');
if (!columns) {
return Ember.A();
}
var numFixedColumns = this.get('numFixedColumns') || 0;
return columns.slice(numFixedColumns, columns.get('length')) || [];
}).property('columns.[]', 'numFixedColumns'),
prepareTableColumns: function() {
var _this = this;
var columns = this.get('columns') || Ember.A();
columns.setEach('controller', this);
columns.forEach(function(col, i) {
col.set('nextResizableColumn', _this.getNextResizableColumn(columns, i));
});
},
getNextResizableColumn: function(columns, index) {
var column;
while (index < columns.length) {
index += 1;
column = columns.objectAt(index);
if (column != null && column.get('isResizable')) {
return column;
}
}
return null;
},
// ---------------------------------------------------------------------------
// View concerns
// ---------------------------------------------------------------------------
didInsertElement: function() {
this._super();
this.set('_tableScrollTop', 0);
this.elementSizeDidChange();
this.doForceFillColumns();
},
willDestroyElement: function() {
var antiscrollElements = this.$('.antiscroll-wrap');
var antiscroll;
antiscrollElements.each(function(i, antiscrollElement) {
antiscroll = Ember.$(antiscrollElement).data('antiscroll');
if (antiscroll) {
antiscroll.destroy();
Ember.$(antiscrollElement).removeData('antiscroll');
}
});
this._super();
},
onResizeEnd: function() {
// We need to put this on the run loop, because resize event came from
// window. Otherwise, we get this warning when used in tests. You have
// turned on testing mode, which disabled the run-loop's autorun. You
// will need to wrap any code with asynchronous side-effects in an
// Ember.run
if (this.tableWidthNowTooSmall()) {
this.set('columnsFillTable', true);
}
Ember.run(this, this.elementSizeDidChange);
},
elementSizeDidChange: function() {
if ((this.get('_state') || this.get('state')) !== 'inDOM') {
return;
}
this.set('_width', this.$().parent().width());
this.set('_height', this.$().parent().height());
// we need to wait for the table to be fully rendered before antiscroll can
// be used
Ember.run.next(this, this.updateLayout);
},
tableWidthNowTooSmall: function() {
if ((this.get('_state') || this.get('state')) !== 'inDOM') {
return false;
}
var oldTableWidth = this.get('_width');
var newTableWidth = this.$().parent().width();
// TODO(azirbel): This should be 'columns', I believe. Fix separately.
var totalColumnWidth = this._getTotalWidth(this.get('tableColumns'));
return (oldTableWidth > totalColumnWidth) && (newTableWidth < totalColumnWidth);
},
updateLayout: function() {
if ((this.get('_state') || this.get('state')) !== 'inDOM') {
return;
}
// updating antiscroll
this.$('.antiscroll-wrap').antiscroll().data('antiscroll').rebuild();
if (this.get('columnsFillTable')) {
this.doForceFillColumns();
}
},
/**
* Resizes a column, and returns whether or not the column is now at it's
* minimum or maximum.
*
* @private
* @param {ColumnDefinition} column The column to be resized
* @param {number} totalResizableWidth The total width of the table that
* can be resized
* @param {number} availableWidth The total width available in the table
* @returns {boolean}
*/
_resizeColumn: function(column, totalResizableWidth, availableWidth) {
var newWidth = Math.round(column.get('width') * (availableWidth / totalResizableWidth));
var minWidth = column.get('minWidth');
var maxWidth = column.get('maxWidth');
if (newWidth < minWidth) {
column.set('width', minWidth);
return true;
} else if (newWidth > maxWidth) {
column.set('width', maxWidth);
return true;
} else {
column.set('width', newWidth);
return false;
}
},
// Iteratively adjusts column widths to adjust to a changed table width.
// Attempts to scale columns proportionally. However, if a column hits a min
// or max width after scaling proportionally, we need to respect that setting.
// In that case, keep iterating until all column widths are set to the best
// they can be. Note that this may fail to arrive at the table width if the
// resizable columns are all restricted by min/max widths.
doForceFillColumns: function() {
var allColumns = this.get('columns');
var columnsToResize = allColumns.filterProperty('canAutoResize');
var unresizableColumns = allColumns.filterProperty('canAutoResize', false);
var availableWidth = this.get('_width') - this._getTotalWidth(unresizableColumns);
var continueResizingColumns = true;
while (continueResizingColumns) {
var totalResizableWidth = this._getTotalWidth(columnsToResize);
var nextColumnsToResize = [];
continueResizingColumns = false;
for (var i = 0; i < columnsToResize.get('length'); ++i) {
var column = columnsToResize[i];
var isColumnAtExtremum = this._resizeColumn(column, totalResizableWidth,
availableWidth);
if (isColumnAtExtremum) {
continueResizingColumns = true;
availableWidth -= column.get('width');
} else {
nextColumnsToResize.pushObject(column);
}
}
columnsToResize = nextColumnsToResize;
}
},
onBodyContentLengthDidChange: Ember.observer(function() {
Ember.run.next(this, function() {
Ember.run.once(this, this.updateLayout);
});
}, 'bodyContent.length'),
// ---------------------------------------------------------------------------
// Private variables
// ---------------------------------------------------------------------------
_tableScrollTop: 0,
_tableScrollLeft: 0,
_width: null,
_height: null,
_contentHeaderHeight: null,
_hasVerticalScrollbar: Ember.computed(function() {
var height = this.get('_height');
var contentHeight = this.get('_tableContentHeight') +
this.get('_headerHeight') + this.get('_footerHeight');
return height < contentHeight;
}).property('_height', '_tableContentHeight', '_headerHeight',
'_footerHeight'),
_hasHorizontalScrollbar: Ember.computed(function() {
var contentWidth = this.get('_tableColumnsWidth');
var tableWidth = this.get('_width') - this.get('_fixedColumnsWidth');
return contentWidth > tableWidth;
}).property('_tableColumnsWidth', '_width', '_fixedColumnsWidth'),
// tables-container height adjusts to the content height
_tablesContainerHeight: Ember.computed(function() {
var height = this.get('_height');
var contentHeight = this.get('_tableContentHeight') +
this.get('_headerHeight') + this.get('_footerHeight');
return Math.min(contentHeight, height);
}).property('_height', '_tableContentHeight', '_headerHeight',
'_footerHeight'),
// Actual width of the fixed columns
_fixedColumnsWidth: Ember.computed(function() {
return this._getTotalWidth(this.get('fixedColumns'));
}).property('fixedColumns.@each.width'),
// Actual width of the (non-fixed) columns
_tableColumnsWidth: Ember.computed(function() {
// Hack: We add 3px padding to the right of the table content so that we can
// reorder into the last column.
var contentWidth = this._getTotalWidth(this.get('tableColumns')) + 3;
var availableWidth = this.get('_width') - this.get('_fixedColumnsWidth');
return Math.max(contentWidth, availableWidth);
}).property('tableColumns.@each.width', '_width', '_fixedColumnsWidth'),
_rowWidth: Ember.computed(function() {
var columnsWidth = this.get('_tableColumnsWidth');
var nonFixedTableWidth = this.get('_tableContainerWidth') -
this.get('_fixedColumnsWidth');
return Math.max(columnsWidth, nonFixedTableWidth);
}).property('_fixedColumnsWidth', '_tableColumnsWidth',
'_tableContainerWidth'),
// Dynamic header height that adjusts according to the header content height
_headerHeight: Ember.computed(function() {
var minHeight = this.get('minHeaderHeight');
var contentHeaderHeight = this.get('_contentHeaderHeight');
return Math.max(contentHeaderHeight, minHeight);
}).property('_contentHeaderHeight', 'minHeaderHeight'),
// Dynamic footer height that adjusts according to the footer content height
_footerHeight: Ember.computed(function() {
return this.get('hasFooter') ? this.get('footerHeight') : 0;
}).property('footerHeight', 'hasFooter'),
_bodyHeight: Ember.computed(function() {
var bodyHeight = this.get('_tablesContainerHeight');
if (this.get('hasHeader')) {
bodyHeight -= this.get('_headerHeight');
}
if (this.get('hasFooter')) {
bodyHeight -= this.get('footerHeight');
}
return bodyHeight;
}).property('_tablesContainerHeight', '_hasHorizontalScrollbar',
'_headerHeight', 'footerHeight', 'hasHeader', 'hasFooter'),
_tableBlockWidth: Ember.computed(function() {
return this.get('_width') - this.get('_fixedColumnsWidth');
}).property('_width', '_fixedColumnsWidth'),
_fixedBlockWidthBinding: '_fixedColumnsWidth',
_tableContentHeight: Ember.computed(function() {
return this.get('rowHeight') * this.get('bodyContent.length');
}).property('rowHeight', 'bodyContent.length'),
_tableContainerWidth: Ember.computed(function() {
return this.get('_width');
}).property('_width'),
_scrollContainerWidth: Ember.computed(function() {
return this.get('_width') - this.get('_fixedColumnsWidth');
}).property('_width', '_fixedColumnsWidth'),
_numItemsShowing: Ember.computed(function() {
return Math.floor(this.get('_bodyHeight') / this.get('rowHeight'));
}).property('_bodyHeight', 'rowHeight'),
_startIndex: Ember.computed(function() {
var numContent = this.get('bodyContent.length');
var numViews = this.get('_numItemsShowing');
var rowHeight = this.get('rowHeight');
var scrollTop = this.get('_tableScrollTop');
var index = Math.floor(scrollTop / rowHeight);
// Adjust start index so that end index doesn't exceed content length
if (index + numViews >= numContent) {
index = numContent - numViews;
}
return Math.max(index, 0);
}).property('bodyContent.length', '_numItemsShowing', 'rowHeight',
'_tableScrollTop'),
_getTotalWidth: function(columns, columnWidthPath) {
if (columnWidthPath == null) {
columnWidthPath = 'width';
}
if (!columns) {
return 0;
}
var widths = columns.getEach(columnWidthPath) || [];
return widths.reduce((function(total, w) {
return total + w;
}), 0);
},
// ---------------------------------------------------------------------------
// Selection
// TODO: Make private or reorganize into a new section
// ---------------------------------------------------------------------------
lastSelected: null,
isSelected: function(row) {
switch (this.get('selectionMode')) {
case 'none':
return false;
case 'single':
return this.get('selection') === row.get('content');
case 'multiple':
return this.get('selection').contains(row.get('content'));
}
},
setSelected: function(row, val) {
this.persistSelection();
var item = row.get('content');
if (val) {
return this.get('persistedSelection').addObject(item);
} else {
return this.get('persistedSelection').removeObject(item);
}
},
// items that were selected directly or as part of a previous
// range selection (shift-click)
persistedSelection: Ember.computed(function() {
return Ember.A();
}),
// items that are part of the currently editable range selection
rangeSelection: Ember.computed(function() {
return Ember.A();
}),
// TODO: Handle click event in the row view
click: function(event) {
var row = this.getRowForEvent(event);
if (!row || !row.get('content')) {
return;
}
var item = row.get('content');
switch (this.get('selectionMode')) {
case 'none':
break;
case 'single':
this.get('persistedSelection').clear();
this.get('persistedSelection').addObject(item);
break;
case 'multiple':
if (event.shiftKey) {
this.get('rangeSelection').clear();
var lastIndex = this.rowIndex(this.get('lastSelected'));
// If the last selected row is no longer in the table, use the
// first row in the table
if (lastIndex === -1) {
lastIndex = 0;
}
var curIndex = this.rowIndex(this.getRowForEvent(event));
var minIndex = Math.min(lastIndex, curIndex);
var maxIndex = Math.max(lastIndex, curIndex);
this.get('rangeSelection').addObjects(
this.get('bodyContent').slice(minIndex, maxIndex + 1)
.mapBy('content')
);
} else {
if (!event.ctrlKey && !event.metaKey) {
this.get('persistedSelection').clear();
this.get('rangeSelection').clear();
} else {
this.persistSelection();
}
if (this.get('persistedSelection').contains(item)) {
this.get('persistedSelection').removeObject(item);
} else {
this.get('persistedSelection').addObject(item);
}
this.set('lastSelected', row);
}
break;
}
},
findRow: function(content) {
// TODO(azirbel): Replace with filter
this.get('bodyContent').forEach(function(row) {
if (row.get('content') === content) {
return row;
}
});
return null;
},
rowIndex: function(row) {
if (!this.get('bodyContent')) {
return null;
}
return this.get('bodyContent').indexOf(row);
},
persistSelection: function() {
this.get('persistedSelection').addObjects(this.get('rangeSelection'));
this.get('rangeSelection').clear();
},
getRowForEvent: function(event) {
var $rowView = Ember.$(event.target).parents('.ember-table-table-row');
var view = Ember.View.views[$rowView.attr('id')];
if (view) {
return view.get('row');
}
return null;
},
// TODO(azirbel): Document
actions: {
addColumn: Ember.K,
sortByColumn: Ember.K
}
});
});
;define("ember-table/mixins/style-bindings",
["ember","exports"],
function(__dependency1__, __exports__) {
"use strict";
// TODO(azirbel): This needs to be an external dependency.
var Ember = __dependency1__["default"];
__exports__["default"] = Ember.Mixin.create({
concatenatedProperties: ['styleBindings'],
attributeBindings: ['style'],
unitType: 'px',
createStyleString: function(styleName, property) {
var value;
value = this.get(property);
if (Ember.isNone(value)) {
return;
}
if (Ember.typeOf(value) === 'number') {
value = value + this.get('unitType');
}
return Ember.String.dasherize("" + styleName) + ":" + value + ";";
},
applyStyleBindings: Ember.on('init',
Ember.observer('styleBindings', function() {
var lookup, properties, styleBindings, styleComputed, styles,
_this = this;
styleBindings = this.get('styleBindings');
if (!styleBindings) {
return;
}
lookup = {};
styleBindings.forEach(function(binding) {
var property, style, tmp;
tmp = binding.split(':');
property = tmp[0];
style = tmp[1];
lookup[style || property] = property;
});
styles = Ember.keys(lookup);
properties = styles.map(function(style) {
return lookup[style];
});
styleComputed = Ember.computed(function() {
var styleString, styleTokens;
styleTokens = styles.map(function(style) {
return _this.createStyleString(style, lookup[style]);
});
styleString = styleTokens.join('');
if (styleString.length !== 0) {
return new Ember.Handlebars.SafeString(styleString);
}
});
styleComputed.property.apply(styleComputed, properties);
return Ember.defineProperty(this, 'style', styleComputed);
}))
});
});
;define("ember-table/mixins/resize-handler",
["ember","exports"],
function(__dependency1__, __exports__) {
"use strict";
// TODO(azirbel): This needs to be an external dependency.
var Ember = __dependency1__["default"];
__exports__["default"] = Ember.Mixin.create({
resizeEndDelay: 200,
resizing: false,
onResizeStart: Ember.K,
onResizeEnd: Ember.K,
onResize: Ember.K,
endResize: Ember.computed(function() {
return function(event) {
if (this.isDestroyed) {
return;
}
this.set('resizing', false);
return typeof this.onResizeEnd === "function" ? this.onResizeEnd(event) : void 0;
};
}),
handleWindowResize: function(event) {
if ((typeof event.target.id !== "undefined" && event.target.id !== null) &&
(event.target.id !== this.elementId)) {
return;
}
if (!this.get('resizing')) {
this.set('resizing', true);
if (typeof this.onResizeStart === "function") {
this.onResizeStart(event);
}
}
if (typeof this.onResize === "function") {
this.onResize(event);
}
return Ember.run.debounce(this, this.get('endResize'), event, this.get('resizeEndDelay'));
},
didInsertElement: function() {
this._super();
return this._setupDocumentHandlers();
},
willDestroyElement: function() {
this._removeDocumentHandlers();
return this._super();
},
_setupDocumentHandlers: function() {
if (this._resizeHandler) {
return;
}
this._resizeHandler = Ember.$.proxy(this.get('handleWindowResize'), this);
return Ember.$(window).on("resize." + this.elementId, this._resizeHandler);
},
_removeDocumentHandlers: function() {
Ember.$(window).off("resize." + this.elementId, this._resizeHandler);
return this._resizeHandler = null;
}
});
});
;define("ember-table/controllers/row-array",
["ember","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Ember = __dependency1__["default"];
__exports__["default"] = Ember.ArrayController.extend({
itemController: null,
content: null,
lastItem: null,
rowContent: Ember.computed(function() {
return [];
}).property(),
controllerAt: function(idx, object) {
var subControllers = this.get('_subControllers');
var subController = subControllers[idx];
if (subController) {
return subController;
}
subController = this.get('itemController').create({
target: this,
parentController: this.get('parentController') || this,
content: object
});
subControllers[idx] = subController;
// Keep track of the last row. Because we only use last row status to apply
// CSS styles, we only need to know which row is the last row when the row
// is loaded/scrolled into view. At that time, we update the `lastItem`
// property. This avoids the problem where the last row's data is always
// loaded (e.g. in the AJAX table). See issue #165.
if (this._isLastItem(idx)) {
this.set('lastItem', subController);
}
return subController;
},