diff --git a/webroot/js/bootstrap-helper.js b/webroot/js/bootstrap-helper.js index 7f60c9c..d29d0c7 100644 --- a/webroot/js/bootstrap-helper.js +++ b/webroot/js/bootstrap-helper.js @@ -284,6 +284,67 @@ class UIFactory { }) return promise } + + /** + * Place an overlay onto a node and remove it whenever the promise resolves + * @param {(jQuery|string)} node - The node on which the confirm popover should be palced + * @param {Object} options - The options to be passed to the overlay class + * @return {Promise} Result of the passed promised + */ + quickConfirm(node, options={}) { + const $node = $(node) + const defaultOptions = { + title: 'Confirm action', + description: '', + descriptionHtml: false, + container: 'body', + variant: 'success', + confirmText: 'Confirm', + confirm: function() {} + } + options = Object.assign({}, defaultOptions, options) + options.description = options.descriptionHtml ? options.descriptionHtml : sanitize(options.description) + const popoverOptions = { + title: options.title, + titleHtml: options.titleHtml, + container: options.container, + html: true, + } + + var promiseResolve, promiseReject; + const confirmPromise = new Promise(function (resolve, reject) { + promiseResolve = resolve; + promiseReject = reject; + }) + popoverOptions.content = function() { + const $node = $(this) + const $container = $('
${options.description}
`) + $container.append($(`