cheetah-framework
Version:
Cheetah Framework JS used in all our applications
103 lines (90 loc) • 2.68 kB
JavaScript
/* global _ cheetahApp */
import { isObject } from './Var'
class AlertClass {
/**
* Display a confirmation popup message
*
* Usage : Alert.confirm('title', 'message'[, options]).then(callback, onDismiss)
*
* example of dismiss function:
*
* inDismiss (dismiss) {
* dismiss can be 'cancel', 'overlay', 'close', and 'timer'
* // body...
* }
*
* more informations ==> https://limonte.github.io/sweetalert2/
*
* @param {String|null} title
* @param {String|null} message
* @param {Object} options
* @return {Promise}
*/
confirm (title, message = null, options = {}) {
options = isObject(message) ? message : options
options = _.extend({}, {
type: 'warning',
showCloseButton: true,
dangerouslyUseHTMLString: true,
confirmButtonText: cheetahApp.$t('yes')
}, options)
return cheetahApp.$confirm(...(message === null ? [title, options] : [message, title, options]))
}
/**
* Display a simple success popup message
*
* @param {String|null} title
* @param {String|null} message
* @param {Object|null} options
* @return {Promise}
*/
success (title, message, options) {
options = _.extend({ type: 'success' }, options)
return cheetahApp.$alert(message, title, options)
}
/**
* Display a simple info popup message
*
* @param {String|null} title
* @param {String|null} message
* @param {Object|null} options
* @return {Promise}
*/
info (title, message, options) {
options = _.extend({ type: 'info' }, options)
return cheetahApp.$alert(message, title, options)
}
/**
* Display a simple error popup message
*
* @param {String|null} title
* @param {String|null} message
* @param {Object|null} options
* @return {Promise}
*/
error (title, message, options) {
options = _.extend({ type: 'error' }, options)
return cheetahApp.$alert(message, title, options)
}
/**
* Display a error popup message + a try again button
*
* Usage : Alert.errorTryAgain('title', 'message'[, options]).then(tryagainFunction, onDismiss)
*
* use options.confirmButtonText to change try again text
*
* @param {String|null} title
* @param {String|null} message
* @param {Object|null} options
* @return {Promise}
*/
errorTryAgain (title, message, options) {
options = _.extend({
type: 'error',
showCloseButton: true,
confirmButtonText: '<i class="glyphicon glyphicon-repeat"></i> ' + cheetahApp.$t('retry')
}, options)
return cheetahApp.$alert(message, title, options)
}
}
export default new AlertClass()