|
| 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