UNPKG

11.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('lodash'), require('sweetalert2'), require('ng-snotify'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'lodash', 'sweetalert2', 'ng-snotify', '@angular/common'], factory) :
4 (factory((global['ngx-plus'] = global['ngx-plus'] || {}, global['ngx-plus']['ngx-alerts'] = {}),global.ng.core,global.lodash,global.swal,global.ngSnotify,global.ng.common));
5}(this, (function (exports,core,lodash,swal,ngSnotify,common) { 'use strict';
6
7swal = swal && swal.hasOwnProperty('default') ? swal['default'] : swal;
8
9/*! *****************************************************************************
10Copyright (c) Microsoft Corporation. All rights reserved.
11Licensed under the Apache License, Version 2.0 (the "License"); you may not use
12this file except in compliance with the License. You may obtain a copy of the
13License at http://www.apache.org/licenses/LICENSE-2.0
14THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17MERCHANTABLITY OR NON-INFRINGEMENT.
18See the Apache Version 2.0 License for specific language governing permissions
19and limitations under the License.
20***************************************************************************** */
21/* global Reflect, Promise */
22
23
24
25
26
27
28
29
30
31
32function __read(o, n) {
33 var m = typeof Symbol === "function" && o[Symbol.iterator];
34 if (!m) return o;
35 var i = m.call(o), r, ar = [], e;
36 try {
37 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
38 }
39 catch (error) { e = { error: error }; }
40 finally {
41 try {
42 if (r && !r.done && (m = i["return"])) m.call(i);
43 }
44 finally { if (e) throw e.error; }
45 }
46 return ar;
47}
48function __spread() {
49 for (var ar = [], i = 0; i < arguments.length; i++)
50 ar = ar.concat(__read(arguments[i]));
51 return ar;
52}
53
54/**
55 * @fileoverview added by tsickle
56 * @suppress {checkTypes} checked by tsc
57 */
58var NgxAlertTemplatesComponent = /** @class */ (function () {
59 function NgxAlertTemplatesComponent() {
60 }
61 return NgxAlertTemplatesComponent;
62}());
63NgxAlertTemplatesComponent.decorators = [
64 { type: core.Component, args: [{
65 selector: 'ngx-alert-templates',
66 template: "\n <ng-snotify></ng-snotify>\n ",
67 },] },
68];
69/** @nocollapse */
70NgxAlertTemplatesComponent.ctorParameters = function () { return []; };
71/**
72 * @fileoverview added by tsickle
73 * @suppress {checkTypes} checked by tsc
74 */
75var NgxAlertInterfaces = /** @class */ (function () {
76 function NgxAlertInterfaces() {
77 }
78 return NgxAlertInterfaces;
79}());
80/**
81 * @fileoverview added by tsickle
82 * @suppress {checkTypes} checked by tsc
83 */
84/**
85 * @fileoverview added by tsickle
86 * @suppress {checkTypes} checked by tsc
87 */
88/**
89 * @record
90 */
91var NgxAlertsService = /** @class */ (function () {
92 /**
93 * @param {?} notifyService
94 */
95 function NgxAlertsService(notifyService) {
96 this.notifyService = notifyService;
97 }
98 /**
99 * @param {?} type
100 * @param {?} config
101 * @return {?}
102 */
103 NgxAlertsService.prototype.defaultNotify = function (type, config) {
104 return this.notifyService[type](config.body, config.title || null, {
105 timeout: config.timeout || 3000,
106 showProgressBar: config.showProgressBar || true,
107 closeOnClick: config.closeOnClick || true,
108 pauseOnHover: config.pauseOnHover || true,
109 buttons: config.buttons,
110 placeholder: config.placeholder,
111 html: config.html || null,
112 position: config.position || 'rightBottom',
113 });
114 };
115 /**
116 * @param {?} config
117 * @return {?}
118 */
119 NgxAlertsService.prototype.notifySimple = function (config) {
120 this.defaultNotify('simple', config);
121 };
122 /**
123 * @param {?} config
124 * @return {?}
125 */
126 NgxAlertsService.prototype.notifySuccess = function (config) {
127 this.defaultNotify('success', config);
128 };
129 /**
130 * @param {?} config
131 * @return {?}
132 */
133 NgxAlertsService.prototype.notifyInfo = function (config) {
134 this.defaultNotify('info', config);
135 };
136 /**
137 * @param {?} config
138 * @return {?}
139 */
140 NgxAlertsService.prototype.notifyWarning = function (config) {
141 this.defaultNotify('warning', config);
142 };
143 /**
144 * @param {?} config
145 * @return {?}
146 */
147 NgxAlertsService.prototype.notifyError = function (config) {
148 this.defaultNotify('error', config);
149 };
150 /**
151 * @param {?} config
152 * @return {?}
153 */
154 NgxAlertsService.prototype.notifyPrompt = function (config) {
155 this.defaultNotify('prompt', config);
156 };
157 /**
158 * @param {?} config
159 * @return {?}
160 */
161 NgxAlertsService.prototype.notifyConfirm = function (config) {
162 this.defaultNotify('confirm', config);
163 };
164 /**
165 * @param {?} toastId
166 * @return {?}
167 */
168 NgxAlertsService.prototype.notifyDismiss = function (toastId) {
169 this.notifyService.remove(toastId);
170 };
171 /**
172 * @param {?=} options
173 * @param {?=} successCb
174 * @param {?=} closeCb
175 * @return {?}
176 */
177 NgxAlertsService.prototype.alert = function (options, successCb, closeCb) {
178 if (options === void 0) { options = {}; }
179 if (successCb === void 0) { successCb = lodash.noop; }
180 if (closeCb === void 0) { closeCb = lodash.noop; }
181 var /** @type {?} */ defaultOptions = {
182 type: options.type || null,
183 title: options.title || null,
184 text: options.text || null,
185 buttonsStyling: options.buttonsStyling || false,
186 confirmButtonClass: options.confirmButtonClass || 'btn btn-lg btn-secondary',
187 animation: options.animation || true,
188 customClass: options.customClass || '',
189 };
190 if (closeCb !== lodash.noop) {
191 defaultOptions.showCancelButton = options.showCancelButton || true;
192 defaultOptions.cancelButtonClass = options.cancelButtonClass || 'btn btn-lg btn-secondary';
193 }
194 return swal(lodash.assign(defaultOptions, options)).then(function (res) { return successCb(res); }, function (dismiss) { return closeCb(dismiss); });
195 };
196 /**
197 * @param {?=} options
198 * @param {?=} successCb
199 * @param {?=} closeCb
200 * @return {?}
201 */
202 NgxAlertsService.prototype.alertSuccess = function (options, successCb, closeCb) {
203 if (options === void 0) { options = {}; }
204 if (successCb === void 0) { successCb = lodash.noop; }
205 if (closeCb === void 0) { closeCb = lodash.noop; }
206 var /** @type {?} */ defaultOptions = {
207 type: 'success',
208 confirmButtonClass: 'btn btn-lg btn-success',
209 };
210 return this.alert(lodash.assign(defaultOptions, options), successCb, closeCb);
211 };
212 /**
213 * @param {?=} options
214 * @param {?=} successCb
215 * @param {?=} closeCb
216 * @return {?}
217 */
218 NgxAlertsService.prototype.alertWarning = function (options, successCb, closeCb) {
219 if (options === void 0) { options = {}; }
220 if (successCb === void 0) { successCb = lodash.noop; }
221 if (closeCb === void 0) { closeCb = lodash.noop; }
222 var /** @type {?} */ defaultOptions = {
223 type: 'warning',
224 confirmButtonClass: 'btn btn-lg btn-warning',
225 };
226 return this.alert(lodash.assign(defaultOptions, options), successCb, closeCb);
227 };
228 /**
229 * @param {?=} options
230 * @param {?=} successCb
231 * @param {?=} closeCb
232 * @return {?}
233 */
234 NgxAlertsService.prototype.alertError = function (options, successCb, closeCb) {
235 if (options === void 0) { options = {}; }
236 if (successCb === void 0) { successCb = lodash.noop; }
237 if (closeCb === void 0) { closeCb = lodash.noop; }
238 var /** @type {?} */ defaultOptions = {
239 type: 'error',
240 confirmButtonClass: 'btn btn-lg btn-danger',
241 };
242 return this.alert(lodash.assign(defaultOptions, options), successCb, closeCb);
243 };
244 /**
245 * @param {?=} options
246 * @param {?=} successCb
247 * @param {?=} closeCb
248 * @return {?}
249 */
250 NgxAlertsService.prototype.alertInfo = function (options, successCb, closeCb) {
251 if (options === void 0) { options = {}; }
252 if (successCb === void 0) { successCb = lodash.noop; }
253 if (closeCb === void 0) { closeCb = lodash.noop; }
254 var /** @type {?} */ defaultOptions = {
255 type: 'info',
256 confirmButtonClass: 'btn btn-lg btn-info',
257 };
258 return this.alert(lodash.assign(defaultOptions, options), successCb, closeCb);
259 };
260 /**
261 * @param {?=} options
262 * @param {?=} successCb
263 * @param {?=} closeCb
264 * @return {?}
265 */
266 NgxAlertsService.prototype.alertQuestion = function (options, successCb, closeCb) {
267 if (options === void 0) { options = {}; }
268 if (successCb === void 0) { successCb = lodash.noop; }
269 if (closeCb === void 0) { closeCb = lodash.noop; }
270 var /** @type {?} */ defaultOptions = {
271 type: 'question',
272 confirmButtonClass: 'btn btn-lg btn-primary',
273 };
274 return this.alert(lodash.assign(defaultOptions, options), successCb, closeCb);
275 };
276 return NgxAlertsService;
277}());
278NgxAlertsService.decorators = [
279 { type: core.Injectable },
280];
281/** @nocollapse */
282NgxAlertsService.ctorParameters = function () { return [
283 { type: ngSnotify.SnotifyService, },
284]; };
285/**
286 * @fileoverview added by tsickle
287 * @suppress {checkTypes} checked by tsc
288 */
289/**
290 * @fileoverview added by tsickle
291 * @suppress {checkTypes} checked by tsc
292 */
293var components = [NgxAlertTemplatesComponent];
294var NgxAlertsModule = /** @class */ (function () {
295 function NgxAlertsModule() {
296 }
297 /**
298 * @return {?}
299 */
300 NgxAlertsModule.forRoot = function () {
301 return {
302 ngModule: NgxAlertsModule,
303 providers: [{ provide: 'SnotifyToastConfig', useValue: ngSnotify.ToastDefaults }, ngSnotify.SnotifyService, NgxAlertsService],
304 };
305 };
306 return NgxAlertsModule;
307}());
308NgxAlertsModule.decorators = [
309 { type: core.NgModule, args: [{
310 imports: [common.CommonModule, ngSnotify.SnotifyModule],
311 declarations: __spread(components),
312 exports: __spread(components),
313 },] },
314];
315/** @nocollapse */
316NgxAlertsModule.ctorParameters = function () { return []; };
317
318exports.NgxAlertTemplatesComponent = NgxAlertTemplatesComponent;
319exports.NgxAlertInterfaces = NgxAlertInterfaces;
320exports.NgxAlertsService = NgxAlertsService;
321exports.NgxAlertsModule = NgxAlertsModule;
322
323Object.defineProperty(exports, '__esModule', { value: true });
324
325})));
326//# sourceMappingURL=ngx-plus-ngx-alerts.umd.js.map