mirror of https://github.com/moparisthebest/mail
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
var ngModule = angular.module('woUtil');
|
|
ngModule.service('dialog', Dialog);
|
|
module.exports = Dialog;
|
|
|
|
/**
|
|
* A central service to display messages to the user in a dialog
|
|
*/
|
|
function Dialog($q, axe) {
|
|
this._q = $q;
|
|
this._axe = axe;
|
|
}
|
|
|
|
/**
|
|
* Show an information dialog
|
|
* @param {String} options.title The title of the displayed dialog
|
|
* @param {String} options.message The message to be displayed
|
|
* @return {Promise}
|
|
*/
|
|
Dialog.prototype.info = function(options) {
|
|
return this._handle(options, this.displayInfo, 'displayInfo');
|
|
};
|
|
|
|
/**
|
|
* Show an error dialog
|
|
* @param {String} options.title (optional) The title of the displayed dialog
|
|
* @param {String} options.message The message to be displayed
|
|
* @return {Promise}
|
|
*/
|
|
Dialog.prototype.error = function(options) {
|
|
// log the error
|
|
this._axe.error((options.errMsg || options.message) + (options.stack ? ('\n' + options.stack) : ''));
|
|
return this._handle(options, this.displayError, 'displayError');
|
|
};
|
|
|
|
/**
|
|
* Show an confirm dialog
|
|
* @param {String} options.title The title of the displayed dialog
|
|
* @param {String} options.message The message to be displayed
|
|
* @param {String} options.callback The callback that is called after the confirmation has been granted or denied
|
|
* @return {Promise}
|
|
*/
|
|
Dialog.prototype.confirm = function(options) {
|
|
return this._handle(options, this.displayConfirm, 'displayConfirm');
|
|
};
|
|
|
|
/**
|
|
* Helper function which returns a promise
|
|
*/
|
|
Dialog.prototype._handle = function(options, fn, errMsg) {
|
|
return this._q(function(resolve, reject) {
|
|
if (fn) {
|
|
fn(options);
|
|
resolve();
|
|
} else {
|
|
reject(new Error('Dialog service ' + errMsg + ' not set!'));
|
|
}
|
|
});
|
|
}; |