/
TableAdapter.js
726 lines (636 loc) · 23.9 KB
/
TableAdapter.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
/*******************************************************************************
* Copyright (c) 2014-2018 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
******************************************************************************/
scout.TableAdapter = function() {
scout.TableAdapter.parent.call(this);
this._addRemoteProperties(['contextColumn']);
};
scout.inherits(scout.TableAdapter, scout.ModelAdapter);
scout.TableAdapter.prototype._postCreateWidget = function() {
// if a newly created table has already a userfilter defined, we need to fire the filter event after creation
// because the original event had been fired before the eventhandler was registered.
if (scout.objects.values(this.widget._filterMap).some(function(filter) {
return filter instanceof scout.TableUserFilter;
})) {
this._onWidgetFilter();
}
};
scout.TableAdapter.prototype._sendRowsSelected = function(rowIds, debounceSend) {
var eventData = {
rowIds: rowIds
};
// send delayed to avoid a lot of requests while selecting
// coalesce: only send the latest selection changed event for a field
this._send('rowsSelected', eventData, {
delay: debounceSend ? 250 : 0,
coalesce: function(previous) {
return this.target === previous.target && this.type === previous.type;
}
});
};
scout.TableAdapter.prototype._sendRowClick = function(rowId, mouseButton, columnId) {
var data = {
rowId: rowId,
columnId: columnId,
mouseButton: mouseButton
};
this._send('rowClick', data);
};
scout.TableAdapter.prototype._onWidgetRowsSelected = function(event) {
var rowIds = this.widget._rowsToIds(this.widget.selectedRows);
this._sendRowsSelected(rowIds, event.debounce);
};
scout.TableAdapter.prototype._onWidgetRowClick = function(event) {
var columnId;
if (event.column !== undefined) {
columnId = event.column.id;
}
this._sendRowClick(event.row.id, event.mouseButton, columnId);
};
scout.TableAdapter.prototype._onWidgetFilterAdded = function(event) {
var filter = event.filter;
if (filter instanceof scout.TableUserFilter) {
this._send('filterAdded', filter.createFilterAddedEventData());
}
};
scout.TableAdapter.prototype._onWidgetFilterRemoved = function(event) {
var filter = event.filter;
if (filter instanceof scout.TableUserFilter) {
this._send('filterRemoved', filter.createFilterRemovedEventData());
}
};
scout.TableAdapter.prototype._onWidgetColumnResized = function(event) {
this._sendColumnResized(event.column);
};
scout.TableAdapter.prototype._sendColumnResized = function(column) {
if (column.fixedWidth || this.widget.autoResizeColumns) {
return;
}
var eventData = {
columnId: column.id,
width: column.width
};
// send delayed to avoid a lot of requests while resizing
// coalesce: only send the latest resize event for a column
this._send('columnResized', eventData, {
delay: 750,
coalesce: function(previous) {
return this.target === previous.target && this.type === previous.type && this.columnId === previous.columnId;
},
showBusyIndicator: false
});
};
scout.TableAdapter.prototype._onWidgetAggregationFunctionChanged = function(event) {
this._sendAggregationFunctionChanged(event.column);
};
scout.TableAdapter.prototype._sendAggregationFunctionChanged = function(column) {
var data = {
columnId: column.id,
aggregationFunction: column.aggregationFunction
};
this._send('aggregationFunctionChanged', data);
};
scout.TableAdapter.prototype._onWidgetColumnBackgroundEffectChanged = function(event) {
this._sendColumnBackgroundEffectChanged(event.column);
};
scout.TableAdapter.prototype._sendColumnBackgroundEffectChanged = function(column) {
var data = {
columnId: column.id,
backgroundEffect: column.backgroundEffect
};
this._send('columnBackgroundEffectChanged', data);
};
scout.TableAdapter.prototype._onWidgetColumnOrganizeAction = function(event) {
this._send('columnOrganizeAction', {
action: event.action,
columnId: event.column.id
});
};
scout.TableAdapter.prototype._onWidgetColumnMoved = function(event) {
var index = event.newPos;
this.widget.columns.forEach(function(iteratingColumn, i) {
// Adjust index if column is only known on the gui
if (iteratingColumn.guiOnly) {
index--;
}
});
this._sendColumnMoved(event.column, index);
};
scout.TableAdapter.prototype._sendColumnMoved = function(column, index) {
var data = {
columnId: column.id,
index: index
};
this._send('columnMoved', data);
};
scout.TableAdapter.prototype._onWidgetPrepareCellEdit = function(event) {
event.preventDefault();
this._sendPrepareCellEdit(event.row, event.column);
};
scout.TableAdapter.prototype._sendPrepareCellEdit = function(row, column) {
var data = {
rowId: row.id,
columnId: column.id
};
this._send('prepareCellEdit', data);
};
scout.TableAdapter.prototype._onWidgetCompleteCellEdit = function(event) {
event.preventDefault();
this._sendCompleteCellEdit(event.field);
};
scout.TableAdapter.prototype._sendCompleteCellEdit = function(field) {
var data = {
fieldId: field.id
};
this._send('completeCellEdit', data);
};
scout.TableAdapter.prototype._onWidgetCancelCellEdit = function(event) {
event.preventDefault();
this._sendCancelCellEdit(event.field);
};
scout.TableAdapter.prototype._sendCancelCellEdit = function(field) {
var data = {
fieldId: field.id
};
this._send('cancelCellEdit', data);
};
scout.TableAdapter.prototype._onWidgetRowsChecked = function(event) {
this._sendRowsChecked(event.rows);
};
scout.TableAdapter.prototype._sendRowsChecked = function(rows) {
var data = {
rows: []
};
for (var i = 0; i < rows.length; i++) {
data.rows.push({
rowId: rows[i].id,
checked: rows[i].checked
});
}
this._send('rowsChecked', data);
};
scout.TableAdapter.prototype._onWidgetRowsExpanded = function(event) {
this._sendRowsExpanded(event.rows);
};
scout.TableAdapter.prototype._sendRowsExpanded = function(rows) {
var data = {
rows: rows.map(function(row) {
return {
rowId: row.id,
expanded: row.expanded
};
})
};
this._send('rowsExpanded', data);
};
scout.TableAdapter.prototype._onWidgetFilter = function(event) {
var rowIds = this.widget._rowsToIds(this.widget.filteredRows());
this._sendFilter(rowIds);
};
scout.TableAdapter.prototype._sendFilter = function(rowIds) {
var eventData = {};
if (rowIds.length === this.widget.rows.length) {
eventData.remove = true;
} else {
eventData.rowIds = rowIds;
}
// send with timeout, mainly for incremental load of a large table
// coalesce: only send last event (don't coalesce remove and 'add' events, the UI server needs both)
this._send('filter', eventData, {
delay: 250,
coalesce: function(previous) {
return this.target === previous.target && this.type === previous.type && this.remove === previous.remove;
},
showBusyIndicator: false
});
};
scout.TableAdapter.prototype._onWidgetSort = function(event) {
this._send('sort', {
columnId: event.column.id,
sortAscending: event.sortAscending,
sortingRemoved: event.sortingRemoved,
multiSort: event.multiSort,
sortingRequested: event.sortingRequested
});
};
scout.TableAdapter.prototype._onWidgetGroup = function(event) {
this._send('group', {
columnId: event.column.id,
groupAscending: event.groupAscending,
groupingRemoved: event.groupingRemoved,
multiGroup: event.multiGroup,
groupingRequested: event.groupingRequested
});
};
scout.TableAdapter.prototype._onWidgetRowAction = function(event) {
this._sendRowAction(event.row, event.column);
};
scout.TableAdapter.prototype._sendRowAction = function(row, column) {
this._send('rowAction', {
rowId: row.id,
columnId: column.id
});
};
scout.TableAdapter.prototype._onWidgetAppLinkAction = function(event) {
this._sendAppLinkAction(event.column, event.ref);
};
scout.TableAdapter.prototype._sendAppLinkAction = function(column, ref) {
this._send('appLinkAction', {
columnId: column.id,
ref: ref
});
};
scout.TableAdapter.prototype._sendContextColumn = function(contextColumn) {
if (contextColumn.guiOnly) {
contextColumn = null;
this.widget.contextColumn = null;
}
var columnId = null;
if (contextColumn) {
columnId = contextColumn.id;
}
this._send('property', {
contextColumn: columnId
});
};
scout.TableAdapter.prototype._onWidgetReload = function(event) {
var data = {
reloadReason: event.reloadReason
};
this._send('reload', data);
};
scout.TableAdapter.prototype._onWidgetExportToClipboard = function(event) {
this._send('clipboardExport');
event.preventDefault();
};
scout.TableAdapter.prototype._onWidgetEvent = function(event) {
if (event.type === 'rowsSelected') {
this._onWidgetRowsSelected(event);
} else if (event.type === 'rowsChecked') {
this._onWidgetRowsChecked(event);
} else if (event.type === 'rowsExpanded') {
this._onWidgetRowsExpanded(event);
} else if (event.type === 'filter') {
this._onWidgetFilter(event);
} else if (event.type === 'sort') {
this._onWidgetSort(event);
} else if (event.type === 'group') {
this._onWidgetGroup(event);
} else if (event.type === 'rowClick') {
this._onWidgetRowClick(event);
} else if (event.type === 'rowAction') {
this._onWidgetRowAction(event);
} else if (event.type === 'prepareCellEdit') {
this._onWidgetPrepareCellEdit(event);
} else if (event.type === 'completeCellEdit') {
this._onWidgetCompleteCellEdit(event);
} else if (event.type === 'cancelCellEdit') {
this._onWidgetCancelCellEdit(event);
} else if (event.type === 'appLinkAction') {
this._onWidgetAppLinkAction(event);
} else if (event.type === 'clipboardExport') {
this._onWidgetExportToClipboard(event);
} else if (event.type === 'reload') {
this._onWidgetReload(event);
} else if (event.type === 'filterAdded') {
this._onWidgetFilterAdded(event);
} else if (event.type === 'filterRemoved') {
this._onWidgetFilterRemoved(event);
} else if (event.type === 'columnResized') {
this._onWidgetColumnResized(event);
} else if (event.type === 'columnMoved') {
this._onWidgetColumnMoved(event);
} else if (event.type === 'columnBackgroundEffectChanged') {
this._onWidgetColumnBackgroundEffectChanged(event);
} else if (event.type === 'columnOrganizeAction') {
this._onWidgetColumnOrganizeAction(event);
} else if (event.type === 'aggregationFunctionChanged') {
this._onWidgetAggregationFunctionChanged(event);
} else if (event.type === 'drop' && this.widget.dragAndDropHandler) {
this.widget.dragAndDropHandler.uploadFiles(event.files);
} else {
scout.TableAdapter.parent.prototype._onWidgetEvent.call(this, event);
}
};
scout.TableAdapter.prototype._onRowsInserted = function(rows) {
this.widget.insertRows(rows);
this._rebuildingTable = false;
};
scout.TableAdapter.prototype._onRowsDeleted = function(rowIds) {
var rows = this.widget._rowsByIds(rowIds);
this.addFilterForWidgetEventType('rowsSelected');
this.widget.deleteRows(rows);
};
scout.TableAdapter.prototype._onAllRowsDeleted = function() {
this.addFilterForWidgetEventType('rowsSelected');
this.widget.deleteAllRows();
};
scout.TableAdapter.prototype._onRowsUpdated = function(rows) {
this.widget.updateRows(rows);
};
scout.TableAdapter.prototype._onRowsSelected = function(rowIds) {
var rows = this.widget._rowsByIds(rowIds);
this.addFilterForWidgetEventType('rowsSelected');
this.widget.selectRows(rows);
// TODO [7.0] cgu what is this for? seems wrong here
this.widget.selectionHandler.clearLastSelectedRowMarker();
};
scout.TableAdapter.prototype._onRowsChecked = function(rows) {
var checkedRows = [],
uncheckedRows = [];
rows.forEach(function(rowData) {
var row = this.widget._rowById(rowData.id);
if (rowData.checked) {
checkedRows.push(row);
} else {
uncheckedRows.push(row);
}
}, this);
this.addFilterForWidgetEventType('rowsChecked');
this.widget.checkRows(checkedRows, {
checked: true,
checkOnlyEnabled: false
});
this.widget.uncheckRows(uncheckedRows, {
checkOnlyEnabled: false
});
};
scout.TableAdapter.prototype._onRowsExpanded = function(rows) {
var expandedRows = [],
collapsedRows = [];
rows.forEach(function(rowData) {
var row = this.widget._rowById(rowData.id);
if (rowData.expanded) {
expandedRows.push(row);
} else {
collapsedRows.push(row);
}
}, this);
this.addFilterForWidgetEventType('rowsExpanded');
this.widget.expandRows(expandedRows);
this.widget.collapseRows(collapsedRows);
};
scout.TableAdapter.prototype._onRowOrderChanged = function(rowIds) {
var rows = this.widget._rowsByIds(rowIds);
this.widget.updateRowOrder(rows);
};
scout.TableAdapter.prototype._onColumnStructureChanged = function(columns) {
this._rebuildingTable = true;
this.widget.updateColumnStructure(columns);
};
scout.TableAdapter.prototype._onColumnOrderChanged = function(columnIds) {
var columns = this.widget.columnsByIds(columnIds);
this.widget.updateColumnOrder(columns);
};
scout.TableAdapter.prototype._onColumnHeadersUpdated = function(columns) {
columns.forEach(function(column) {
scout.defaultValues.applyTo(column);
});
this.widget.updateColumnHeaders(columns);
};
scout.TableAdapter.prototype._onStartCellEdit = function(columnId, rowId, fieldId) {
var column = this.widget.columnById(columnId),
row = this.widget._rowById(rowId),
field = this.session.getOrCreateWidget(fieldId, this.widget);
this.widget.startCellEdit(column, row, field);
};
scout.TableAdapter.prototype._onEndCellEdit = function(fieldId) {
var field = this.session.getModelAdapter(fieldId);
this.widget.endCellEdit(field.widget);
};
scout.TableAdapter.prototype._onRequestFocus = function() {
this.widget.focus();
};
scout.TableAdapter.prototype._onScrollToSelection = function() {
this.widget.revealSelection();
};
scout.TableAdapter.prototype._onColumnBackgroundEffectChanged = function(event) {
event.eventParts.forEach(function(eventPart) {
var column = this.widget.columnById(eventPart.columnId),
backgroundEffect = eventPart.backgroundEffect;
this.addFilterForWidgetEvent(function(widgetEvent) {
return (widgetEvent.type === 'columnBackgroundEffectChanged' &&
widgetEvent.column.id === column.id &&
widgetEvent.column.backgroundEffect === backgroundEffect);
});
column.setBackgroundEffect(backgroundEffect);
}, this);
};
scout.TableAdapter.prototype._onRequestFocusInCell = function(event) {
var row = this.widget._rowById(event.rowId),
column = this.widget.columnById(event.columnId);
this.widget.focusCell(column, row);
};
scout.TableAdapter.prototype._onAggregationFunctionChanged = function(event) {
var columns = [],
functions = [];
event.eventParts.forEach(function(eventPart) {
var func = eventPart.aggregationFunction,
column = this.widget.columnById(eventPart.columnId);
this.addFilterForWidgetEvent(function(widgetEvent) {
return (widgetEvent.type === 'aggregationFunctionChanged' &&
widgetEvent.column.id === column.id &&
widgetEvent.column.aggregationFunction === func);
});
columns.push(column);
functions.push(func);
}, this);
this.widget.changeAggregations(columns, functions);
};
scout.TableAdapter.prototype._onFiltersChanged = function(filters) {
this.addFilterForWidgetEventType('filterAdded');
this.addFilterForWidgetEventType('filterRemoved');
this.widget.setFilters(filters);
// do not refilter while the table is being rebuilt (because column.index in filter and row.cells may be inconsistent)
if (!this._rebuildingTable) {
this.widget.filter();
}
};
scout.TableAdapter.prototype.onModelAction = function(event) {
if (event.type === 'rowsInserted') {
this._onRowsInserted(event.rows);
} else if (event.type === 'rowsDeleted') {
this._onRowsDeleted(event.rowIds);
} else if (event.type === 'allRowsDeleted') {
this._onAllRowsDeleted();
} else if (event.type === 'rowsSelected') {
this._onRowsSelected(event.rowIds);
} else if (event.type === 'rowOrderChanged') {
this._onRowOrderChanged(event.rowIds);
} else if (event.type === 'rowsUpdated') {
this._onRowsUpdated(event.rows);
} else if (event.type === 'filtersChanged') {
this._onFiltersChanged(event.filters);
} else if (event.type === 'rowsChecked') {
this._onRowsChecked(event.rows);
} else if (event.type === 'rowsExpanded') {
this._onRowsExpanded(event.rows);
} else if (event.type === 'columnStructureChanged') {
this._onColumnStructureChanged(event.columns);
} else if (event.type === 'columnOrderChanged') {
this._onColumnOrderChanged(event.columnIds);
} else if (event.type === 'columnHeadersUpdated') {
this._onColumnHeadersUpdated(event.columns);
} else if (event.type === 'startCellEdit') {
this._onStartCellEdit(event.columnId, event.rowId, event.fieldId);
} else if (event.type === 'endCellEdit') {
this._onEndCellEdit(event.fieldId);
} else if (event.type === 'requestFocus') {
this._onRequestFocus();
} else if (event.type === 'scrollToSelection') {
this._onScrollToSelection();
} else if (event.type === 'aggregationFunctionChanged') {
this._onAggregationFunctionChanged(event);
} else if (event.type === 'columnBackgroundEffectChanged') {
this._onColumnBackgroundEffectChanged(event);
} else if (event.type === 'requestFocusInCell') {
this._onRequestFocusInCell(event);
} else {
scout.TableAdapter.parent.prototype.onModelAction.call(this, event);
}
};
/**
* @override ModelAdapter.js
*/
scout.TableAdapter.prototype.exportAdapterData = function(adapterData) {
adapterData = scout.TableAdapter.parent.prototype.exportAdapterData.call(this, adapterData);
delete adapterData.selectedRows;
adapterData.rows = [];
adapterData.columns.forEach(function(column) {
delete column.classId;
delete column.modelClass;
});
return adapterData;
};
/**
* Static method to modify the prototype of scout.Table.
*/
scout.TableAdapter.modifyTablePrototype = function() {
if (!scout.app.remote) {
return;
}
// _sortAfterInsert
scout.objects.replacePrototypeFunction(scout.Table, '_sortAfterInsert', function(wasEmpty) {
if (this.modelAdapter) {
// There will only be a row order changed event if table was not empty.
// If it was empty, there will be NO row order changed event (tableEventBuffer) -> inserted rows are already in correct order -> no sort necessary but group is
if (wasEmpty) {
this._group();
}
} else {
this._sortAfterInsertOrig(wasEmpty);
}
}, true);
// _sortAfterUpdate
scout.objects.replacePrototypeFunction(scout.Table, '_sortAfterUpdate', function() {
if (this.modelAdapter) {
this._group();
} else {
this._sortAfterUpdateOrig();
}
}, true);
// uiSortPossible
scout.objects.replacePrototypeFunction(scout.Table, '_isSortingPossible', function(sortColumns) {
if (this.modelAdapter) {
// In a JS only app the flag 'uiSortPossible' is never set and thus defaults to true. Additionally we check if each column can install
// its comparator used to sort. If installation failed for some reason, sorting is not possible. In a remote app the server sets the
// 'uiSortPossible' flag, which decides if the column must be sorted by the server or can be sorted by the client.
var uiSortPossible = scout.nvl(this.uiSortPossible, true);
return uiSortPossible && this._isSortingPossibleOrig(sortColumns);
}
return this._isSortingPossibleOrig(sortColumns);
}, true);
// sort
scout.objects.replacePrototypeFunction(scout.Table, 'sort', function(column, direction, multiSort, remove) {
if (this.modelAdapter && column.guiOnly) {
return;
}
this.sortOrig(column, direction, multiSort, remove);
}, true);
};
scout.TableAdapter.modifyColumnPrototype = function() {
if (!scout.app.remote) {
return;
}
// init
scout.objects.replacePrototypeFunction(scout.Column, 'init', function(model) {
if (model.table && model.table.modelAdapter) {
// Fill in the missing default values only in remote case, don't do it JS case to not accidentally set undefined properties (e.g. uiSortEnabled)
model = $.extend({}, model);
scout.defaultValues.applyTo(model);
}
this.initOrig(model);
}, true);
// _ensureCell
scout.objects.replacePrototypeFunction(scout.Column, '_ensureCell', function(vararg) {
if (this.table.modelAdapter) {
// Note: we do almost the same thing as in _ensureCellOrig, the difference is that
// we treat a plain object always as cell-model and we always must apply defaultValues
// to this cell model. In the JS only case a plain-object has no special meaning and
// can be used as cell-value in the same way as a scalar value. Also we must not apply
// defaultValues in JS only case, because it would destroy the 'undefined' state of the
// cell properties, which is required because the Column checks, whether it should apply
// defaults from the Column instance to a cell, or use the values from the cell.
var model;
if (scout.objects.isPlainObject(vararg)) {
model = vararg;
model.value = this._parseValue(model.value);
// Parse the value if a text but no value is provided. The server does only set the text if value and text are equal.
// It is also necessary for custom columns which don't have a UI representation and never send the value.
// Do not parse the value if there is an error status.
// If editing fails, the display text will be the user input, the value unchanged, and the server will set the error status.
if (model.text && model.value === undefined && !model.errorStatus) {
model.value = this._parseValue(model.text);
}
// use null instead of undefined
if (model.value === undefined) {
model.value = null;
}
} else {
model = {
value: this._parseValue(vararg)
};
}
scout.defaultValues.applyTo(model, 'Cell');
return scout.create('Cell', model);
} else {
return this._ensureCellOrig(vararg);
}
}, true);
// uiSortPossible
scout.objects.replacePrototypeFunction(scout.Column, 'isSortingPossible', function() {
if (this.table.modelAdapter) {
// Returns whether or not this column can be used to sort on the client side. In a JS only app the flag 'uiSortPossible'
// is never set and defaults to true. As a side effect of this function a comparator is installed.
// The comparator returns false if it could not be installed which means sorting should be delegated to server (e.g. collator is not available).
// In a remote app the server sets the 'uiSortPossible' flag, which decides if the column must be sorted by the
// server or can be sorted by the client.
var uiSortPossible = scout.nvl(this.uiSortPossible, true);
return uiSortPossible && this.installComparator();
}
return this.isSortingPossibleOrig();
}, true);
};
scout.TableAdapter.modifyBooleanColumnPrototype = function() {
if (!scout.app.remote) {
return;
}
// _toggleCellValue
scout.objects.replacePrototypeFunction(scout.BooleanColumn, '_toggleCellValue', function(row, cell) {
if (this.table.modelAdapter) {
// NOP - do nothing, since server will handle the click, see Java AbstractTable#interceptRowClickSingleObserver
} else {
this._toggleCellValueOrig(row, cell);
}
}, true);
};
scout.addAppListener('bootstrap', scout.TableAdapter.modifyTablePrototype);
scout.addAppListener('bootstrap', scout.TableAdapter.modifyColumnPrototype);
scout.addAppListener('bootstrap', scout.TableAdapter.modifyBooleanColumnPrototype);