Source
240
240
this.checkObjects(object, objectIds, checked);
241
241
},
242
242
243
243
/**
244
244
* Update the general state after toggling a checkbox.
245
245
*
246
246
* @param {string} object
247
247
*/
248
248
update: function(object) {
249
249
// update main checkbox state
250
-
this.updateMainCheckbox();
250
+
this.updateMainCheckbox(object);
251
251
252
252
if (this.pageGoName == object) {
253
253
this.updateGoButton();
254
254
}
255
255
},
256
256
257
257
/**
258
258
* Update the state of the "Go" controls.
259
259
*/
260
260
updateGoButton: function() {
268
268
269
269
jQuery('#action_buttons button').each((_, val) => {
270
270
const $val = jQuery(val);
271
271
272
272
if (!$val.data('disabled')) {
273
273
$val.prop('disabled', count == 0);
274
274
}
275
275
});
276
276
},
277
277
278
-
// check if all checkboxes are selected and select main checkbox, else disable checkbox, select options and button
279
-
updateMainCheckbox: function() {
280
-
var mainCheckbox = jQuery('.list-table .header input[type=checkbox]:not(:disabled)');
281
-
if (!mainCheckbox.length) {
278
+
/**
279
+
* Select main checkbox if all other checkboxes are selected.
280
+
*
281
+
* @param {string} object
282
+
*/
283
+
updateMainCheckbox: function(object) {
284
+
const checkbox_list = this.getObjectCheckboxes(object);
285
+
const $main_checkbox = $(checkbox_list)
286
+
.parents('table')
287
+
.find('thead input[type=checkbox]');
288
+
289
+
if ($main_checkbox.length == 0) {
282
290
return;
283
291
}
284
292
285
-
var countAvailable = jQuery('.list-table tr:not(.header) input[type=checkbox]:not(:disabled)').length;
293
+
const count_available = checkbox_list.length;
286
294
287
-
if (countAvailable > 0) {
288
-
var countChecked = jQuery('.list-table tr:not(.header) input[type=checkbox]:not(:disabled):checked').length;
295
+
if (count_available > 0) {
296
+
const checked = [];
289
297
290
-
mainCheckbox = mainCheckbox[0];
291
-
mainCheckbox.checked = (countChecked == countAvailable);
298
+
jQuery.each(checkbox_list, (i, checkbox) => {
299
+
if (checkbox.checked) {
300
+
checked.push(checkbox);
301
+
}
302
+
});
292
303
293
-
if (mainCheckbox.checked) {
294
-
jQuery('.list-table .header').addClass('selectedMain');
295
-
}
296
-
else {
297
-
jQuery('.list-table .header').removeClass('selectedMain');
298
-
}
299
-
}
300
-
else {
301
-
mainCheckbox.disabled = true;
304
+
$main_checkbox[0].checked = (checked.length == count_available);
302
305
}
303
306
},
304
307
305
308
/**
306
309
* Save the state of the checkboxes belonging to the given object group in SessionStorage.
307
310
*
308
311
* @param {string} object
309
312
* @param {Object} selected_ids key/value pairs of selected ids.
310
313
*/
311
314
saveSessionStorage: function(object, selected_ids) {