Skip to content

Commit e1779aa

Browse files
authored
Merge pull request #28 from aspnetboilerplate/sweet-alert2
Add sweet-alert2 integration
2 parents c40c04c + 9411535 commit e1779aa

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

Abp/Framework/scripts/abp.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
let defaultSourceName: string;
8080

81-
let values: { [key: string]: string };
81+
let values: { [key: string]: { [key: string]: string } };
8282

8383
let abpWeb: (key: string) => string;
8484

@@ -318,8 +318,7 @@
318318

319319
function error(message: string, title?: string, options?: any): any;
320320

321-
function confirm(message: string, title?: string, callback?: (result: boolean, info?: any) => void, options?: any): any;
322-
321+
function confirm(message: string, title?: string, callback?: (isConfirmed: boolean, isCancelled?: boolean) => void, options?: any): any;
323322
}
324323

325324
namespace ui {
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
var abp = abp || {};
2+
(function ($) {
3+
if (!sweetAlert || !$) {
4+
return;
5+
}
6+
7+
/* DEFAULTS *************************************************/
8+
9+
abp.libs = abp.libs || {};
10+
abp.libs.sweetAlert = {
11+
config: {
12+
'default': {
13+
14+
},
15+
info: {
16+
icon: 'info'
17+
},
18+
success: {
19+
icon: 'success'
20+
},
21+
warn: {
22+
icon: 'warning'
23+
},
24+
error: {
25+
icon: 'error'
26+
},
27+
confirm: {
28+
icon: 'warning',
29+
title: 'Are you sure?',
30+
buttons: ['Cancel', 'Yes']
31+
}
32+
}
33+
};
34+
35+
/* MESSAGE **************************************************/
36+
37+
var showMessage = function (type, message, title, callback, options) {
38+
options = options || {};
39+
var messageContent = {};
40+
if(title){
41+
messageContent.title = title;
42+
}
43+
44+
messageContent.text = message;
45+
46+
var opts = $.extend(
47+
{},
48+
abp.libs.sweetAlert.config['default'],
49+
abp.libs.sweetAlert.config[type],
50+
messageContent,
51+
options
52+
);
53+
54+
return $.Deferred(($dfd) => {
55+
Swal.fire(opts).then((result) => {
56+
callback && callback(result);
57+
$dfd.resolve(result)
58+
});
59+
});
60+
};
61+
62+
abp.message.info = function (message, title, options) {
63+
return showMessage('info', message, title, null, options);
64+
};
65+
66+
abp.message.success = function (message, title, options) {
67+
return showMessage('success', message, title, null, options);
68+
};
69+
70+
abp.message.warn = function (message, title, options) {
71+
return showMessage('warn', message, title, null, options);
72+
};
73+
74+
abp.message.error = function (message, title, options) {
75+
return showMessage('error', message, title, null, options);
76+
};
77+
78+
abp.message.confirm = function (message, title, callback, options) {
79+
options = options || {};
80+
options.showCancelButton = true;
81+
82+
const confirmFunc = (result) => {
83+
let isCancelled = result.dismiss === Swal.DismissReason.cancel;
84+
85+
return callback && callback(result.isConfirmed, isCancelled);
86+
}
87+
88+
return showMessage('confirm', message, title, confirmFunc, options);
89+
};
90+
91+
abp.message.swal = function (options, callback){
92+
return showMessage(null, null, null, callback, options);
93+
};
94+
95+
abp.event.on('abp.dynamicScriptsInitialized', function () {
96+
abp.libs.sweetAlert.config.confirm.title = abp.localization.abpWeb('AreYouSure');
97+
abp.libs.sweetAlert.config.confirm.buttons = [abp.localization.abpWeb('Cancel'), abp.localization.abpWeb('Yes')];
98+
});
99+
100+
})(jQuery);

Abp/Framework/scripts/libs/abp.sweet-alert2.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)