Skip to content

Commit

Permalink
Expose the internal JS functions so that they be overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed May 11, 2024
1 parent 0706d3f commit 88eda77
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 157 deletions.
43 changes: 23 additions & 20 deletions assets/js/pages/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ App.Pages.Admins = (function () {
event.preventDefault();
const key = $('#filter-admins .key').val();
$('#filter-admins .selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.Admins.resetForm();
App.Pages.Admins.filter(key);
});

/**
Expand All @@ -111,7 +111,7 @@ App.Pages.Admins = (function () {

const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(adminId));

display(admin);
App.Pages.Admins.display(admin);
$('#filter-admins .selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
$('#edit-admin, #delete-admin').prop('disabled', false);
Expand All @@ -121,7 +121,7 @@ App.Pages.Admins = (function () {
* Event: Add New Admin Button "Click"
*/
$admins.on('click', '#add-admin', () => {
resetForm();
App.Pages.Admins.resetForm();
$admins.find('.add-edit-delete-group').hide();
$admins.find('.save-cancel-group').show();
$admins.find('.record-details').find('input, select, textarea').prop('disabled', false);
Expand Down Expand Up @@ -160,7 +160,7 @@ App.Pages.Admins = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(adminId);
App.Pages.Admins.remove(adminId);
messageModal.dispose();
},
},
Expand Down Expand Up @@ -203,11 +203,11 @@ App.Pages.Admins = (function () {
admin.id = $id.val();
}

if (!validate()) {
if (!App.Pages.Admins.validate()) {
return;
}

save(admin);
App.Pages.Admins.save(admin);
});

/**
Expand All @@ -218,10 +218,10 @@ App.Pages.Admins = (function () {
$admins.on('click', '#cancel-admin', () => {
const id = $id.val();

resetForm();
App.Pages.Admins.resetForm();

if (id) {
select(id, true);
App.Pages.Admins.select(id, true);
}
});
}
Expand All @@ -235,9 +235,9 @@ App.Pages.Admins = (function () {
function save(admin) {
App.Http.Admins.save(admin).then((response) => {
App.Layouts.Backend.displayNotification(lang('admin_saved'));
resetForm();
App.Pages.Admins.resetForm();
$('#filter-admins .key').val('');
filter('', response.id, true);
App.Pages.Admins.filter('', response.id, true);
});
}

Expand All @@ -249,8 +249,8 @@ App.Pages.Admins = (function () {
function remove(id) {
App.Http.Admins.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('admin_deleted'));
resetForm();
filter($('#filter-admins .key').val());
App.Pages.Admins.resetForm();
App.Pages.Admins.filter($('#filter-admins .key').val());
});
}

Expand Down Expand Up @@ -386,7 +386,7 @@ App.Pages.Admins = (function () {
$filterAdmins.find('.results').empty();

response.forEach((admin) => {
$filterAdmins.find('.results').append(getFilterHtml(admin)).append($('<hr/>'));
$filterAdmins.find('.results').append(App.Pages.Admins.getFilterHtml(admin)).append($('<hr/>'));
});

if (!response.length) {
Expand All @@ -402,13 +402,13 @@ App.Pages.Admins = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Admins.filter(keyword, selectId, show);
},
}).appendTo('#filter-admins .results');
}

if (selectId) {
select(selectId, show);
App.Pages.Admins.select(selectId, show);
}
});
}
Expand Down Expand Up @@ -462,7 +462,7 @@ App.Pages.Admins = (function () {
if (show) {
const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));

display(admin);
App.Pages.Admins.display(admin);

$('#edit-admin, #delete-admin').prop('disabled', false);
}
Expand All @@ -472,9 +472,9 @@ App.Pages.Admins = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.Admins.resetForm();
App.Pages.Admins.filter('');
App.Pages.Admins.addEventListeners();
}

document.addEventListener('DOMContentLoaded', initialize);
Expand All @@ -483,8 +483,11 @@ App.Pages.Admins = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();
45 changes: 25 additions & 20 deletions assets/js/pages/blocked_periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ App.Pages.BlockedPeriods = (function () {
event.preventDefault();
const key = $('#filter-blocked-periods .key').val();
$('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.BlockedPeriods.resetForm();
App.Pages.BlockedPeriods.filter(key);
});

/**
Expand All @@ -64,7 +64,7 @@ App.Pages.BlockedPeriods = (function () {
(filterResult) => Number(filterResult.id) === Number(blockedPeriodId),
);

display(blockedPeriod);
App.Pages.BlockedPeriods.display(blockedPeriod);
$('#filter-blocked-periods .selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
$('#edit-blocked-period, #delete-blocked-period').prop('disabled', false);
Expand All @@ -74,7 +74,7 @@ App.Pages.BlockedPeriods = (function () {
* Event: Add Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#add-blocked-period', () => {
resetForm();
App.Pages.BlockedPeriods.resetForm();
$blockedPeriods.find('.add-edit-delete-group').hide();
$blockedPeriods.find('.save-cancel-group').show();
$blockedPeriods.find('.record-details').find('input, select, textarea').prop('disabled', false);
Expand Down Expand Up @@ -114,7 +114,7 @@ App.Pages.BlockedPeriods = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(blockedPeriodId);
App.Pages.BlockedPeriods.remove(blockedPeriodId);
messageModal.dispose();
},
},
Expand Down Expand Up @@ -143,21 +143,21 @@ App.Pages.BlockedPeriods = (function () {
blockedPeriod.id = $id.val();
}

if (!validate()) {
if (!App.Pages.BlockedPeriods.validate()) {
return;
}

save(blockedPeriod);
App.Pages.BlockedPeriods.save(blockedPeriod);
});

/**
* Event: Cancel Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#cancel-blocked-period', () => {
const id = $id.val();
resetForm();
App.Pages.BlockedPeriods.resetForm();
if (id !== '') {
select(id, true);
App.Pages.BlockedPeriods.select(id, true);
}
});

Expand Down Expand Up @@ -198,7 +198,9 @@ App.Pages.BlockedPeriods = (function () {
$('#filter-blocked-periods .results').empty();

response.forEach((blockedPeriod) => {
$('#filter-blocked-periods .results').append(getFilterHtml(blockedPeriod)).append($('<hr/>'));
$('#filter-blocked-periods .results')
.append(App.Pages.BlockedPeriods.getFilterHtml(blockedPeriod))
.append($('<hr/>'));
});

if (response.length === 0) {
Expand All @@ -214,13 +216,13 @@ App.Pages.BlockedPeriods = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.BlockedPeriods.filter(keyword, selectId, show);
},
}).appendTo('#filter-blocked-periods .results');
}

if (selectId) {
select(selectId, show);
App.Pages.BlockedPeriods.select(selectId, show);
}
});
}
Expand All @@ -233,9 +235,9 @@ App.Pages.BlockedPeriods = (function () {
function save(blockedPeriod) {
App.Http.BlockedPeriods.save(blockedPeriod).then((response) => {
App.Layouts.Backend.displayNotification(lang('blocked_period_saved'));
resetForm();
App.Pages.BlockedPeriods.resetForm();
$filterBlockedPeriods.find('.key').val('');
filter('', response.id, true);
App.Pages.BlockedPeriods.filter('', response.id, true);
});
}

Expand All @@ -247,8 +249,8 @@ App.Pages.BlockedPeriods = (function () {
function remove(id) {
App.Http.BlockedPeriods.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('blocked_period_deleted'));
resetForm();
filter($('#filter-blocked-periods .key').val());
App.Pages.BlockedPeriods.resetForm();
App.Pages.BlockedPeriods.filter($('#filter-blocked-periods .key').val());
});
}

Expand Down Expand Up @@ -360,7 +362,7 @@ App.Pages.BlockedPeriods = (function () {
if (show) {
const blockedPeriod = filterResults.find((blockedPeriod) => Number(blockedPeriod.id) === Number(id));

display(blockedPeriod);
App.Pages.BlockedPeriods.display(blockedPeriod);

$('#edit-blocked-period, #delete-blocked-period').prop('disabled', false);
}
Expand All @@ -370,9 +372,9 @@ App.Pages.BlockedPeriods = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.BlockedPeriods.resetForm();
App.Pages.BlockedPeriods.filter('');
App.Pages.BlockedPeriods.addEventListeners();
App.Utils.UI.initializeDateTimePicker($startDateTime);
App.Utils.UI.initializeDateTimePicker($endDateTime);
}
Expand All @@ -383,8 +385,11 @@ App.Pages.BlockedPeriods = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();
21 changes: 11 additions & 10 deletions assets/js/pages/booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ App.Pages.Booking = (function () {
maxDate: moment().add(vars('future_booking_limit'), 'days').toDate(),
onChange: (selectedDates) => {
App.Http.Booking.getAvailableHours(moment(selectedDates[0]).format('YYYY-MM-DD'));
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
},

onMonthChange: (selectedDates, dateStr, instance) => {
Expand Down Expand Up @@ -312,7 +312,7 @@ App.Pages.Booking = (function () {

App.Http.Booking.getAvailableHours(moment(date).format('YYYY-MM-DD'));

updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
});

/**
Expand All @@ -333,7 +333,7 @@ App.Pages.Booking = (function () {
$selectService.val(),
todayDateTimeMoment.format('YYYY-MM-DD'),
);
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
});

/**
Expand Down Expand Up @@ -370,9 +370,9 @@ App.Pages.Booking = (function () {
moment(App.Utils.UI.getDateTimePickerValue($selectDate)).format('YYYY-MM-DD'),
);

updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();

updateServiceDescription(serviceId);
App.Pages.Booking.updateServiceDescription(serviceId);
});

/**
Expand Down Expand Up @@ -406,10 +406,10 @@ App.Pages.Booking = (function () {
// If we are on the 3rd tab then we will need to validate the user's input before proceeding to the next
// step.
if ($target.attr('data-step_index') === '3') {
if (!validateCustomerForm()) {
if (!App.Pages.Booking.validateCustomerForm()) {
return; // Validation failed, do not continue.
} else {
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
}
}

Expand Down Expand Up @@ -453,7 +453,7 @@ App.Pages.Booking = (function () {
$availableHours.on('click', '.available-hour', (event) => {
$availableHours.find('.selected-hour').removeClass('selected-hour');
$(event.target).addClass('selected-hour');
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
});

if (manageMode) {
Expand Down Expand Up @@ -855,7 +855,7 @@ App.Pages.Booking = (function () {
$customField4.val(customer.custom_field_4);
$customField5.val(customer.custom_field_5);

updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();

return true;
} catch (exc) {
Expand Down Expand Up @@ -928,7 +928,8 @@ App.Pages.Booking = (function () {

return {
manageMode,
initialize,
updateConfirmFrame,
updateServiceDescription,
validateCustomerForm,
};
})();
Loading

0 comments on commit 88eda77

Please sign in to comment.