Loading js/frontUi.js +33 −32 Original line number Original line Diff line number Diff line Loading @@ -17,22 +17,24 @@ }; }; /** /** * Views Bulk Operation selection object. * VBO selection handling class. */ */ Drupal.viewsBulkOperationsSelection = { class viewsBulkOperationsSelection { view_id: '', display_id: '', constructor(vbo_form) { list: {}, this.vbo_form = vbo_form; $summary: null, this.$actionSelect = $('select[name="action"]', vbo_form); $actionSelect: null, this.view_id = ''; vbo_form: null, this.display_id = ''; this.$summary = null; } /** /** * Bind event handlers to an element. * Bind event handlers to an element. * * * @param {jQuery} element * @param {jQuery} element */ */ bindEventHandlers: function ($element, index) { bindEventHandlers($element, index) { if ($element.length) { if ($element.length) { var selectionObject = this; var selectionObject = this; $element.on('keypress', function (event) { $element.on('keypress', function (event) { Loading @@ -54,17 +56,17 @@ } } }); }); } } }, } bindCheckboxes: function () { bindCheckboxes() { var selectionObject = this; var selectionObject = this; var checkboxes = $('.form-checkbox', this.vbo_form); var checkboxes = $('.form-checkbox', this.vbo_form); checkboxes.on('change', function (event) { checkboxes.on('change', function (event) { selectionObject.toggleButtonsState(); selectionObject.toggleButtonsState(); }); }); }, } toggleButtonsState: function() { toggleButtonsState() { // If no rows are checked, disable any form submit actions. // If no rows are checked, disable any form submit actions. var checkedCheckboxes = $('.form-checkbox:checked', this.vbo_form); var checkedCheckboxes = $('.form-checkbox:checked', this.vbo_form); var buttons = $('[id^="edit-actions"] input[type="submit"], [id^="edit-actions"] button[type="submit"]', this.vbo_form); var buttons = $('[id^="edit-actions"] input[type="submit"], [id^="edit-actions"] button[type="submit"]', this.vbo_form); Loading @@ -77,16 +79,16 @@ else { else { buttons.prop('disabled', !anyItemsSelected); buttons.prop('disabled', !anyItemsSelected); } } }, } bindActionSelect: function () { bindActionSelect() { if (this.$actionSelect.length) { if (this.$actionSelect.length) { var selectionObject = this; var selectionObject = this; this.$actionSelect.on('change', function (event) { this.$actionSelect.on('change', function (event) { selectionObject.toggleButtonsState(); selectionObject.toggleButtonsState(); }); }); } } }, } /** /** * Perform an AJAX request to update selection. * Perform an AJAX request to update selection. Loading @@ -95,7 +97,7 @@ * @param {mixed} index * @param {mixed} index * @param {string} value * @param {string} value */ */ update: function (state, index, value) { update(state, index, value) { if (value === undefined) { if (value === undefined) { value = null; value = null; } } Loading Loading @@ -148,8 +150,7 @@ var $viewsTables = $('.vbo-table', $vboForm); var $viewsTables = $('.vbo-table', $vboForm); var $primarySelectAll = $('.vbo-select-all', $vboForm); var $primarySelectAll = $('.vbo-select-all', $vboForm); var tableSelectAll = []; var tableSelectAll = []; Drupal.viewsBulkOperationsSelection.vbo_form = $vboForm; let vboSelection = new viewsBulkOperationsSelection($vboForm); Drupal.viewsBulkOperationsSelection.$actionSelect = $('select[name="action"]', $vboForm); // When grouping is enabled, there can be multiple tables. // When grouping is enabled, there can be multiple tables. if ($viewsTables.length) { if ($viewsTables.length) { Loading @@ -163,13 +164,13 @@ var $multiSelectElement = $vboForm.find('.vbo-multipage-selector').first(); var $multiSelectElement = $vboForm.find('.vbo-multipage-selector').first(); if ($multiSelectElement.length) { if ($multiSelectElement.length) { Drupal.viewsBulkOperationsSelection.$selectionInfo = $multiSelectElement.find('.vbo-info-list-wrapper').first(); vboSelection.$selectionInfo = $multiSelectElement.find('.vbo-info-list-wrapper').first(); Drupal.viewsBulkOperationsSelection.$summary = $multiSelectElement.find('summary').first(); vboSelection.$summary = $multiSelectElement.find('summary').first(); Drupal.viewsBulkOperationsSelection.view_id = $multiSelectElement.attr('data-view-id'); vboSelection.view_id = $multiSelectElement.attr('data-view-id'); Drupal.viewsBulkOperationsSelection.display_id = $multiSelectElement.attr('data-display-id'); vboSelection.display_id = $multiSelectElement.attr('data-display-id'); // Get the list of all checkbox values and add AJAX callback. // Get the list of all checkbox values and add AJAX callback. Drupal.viewsBulkOperationsSelection.list = []; vboSelection.list = []; var $contentWrappers; var $contentWrappers; if ($viewsTables.length) { if ($viewsTables.length) { Loading @@ -181,19 +182,19 @@ $contentWrappers.each(function (index) { $contentWrappers.each(function (index) { var $contentWrapper = $(this); var $contentWrapper = $(this); Drupal.viewsBulkOperationsSelection.list[index] = {}; vboSelection.list[index] = {}; $contentWrapper.find('.views-field-views-bulk-operations-bulk-form input[type="checkbox"]').each(function () { $contentWrapper.find('.views-field-views-bulk-operations-bulk-form input[type="checkbox"]').each(function () { var value = $(this).val(); var value = $(this).val(); if (value != 'on') { if (value != 'on') { Drupal.viewsBulkOperationsSelection.list[index][value] = value; vboSelection.list[index][value] = value; Drupal.viewsBulkOperationsSelection.bindEventHandlers($(this), index); vboSelection.bindEventHandlers($(this), index); } } }); }); // Bind event handlers to select all checkbox. // Bind event handlers to select all checkbox. if ($viewsTables.length && tableSelectAll.length) { if ($viewsTables.length && tableSelectAll.length) { Drupal.viewsBulkOperationsSelection.bindEventHandlers(tableSelectAll[index], index); vboSelection.bindEventHandlers(tableSelectAll[index], index); } } }); }); } } Loading Loading @@ -228,12 +229,12 @@ }); }); if ($multiSelectElement.length) { if ($multiSelectElement.length) { Drupal.viewsBulkOperationsSelection.bindEventHandlers($primarySelectAll, 'selection_method_change'); vboSelection.bindEventHandlers($primarySelectAll, 'selection_method_change'); } } } } Drupal.viewsBulkOperationsSelection.bindCheckboxes(); vboSelection.bindCheckboxes(); Drupal.viewsBulkOperationsSelection.bindActionSelect(); vboSelection.bindActionSelect(); Drupal.viewsBulkOperationsSelection.toggleButtonsState(); vboSelection.toggleButtonsState(); }; }; })(jQuery, Drupal); })(jQuery, Drupal); Loading
js/frontUi.js +33 −32 Original line number Original line Diff line number Diff line Loading @@ -17,22 +17,24 @@ }; }; /** /** * Views Bulk Operation selection object. * VBO selection handling class. */ */ Drupal.viewsBulkOperationsSelection = { class viewsBulkOperationsSelection { view_id: '', display_id: '', constructor(vbo_form) { list: {}, this.vbo_form = vbo_form; $summary: null, this.$actionSelect = $('select[name="action"]', vbo_form); $actionSelect: null, this.view_id = ''; vbo_form: null, this.display_id = ''; this.$summary = null; } /** /** * Bind event handlers to an element. * Bind event handlers to an element. * * * @param {jQuery} element * @param {jQuery} element */ */ bindEventHandlers: function ($element, index) { bindEventHandlers($element, index) { if ($element.length) { if ($element.length) { var selectionObject = this; var selectionObject = this; $element.on('keypress', function (event) { $element.on('keypress', function (event) { Loading @@ -54,17 +56,17 @@ } } }); }); } } }, } bindCheckboxes: function () { bindCheckboxes() { var selectionObject = this; var selectionObject = this; var checkboxes = $('.form-checkbox', this.vbo_form); var checkboxes = $('.form-checkbox', this.vbo_form); checkboxes.on('change', function (event) { checkboxes.on('change', function (event) { selectionObject.toggleButtonsState(); selectionObject.toggleButtonsState(); }); }); }, } toggleButtonsState: function() { toggleButtonsState() { // If no rows are checked, disable any form submit actions. // If no rows are checked, disable any form submit actions. var checkedCheckboxes = $('.form-checkbox:checked', this.vbo_form); var checkedCheckboxes = $('.form-checkbox:checked', this.vbo_form); var buttons = $('[id^="edit-actions"] input[type="submit"], [id^="edit-actions"] button[type="submit"]', this.vbo_form); var buttons = $('[id^="edit-actions"] input[type="submit"], [id^="edit-actions"] button[type="submit"]', this.vbo_form); Loading @@ -77,16 +79,16 @@ else { else { buttons.prop('disabled', !anyItemsSelected); buttons.prop('disabled', !anyItemsSelected); } } }, } bindActionSelect: function () { bindActionSelect() { if (this.$actionSelect.length) { if (this.$actionSelect.length) { var selectionObject = this; var selectionObject = this; this.$actionSelect.on('change', function (event) { this.$actionSelect.on('change', function (event) { selectionObject.toggleButtonsState(); selectionObject.toggleButtonsState(); }); }); } } }, } /** /** * Perform an AJAX request to update selection. * Perform an AJAX request to update selection. Loading @@ -95,7 +97,7 @@ * @param {mixed} index * @param {mixed} index * @param {string} value * @param {string} value */ */ update: function (state, index, value) { update(state, index, value) { if (value === undefined) { if (value === undefined) { value = null; value = null; } } Loading Loading @@ -148,8 +150,7 @@ var $viewsTables = $('.vbo-table', $vboForm); var $viewsTables = $('.vbo-table', $vboForm); var $primarySelectAll = $('.vbo-select-all', $vboForm); var $primarySelectAll = $('.vbo-select-all', $vboForm); var tableSelectAll = []; var tableSelectAll = []; Drupal.viewsBulkOperationsSelection.vbo_form = $vboForm; let vboSelection = new viewsBulkOperationsSelection($vboForm); Drupal.viewsBulkOperationsSelection.$actionSelect = $('select[name="action"]', $vboForm); // When grouping is enabled, there can be multiple tables. // When grouping is enabled, there can be multiple tables. if ($viewsTables.length) { if ($viewsTables.length) { Loading @@ -163,13 +164,13 @@ var $multiSelectElement = $vboForm.find('.vbo-multipage-selector').first(); var $multiSelectElement = $vboForm.find('.vbo-multipage-selector').first(); if ($multiSelectElement.length) { if ($multiSelectElement.length) { Drupal.viewsBulkOperationsSelection.$selectionInfo = $multiSelectElement.find('.vbo-info-list-wrapper').first(); vboSelection.$selectionInfo = $multiSelectElement.find('.vbo-info-list-wrapper').first(); Drupal.viewsBulkOperationsSelection.$summary = $multiSelectElement.find('summary').first(); vboSelection.$summary = $multiSelectElement.find('summary').first(); Drupal.viewsBulkOperationsSelection.view_id = $multiSelectElement.attr('data-view-id'); vboSelection.view_id = $multiSelectElement.attr('data-view-id'); Drupal.viewsBulkOperationsSelection.display_id = $multiSelectElement.attr('data-display-id'); vboSelection.display_id = $multiSelectElement.attr('data-display-id'); // Get the list of all checkbox values and add AJAX callback. // Get the list of all checkbox values and add AJAX callback. Drupal.viewsBulkOperationsSelection.list = []; vboSelection.list = []; var $contentWrappers; var $contentWrappers; if ($viewsTables.length) { if ($viewsTables.length) { Loading @@ -181,19 +182,19 @@ $contentWrappers.each(function (index) { $contentWrappers.each(function (index) { var $contentWrapper = $(this); var $contentWrapper = $(this); Drupal.viewsBulkOperationsSelection.list[index] = {}; vboSelection.list[index] = {}; $contentWrapper.find('.views-field-views-bulk-operations-bulk-form input[type="checkbox"]').each(function () { $contentWrapper.find('.views-field-views-bulk-operations-bulk-form input[type="checkbox"]').each(function () { var value = $(this).val(); var value = $(this).val(); if (value != 'on') { if (value != 'on') { Drupal.viewsBulkOperationsSelection.list[index][value] = value; vboSelection.list[index][value] = value; Drupal.viewsBulkOperationsSelection.bindEventHandlers($(this), index); vboSelection.bindEventHandlers($(this), index); } } }); }); // Bind event handlers to select all checkbox. // Bind event handlers to select all checkbox. if ($viewsTables.length && tableSelectAll.length) { if ($viewsTables.length && tableSelectAll.length) { Drupal.viewsBulkOperationsSelection.bindEventHandlers(tableSelectAll[index], index); vboSelection.bindEventHandlers(tableSelectAll[index], index); } } }); }); } } Loading Loading @@ -228,12 +229,12 @@ }); }); if ($multiSelectElement.length) { if ($multiSelectElement.length) { Drupal.viewsBulkOperationsSelection.bindEventHandlers($primarySelectAll, 'selection_method_change'); vboSelection.bindEventHandlers($primarySelectAll, 'selection_method_change'); } } } } Drupal.viewsBulkOperationsSelection.bindCheckboxes(); vboSelection.bindCheckboxes(); Drupal.viewsBulkOperationsSelection.bindActionSelect(); vboSelection.bindActionSelect(); Drupal.viewsBulkOperationsSelection.toggleButtonsState(); vboSelection.toggleButtonsState(); }; }; })(jQuery, Drupal); })(jQuery, Drupal);