| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- var abp = abp || {};
- (function ($) {
- if (!sweetAlert || !$) {
- return;
- }
- /* DEFAULTS *************************************************/
- abp.libs = abp.libs || {};
- abp.libs.sweetAlert = {
- config: {
- 'default': {
- },
- info: {
- type: 'info'
- },
- success: {
- type: 'success'
- },
- warning: {
- type: 'warning'
- },
- error: {
- type: 'error'
- },
- confirm: {
- title: 'Are you sure?',
- type: 'warning',
- showCancelButton: true,
- /*confirmButtonColor: '#3085d6',
- cancelButtonColor: '#d33',*/
- confirmButtonText: abp.localization
- .iwbZero("Confirm"),
- cancelButtonText: abp.localization
- .iwbZero("Cancel")
- }
- }
- };
- /* MESSAGE **************************************************/
- var showMessage = function (type, message, title) {
- if (!title) {
- title = message;
- message = undefined;
- }
- var opts = $.extend(
- {},
- abp.libs.sweetAlert.config['default'],
- abp.libs.sweetAlert.config[type],
- {
- title: title,
- text: message
- }
- );
- return $.Deferred(function ($dfd) {
- sweetAlert(opts).then(function () {
- $dfd.resolve();
- });
- });
- };
- abp.message.info = function (message, title) {
- return showMessage('info', message, title);
- };
- abp.message.success = function (message, title) {
- title = title || "Success";
- return showMessage('success', message, title);
- };
- abp.message.warn = function (message, title) {
- title = title || "Warning";
- return showMessage('warning', message, title);
- };
- abp.message.error = function (message, title) {
- title = title || "Error";
- return showMessage('error', message, title);
- };
- abp.message.confirm = function (message, titleOrCallback, callback) {
- var userOpts = {
- text: message
- };
- if ($.isFunction(titleOrCallback)) {
- callback = titleOrCallback;
- } else if (titleOrCallback) {
- userOpts.title = titleOrCallback;
- };
- var opts = $.extend(
- {},
- abp.libs.sweetAlert.config['default'],
- abp.libs.sweetAlert.config.confirm,
- userOpts,
- opts
- );
- return $.Deferred(function ($dfd) {
- sweetAlert(opts).then(function (result) {
- if (result.value) {
- callback && callback(result);
- }
- $dfd.resolve(result);
- });
- });
- };
- abp.event.on('abp.dynamicScriptsInitialized', function () {
- abp.libs.sweetAlert.config.confirm.title = abp.localization.abpWeb('AreYouSure');
- abp.libs.sweetAlert.config.confirm.buttons = [abp.localization.abpWeb('Cancel'), abp.localization.abpWeb('Yes')];
- });
- })(jQuery);
|