diff --git a/client/src/i18n/en.json b/client/src/i18n/en.json index 45f4901ec8..b08a1cd207 100644 --- a/client/src/i18n/en.json +++ b/client/src/i18n/en.json @@ -1874,6 +1874,11 @@ "REFERENCE_LOOKUP" : "Reference Lookup", "NO_RECEIPT" : "No receipt matches that reference.", "SUCCESS" : "Successfully found a receipt!" + }, + "CONFIRM" : { + "TITLE" : "Action Confirmation", + "PROMPT" : "Are you sure you would like to perform that action?", + "ACCEPT" : "Accept" } }, "NO_EXCHANGE": { diff --git a/client/src/js/services/ModalService.js b/client/src/js/services/ModalService.js new file mode 100644 index 0000000000..8929fd32cd --- /dev/null +++ b/client/src/js/services/ModalService.js @@ -0,0 +1,59 @@ +angular.module('bhima.services') +.service('ModalService', ModalService); + +ModalService.$inject = [ '$uibModal' ]; + +/** + * Modal Service + * + * A service to house generic modals useful through out the application. These + * will replace a lot of the native JavaScript alerts/confirms to allow easier + * translation, testing, and functionality. + * + * @todo - build following methods/modals: + * - alert() to show a generic alert with "dismiss" or "acknowledge" button. + * It might be useful to have an associated icon and state (error, info, + * warning, etc). + * + * - sudo() to bring up a modal requiring correct user password entry and set + * the application state into super user mode (if appropriate) + * + * - confirmText() to bring up a "type this text to confirm" input that will + * only allow a user to enter text and only enable the "confirm" button once + * the text matches exactly what is anticipated. + * + */ +function ModalService(Modal) { + var service = this; + + service.confirm = confirm; + + /** + * Opens a "confirm delete" modal with a button for "Confirm" or "Cancel". + * The modal is a safe replacement for $window.confirm(), since you cannot + * disable javascript alerts from within it. + * + * @param {String} prompt - a translateable message to pass the template + * @param {Object} options - optional object with properties to configure the + * ui-bootstrap modal. + * @returns {Promise} result - a promise resolved by the modal instance + */ + function confirm(prompt, options) { + + // default options for modal rendering + var opts = options || {}; + + var instance = Modal.open({ + animation : opts.animation || false, + keyboard : opts.keyboard || true, + size : opts.size || 'md', + controller : 'ConfirmModalController as ConfirmModalCtrl', + resolve : { prompt : function provider() { return prompt;} }, + templateUrl : '/partials/templates/modals/confirm.modal.html' + }); + + return instance.result; + } + + +} diff --git a/client/src/partials/billing_services/index.html b/client/src/partials/billing_services/index.html index 00a18ae6e3..9d023f5bf6 100644 --- a/client/src/partials/billing_services/index.html +++ b/client/src/partials/billing_services/index.html @@ -9,8 +9,6 @@
- - +

{{ "MODALS.CONFIRM.TITLE" | translate }}

+
+ + + + diff --git a/client/src/partials/templates/modals/confirm.modal.js b/client/src/partials/templates/modals/confirm.modal.js new file mode 100644 index 0000000000..699fa5d609 --- /dev/null +++ b/client/src/partials/templates/modals/confirm.modal.js @@ -0,0 +1,22 @@ +angular.module('bhima.controllers') +.controller('ConfirmModalController', ConfirmModalController); + +ConfirmModalController.$inject = ['$uibModalInstance', 'prompt']; + +/** + * Confirm Modal Controller + * + * This controller provides bindings for the confirm modal. + */ +function ConfirmModalController(Instance, prompt) { + var vm = this; + + /** + * bind the prompt to the view, if provided + * @todo - should this be done automatically with controllerAs? + */ + vm.prompt = prompt; + + // bind modal controls + vm.close = Instance.close; +}