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 ) ;
0 commit comments