-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathListView.coffee
More file actions
1326 lines (1047 loc) · 35.6 KB
/
Copy pathListView.coffee
File metadata and controls
1326 lines (1047 loc) · 35.6 KB
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
###
* coffeescript-ui - Coffeescript User Interface System (CUI)
* Copyright (c) 2013 - 2016 Programmfabrik GmbH
* MIT Licence
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
###
class CUI.ListView extends CUI.SimplePane
@defaults:
row_move_handle_tooltip: "Drag to move row"
#Construct a new CUI.ListView.
#
# @param [Object] options for listview creation
# @option options [String] TODO
constructor: (opts) ->
super(opts)
@initListView()
initListView: ->
@fixedColsCount = @_fixedCols
@fixedRowsCount = @_fixedRows
@__cols = @_cols.slice(0)
if @_colClasses
@__colClasses = @_colClasses.slice(0)
if @_rowMove
CUI.util.assert(not @_rowMovePlaceholder, "new CUI.ListView", "opts.rowMove cannot be used with opts.rowMovePlaceholder", opts: @opts)
if @_rowMove or @_rowMovePlaceholder
@__cols.splice(0,0, "fixed")
if not @__colClasses
@__colClasses = []
@__colClasses.splice(0,0, "cui-lv-row-move-handle-column")
CUI.util.assert(@fixedColsCount < @__cols.length, "new CUI.ListView", "opts.fixedCols must be less than column count.", opts: @opts)
if @_colResize
@__colResize = true
else if @fixedRowsCount > 0 and @_colResize == undefined
@__colResize = true
if @__colResize
CUI.util.assert(@fixedRowsCount > 0, "new CUI.ListView", "Cannot enable col resize with no fixed rows.", opts: @opts)
@__maxCols = []
for col, col_i in @__cols
CUI.util.assert(col in ["auto", "maximize", "fixed", "manual"], "new #{@__cls}", "Unknown type of col: \"#{col}\". opts.cols can only contain \"auto\" and \"maximize\" elements.")
if col == "maximize"
# CUI.util.assert(@_maximize, "new CUI.ListView", "maximized columns can only exist inside an maximized ListView", opts: @opts)
CUI.util.assert(col_i >= @fixedColsCount, "new CUI.ListView", "maximized columns can only be in the non-fixed side of the ListView.", opts: @opts)
@__maxCols.push(col_i)
if @__maximize_horizontal and @__maxCols.length == 0
# auto-max the last column
len = @__cols.length - 1
if len >= @fixedColsCount
@__maxCols.push(len)
@__cols[len] = 'maximize'
@rowsCount = 0
@colsCount = @__cols.length
@listViewCounter = CUI.ListView.counter++
@__manualColWidths = []
@__colspanRows = {}
@colsOrder = []
for col_i in [0...@colsCount]
@colsOrder.push(col_i)
@rowsOrder = []
@__maxRowIdx = -1
@__resetCellDims()
@__cells = []
@__rows = []
@__lvClass = "cui-lv-#{@listViewCounter}"
@__deferredRows = []
@__isInDOM = false
@__doLayoutBound = =>
@__doLayout()
if @_useCSSGridLayout
@__useCSSGridLayout = true
@addClass("use-css-grid-layout")
CUI.dom.setStyle(@, "--grid-column-count": @__cols.length, "")
@addClass("cui-list-view")
initOpts: ->
super()
@addOpts
colClasses:
check: "Array"
cols:
mandatory: true
check: "Array"
fixedCols:
default: 0
check: "Integer"
fixedRows:
default: 0
check: "Integer"
# this adds an extra column at the beginning
# it also adds a dummy colClasses item if colClasses
# are set
rowMove:
default: false
check: Boolean
rowMoveFixedRows:
default: 0
check: "Integer"
# if set, add a rowMovePlaceholder to
# all rows
rowMovePlaceholder:
default: false
check: Boolean
colResize:
check: Boolean
useCSSGridLayout:
check: Boolean
selectableRows:
check: (v) ->
v == false or v == true or v == "multiple"
focusable:
check: Boolean
default: false
onRowMove:
check: Function
onScroll:
check: Function
onColumnResize:
check: Function
header:
deprecated: true
footer:
deprecated: true
# ListViewRow uses _onSelect and _onDeselect
onSelect:
check: Function
onDeselect:
check: Function
ignoreKeyEvents:
check: Boolean
default: false
hierarchyDragAndDrop:
check: Boolean
default: false
onHierarchyDrop:
check: Function
readOpts: ->
if @opts.rowMove and @opts.hierarchyDragAndDrop
throw new Error("rowMove and hierarchyDragAndDrop cannot be set together")
if @opts.header
@opts.header_center = @opts.header
if @opts.footer
@opts.footer_left = @opts.footer
super()
@__selectableRows = @_selectableRows
@
destroy: ->
# console.error "#{CUI.util.getObjectClass(@)}.destroy list-view-#{@listViewCounter} called. This is NOT an error."
delete(@colsOrder)
delete(@rowsOrder)
delete(@__fillRowQ3)
# @hideWaitBlock()
@__isInDOM = null
CUI.scheduleCallbackCancel(call: @__doLayoutBound)
@listViewTemplate?.destroy()
@__layoutIsStopped = false
super()
@
getListViewClass: ->
@__lvClass
isKeyEventsEnabled: ->
!@_ignoreKeyEvents
getGrid: ->
@grid
hasResizableColumns: ->
@__colResize
hasCSSGridLayout: ->
@__useCSSGridLayout
hasMovableRows: ->
@_rowMove
isInactive: ->
!!@__inactive
setInactive: (inactive, addClass="inactive") ->
@__inactive = !!inactive
if @grid
if @__inactive
CUI.dom.addClass(@grid, addClass)
@__inactiveWaitBlock = new CUI.WaitBlock(element: @grid, inactive: true).show()
else
@__inactiveWaitBlock?.destroy()
@__inactiveWaitBlock = null
CUI.dom.removeClass(@grid, addClass)
@
render: ->
CUI.util.assert(not @grid, "ListView.render", "ListView already rendered", opts: @opts)
html = []
cls = ["cui-list-view-grid", @__lvClass]
if @_fixedCols == 1 and (@_rowMove or @_rowMovePlaceholder)
cls.push("cui-list-view-grid-fixed-col-has-only-row-move-handle")
if @_rowMovePlaceholder
cls.push("cui-list-view-has-row-move-placeholder")
if @_rowMove
cls.push("cui-list-view-has-row-move")
if @__maxCols.length > 0
cls.push("cui-list-view-grid-has-maximized-columns")
if @fixedColsCount > 0
cls.push("cui-list-view-grid-has-fixed-cols")
if @fixedRowsCount > 0
cls.push("cui-list-view-grid-has-fixed-rows")
html.push("<div class=\"")
html.push(cls.join(" "))
html.push("\">")
html.push("<style></style>")
add_quadrant = (qi) =>
if @__isFocusable()
# add tabindex="-1"
html.push("<div cui-lv-quadrant=\"#{qi}\" class=\"cui-drag-scroll cui-list-view-grid-quadrant cui-lv-tbody cui-list-view-grid-quadrant-#{qi} #{@__lvClass}-quadrant\">")
else
html.push("<div cui-lv-quadrant=\"#{qi}\" class=\"cui-drag-scroll cui-list-view-grid-quadrant cui-lv-tbody cui-list-view-grid-quadrant-#{qi} #{@__lvClass}-quadrant\">")
if qi in [2, 3]
html.push("<div class=\"cui-lv-tr-fill-outer\"><div class=\"cui-lv-tr\">")
ft = @__getColsFromAndTo(qi)
for col_i in [ft.from..ft.to] by 1
cls = @__getColClass(col_i)
html.push("<div class=\"#{cls} cui-lv-td cui-lv-td-fill cui-list-view-grid-fill-col-#{col_i}\"></div>")
html.push("</div></div>")
html.push("</div>")
return
if @fixedColsCount > 0 and @fixedRowsCount > 0
html.push("<div class=\"cui-list-view-grid-inner-top\">")
add_quadrant(0)
add_quadrant(1)
html.push("</div>")
html.push("<div class=\"cui-list-view-grid-inner-bottom\">")
add_quadrant(2)
add_quadrant(3)
html.push("</div>")
else if @fixedColsCount > 0
html.push("<div class=\"cui-list-view-grid-inner-bottom\">")
add_quadrant(2)
add_quadrant(3)
html.push("</div>")
else if @fixedRowsCount > 0
html.push("<div class=\"cui-list-view-grid-inner-top\">")
add_quadrant(1)
html.push("</div>")
html.push("<div class=\"cui-list-view-grid-inner-bottom\">")
add_quadrant(3)
html.push("</div>")
else
add_quadrant(3)
html.push("</div>")
outer = @center()
outer.innerHTML = html.join("")
@grid = outer.firstChild
@quadrant = [
CUI.dom.matchSelector(outer, ".cui-list-view-grid-quadrant-0")[0]
CUI.dom.matchSelector(outer, ".cui-list-view-grid-quadrant-1")[0]
CUI.dom.matchSelector(outer, ".cui-list-view-grid-quadrant-2")[0]
CUI.dom.matchSelector(outer, ".cui-list-view-grid-quadrant-3")[0]
]
@styleElement = CUI.dom.matchSelector(outer, "style")[0]
@__fillRowQ3 = CUI.dom.matchSelector(@grid, ".cui-list-view-grid-fills-3")[0]
@__topQuadrants = CUI.dom.matchSelector(outer, ".cui-list-view-grid-inner-top")[0]
if (@fixedColsCount == 0 and @fixedRowsCount == 0 ) # we only have Q3
@__bottomQuadrants = @quadrant[3]
else
@__bottomQuadrants = CUI.dom.matchSelector(outer, ".cui-list-view-grid-inner-bottom")[0]
@__fillCells = []
for col in [0..@colsCount-1] by 1
@__fillCells.push(CUI.dom.matchSelector(outer, ".cui-list-view-grid-fill-col-#{col}")[0])
on_scroll = =>
@__syncScrolling()
@_onScroll?()
if @quadrant[3].scrollTop > 0
CUI.dom.addClass(@grid, "is-scrolling-vertically")
else
CUI.dom.removeClass(@grid, "is-scrolling-vertically")
if @quadrant[3].scrollLeft > 0
CUI.dom.addClass(@grid, "is-scrolling-horizontally")
else
CUI.dom.removeClass(@grid, "is-scrolling-horizontally")
if @__useCSSGridLayout
CUI.Events.listen
node: @grid
type: "scroll"
call: (ev) =>
if @grid.scrollTop > 0
CUI.dom.addClass(@grid, "is-scrolling-vertically")
else
CUI.dom.removeClass(@grid, "is-scrolling-vertically")
if @grid.scrollLeft > 0
CUI.dom.addClass(@grid, "is-scrolling-horizontally")
else
CUI.dom.removeClass(@grid, "is-scrolling-horizontally")
else
CUI.Events.listen
node: @quadrant[3]
type: "scroll"
call: on_scroll
@__currentScroll = top: 0, left: 0
if @hasSelectableRows()
selector = "."+@__lvClass+"-quadrant > .cui-lv-tr-outer"
CUI.Events.listen
type: ["click"]
node: @DOM
selector: selector
call: (ev) =>
row = CUI.dom.data(ev.getCurrentTarget(), "listViewRow")
if not row.isSelectable()
return
ev.stopImmediatePropagation()
@selectRow(ev, row)
return
if @__isFocusable()
selectorFocus = "."+@__lvClass+"-quadrant > .cui-lv-tr-outer:focus"
CUI.Events.listen
type: ["keydown"]
node: @DOM
selector: selectorFocus
call: (ev) =>
if ev.getKeyboard() not in ["Return", "Space"]
return
row = CUI.dom.data(ev.getCurrentTarget(), "listViewRow")
if not row.isSelectable()
return
ev.stopImmediatePropagation()
@selectRow(ev, row)
return
if @quadrant[2]
CUI.Events.listen
type: "wheel"
node: @quadrant[2]
call: (ev) =>
scroll_delta = 100
if ev.wheelDeltaY() > 0
if @quadrant[3].scrollTop == (@quadrant[3].scrollHeight - @quadrant[3].offsetHeight)
# at bottom
return
@quadrant[3].scrollTop += scroll_delta
else if ev.wheelDeltaY() < 0
if @quadrant[3].scrollTop == 0
# at top
return
@quadrant[3].scrollTop -= scroll_delta
else
return
ev.preventDefault()
on_scroll()
return
CUI.Events.listen
type: "viewport-resize"
node: @grid
call: (ev, info) =>
if not @__hasLayout
return
@__doLayout(resetRows: !!(info.css_load or info.tab))
return
CUI.Events.listen
type: "content-resize"
node: @DOM
call: (ev, info) =>
if not @__isInDOM
return
cell = CUI.dom.closest(ev.getNode(), ".cui-lv-td")
if not cell
return
ev.stopPropagation()
row = parseInt(cell.getAttribute("row"))
col = parseInt(cell.getAttribute("col"))
if @fixedColsCount > 0 and CUI.dom.getAttribute(cell.parentNode, "cui-lv-tr-unmeasured")
# row has not been measured
return
@__resetRowDim(row)
@__scheduleLayout()
return
if @isInactive()
@setInactive(true)
# if @__showWaitBlock
# @showWaitBlock()
@appendDeferredRows()
CUI.dom.waitForDOMInsert(node: @DOM)
.done =>
@__isInDOM = true
@__doLayout()
@DOM
__getScrolling: ->
dim =
top: @quadrant[3].scrollTop
left: @quadrant[3].scrollLeft
height: @quadrant[3].scrollHeight
dim
getScrollingContainer: ->
@quadrant[3]
__setScrolling: (scroll) ->
@quadrant[3].scrollTop = scroll.top
@quadrant[3].scrollLeft = scroll.left
__syncScrolling: ->
@__currentScroll = @__getScrolling()
if @fixedColsCount > 0
@quadrant[2].scrollTop = @__currentScroll.top
if @fixedRowsCount > 0
@quadrant[1].scrollLeft = @__currentScroll.left
if @__fillRowQ3
@__fillRowQ3.style.width = ""
@__fillRowQ3.style.width = @__getValue(@__fillRowQ3.scrollWidth)
@
__setMargins: ->
width = @quadrant[3].offsetWidth - @quadrant[3].clientWidth
height = @quadrant[3].offsetHeight - @quadrant[3].clientHeight
@quadrant[1]?.style.marginRight = @__getValue(width)
@quadrant[2]?.style.marginBottom = @__getValue(height)
@
getSelectedRows: ->
# console.time "getSelectedRows"
sel_rows = []
for row_i in @rowsOrder
listViewRow = @getListViewRow(row_i)
if listViewRow.isSelected()
sel_rows.push(listViewRow)
# console.timeEnd "getSelectedRows"
sel_rows
hasSelectableRows: ->
!!@__selectableRows
__isFocusable: ->
return @_focusable
selectRowById: (row_id) ->
@selectRow(null, @getListViewRow(row_id), true)
selectRowByDisplayIdx: (row_display_idx) ->
@selectRowById(@getRowIdx(row_display_idx))
# deselectRow deselects the given row, this
# method is here, so it can be overwritten in ListViewTree where
# we support different selection groups
deselectRow: (ev, row, newRow) ->
return row.deselect(ev, newRow)
selectRow: (ev, rowChosen, noDeselect=false) ->
CUI.util.assert(CUI.util.isNull(rowChosen) or rowChosen instanceof CUI.ListViewRow, "#{@__cls}.setSelectedRow", "Parameter needs to be instance of CUI.ListViewRow.", selectedRow: rowChosen)
dfr = new CUI.Deferred()
selectRowChosen = =>
if rowChosen.isSelected()
if not noDeselect
# this is a "toggle", so if the row is selected, we deselect it
# otherwise it is selected.
@deselectRow(ev, rowChosen, rowChosen)
else
dfr.resolve()
else
rowChosen.select(ev).done(dfr.resolve).fail(dfr.reject)
return
deselectAllRows = (skipSelf = true) =>
promises = []
for _row in @getSelectedRows()
if rowChosen == _row and skipSelf
# we handle this in do_select
continue
promise = @deselectRow(null, _row, rowChosen) # null is sent as event parameter, to avoids checks.
if CUI.util.isPromise(promise)
promises.push(promise)
CUI.when(promises).done(selectRowChosen).fail(dfr.reject)
if @__selectableRows == true # only one row
deselectAllRows()
else if @__selectableRows == "multiple"
# If CTRL key is pressed, then It is allowed to select more rows.
if ev?.ctrlKey() or ev?.metaKey()
selectRowChosen()
# If Shift key is pressed then all next or previous rows are selected.
else if ev?.shiftKey() and @getSelectedRows().length > 0
selectedRow = @getSelectedRows().pop()
idxSelectedRow = selectedRow.getRowIdx()
idxClickedRow = rowChosen.getRowIdx()
while(idxClickedRow != idxSelectedRow)
@getListViewRow(idxClickedRow).select(ev)
if idxClickedRow > idxSelectedRow then idxClickedRow-- else idxClickedRow++
else
# Otherwise all rows are deselected except for the clicked one.
deselectAllRows(false)
else
selectRowChosen()
dfr.promise()
getCellByTarget: ($target) ->
# find the closest listview cell element of the mousemove target
# this is necessary when the mousemove target is a descendant of the cell and the cell element itself never gets to be the direct event target
target = CUI.dom.closest($target, ".cui-lv-td")
if target
cell =
col_i: parseInt(target.getAttribute("col"))
row_i: parseInt(target.getAttribute("row"))
cell.display_col_i = @getDisplayColIdx(cell.col_i)
cell.display_row_i = @getDisplayRowIdx(cell.row_i)
cell
else
null
getRowMoveTool: (opts = {}) ->
new CUI.ListViewRowMove(opts)
getListViewRow: (row_i) ->
CUI.dom.data(@getRow(row_i)[0], "listViewRow")
getDisplayColIdx: (col_i) ->
@colsOrder.indexOf(parseInt(col_i))
getDisplayRowIdx: (row_i) ->
@rowsOrder.indexOf(parseInt(row_i))
getColIdx: (display_col_i) ->
CUI.util.assert(CUI.util.isArray(@colsOrder), "ListView[#{@listViewCounter}].getColIdx", "colsOrder Array is missing", this: @, display_col_i: display_col_i)
@colsOrder[display_col_i]
getRowIdx: (display_row_i) ->
@rowsOrder[display_row_i]
moveInOrderArray: (from_i, to_i, array, after) ->
display_from_i = array.indexOf(from_i)
display_to_i = array.indexOf(to_i)
CUI.util.moveInArray(display_from_i, display_to_i, array, after)
null
moveRow: (from_i, to_i, after=false, trigger_row_moved=true) ->
CUI.util.assert(from_i >= @fixedRowsCount and to_i >= @fixedRowsCount, "ListView.moveRow", "from_i and to_i must not be in flexible area of the list view", from_i: from_i, to_i: to_i, fixed_i: @fixedRowsCount)
if after
func = CUI.dom.insertAfter
else
func = CUI.dom.insertBefore
for row, idx in @getRow(from_i)
func(@getRow(to_i)[idx], (row))
display_from_i = @getDisplayRowIdx(from_i)
display_to_i = @getDisplayRowIdx(to_i)
@moveInOrderArray(from_i, to_i, @rowsOrder, after)
if trigger_row_moved
@_onRowMove?(display_from_i, display_to_i, after)
CUI.Events.trigger
type: "row_moved"
node: @grid
info:
from_i: from_i
to_i: to_i
display_from_i: display_from_i
display_to_i: display_to_i
after: after
@
rowAddClass: (row_i, cls) ->
rows = @getRow(row_i)
if not rows
return
for row in rows
CUI.dom.addClass(row, cls)
@
rowRemoveClass: (row_i, cls) ->
rows = @getRow(row_i)
if not rows
return
for row in rows
CUI.dom.removeClass(row, cls)
@
getColdef: (col_i) ->
@__cols[col_i]
getColsCount: ->
@colsCount
resetColWidth: (col_i) ->
delete(@__manualColWidths[col_i])
@__resetColWidth(col_i)
@__doLayout(resetRows: true)
@
setColWidth: (col_i, width) ->
@__manualColWidths[col_i] = Math.max(5, width)
delete(@__colWidths[col_i])
@__doLayout(resetRows: true)
@
getManualColWidth: (col_i) ->
@__manualColWidths[col_i]
getRowHeight: (row_i) ->
@__rows[row_i][0].offsetHeight
getColWidth: (col_i) ->
@__colWidths[col_i]
getCellGridRect: (row_i, col_i) ->
cell = @__cells[row_i]?[col_i]
if not cell
return null
grid_rect = CUI.dom.getRect(@grid)
pos_grid =
top: grid_rect.top
left: grid_rect.left
dim = CUI.dom.getDimensions(cell)
rect =
left_abs: dim.clientBoundingRect.left
top_abs: dim.clientBoundingRect.top
left: dim.clientBoundingRect.left - pos_grid.left
top: dim.clientBoundingRect.top - pos_grid.top
width: dim.borderBoxWidth
height: dim.borderBoxHeight
contentWidthAdjust: dim.contentWidthAdjust
contentHeightAdjust: dim.contentHeightAdjust
rect
getRowGridRect: (row_i) ->
_rect =
width: 0
for row in @__rows[row_i]
dim = CUI.dom.getDimensions(row)
_rect.width = _rect.width + dim.borderBoxWidth
if not _rect.hasOwnProperty("height")
_rect.height = dim.borderBoxHeight
_rect.top = dim.clientBoundingRect.top
if not _rect.hasOwnProperty("left")
_rect.left = dim.clientBoundingRect.left
grid_rect = CUI.dom.getRect(@grid)
_pos_grid =
top: grid_rect.top
left: grid_rect.left
rect =
left_abs: _rect.left
top_abs: _rect.top
left: _rect.left - _pos_grid.left
top: _rect.top - _pos_grid.top
height: _rect.height
rect.width = CUI.dom.width(@getGrid())
return rect
# rect = @getCellGridRect(0, row_i)
# rect.width = @getGrid().width()
# rect
appendRow: (row, _defer=!@grid) ->
if _defer
@__deferRow(row)
else
@appendRows([row])
prependRow: (row) ->
CUI.util.assert(not @isDestroyed(), "ListView.prependRow", "ListView #{@listViewCounter} is already destroyed.")
row_i = ++@__maxRowIdx
@rowsCount++
@rowsOrder.splice(0, 0, row_i)
@__addRow(row_i, row, "prepend")
replaceRow: (row_i, row) ->
@__addRow(row_i, row, "replace")
insertRowAt: (display_row_i, row) ->
CUI.util.assert(not @isDestroyed(), "ListView.insertRowAfter", "ListView #{@listViewCounter} is already destroyed.")
if display_row_i == @rowsCount or @rowsCount == 0
@appendRow(row)
else if display_row_i == 0
@prependRow(row)
else
@insertRowBefore(@getRowIdx(display_row_i), row)
insertRowAfter: (sibling_row_i, row) ->
CUI.util.assert(not @isDestroyed(), "ListView.insertRowAfter", "ListView ##{@listViewCounter} is already destroyed.")
sibling_display_row_i = @getDisplayRowIdx(sibling_row_i)
CUI.util.assert(sibling_display_row_i > -1, "ListView.insertRowAfter", "ListView ##{@listViewCounter}: Row #{sibling_row_i} not found.", row_i: sibling_row_i, row: row, rowsCount: @rowsCount)
row_i = ++@__maxRowIdx
@rowsCount++
@rowsOrder.splice(sibling_display_row_i+1, 0, row_i)
@__addRow(row_i, row, "after", sibling_row_i)
insertRowBefore: (sibling_row_i, row) ->
CUI.util.assert(not @isDestroyed(), "ListView.insertRowBefore", "ListView ##{@listViewCounter} is already destroyed.")
sibling_display_row_i = @getDisplayRowIdx(sibling_row_i)
if sibling_display_row_i == 0
return @prependRow(row)
before_row_i = @getRowIdx(sibling_display_row_i-1)
row_i = ++@__maxRowIdx
@rowsCount++
@rowsOrder.splice(sibling_display_row_i, 0, row_i)
@__addRow(row_i, row, "after", before_row_i)
removeAllRows: ->
for row_i in @rowsOrder.slice(0)
@removeRow(row_i)
@__scheduleLayout()
@
removeDeferredRow: (listViewRow) ->
count = CUI.util.removeFromArray(listViewRow, @__deferredRows)
CUI.util.assert(count == 1, "ListView.removeListViewRow", "row not found", listViewRow: listViewRow)
@
removeRow: (row_i) ->
CUI.util.assert(row_i != null and row_i >= 0, "ListView.removeRow", "row_i must be >= 0", row_i: row_i)
display_row_i = @getDisplayRowIdx(row_i)
CUI.util.assert(display_row_i > -1, "ListView.removeRow", "display_row_id not found for row_i", row_i: row_i)
@rowsOrder.splice(display_row_i, 1)
@rowsCount--
delete(@__colspanRows[row_i])
for row in @getRow(row_i)
CUI.dom.remove(row)
delete(@__rows[row_i])
@__resetRowDim(row_i)
delete(@__cells[row_i])
@__scheduleLayout()
@
appendDeferredRows: ->
if @__deferredRows.length
@appendRows(@__deferredRows)
@__deferredRows = []
@
getRow: (row_i) ->
@__rows[row_i]
getBottom: ->
@__bottomQuadrants
getTop: ->
@__topQuadrants
__scheduleLayout: ->
# console.error "ListView.__scheduleLayout", @__lvClass
if not @__isInDOM
return
if @layoutIsStopped()
@__layoutAfterStart = true
return
CUI.scheduleCallback(ms: 10, call: @__doLayoutBound)
@
layoutIsStopped: ->
@__layoutIsStopped
stopLayout: ->
# console.error @getUniqueId(), "stopping layout..."
if @__layoutIsStopped
false
else
@__layoutIsStopped = true
true
startLayout: ->
# console.error @getUniqueId(), "starting layout..."
if @__layoutAfterStart
@__layoutAfterStart = false
@__doLayout()
@__layoutIsStopped = null
@
__doLayout: (opts={}) ->
css = []
add_css = (col_i, width) =>
css.push("."+@__lvClass+"-cell[col=\""+col_i+"\"] { width: #{width}px !important; flex: 0 0 auto !important;}")
has_max_cols = false
has_manually_sized_column = false
# set width on colspan cells
@__colWidths = []
for fc, display_col_i in @__fillCells
col_i = @getColIdx(display_col_i)
manual_col_width = @__manualColWidths[col_i]
if manual_col_width > 0
has_manually_sized_column = true
add_css(col_i, manual_col_width)
fc.style.setProperty("width", manual_col_width+"px")
fc.style.setProperty("flex", "0 0 auto")
else
if col_i in @__maxCols
has_max_cols = true
fc.style.removeProperty("width")
fc.style.removeProperty("flex")
for fc, display_col_i in @__fillCells
col_i = @getColIdx(display_col_i)
@__colWidths[col_i] = fc.offsetWidth
if @__maximize_horizontal
if not has_max_cols and has_manually_sized_column
CUI.dom.addClass(@grid, "cui-lv--max-last-col")
else
CUI.dom.removeClass(@grid, "cui-lv--max-last-col")
@styleElement.innerHTML = css.join("\n")
for row_i, row_info of @__colspanRows
for col_i, colspan of row_info
# __cells is populated in find_cells_and_rows with this exact element
# (same int row/col); avoids a full-grid querySelectorAll per colspan cell
cell = @__cells[parseInt(row_i)]?[parseInt(col_i)]
width = 0
for i in [0...colspan] by 1
# we assume that colspanned columns
# are never torn apart, so it is
# safe to add "1" here
width = width + @__colWidths[parseInt(col_i)+i]
dim = CUI.dom.getDimensions(cell)
if not @__useCSSGridLayout
if dim.computedStyle.boxSizing == "border-box"
cell.style.setProperty("width", width+"px", "important")
else
cell.style.setProperty("width", (width - dim.paddingHorizontal - dim.borderHorizontal)+"px", "important")
if @fixedColsCount > 0
# find unmeasured rows in Q2 & Q3 and set height
# in Q2
for qi in [0, 2]
rows = []
if opts.resetRows
sel = ".cui-lv-tr-outer"
else
sel = "[cui-lv-tr-unmeasured=\""+@listViewCounter+"\"]"
for row in CUI.dom.matchSelector(@grid, "."+@__lvClass+"-quadrant[cui-lv-quadrant='#{qi}'] > "+sel)
rows[parseInt(CUI.dom.getAttribute(row, "row"))] = row
CUI.dom.removeAttribute(row, "cui-lv-tr-unmeasured")
for row, idx in CUI.dom.matchSelector(@grid, "."+@__lvClass+"-quadrant[cui-lv-quadrant='#{qi+1}'] > "+sel)
row_i2 = parseInt(CUI.dom.getAttribute(row, "row"))
CUI.dom.prepareSetDimensions(rows[row_i2])
row.__offsetHeight = row.offsetHeight
for row, idx in CUI.dom.matchSelector(@grid, "."+@__lvClass+"-quadrant[cui-lv-quadrant='#{qi+1}'] > "+sel)
row_i2 = parseInt(CUI.dom.getAttribute(row, "row"))
CUI.dom.setDimensions(rows[row_i2], borderBoxHeight: row.__offsetHeight)
delete(row.__offsetHeight)
CUI.dom.removeAttribute(row, "cui-lv-tr-unmeasured")
@__setMargins()
@__addRowsOddEvenClasses()
@__hasLayout = true
@
__addRowsOddEvenClasses: ->
if (@rowsCount - @fixedRowsCount)%2 == 0
CUI.dom.addClass(@grid, "cui-list-view-grid-rows-even")
CUI.dom.removeClass(@grid, "cui-list-view-grid-rows-odd")
else
CUI.dom.removeClass(@grid, "cui-list-view-grid-rows-even")
CUI.dom.addClass(@grid, "cui-list-view-grid-rows-odd")
@
__getValue: (px) ->
if not isNaN(parseFloat(px))
px+"px"
else if CUI.util.isNull(px)
""
else
px
hideWaitBlock: ->
if @__waitBlock
@__waitBlock.destroy()
delete(@__waitBlock)
@
showWaitBlock: ->
if @__waitBlock
return @
@__waitBlock = new CUI.WaitBlock(element: @DOM)
@__waitBlock.show()
@