From e21eceed8a1bb5650be77d15cd7a62f56dfaf373 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Thu, 16 Feb 2023 13:33:20 +0100 Subject: [PATCH] chg: [js-bootstrap] Added new quick function to display a modal from an URL --- webroot/js/bootstrap-helper.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/webroot/js/bootstrap-helper.js b/webroot/js/bootstrap-helper.js index ed31871..7f60c9c 100644 --- a/webroot/js/bootstrap-helper.js +++ b/webroot/js/bootstrap-helper.js @@ -60,7 +60,33 @@ class UIFactory { }).catch((error) => { UI.toast({ variant: 'danger', - title: 'Error while loading the processor', + title: 'Error while loading the modal', + body: error.message + }) + }) + } + + /** + * Create and display a modal where the modal's content is fetched from the provided URL + * @param {string} url - The URL from which the modal's content should be fetched + * @param {Object=[]} modalOptions - Additional options to be passed to the modal constructor + * @return {Promise} Promise object resolving to the ModalFactory object + */ + async modalFromUrl(url, modalOptions={}) { + return AJAXApi.quickFetchURL(url).then((modalHTML) => { + const defaultOptions = { + rawHtml: modalHTML, + } + const options = Object.assign({}, defaultOptions, modalOptions) + const theModal = new ModalFactory(options); + theModal.makeModal() + theModal.show() + theModal.$modal.data('modalObject', theModal) + return [theModal, theModal.ajaxApi] + }).catch((error) => { + UI.toast({ + variant: 'danger', + title: 'Error while loading the modal', body: error.message }) }) @@ -183,7 +209,6 @@ class UIFactory { } return UI.submissionModal(url, successCallback) } - /** * Creates and displays a modal where the modal's content is fetched from the provided URL. Reloads the provided element after a successful operation. @@ -448,13 +473,13 @@ class ModalFactory { */ /** * @callback ModalFactory~confirm - * @param {ModalFactory~closeModalFunction} closeFunction - A function that will close the modal if called + * @param {ModalFactory~confirm} closeFunction - A function that will close the modal if called * @param {Object} modalFactory - The instance of the ModalFactory * @param {Object} evt - The event that triggered the confirm operation */ /** * @callback ModalFactory~cancel - * @param {ModalFactory~closeModalFunction} closeFunction - A function that will close the modal if called + * @param {ModalFactory~cancel} closeFunction - A function that will close the modal if called * @param {Object} modalFactory - The instance of the ModalFactory * @param {Object} evt - The event that triggered the confirm operation */