-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDataRegion.js
More file actions
5088 lines (4354 loc) · 197 KB
/
DataRegion.js
File metadata and controls
5088 lines (4354 loc) · 197 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
/*
* Copyright (c) 2015-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
if (!LABKEY.DataRegions) {
LABKEY.DataRegions = {};
}
(function($) {
//
// CONSTANTS
//
// Issue 48715: Limit the number of rows that can be displayed in a data region
var ALL_ROWS_MAX = 5_000;
var CUSTOM_VIEW_PANELID = '~~customizeView~~';
var DEFAULT_TIMEOUT = 30_000;
const MAX_SELECTION_SIZE = LABKEY.moduleContext?.query?.maxQuerySelection ?? 100_000;
var PARAM_PREFIX = '.param.';
var SORT_ASC = '+';
var SORT_DESC = '-';
//
// URL PREFIXES
//
var ALL_FILTERS_SKIP_PREFIX = '.~';
var COLUMNS_PREFIX = '.columns';
var CONTAINER_FILTER_NAME = '.containerFilterName';
var MAX_ROWS_PREFIX = '.maxRows';
var OFFSET_PREFIX = '.offset';
var REPORTID_PREFIX = '.reportId';
var SORT_PREFIX = '.sort';
var SHOW_ROWS_PREFIX = '.showRows';
var VIEWNAME_PREFIX = '.viewName';
// Issue 33536: These prefixes should match the URL parameter key exactly
var EXACT_MATCH_PREFIXES = [
COLUMNS_PREFIX,
CONTAINER_FILTER_NAME,
MAX_ROWS_PREFIX,
OFFSET_PREFIX,
REPORTID_PREFIX,
SORT_PREFIX,
SHOW_ROWS_PREFIX,
VIEWNAME_PREFIX
];
var VALID_LISTENERS = [
/**
* @memberOf LABKEY.DataRegion.prototype
* @name afterpanelhide
* @event LABKEY.DataRegion.prototype#hidePanel
* @description Fires after hiding a visible 'Customize Grid' panel.
*/
'afterpanelhide',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name afterpanelshow
* @event LABKEY.DataRegion.prototype.showPanel
* @description Fires after showing 'Customize Grid' panel.
*/
'afterpanelshow',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforechangeview
* @event
* @description Fires before changing grid/view/report.
* @see LABKEY.DataRegion#changeView
*/
'beforechangeview',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforeclearsort
* @event
* @description Fires before clearing sort applied to grid.
* @see LABKEY.DataRegion#clearSort
*/
'beforeclearsort',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforemaxrowschange
* @event
* @description Fires before change page size.
* @see LABKEY.DataRegion#setMaxRows
*/
'beforemaxrowschange',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforeoffsetchange
* @event
* @description Fires before change page number.
* @see LABKEY.DataRegion#setPageOffset
*/
'beforeoffsetchange',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforerefresh
* @event
* @description Fires before refresh grid.
* @see LABKEY.DataRegion#refresh
*/
'beforerefresh',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforesetparameters
* @event
* @description Fires before setting the parameterized query values for this query.
* @see LABKEY.DataRegion#setParameters
*/
'beforesetparameters',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name beforesortchange
* @event
* @description Fires before change sorting on the grid.
* @see LABKEY.DataRegion#changeSort
*/
'beforesortchange',
/**
* @memberOf LABKEY.DataRegion.prototype
* @member
* @name render
* @event
* @description Fires when data region renders.
*/
'render',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name selectchange
* @event
* @description Fires when data region selection changes.
*/
'selectchange',
/**
* @memberOf LABKEY.DataRegion.prototype
* @name success
* @event
* @description Fires when data region loads successfully.
*/
'success'];
// TODO: Update constants to not include '.' so mapping can be used easier
var REQUIRE_NAME_PREFIX = {
'~': true,
'columns': true,
'param': true,
'reportId': true,
'sort': true,
'offset': true,
'maxRows': true,
'showRows': true,
'containerFilterName': true,
'viewName': true,
'disableAnalytics': true
};
//
// PRIVATE VARIABLES
//
var _paneCache = {};
/**
* The DataRegion constructor is private - to get a LABKEY.DataRegion object, use LABKEY.DataRegions['dataregionname'].
* @class LABKEY.DataRegion
* The DataRegion class allows you to interact with LabKey grids, including querying and modifying selection state, filters, and more.
* @constructor
*/
LABKEY.DataRegion = function(config) {
_init.call(this, config, true);
};
LABKEY.DataRegion.prototype.toJSON = function() {
return {
name: this.name,
schemaName: this.schemaName,
queryName: this.queryName,
viewName: this.viewName,
offset: this.offset,
maxRows: this.maxRows,
messages: this.msgbox.toJSON() // hmm, unsure exactly how this works
};
};
/**
*
* @param {Object} config
* @param {Boolean} [applyDefaults=false]
* @private
*/
var _init = function(config, applyDefaults) {
// ensure name
if (!config.dataRegionName) {
if (!config.name) {
this.name = LABKEY.Utils.id('aqwp');
}
else {
this.name = config.name;
}
}
else if (!config.name) {
this.name = config.dataRegionName;
}
else {
this.name = config.name;
}
if (!this.name) {
throw '"name" is required to initialize a LABKEY.DataRegion';
}
// _useQWPDefaults is only used on initial construction
var isQWP = config._useQWPDefaults === true;
delete config._useQWPDefaults;
if (config.buttonBar && config.buttonBar.items && LABKEY.Utils.isArray(config.buttonBar.items)) {
// Be tolerant of the caller passing in undefined items, as pageSize has been removed as an option. Strip
// them out so they don't cause problems downstream. See Issue 34562.
config.buttonBar.items = config.buttonBar.items.filter(function (value, index, arr) {
return value;
});
}
var settings;
if (applyDefaults) {
// defensively remove, not allowed to be set
delete config._userSort;
/**
* Config Options
*/
var defaults = {
_allowHeaderLock: isQWP,
_failure: isQWP ? LABKEY.Utils.getOnFailure(config) : undefined,
_success: isQWP ? LABKEY.Utils.getOnSuccess(config) : undefined,
aggregates: undefined,
allowChooseQuery: undefined,
allowChooseView: undefined,
async: isQWP,
bodyClass: undefined,
buttonBar: undefined,
buttonBarPosition: undefined,
chartWizardURL: undefined,
/**
* All rows visible on the current page.
*/
complete: false,
/**
* The currently applied container filter. Note, this is only if it is set on the URL, otherwise
* the containerFilter could come from the view configuration. Use getContainerFilter()
* on this object to get the right value.
*/
containerFilter: undefined,
containerPath: undefined,
/**
* @deprecated use region.name instead
*/
dataRegionName: this.name,
detailsURL: undefined,
domId: undefined,
/**
* The faceted filter pane as been loaded
* @private
*/
facetLoaded: false,
filters: undefined,
frame: isQWP ? undefined : 'none',
errorType: 'html',
/**
* Id of the DataRegion. Same as name property.
*/
id: this.name,
deleteURL: undefined,
importURL: undefined,
insertURL: undefined,
linkTarget: undefined,
/**
* Maximum number of rows to be displayed. 0 if the count is not limited. Read-only.
*/
maxRows: 0,
metadata: undefined,
/**
* Name of the DataRegion. Should be unique within a given page. Read-only. This will also be used as the id.
*/
name: this.name,
/**
* The index of the first row to return from the server (defaults to 0). Use this along with the maxRows config property to request pages of data.
*/
offset: 0,
parameters: undefined,
/**
* Name of the query to which this DataRegion is bound. Read-only.
*/
queryName: '',
disableAnalytics: false,
removeableContainerFilter: undefined,
removeableFilters: undefined,
removeableSort: undefined,
renderTo: undefined,
reportId: undefined,
requestURL: isQWP ? window.location.href : (document.location.search.substring(1) /* strip the ? */ || ''),
returnUrl: isQWP ? window.location.href : undefined,
/**
* Schema name of the query to which this DataRegion is bound. Read-only.
*/
schemaName: '',
/**
* An object to use as the callback function's scope. Defaults to this.
*/
scope: this,
/**
* URL to use when selecting all rows in the grid. May be null. Read-only.
*/
selectAllURL: undefined,
selectedCount: 0,
shadeAlternatingRows: undefined,
showBorders: undefined,
showDeleteButton: undefined,
showDetailsColumn: undefined,
showExportButtons: undefined,
showRStudioButton: undefined,
showImportDataButton: undefined,
showInsertNewButton: undefined,
showPagination: undefined,
showPaginationCount: undefined,
showPaginationCountAsync: false,
showRecordSelectors: false,
showFilterDescription: true,
showReports: undefined,
/**
* An enum declaring which set of rows to show. all | selected | unselected | paginated
*/
showRows: 'paginated',
showSurroundingBorder: undefined,
showUpdateColumn: undefined,
/**
* Open the customize view panel after rendering. The value of this option can be "true" or one of "ColumnsTab", "FilterTab", or "SortTab".
*/
showViewPanel: undefined,
sort: undefined,
sql: undefined,
/**
* If true, no alert will appear if there is a problem rendering the QueryWebpart. This is most often encountered if page configuration changes between the time when a request was made and the content loads. Defaults to false.
*/
suppressRenderErrors: false,
/**
* A timeout for the AJAX call, in milliseconds.
*/
timeout: undefined,
title: undefined,
titleHref: undefined,
totalRows: undefined, // totalRows isn't available when showing all rows.
updateURL: undefined,
userContainerFilter: undefined, // TODO: Incorporate this with the standard containerFilter
userFilters: {},
/**
* Name of the custom view to which this DataRegion is bound, may be blank. Read-only.
*/
viewName: null
};
settings = $.extend({}, defaults, config);
}
else {
settings = $.extend({}, config);
}
// if showPaginationCountAsync is set to true, make sure that showPaginationCount is false
if (settings.showPaginationCountAsync && settings.showPaginationCount) {
settings.showPaginationCount = false;
}
// if 'filters' is not specified and 'filterArray' is, use 'filterArray'
if (!LABKEY.Utils.isArray(settings.filters) && LABKEY.Utils.isArray(config.filterArray)) {
settings.filters = config.filterArray;
}
// Any 'key' of this object will not be copied from settings to the region instance
var blackList = {
failure: true,
success: true
};
for (var s in settings) {
if (settings.hasOwnProperty(s) && !blackList[s]) {
this[s] = settings[s];
}
}
if (config.renderTo) {
_convertRenderTo(this, config.renderTo);
}
if (LABKEY.Utils.isArray(this.removeableFilters)) {
LABKEY.Filter.appendFilterParams(this.userFilters, this.removeableFilters, this.name);
delete this.removeableFilters; // they've been applied
}
// initialize sorting
if (this._userSort === undefined) {
this._userSort = _getUserSort(this, true /* asString */);
}
if (LABKEY.Utils.isString(this.removeableSort)) {
this._userSort = this.removeableSort + (this._userSort ? this._userSort : '');
delete this.removeableSort;
}
this._allowHeaderLock = this.allowHeaderLock === true;
if (!config.messages) {
this.messages = {};
}
/**
* @ignore
* Non-configurable Options
*/
this.selectionModified = false;
this.selectionLoading = false;
if (this.panelConfigurations === undefined) {
this.panelConfigurations = {};
}
if (isQWP && this.renderTo) {
_load(this);
}
else if (!isQWP) {
_initContexts.call(this);
_initMessaging.call(this);
_initSelection.call(this);
_initPaging.call(this);
_initHeaderLocking.call(this);
_initCustomViews.call(this);
_initPanes.call(this);
_initReport.call(this);
}
// else the user needs to call render
// bind supported listeners
if (isQWP) {
var me = this;
if (config.listeners) {
var scope = config.listeners.scope || me;
$.each(config.listeners, function(event, handler) {
if ($.inArray(event, VALID_LISTENERS) > -1) {
// support either "event: function" or "event: { fn: function }"
var callback;
if ($.isFunction(handler)) {
callback = handler;
}
else if ($.isFunction(handler.fn)) {
callback = handler.fn;
}
else {
throw 'Unsupported listener configuration: ' + event;
}
$(me).bind(event, function() {
callback.apply(scope, $(arguments).slice(1));
});
}
else if (event != 'scope') {
throw 'Unsupported listener: ' + event;
}
});
}
}
};
LABKEY.DataRegion.prototype.destroy = function() {
// clean-up panel configurations because we preserve this in init
this.panelConfigurations = {};
// currently a no-op, but should be used to clean-up after ourselves
this.disableHeaderLock();
};
/**
* Refreshes the grid, via AJAX region is in async mode (loaded through a QueryWebPart),
* and via a page reload otherwise. Can be prevented with a listener
* on the 'beforerefresh'
* event.
*/
LABKEY.DataRegion.prototype.refresh = function() {
$(this).trigger('beforerefresh', this);
if (this.async) {
_load(this);
}
else {
window.location.reload();
}
};
//
// Filtering
//
/**
* Add a filter to this Data Region.
* @param {LABKEY.Filter} filter
* @see LABKEY.DataRegion.addFilter static method.
*/
LABKEY.DataRegion.prototype.addFilter = function(filter) {
this.clearSelected({quiet: true});
_updateFilter(this, filter);
};
/**
* Removes all filters from the DataRegion
*/
LABKEY.DataRegion.prototype.clearAllFilters = function() {
this.clearSelected({quiet: true});
if (this.async) {
this.offset = 0;
this.userFilters = {};
}
_removeParameters(this, [ALL_FILTERS_SKIP_PREFIX, OFFSET_PREFIX]);
};
/**
* Removes all the filters for a particular field
* @param {string|FieldKey} fieldKey the name of the field from which all filters should be removed
*/
LABKEY.DataRegion.prototype.clearFilter = function(fieldKey) {
this.clearSelected({quiet: true});
var fk = _resolveFieldKey(this, fieldKey);
if (fk) {
var columnPrefix = '.' + fk.toString() + '~';
if (this.async) {
this.offset = 0;
if (this.userFilters) {
var namePrefix = this.name + columnPrefix,
me = this;
$.each(this.userFilters, function(name, v) {
if (name.indexOf(namePrefix) >= 0) {
delete me.userFilters[name];
}
});
}
}
_removeParameters(this, [columnPrefix, OFFSET_PREFIX]);
}
};
/**
* Returns an Array of LABKEY.Filter instances applied when creating this DataRegion. These cannot be removed through the UI.
* @returns {Array} Array of {@link LABKEY.Filter} objects that represent currently applied base filters.
*/
LABKEY.DataRegion.prototype.getBaseFilters = function() {
if (this.filters) {
return this.filters.slice();
}
return [];
};
/**
* Returns the {@link LABKEY.Query.containerFilter} currently applied to the DataRegion. Defaults to LABKEY.Query.containerFilter.current.
* @returns {String} The container filter currently applied to this DataRegion. Defaults to 'undefined' if a container filter is not specified by the configuration.
* @see LABKEY.DataRegion#getUserContainerFilter to get the containerFilter value from the URL.
*/
LABKEY.DataRegion.prototype.getContainerFilter = function() {
var cf;
if (LABKEY.Utils.isString(this.containerFilter) && this.containerFilter.length > 0) {
cf = this.containerFilter;
}
else if (LABKEY.Utils.isObject(this.view) && LABKEY.Utils.isString(this.view.containerFilter) && this.view.containerFilter.length > 0) {
cf = this.view.containerFilter;
}
return cf;
};
LABKEY.DataRegion.prototype.getDataRegion = function() {
return this;
};
/**
* Returns the user {@link LABKEY.Query.containerFilter} parameter from the URL.
* @returns {LABKEY.Query.containerFilter} The user container filter.
*/
LABKEY.DataRegion.prototype.getUserContainerFilter = function() {
return this.getParameter(this.name + CONTAINER_FILTER_NAME);
};
/**
* Returns the user filter from the URL. The filter is represented as an Array of objects of the form:
* <ul>
* <li><b>fieldKey</b>: {String} The field key of the filter.
* <li><b>op</b>: {String} The filter operator (eg. "eq" or "in")
* <li><b>value</b>: {String} Optional value to filter by.
* </ul>
* @returns {Object} Object representing the user filter.
* @deprecated 12.2 Use getUserFilterArray instead
*/
LABKEY.DataRegion.prototype.getUserFilter = function() {
if (LABKEY.devMode) {
console.warn([
'LABKEY.DataRegion.getUserFilter() is deprecated since release 12.2.',
'Consider using getUserFilterArray() instead.'
].join(' '));
}
return this.getUserFilterArray().map(function(filter) {
return {
fieldKey: filter.getColumnName(),
op: filter.getFilterType().getURLSuffix(),
value: filter.getValue()
};
});
};
/**
* Returns an Array of LABKEY.Filter instances constructed from the URL.
* @returns {Array} Array of {@link LABKEY.Filter} objects that represent currently applied filters.
*/
LABKEY.DataRegion.prototype.getUserFilterArray = function() {
var userFilter = [], me = this;
_getParameters(this).forEach(function(pair) {
if (pair[0].indexOf(me.name + '.') == 0 && pair[0].indexOf('~') > -1) {
var tilde = pair[0].indexOf('~');
var fieldKey = pair[0].substring(me.name.length + 1, tilde);
var op = pair[0].substring(tilde + 1);
userFilter.push(LABKEY.Filter.create(fieldKey, pair[1], LABKEY.Filter.getFilterTypeForURLSuffix(op)));
}
});
return userFilter;
};
/**
* Remove a filter on this DataRegion.
* @param {LABKEY.Filter} filter
*/
LABKEY.DataRegion.prototype.removeFilter = function(filter) {
this.clearSelected({quiet: true});
if (LABKEY.Utils.isObject(filter) && LABKEY.Utils.isFunction(filter.getColumnName)) {
_updateFilter(this, null, [this.name + '.' + filter.getColumnName() + '~']);
}
};
/**
* Replace a filter on this Data Region. Optionally, supply another filter to replace for cases when the filter
* columns don't match exactly.
* @param {LABKEY.Filter} filter
* @param {LABKEY.Filter} [filterToReplace]
*/
LABKEY.DataRegion.prototype.replaceFilter = function(filter, filterToReplace) {
this.clearSelected({quiet: true});
var target = filterToReplace ? filterToReplace : filter;
_updateFilter(this, filter, [this.name + '.' + target.getColumnName() + '~']);
};
/**
* @ignore
* @param filters
* @param columnNames
*/
LABKEY.DataRegion.prototype.replaceFilters = function(filters, columnNames) {
this.clearSelected({quiet: true});
var filterPrefixes = [],
filterParams = [],
me = this;
if (LABKEY.Utils.isArray(filters)) {
filters.forEach(function(filter) {
filterPrefixes.push(me.name + '.' + filter.getColumnName() + '~');
filterParams.push([filter.getURLParameterName(me.name), filter.getURLParameterValue()]);
});
}
var fieldKeys = [];
if (LABKEY.Utils.isArray(columnNames)) {
fieldKeys = fieldKeys.concat(columnNames);
}
else if ($.isPlainObject(columnNames) && columnNames.fieldKey) {
fieldKeys.push(columnNames.fieldKey.toString());
}
// support fieldKeys (e.g. ["ColumnA", "ColumnA/Sub1"])
// A special case of fieldKey is "SUBJECT_PREFIX/", used by participant group facet
if (fieldKeys.length > 0) {
_getParameters(this).forEach(function(param) {
var p = param[0];
if (p.indexOf(me.name + '.') === 0 && p.indexOf('~') > -1) {
$.each(fieldKeys, function(j, name) {
var postfix = name && name.length && name[name.length - 1] == '/' ? '' : '~';
if (p.indexOf(me.name + '.' + name + postfix) > -1) {
filterPrefixes.push(p);
}
});
}
});
}
_setParameters(this, filterParams, [OFFSET_PREFIX].concat($.unique(filterPrefixes)));
};
/**
* @private
* @param filter
* @param filterMatch
*/
LABKEY.DataRegion.prototype.replaceFilterMatch = function(filter, filterMatch) {
this.clearSelected({quiet: true});
var skips = [], me = this;
_getParameters(this).forEach(function(param) {
if (param[0].indexOf(me.name + '.') === 0 && param[0].indexOf(filterMatch) > -1) {
skips.push(param[0]);
}
});
_updateFilter(this, filter, skips);
};
//
// Selection
//
/**
* @private
*/
var _initSelection = function() {
var me = this,
form = _getFormSelector(this);
if (form && form.length) {
// backwards compatibility -- some references use this directly
// if you're looking to use this internally to the region use _getFormSelector() instead
this.form = form[0];
}
if (form && this.showRecordSelectors) {
_onSelectionChange(this);
}
// Bind Events
_getAllRowSelectors(this).on('click', function(evt) {
evt.stopPropagation();
me.selectPage.call(me, this.checked);
});
_getRowSelectors(this).on('click', function() { me.selectRow.call(me, this); });
// click row highlight
var rows = form.find('.labkey-data-region > tbody > tr');
rows.on('click', function(e) {
if (e.target && e.target.tagName.toLowerCase() === 'td') {
$(this).siblings('tr').removeClass('lk-row-hl');
$(this).addClass('lk-row-hl');
_selClickLock = me;
}
});
rows.on('mouseenter', function() {
$(this).siblings('tr').removeClass('lk-row-over');
$(this).addClass('lk-row-over');
});
rows.on('mouseleave', function() {
$(this).removeClass('lk-row-over');
});
if (!_selDocClick) {
_selDocClick = $(document).on('click', _onDocumentClick);
}
// Issue 53997: Establish a maximum size for query selections
if (_isShowSelectAll(this)) {
_getNavTreeSelectAllSelector(this).html(_getSelectAllText(this));
}
};
var _selClickLock; // lock to prevent removing a row highlight that was just applied
var _selDocClick; // global (shared across all Data Region instances) click event handler instance
// Issue 32898: Clear row highlights on document click
var _onDocumentClick = function() {
if (_selClickLock) {
var form = _getFormSelector(_selClickLock);
_selClickLock = undefined;
$('.lk-row-hl').each(function() {
if (!form.has($(this)).length) {
$(this).removeClass('lk-row-hl');
}
});
}
else {
$('.lk-row-hl').removeClass('lk-row-hl');
}
};
/**
* Clear all selected items for the current DataRegion.
*
* @param config A configuration object with the following properties:
* @param {Function} config.success The function to be called upon success of the request.
* The callback will be passed the following parameters:
* <ul>
* <li><b>data:</b> an object with the property 'count' of 0 to indicate an empty selection.
* <li><b>response:</b> The XMLHttpResponse object</li>
* </ul>
* @param {Function} [config.failure] The function to call upon error of the request.
* The callback will be passed the following parameters:
* <ul>
* <li><b>errorInfo:</b> an object containing detailed error information (may be null)</li>
* <li><b>response:</b> The XMLHttpResponse object</li>
* </ul>
* @param {Object} [config.scope] An optional scoping object for the success and error callback functions (default to this).
* @param {string} [config.containerPath] An alternate container path. If not specified, the current container path will be used.
*
* @see LABKEY.DataRegion#selectPage
* @see LABKEY.DataRegion.clearSelected static method.
*/
LABKEY.DataRegion.prototype.clearSelected = function(config) {
config = config || {};
config.selectionKey = this.selectionKey;
config.scope = config.scope || this;
this.selectedCount = 0;
if (!config.quiet)
{
_onSelectionChange(this);
}
if (config.selectionKey) {
LABKEY.DataRegion.clearSelected(config);
}
if (this.showRows === 'selected') {
_removeParameters(this, [SHOW_ROWS_PREFIX]);
}
else if (this.showRows === 'unselected') {
// keep "SHOW_ROWS_PREFIX=unselected" parameter
window.location.reload(true);
}
else {
_toggleAllRows(this, false);
this.removeMessage('selection');
}
};
/**
* Get selected items on the current page of the DataRegion, based on the current state of the checkboxes in the
* browser's DOM. Note, if the region is paginated, selected items may exist on other pages which will not be
* included in the results of this function.
* @see LABKEY.DataRegion#getSelected
*/
LABKEY.DataRegion.prototype.getChecked = function() {
var values = [];
_getRowSelectors(this).each(function() {
if (this.checked) {
values.push(this.value);
}
});
return values;
};
/**
* Get all selected items for this DataRegion, as maintained in server-state. This will include rows on any
* pages of a paginated grid, and may not correspond directly with the state of the checkboxes in the current
* browser window's DOM if the server-side state has been modified.
*
* @param config A configuration object with the following properties:
* @param {Function} config.success The function to be called upon success of the request.
* The callback will be passed the following parameters:
* <ul>
* <li><b>data:</b> an object with the property 'selected' that is an array of the primary keys for the selected rows.
* <li><b>response:</b> The XMLHttpResponse object</li>
* </ul>
* @param {Function} [config.failure] The function to call upon error of the request.
* The callback will be passed the following parameters:
* <ul>
* <li><b>errorInfo:</b> an object containing detailed error information (may be null)</li>
* <li><b>response:</b> The XMLHttpResponse object</li>
* </ul>
* @param {Object} [config.scope] An optional scoping object for the success and error callback functions (default to this).
* @param {string} [config.containerPath] An alternate container path. If not specified, the current container path will be used.
*
* @see LABKEY.DataRegion.getSelected static method.
*/
LABKEY.DataRegion.prototype.getSelected = function(config) {
if (!this.selectionKey)
return;
config = config || {};
config.selectionKey = this.selectionKey;
LABKEY.DataRegion.getSelected(config);
};
/**
* Returns the number of selected rows on the current page of the DataRegion. Selected items may exist on other pages.
* @returns {Integer} the number of selected rows on the current page of the DataRegion.
* @see LABKEY.DataRegion#getSelected to get all selected rows.
*/
LABKEY.DataRegion.prototype.getSelectionCount = function() {
if (!$('#' + this.domId)) {
return 0;
}
var count = 0;
_getRowSelectors(this).each(function() {
if (this.checked === true) {
count++;
}
});
return count;
};