Skip to content

Commit adb12a4

Browse files
committed
abp ui's notify&message methods reimpled via swal2
1 parent 203acba commit adb12a4

File tree

3 files changed

+180
-12
lines changed

3 files changed

+180
-12
lines changed

angular/angular.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
],
3333
"styles": [
3434
"node_modules/famfamfam-flags/dist/sprite/famfamfam-flags.css",
35-
"node_modules/toastr/build/toastr.css",
35+
"node_modules/sweetalert2/dist/sweetalert2.css",
3636
"node_modules/@fortawesome/fontawesome-free/css/all.min.css",
3737
"node_modules/admin-lte-css-only/css/adminlte.min.css",
3838
"src/shared/core.less"
@@ -41,18 +41,16 @@
4141
"node_modules/jquery/dist/jquery.min.js",
4242
"node_modules/moment/min/moment.min.js",
4343
"node_modules/@aspnet/signalr/dist/browser/signalr.min.js",
44-
"node_modules/toastr/toastr.js",
45-
"node_modules/sweetalert/dist/sweetalert.min.js",
44+
"node_modules/sweetalert2/dist/sweetalert2.js",
4645
"node_modules/block-ui/jquery.blockUI.js",
4746
"node_modules/spin.js/spin.min.js",
4847
"node_modules/spin.js/jquery.spin.js",
4948
"node_modules/push.js/bin/push.min.js",
5049
"node_modules/abp-web-resources/Abp/Framework/scripts/abp.js",
50+
"src/assets/abp-web-resources/abp.sweet-alert.js",
5151
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js",
52-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js",
5352
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js",
5453
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js",
55-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js",
5654
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.moment.js"
5755
]
5856
},
@@ -126,7 +124,7 @@
126124
],
127125
"styles": [
128126
"node_modules/famfamfam-flags/dist/sprite/famfamfam-flags.css",
129-
"node_modules/toastr/build/toastr.css",
127+
"node_modules/sweetalert2/dist/sweetalert2.css",
130128
"node_modules/@fortawesome/fontawesome-free/css/all.min.css",
131129
"node_modules/admin-lte-css-only/css/adminlte.min.css",
132130
"src/shared/core.less"
@@ -135,18 +133,16 @@
135133
"node_modules/jquery/dist/jquery.min.js",
136134
"node_modules/moment/min/moment.min.js",
137135
"node_modules/@aspnet/signalr/dist/browser/signalr.min.js",
138-
"node_modules/toastr/toastr.js",
139-
"node_modules/sweetalert/dist/sweetalert.min.js",
136+
"node_modules/sweetalert2/dist/sweetalert2.js",
140137
"node_modules/block-ui/jquery.blockUI.js",
141138
"node_modules/spin.js/spin.min.js",
142139
"node_modules/spin.js/jquery.spin.js",
143140
"node_modules/push.js/bin/push.min.js",
144141
"node_modules/abp-web-resources/Abp/Framework/scripts/abp.js",
142+
"src/assets/abp-web-resources/abp.sweet-alert.js",
145143
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js",
146-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js",
147144
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js",
148145
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js",
149-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js",
150146
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.moment.js"
151147
]
152148
}

angular/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"push.js": "1.0.9",
3939
"rxjs": "^6.4.0",
4040
"spin.js": "^2.3.2",
41-
"sweetalert": "^2.0.8",
42-
"toastr": "^2.1.2",
41+
"sweetalert2": "^9.10.12",
4342
"ts-helpers": "^1.1.2",
4443
"web-animations-js": "^2.3.2",
4544
"zone.js": "~0.9.1"
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
var abp = abp || {};
2+
(() => {
3+
if (!Swal) {
4+
return;
5+
}
6+
7+
/* MESSAGE **************************************************/
8+
9+
let showMessage = (type, message, title, isHtml, options) => {
10+
if (!title) {
11+
title = message;
12+
message = undefined;
13+
}
14+
15+
options = options || {};
16+
options.title = title;
17+
options.type = type;
18+
options.confirmButtonText =
19+
options.confirmButtonText || abp.localization.abpWeb("Ok");
20+
21+
if (isHtml) {
22+
options.html = message;
23+
} else {
24+
options.text = message;
25+
}
26+
27+
return Swal.fire(options);
28+
};
29+
30+
abp.message.info = (message, title, isHtml, options) => {
31+
return showMessage("info", message, title, isHtml, options);
32+
};
33+
34+
abp.message.success = (message, title, isHtml, options) => {
35+
return showMessage("success", message, title, isHtml, options);
36+
};
37+
38+
abp.message.warn = (message, title, isHtml, options) => {
39+
return showMessage("warning", message, title, isHtml, options);
40+
};
41+
42+
abp.message.error = (message, title, isHtml, options) => {
43+
return showMessage("error", message, title, isHtml, options);
44+
};
45+
46+
abp.message.confirm = (
47+
message,
48+
titleOrCallback,
49+
callback,
50+
isHtml,
51+
options
52+
) => {
53+
let title = undefined;
54+
55+
if (typeof titleOrCallback === "function") {
56+
callback = titleOrCallback;
57+
} else if (titleOrCallback) {
58+
title = titleOrCallback;
59+
}
60+
61+
options = options || {};
62+
options.title = title ? title : abp.localization.abpWeb("AreYouSure");
63+
options.type = "warning";
64+
65+
options.confirmButtonText =
66+
options.confirmButtonText || abp.localization.abpWeb("Yes");
67+
options.cancelButtonText =
68+
options.cancelButtonText || abp.localization.abpWeb("Cancel");
69+
options.showCancelButton = true;
70+
71+
if (isHtml) {
72+
options.html = message;
73+
} else {
74+
options.text = message;
75+
}
76+
77+
return Swal.fire(options).then(function (result) {
78+
callback && callback(result.value);
79+
});
80+
};
81+
82+
/* NOTIFICATION *********************************************/
83+
84+
const Toast = Swal.mixin({
85+
toast: true,
86+
position: "bottom-end",
87+
showConfirmButton: false,
88+
timer: 3000,
89+
});
90+
91+
let showNotification = (type, message, title, options) => {
92+
const icon = options.customClass.icon
93+
? `<i class="mr-2 text-light ${options.customClass.icon}"></i>`
94+
: "";
95+
96+
if (title) {
97+
options.title = `${icon}<span class="text-light">${title}</span>`;
98+
}
99+
100+
options.html = `${title ? "" : icon}
101+
<span class="text-light">${message}</span>`;
102+
103+
Toast.fire(options);
104+
};
105+
106+
abp.notify.success = (message, title, options) => {
107+
showNotification(
108+
"success",
109+
message,
110+
title,
111+
Object.assign(
112+
{
113+
background: "#34bfa3",
114+
customClass: {
115+
icon: "fas fa-check-circle",
116+
},
117+
},
118+
options
119+
)
120+
);
121+
};
122+
123+
abp.notify.info = (message, title, options) => {
124+
showNotification(
125+
"info",
126+
message,
127+
title,
128+
Object.assign(
129+
{
130+
background: "#36a3f7",
131+
customClass: {
132+
icon: "fas fa-info-circle",
133+
},
134+
},
135+
options
136+
)
137+
);
138+
};
139+
140+
abp.notify.warn = (message, title, options) => {
141+
showNotification(
142+
"warning",
143+
message,
144+
title,
145+
Object.assign(
146+
{
147+
background: "#ffb822",
148+
customClass: {
149+
icon: "fas fa-exclamation-triangle",
150+
},
151+
},
152+
options
153+
)
154+
);
155+
};
156+
157+
abp.notify.error = (message, title, options) => {
158+
showNotification(
159+
"error",
160+
message,
161+
title,
162+
Object.assign(
163+
{
164+
background: "#f4516c",
165+
customClass: {
166+
icon: "fas fa-exclamation-circle",
167+
},
168+
},
169+
options
170+
)
171+
);
172+
};
173+
})();

0 commit comments

Comments
 (0)