Expose the internal JS functions so that they be overriden

This commit is contained in:
Alex Tselegidis 2024-05-11 16:13:00 +02:00
parent 0706d3fdab
commit 88eda77d0c
9 changed files with 191 additions and 157 deletions

View file

@ -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);
});
/**
@ -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);
@ -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);
@ -160,7 +160,7 @@ App.Pages.Admins = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(adminId);
App.Pages.Admins.remove(adminId);
messageModal.dispose();
},
},
@ -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);
});
/**
@ -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);
}
});
}
@ -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);
});
}
@ -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());
});
}
@ -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) {
@ -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);
}
});
}
@ -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);
}
@ -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);
@ -483,8 +483,11 @@ App.Pages.Admins = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -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);
});
/**
@ -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);
@ -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);
@ -114,7 +114,7 @@ App.Pages.BlockedPeriods = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(blockedPeriodId);
App.Pages.BlockedPeriods.remove(blockedPeriodId);
messageModal.dispose();
},
},
@ -143,11 +143,11 @@ App.Pages.BlockedPeriods = (function () {
blockedPeriod.id = $id.val();
}
if (!validate()) {
if (!App.Pages.BlockedPeriods.validate()) {
return;
}
save(blockedPeriod);
App.Pages.BlockedPeriods.save(blockedPeriod);
});
/**
@ -155,9 +155,9 @@ App.Pages.BlockedPeriods = (function () {
*/
$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);
}
});
@ -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) {
@ -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);
}
});
}
@ -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);
});
}
@ -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());
});
}
@ -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);
}
@ -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);
}
@ -383,8 +385,11 @@ App.Pages.BlockedPeriods = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -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) => {
@ -312,7 +312,7 @@ App.Pages.Booking = (function () {
App.Http.Booking.getAvailableHours(moment(date).format('YYYY-MM-DD'));
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
});
/**
@ -333,7 +333,7 @@ App.Pages.Booking = (function () {
$selectService.val(),
todayDateTimeMoment.format('YYYY-MM-DD'),
);
updateConfirmFrame();
App.Pages.Booking.updateConfirmFrame();
});
/**
@ -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);
});
/**
@ -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();
}
}
@ -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) {
@ -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) {
@ -928,7 +928,8 @@ App.Pages.Booking = (function () {
return {
manageMode,
initialize,
updateConfirmFrame,
updateServiceDescription,
validateCustomerForm,
};
})();

View file

@ -36,6 +36,8 @@ App.Pages.Customers = (function () {
const $formMessage = $('#form-message');
const $customerAppointments = $('#customer-appointments');
const moment = window.moment;
let filterResults = {};
let filterLimit = 20;
@ -53,8 +55,8 @@ App.Pages.Customers = (function () {
const key = $filterCustomers.find('.key').val();
$filterCustomers.find('.selected').removeClass('selected');
filterLimit = 20;
resetForm();
filter(key);
App.Pages.Customers.resetForm();
App.Pages.Customers.filter(key);
});
/**
@ -82,7 +84,7 @@ App.Pages.Customers = (function () {
* Event: Add Customer Button "Click"
*/
$customers.on('click', '#add-customer', () => {
resetForm();
App.Pages.Customers.resetForm();
$customers.find('#add-edit-delete-group').hide();
$customers.find('#save-cancel-group').show();
$customers.find('.record-details').find('input, select, textarea').prop('disabled', false);
@ -109,7 +111,7 @@ App.Pages.Customers = (function () {
$customers.on('click', '#cancel-customer', () => {
const id = $id.val();
resetForm();
App.Pages.Customers.resetForm();
if (id) {
select(id, true);
@ -142,11 +144,11 @@ App.Pages.Customers = (function () {
customer.id = $id.val();
}
if (!validate()) {
if (!App.Pages.Customers.validate()) {
return;
}
save(customer);
App.Pages.Customers.save(customer);
});
/**
@ -164,7 +166,7 @@ App.Pages.Customers = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(customerId);
App.Pages.Customers.remove(customerId);
messageModal.dispose();
},
},
@ -182,9 +184,9 @@ App.Pages.Customers = (function () {
function save(customer) {
App.Http.Customers.save(customer).then((response) => {
App.Layouts.Backend.displayNotification(lang('customer_saved'));
resetForm();
App.Pages.Customers.resetForm();
$('#filter-customers .key').val('');
filter('', response.id, true);
App.Pages.Customers.filter('', response.id, true);
});
}
@ -196,8 +198,8 @@ App.Pages.Customers = (function () {
function remove(id) {
App.Http.Customers.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('customer_deleted'));
resetForm();
filter($('#filter-customers .key').val());
App.Pages.Customers.resetForm();
App.Pages.Customers.filter($('#filter-customers .key').val());
});
}
@ -392,7 +394,7 @@ App.Pages.Customers = (function () {
$filterCustomers.find('.results').empty();
response.forEach((customer) => {
$('#filter-customers .results').append(getFilterHtml(customer)).append($('<hr/>'));
$('#filter-customers .results').append(App.Pages.Customers.getFilterHtml(customer)).append($('<hr/>'));
});
if (!response.length) {
@ -408,13 +410,13 @@ App.Pages.Customers = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Customers.filter(keyword, selectId, show);
},
}).appendTo('#filter-customers .results');
}
if (selectId) {
select(selectId, show);
App.Pages.Customers.select(selectId, show);
}
});
}
@ -466,7 +468,7 @@ App.Pages.Customers = (function () {
if (show) {
const customer = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
display(customer);
App.Pages.Customers.display(customer);
$('#edit-customer, #delete-customer').prop('disabled', false);
}
@ -476,9 +478,9 @@ App.Pages.Customers = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
addEventListeners();
filter('');
App.Pages.Customers.resetForm();
App.Pages.Customers.addEventListeners();
App.Pages.Customers.filter('');
}
document.addEventListener('DOMContentLoaded', initialize);
@ -487,8 +489,11 @@ App.Pages.Customers = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -55,8 +55,8 @@ App.Pages.Providers = (function () {
event.preventDefault();
const key = $('#filter-providers .key').val();
$('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.Providers.resetForm();
App.Pages.Providers.filter(key);
});
/**
@ -73,7 +73,7 @@ App.Pages.Providers = (function () {
const providerId = $(event.currentTarget).attr('data-id');
const provider = filterResults.find((filterResult) => Number(filterResult.id) === Number(providerId));
display(provider);
App.Pages.Providers.display(provider);
$filterProviders.find('.selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
$('#edit-provider, #delete-provider').prop('disabled', false);
@ -83,7 +83,7 @@ App.Pages.Providers = (function () {
* Event: Add New Provider Button "Click"
*/
$providers.on('click', '#add-provider', () => {
resetForm();
App.Pages.Providers.resetForm();
$filterProviders.find('button').prop('disabled', true);
$filterProviders.find('.results').css('color', '#AAA');
$providers.find('.add-edit-delete-group').hide();
@ -141,7 +141,7 @@ App.Pages.Providers = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(providerId);
App.Pages.Providers.remove(providerId);
messageModal.dispose();
},
},
@ -195,11 +195,11 @@ App.Pages.Providers = (function () {
provider.id = $id.val();
}
if (!validate()) {
if (!App.Pages.Providers.validate()) {
return;
}
save(provider);
App.Pages.Providers.save(provider);
});
/**
@ -209,9 +209,9 @@ App.Pages.Providers = (function () {
*/
$providers.on('click', '#cancel-provider', () => {
const id = $('#filter-providers .selected').attr('data-id');
resetForm();
App.Pages.Providers.resetForm();
if (id) {
select(id, true);
App.Pages.Providers.select(id, true);
}
});
@ -237,9 +237,9 @@ App.Pages.Providers = (function () {
function save(provider) {
App.Http.Providers.save(provider).then((response) => {
App.Layouts.Backend.displayNotification(lang('provider_saved'));
resetForm();
App.Pages.Providers.resetForm();
$('#filter-providers .key').val('');
filter('', response.id, true);
App.Pages.Providers.filter('', response.id, true);
});
}
@ -251,8 +251,8 @@ App.Pages.Providers = (function () {
function remove(id) {
App.Http.Providers.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('provider_deleted'));
resetForm();
filter($('#filter-providers .key').val());
App.Pages.Providers.resetForm();
App.Pages.Providers.filter($('#filter-providers .key').val());
});
}
@ -468,7 +468,7 @@ App.Pages.Providers = (function () {
$filterProviders.find('.results').empty();
response.forEach((provider) => {
$('#filter-providers .results').append(getFilterHtml(provider)).append($('<hr/>'));
$('#filter-providers .results').append(App.Pages.Providers.getFilterHtml(provider)).append($('<hr/>'));
});
if (!response.length) {
@ -484,13 +484,13 @@ App.Pages.Providers = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Providers.filter(keyword, selectId, show);
},
}).appendTo('#filter-providers .results');
}
if (selectId) {
select(selectId, show);
App.Pages.Providers.select(selectId, show);
}
});
}
@ -542,7 +542,7 @@ App.Pages.Providers = (function () {
if (show) {
const provider = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
display(provider);
App.Pages.Providers.display(provider);
$('#edit-provider, #delete-provider').prop('disabled', false);
}
@ -555,9 +555,9 @@ App.Pages.Providers = (function () {
workingPlanManager = new App.Utils.WorkingPlan();
workingPlanManager.addEventListeners();
resetForm();
filter('');
addEventListeners();
App.Pages.Providers.resetForm();
App.Pages.Providers.filter('');
App.Pages.Providers.addEventListeners();
vars('services').forEach((service) => {
const checkboxId = `provider-service-${service.id}`;
@ -595,8 +595,11 @@ App.Pages.Providers = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -92,8 +92,8 @@ App.Pages.Secretaries = (function () {
event.preventDefault();
const key = $('#filter-secretaries .key').val();
$filterSecretaries.find('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.Secretaries.resetForm();
App.Pages.Secretaries.filter(key);
});
/**
@ -111,7 +111,7 @@ App.Pages.Secretaries = (function () {
const secretary = filterResults.find((filterResult) => Number(filterResult.id) === Number(secretaryId));
display(secretary);
App.Pages.Secretaries.display(secretary);
$('#filter-secretaries .selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
@ -122,7 +122,7 @@ App.Pages.Secretaries = (function () {
* Event: Add New Secretary Button "Click"
*/
$secretaries.on('click', '#add-secretary', () => {
resetForm();
App.Pages.Secretaries.resetForm();
$filterSecretaries.find('button').prop('disabled', true);
$filterSecretaries.find('.results').css('color', '#AAA');
@ -216,11 +216,11 @@ App.Pages.Secretaries = (function () {
secretary.id = $id.val();
}
if (!validate()) {
if (!App.Pages.Secretaries.validate()) {
return;
}
save(secretary);
App.Pages.Secretaries.save(secretary);
});
/**
@ -246,9 +246,9 @@ App.Pages.Secretaries = (function () {
function save(secretary) {
App.Http.Secretaries.save(secretary).done((response) => {
App.Layouts.Backend.displayNotification(lang('secretary_saved'));
resetForm();
App.Pages.Secretaries.resetForm();
$('#filter-secretaries .key').val('');
filter('', response.id, true);
App.Pages.Secretaries.filter('', response.id, true);
});
}
@ -260,8 +260,8 @@ App.Pages.Secretaries = (function () {
function remove(id) {
App.Http.Secretaries.destroy(id).done(() => {
App.Layouts.Backend.displayNotification(lang('secretary_deleted'));
resetForm();
filter($('#filter-secretaries .key').val());
App.Pages.Secretaries.resetForm();
App.Pages.Secretaries.filter($('#filter-secretaries .key').val());
});
}
@ -407,7 +407,10 @@ App.Pages.Secretaries = (function () {
$filterSecretaries.find('.results').empty();
response.forEach((secretary) => {
$filterSecretaries.find('.results').append(getFilterHtml(secretary)).append($('<hr/>'));
$filterSecretaries
.find('.results')
.append(App.Pages.Secretaries.getFilterHtml(secretary))
.append($('<hr/>'));
});
if (!response.length) {
@ -423,7 +426,7 @@ App.Pages.Secretaries = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Customers.filter(keyword, selectId, show);
},
}).appendTo('#filter-secretaries .results');
}
@ -482,7 +485,7 @@ App.Pages.Secretaries = (function () {
if (show) {
const secretary = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
display(secretary);
App.Pages.Secretaries.display(secretary);
$('#edit-secretary, #delete-secretary').prop('disabled', false);
}
@ -492,9 +495,9 @@ App.Pages.Secretaries = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.Secretaries.resetForm();
App.Pages.Secretaries.filter('');
App.Pages.Secretaries.addEventListeners();
vars('providers').forEach((provider) => {
const checkboxId = `provider-service-${provider.id}`;
@ -532,8 +535,11 @@ App.Pages.Secretaries = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -36,8 +36,8 @@ App.Pages.ServiceCategories = (function () {
event.preventDefault();
const key = $('#filter-service-categories .key').val();
$('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.ServiceCategories.resetForm();
App.Pages.ServiceCategories.filter(key);
});
/**
@ -69,7 +69,7 @@ App.Pages.ServiceCategories = (function () {
* Event: Add Service-Category Button "Click"
*/
$serviceCategories.on('click', '#add-service-category', () => {
resetForm();
App.Pages.ServiceCategories.resetForm();
$serviceCategories.find('.add-edit-delete-group').hide();
$serviceCategories.find('.save-cancel-group').show();
$serviceCategories.find('.record-details').find('input, select, textarea').prop('disabled', false);
@ -132,7 +132,7 @@ App.Pages.ServiceCategories = (function () {
return;
}
save(serviceCategory);
App.Pages.ServiceCategories.save(serviceCategory);
});
/**
@ -140,7 +140,7 @@ App.Pages.ServiceCategories = (function () {
*/
$serviceCategories.on('click', '#cancel-service-category', () => {
const id = $id.val();
resetForm();
App.Pages.ServiceCategories.resetForm();
if (id !== '') {
select(id, true);
}
@ -162,7 +162,9 @@ App.Pages.ServiceCategories = (function () {
$('#filter-service-categories .results').empty();
response.forEach((serviceCategory) => {
$('#filter-service-categories .results').append(getFilterHtml(serviceCategory)).append($('<hr/>'));
$('#filter-service-categories .results')
.append(App.Pages.ServiceCategories.getFilterHtml(serviceCategory))
.append($('<hr/>'));
});
if (response.length === 0) {
@ -178,7 +180,7 @@ App.Pages.ServiceCategories = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.ServiceCategories.filter(keyword, selectId, show);
},
}).appendTo('#filter-service-categories .results');
}
@ -197,9 +199,9 @@ App.Pages.ServiceCategories = (function () {
function save(serviceCategory) {
App.Http.ServiceCategories.save(serviceCategory).then((response) => {
App.Layouts.Backend.displayNotification(lang('service_category_saved'));
resetForm();
App.Pages.ServiceCategories.resetForm();
$filterServiceCategories.find('.key').val('');
filter('', response.id, true);
App.Pages.ServiceCategories.filter('', response.id, true);
});
}
@ -211,8 +213,8 @@ App.Pages.ServiceCategories = (function () {
function remove(id) {
App.Http.ServiceCategories.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('service_category_deleted'));
resetForm();
filter($('#filter-service-categories .key').val());
App.Pages.ServiceCategories.resetForm();
App.Pages.ServiceCategories.filter($('#filter-service-categories .key').val());
});
}
@ -321,9 +323,9 @@ App.Pages.ServiceCategories = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.ServiceCategories.resetForm();
App.Pages.ServiceCategories.filter('');
App.Pages.ServiceCategories.addEventListeners();
}
document.addEventListener('DOMContentLoaded', initialize);
@ -332,8 +334,11 @@ App.Pages.ServiceCategories = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -45,8 +45,8 @@ App.Pages.Services = (function () {
event.preventDefault();
const key = $filterServices.find('.key').val();
$filterServices.find('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.Services.resetForm();
App.Pages.Services.filter(key);
});
/**
@ -83,7 +83,7 @@ App.Pages.Services = (function () {
$services.find('.record-details h4').find('a').remove().end().append($link);
display(service);
App.Pages.Services.display(service);
$filterServices.find('.selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
$('#edit-service, #delete-service').prop('disabled', false);
@ -93,7 +93,7 @@ App.Pages.Services = (function () {
* Event: Add New Service Button "Click"
*/
$services.on('click', '#add-service', () => {
resetForm();
App.Pages.Services.resetForm();
$services.find('.add-edit-delete-group').hide();
$services.find('.save-cancel-group').show();
$services.find('.record-details').find('input, select, textarea').prop('disabled', false);
@ -120,10 +120,10 @@ App.Pages.Services = (function () {
$services.on('click', '#cancel-service', () => {
const id = $id.val();
resetForm();
App.Pages.Services.resetForm();
if (id !== '') {
select(id, true);
App.Pages.Services.select(id, true);
}
});
@ -149,11 +149,11 @@ App.Pages.Services = (function () {
service.id = $id.val();
}
if (!validate()) {
if (!App.Pages.Services.validate()) {
return;
}
save(service);
App.Pages.Services.save(service);
});
/**
@ -184,7 +184,7 @@ App.Pages.Services = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(serviceId);
App.Pages.Services.remove(serviceId);
messageModal.dispose();
},
},
@ -203,9 +203,9 @@ App.Pages.Services = (function () {
function save(service) {
App.Http.Services.save(service).then((response) => {
App.Layouts.Backend.displayNotification(lang('service_saved'));
resetForm();
App.Pages.Services.resetForm();
$filterServices.find('.key').val('');
filter('', response.id, true);
App.Pages.Services.filter('', response.id, true);
});
}
@ -217,8 +217,8 @@ App.Pages.Services = (function () {
function remove(id) {
App.Http.Services.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('service_deleted'));
resetForm();
filter($filterServices.find('.key').val());
App.Pages.Services.resetForm();
App.Pages.Services.filter($filterServices.find('.key').val());
});
}
@ -319,7 +319,7 @@ App.Pages.Services = (function () {
$filterServices.find('.results').empty();
response.forEach((service) => {
$filterServices.find('.results').append(getFilterHtml(service)).append($('<hr/>'));
$filterServices.find('.results').append(App.Pages.Services.getFilterHtml(service)).append($('<hr/>'));
});
if (response.length === 0) {
@ -335,13 +335,13 @@ App.Pages.Services = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Services.filter(keyword, selectId, show);
},
}).appendTo('#filter-services .results');
}
if (selectId) {
select(selectId, show);
App.Pages.Services.select(selectId, show);
}
});
}
@ -392,7 +392,7 @@ App.Pages.Services = (function () {
if (show) {
const service = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
display(service);
App.Pages.Services.display(service);
$('#edit-service, #delete-service').prop('disabled', false);
}
@ -419,9 +419,9 @@ App.Pages.Services = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.Services.resetForm();
App.Pages.Services.filter('');
App.Pages.Services.addEventListeners();
updateAvailableServiceCategories();
}
@ -431,8 +431,11 @@ App.Pages.Services = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();

View file

@ -40,8 +40,8 @@ App.Pages.Webhooks = (function () {
event.preventDefault();
const key = $filterWebhooks.find('.key').val();
$filterWebhooks.find('.selected').removeClass('selected');
resetForm();
filter(key);
App.Pages.Webhooks.resetForm();
App.Pages.Webhooks.filter(key);
});
/**
@ -59,7 +59,7 @@ App.Pages.Webhooks = (function () {
const webhook = filterResults.find((filterResult) => Number(filterResult.id) === Number(webhookId));
display(webhook);
App.Pages.Webhooks.display(webhook);
$filterWebhooks.find('.selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
@ -70,7 +70,7 @@ App.Pages.Webhooks = (function () {
* Event: Add New Webhook Button "Click"
*/
$webhooks.on('click', '#add-webhook', () => {
resetForm();
App.Pages.Webhooks.resetForm();
$webhooks.find('.add-edit-delete-group').hide();
$webhooks.find('.save-cancel-group').show();
$webhooks.find('.record-details').find('input, select, textarea').prop('disabled', false);
@ -87,7 +87,7 @@ App.Pages.Webhooks = (function () {
$webhooks.on('click', '#cancel-webhook', () => {
const id = $id.val();
resetForm();
App.Pages.Webhooks.resetForm();
if (id !== '') {
select(id, true);
@ -120,11 +120,11 @@ App.Pages.Webhooks = (function () {
webhook.id = $id.val();
}
if (!validate()) {
if (!App.Pages.Webhooks.validate()) {
return;
}
save(webhook);
App.Pages.Webhooks.save(webhook);
});
/**
@ -154,7 +154,7 @@ App.Pages.Webhooks = (function () {
{
text: lang('delete'),
click: (event, messageModal) => {
remove(webhookId);
App.Pages.Webhooks.remove(webhookId);
messageModal.dispose();
},
},
@ -173,9 +173,9 @@ App.Pages.Webhooks = (function () {
function save(webhook) {
App.Http.Webhooks.save(webhook).then((response) => {
App.Layouts.Backend.displayNotification(lang('webhook_saved'));
resetForm();
App.Pages.Webhooks.resetForm();
$filterWebhooks.find('.key').val('');
filter('', response.id, true);
App.Pages.Webhooks.filter('', response.id, true);
});
}
@ -187,8 +187,8 @@ App.Pages.Webhooks = (function () {
function remove(id) {
App.Http.Webhooks.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('webhook_deleted'));
resetForm();
filter($filterWebhooks.find('.key').val());
App.Pages.Webhooks.resetForm();
App.Pages.Webhooks.filter($filterWebhooks.find('.key').val());
});
}
@ -280,7 +280,7 @@ App.Pages.Webhooks = (function () {
$filterWebhooks.find('.results').empty();
response.forEach((webhook) => {
$filterWebhooks.find('.results').append(getFilterHtml(webhook)).append($('<hr/>'));
$filterWebhooks.find('.results').append(App.Pages.Webhooks.getFilterHtml(webhook)).append($('<hr/>'));
});
if (response.length === 0) {
@ -296,13 +296,13 @@ App.Pages.Webhooks = (function () {
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
App.Pages.Webhooks.filter(keyword, selectId, show);
},
}).appendTo('#filter-webhooks .results');
}
if (selectId) {
select(selectId, show);
App.Pages.Webhooks.select(selectId, show);
}
});
}
@ -355,7 +355,7 @@ App.Pages.Webhooks = (function () {
if (show) {
const webhook = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
display(webhook);
App.Pages.Webhooks.display(webhook);
$('#edit-webhook, #delete-webhook').prop('disabled', false);
}
@ -365,9 +365,9 @@ App.Pages.Webhooks = (function () {
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
App.Pages.Webhooks.resetForm();
App.Pages.Webhooks.filter('');
App.Pages.Webhooks.addEventListeners();
}
document.addEventListener('DOMContentLoaded', initialize);
@ -376,8 +376,11 @@ App.Pages.Webhooks = (function () {
filter,
save,
remove,
validate,
getFilterHtml,
resetForm,
display,
select,
addEventListeners,
};
})();