Skip to content
Snippets Groups Projects
Commit 47c13d70 authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

Fix jQuery once usage.

parent 9eb4492b
Branches
Tags 2.0.0-alpha10
No related merge requests found
......@@ -7,5 +7,5 @@ bulk:
js/entity-workflow-bulk.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
- core/once
(function ($, Drupal, drupalSettings) {
"use strict";
/**
* Disable checkboxes for any entities that cannot be transitioned.
*/
Drupal.behaviors.EntityWorkflowBulk = {
attach: function (context, settings) {
$('#entity-workflow-bulk-transition-form table thead tr th:first-child')
.once('EntityWorkflowBulkSelect')
$(once('EntityWorkflowBulkSelect', '#entity-workflow-bulk-transition-form table thead tr th:first-child'))
.each(function () {
$(this).html('<input type="checkbox" name="select-all">');
// Create a special select all checkbox. We use this one because core's select all checkbox cannot
......@@ -15,26 +17,24 @@
});
});
$('#entity-workflow-bulk-transition-form select[name="transition"]')
.once('EntityWorkflowBulkSelect')
$(once('EntityWorkflowBulkSelect', '#entity-workflow-bulk-transition-form select[name="transition"]'))
.change(function() {
var transition = $(this).val();
$('#entity-workflow-bulk-transition-form table tbody td input[type="checkbox"]').each(function () {
var entity_id = $(this).val();
if (drupalSettings.entityWorkflowBulkTransitions[transition] && drupalSettings.entityWorkflowBulkTransitions[transition][entity_id]) {
$(this).attr('disabled', false);
$(this).parents('tr').addClass('transition-enabled').removeClass('transition-disabled');
}
else {
$(this).attr('disabled', true).attr('checked', false);
$(this).parents('tr').removeClass('transition-enabled').addClass('transition-disabled');
}
});
}).trigger('change');
var transition = $(this).val();
$('#entity-workflow-bulk-transition-form table tbody td input[type="checkbox"]').each(function () {
var entity_id = $(this).val();
if (drupalSettings.entityWorkflowBulkTransitions[transition] && drupalSettings.entityWorkflowBulkTransitions[transition][entity_id]) {
$(this).attr('disabled', false);
$(this).parents('tr').addClass('transition-enabled').removeClass('transition-disabled');
}
else {
$(this).attr('disabled', true).attr('checked', false);
$(this).parents('tr').removeClass('transition-enabled').addClass('transition-disabled');
}
});
}).trigger('change');
// Make the entire td actually click the row.
$('#entity-workflow-bulk-transition-form tr')
.once('EntityWorkflowBulkSelect')
$(once('EntityWorkflowBulkSelect', '#entity-workflow-bulk-transition-form tr'))
.bind('click', function (e) {
// Ignore if they clicked on the actual checkbox.
if (e.target.type == 'checkbox') {
......@@ -56,8 +56,7 @@
.trigger('change');
});
$('#entity-workflow-bulk-transition-form td input[type="checkbox"]')
.once('EntityWorkflowBulkSelect')
$(once('EntityWorkflowBulkSelect', '#entity-workflow-bulk-transition-form td input[type="checkbox"]'))
.change(function () {
if (!this.checked) {
$('#entity-workflow-bulk-transition-form th input[type="checkbox"]').attr('checked', false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment