Skip to content

Commit

Permalink
Merge pull request #1728 from nelarsen/admin_js_everywere_fix
Browse files Browse the repository at this point in the history
Workaround for #1724: Prevent admin.js from executing on invalid end pages
  • Loading branch information
hansmorb authored Jan 16, 2025
2 parents 21adabb + 8e9f50c commit cce9648
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
19 changes: 15 additions & 4 deletions assets/admin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
let startTimeInput = $("#repetition-start_time");
let endTimeInput = $("#repetition-end_time");
let preserveManualCode = false;
let itemInput = $("#item-id");
let locationInput = $("#location-id");
let startDateInput = $("#repetition-start_date");
let bookingCodeInput = $("#_cb_bookingcode");

// check if this is loaded on right kind of backend page
let allExist = [
fullDayCheckbox, startTimeInput, endTimeInput, itemInput, locationInput, startDateInput, bookingCodeInput
].every(domElement => domElement.length === 1);

if (!allExist) {
// return early to prevent ajax calls with incorrect parameters
return;
}

fullDayCheckbox.on("change", function(event) {
if (fullDayCheckbox.is(":checked")) {
startTimeInput.val("00:00");
Expand All @@ -17,10 +32,6 @@
}
});
fullDayCheckbox.trigger("change");
let itemInput = $("#item-id");
let locationInput = $("#location-id");
let startDateInput = $("#repetition-start_date");
let bookingCodeInput = $("#_cb_bookingcode");
itemInput.on("change", function(event) {
let data = {
itemID: itemInput.val()
Expand Down
21 changes: 15 additions & 6 deletions assets/admin/js/src/booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
let startTimeInput = $('#repetition-start_time');
let endTimeInput = $('#repetition-end_time');
let preserveManualCode = false;
let itemInput = $('#item-id');
let locationInput = $('#location-id');
let startDateInput = $('#repetition-start_date');
let bookingCodeInput = $('#_cb_bookingcode');

// check if this is loaded on right kind of backend page
let allExist = [
fullDayCheckbox, startTimeInput, endTimeInput, itemInput, locationInput, startDateInput, bookingCodeInput
].every(domElement => domElement.length === 1);

if (!allExist) {
// return early to prevent ajax calls with incorrect parameters
return;
}

fullDayCheckbox.on('change', function (event) {
if (fullDayCheckbox.is(':checked')) {
startTimeInput.val('00:00');
Expand All @@ -18,12 +33,6 @@
});
fullDayCheckbox.trigger('change');


let itemInput = $('#item-id');
let locationInput = $('#location-id');
let startDateInput = $('#repetition-start_date');
let bookingCodeInput = $('#_cb_bookingcode');

itemInput.on('change', function (event) {
let data = {
itemID: itemInput.val(),
Expand Down

0 comments on commit cce9648

Please sign in to comment.