UNPKG

@sd-angular/core

Version:

Sd Angular Core Lib

720 lines (707 loc) 40.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/material/dialog'), require('@angular/material/icon'), require('@angular/material/button'), require('@angular/material/form-field'), require('@angular/material/input'), require('@angular/forms'), require('ngx-toastr'), require('@sd-angular/core/button'), require('@sd-angular/core/common'), require('uuid'), require('@sd-angular/core/translate'), require('rxjs/operators'), require('rxjs')) : typeof define === 'function' && define.amd ? define('@sd-angular/core/notify', ['exports', '@angular/core', '@angular/common', '@angular/material/dialog', '@angular/material/icon', '@angular/material/button', '@angular/material/form-field', '@angular/material/input', '@angular/forms', 'ngx-toastr', '@sd-angular/core/button', '@sd-angular/core/common', 'uuid', '@sd-angular/core/translate', 'rxjs/operators', 'rxjs'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['sd-angular'] = global['sd-angular'] || {}, global['sd-angular'].core = global['sd-angular'].core || {}, global['sd-angular'].core.notify = {}), global.ng.core, global.ng.common, global.ng.material.dialog, global.ng.material.icon, global.ng.material.button, global.ng.material.formField, global.ng.material.input, global.ng.forms, global['ngx-toastr'], global['sd-angular'].core.button, global['sd-angular'].core.common, global.uuid, global['sd-angular'].core.translate, global.rxjs.operators, global.rxjs)); }(this, (function (exports, core, common, dialog, icon, button, formField, input, forms, ngxToastr, button$1, common$1, uuid, translate, operators, rxjs) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } /** @deprecated */ function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** @deprecated */ function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } function __spreadArray(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); } function __classPrivateFieldSet(receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; } var DialogConfirmComponent = /** @class */ (function () { function DialogConfirmComponent(dialogRef, data) { var _a, _b, _c, _d; this.dialogRef = dialogRef; this.data = data; this.required = false; this.isString = false; this.id = "I" + uuid.v4(); this.isString = typeof ((_a = this.data) === null || _a === void 0 ? void 0 : _a.message) === 'string'; if (data === null || data === void 0 ? void 0 : data.input) { this.value = (_c = (_b = data === null || data === void 0 ? void 0 : data.input) === null || _b === void 0 ? void 0 : _b.defaultValue) !== null && _c !== void 0 ? _c : ''; this.required = ((_d = data === null || data === void 0 ? void 0 : data.input) === null || _d === void 0 ? void 0 : _d.required) || false; } } return DialogConfirmComponent; }()); DialogConfirmComponent.decorators = [ { type: core.Component, args: [{ selector: 'sd-dialog-confirm', template: "<h1 mat-dialog-title class=\"\">\r\n <mat-icon *ngIf=\"data?.icon\" [ngClass]=\"data?.icon\">\r\n {{ data?.icon }}\r\n </mat-icon>\r\n <span [innerHtml]=\"data?.title || 'Confirm'\"></span>\r\n</h1>\r\n<div mat-dialog-content>\r\n <div *ngIf=\"isString\" [innerHtml]=\"data?.message\"></div>\r\n <div *ngIf=\"!isString\" [innerHtml]=\"data?.message | json\"></div>\r\n <div *ngIf=\"data?.input\">\r\n <mat-form-field appearance=\"outline\">\r\n <textarea style=\"width: 100%\" matInput [placeholder]=\"data.input?.placeholder\" [(ngModel)]=\"value\"\r\n autocomplete=\"off\" rows=\"5\" [maxlength]=\"data.input?.maxlength\"></textarea>\r\n </mat-form-field>\r\n </div>\r\n</div>\r\n<div mat-dialog-actions align=\"end\">\r\n <sd-button *ngIf=\"data?.noTitle\" [color]=\"data?.noButtonColor || 'secondary'\" [mat-dialog-close]=\"'CANCEL'\"\r\n [title]=\"data?.noTitle\" size=\"sm\"></sd-button>\r\n <sd-button class=\"ml-12\" *ngIf=\"data?.yesTitle\" [mat-dialog-close]=\"value || 'ACCEPT'\"\r\n [color]=\"data?.yesButtonColor || 'primary'\" [disabled]=\"required && !value\" cdkFocusInitial\r\n [title]=\"data?.yesTitle\" size=\"sm\"></sd-button>\r\n</div>", styles: [":host .mat-dialog-content{margin:0 -16px 16px!important}:host .mat-button{background-color:#f5f5f5}:host>>>.mat-dialog-title{align-items:center;display:flex;justify-content:flex-start}:host>>>.mat-dialog-title .mat-icon{margin-right:5px}:host{display:block;padding:12px 16px}:host>>>.mat-dialog-title .mat-icon.info{color:#2962ff}:host>>>.mat-dialog-title .mat-icon.warning{color:#ffc107}:host>>>.mat-dialog-title .mat-icon.done{color:#4caf50}:host>>>.mat-dialog-title .mat-icon.error{color:#d32f2f}"] },] } ]; DialogConfirmComponent.ctorParameters = function () { return [ { type: dialog.MatDialogRef }, { type: undefined, decorators: [{ type: core.Inject, args: [dialog.MAT_DIALOG_DATA,] }] } ]; }; var NOTIFY_CONFIG = new core.InjectionToken('notify.configuration'); var _delayDuration, _warningKey, _errorKey, _cache, _notifyWarning, _notifyError, _buildToastMultiMesssage; var SdNotifyService = /** @class */ (function () { function SdNotifyService(dialog, toastr, translateService, configuration) { var _this = this; this.dialog = dialog; this.toastr = toastr; this.translateService = translateService; this.configuration = configuration; _delayDuration.set(this, 500); // Các error/warning message sẽ tự động gộp sau khoảng thời gian trên _warningKey.set(this, uuid.v4()); _errorKey.set(this, uuid.v4()); _cache.set(this, {}); this.alert = { info: function (message, title, yesTitle, icon) { _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { icon: icon || 'info', title: title || _this.translate('Notice'), message: message || 'Done!', yesTitle: yesTitle || _this.translate('Ok'), }, }); }, success: function (message, title, yesTitle, icon) { _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { icon: icon || 'done', title: title || _this.translate('Success'), message: message || 'Done!', yesTitle: yesTitle || _this.translate('Ok'), }, }); }, warning: function (message, title, yesTitle, icon) { _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { icon: icon || 'warning', title: title || _this.translate('Warning'), message: message || 'Something went wrong!', yesTitle: yesTitle || _this.translate('Ok'), }, }); }, error: function (message, title, yesTitle, icon) { _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { icon: icon || 'error', title: title || _this.translate('Error'), message: message || 'Something went wrong!', yesTitle: yesTitle || _this.translate('Ok'), }, }); }, }; this.notify = { success: function (message, delay, title) { var _a; // tslint:disable-next-line: max-line-length // const style = `border-radius: 5px; margin: 0; padding: 12px; z-index: 99999; top: 5px; right: 5px; display: none; position: fixed;color: #4F8A10; background-color: #DFF2BF`; // tslint:disable-next-line: max-line-length // const html = `<div id='${this.notifyId}' style='${style}'><i class='fa fa-check'></i> ${message || this.translate('Success')}</div>`; // this.showNotify(html, delay); var content = message || _this.translate('Success'); _this.toastr.success(content, title, { enableHtml: true, timeOut: delay || ((_a = _this.configuration) === null || _a === void 0 ? void 0 : _a.timeDelay) || 3000, closeButton: true, }); }, warning: function (message, delay, title) { if (!__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)] || Date.addMiliseconds(__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].createdDate, __classPrivateFieldGet(_this, _delayDuration)) < new Date()) { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)] = { createdDate: new Date(), data: { title: title, messages: [], } }; rxjs.timer(__classPrivateFieldGet(_this, _delayDuration)).pipe(operators.take(1)).subscribe(function () { var messages = __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.messages.union(null); if (messages.length === 1) { __classPrivateFieldGet(_this, _notifyWarning).call(_this, { title: __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.title, message: messages[0], delay: delay }); } else { __classPrivateFieldGet(_this, _notifyWarning).call(_this, { title: __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.title, message: messages, delay: delay }); } }); } if (Array.isArray(message)) { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.messages = __spread(__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.messages, message); } else { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _warningKey)].data.messages.push(message); } }, error: function (message, delay, title) { if (!__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)] || Date.addMiliseconds(__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].createdDate, __classPrivateFieldGet(_this, _delayDuration)) < new Date()) { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)] = { createdDate: new Date(), data: { title: title, messages: [], } }; rxjs.timer(__classPrivateFieldGet(_this, _delayDuration)).pipe(operators.take(1)).subscribe(function () { var messages = __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.messages.union(null); if (messages.length === 1) { __classPrivateFieldGet(_this, _notifyError).call(_this, { title: __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.title, message: messages[0], delay: delay }); } else { __classPrivateFieldGet(_this, _notifyError).call(_this, { title: __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.title, message: messages, delay: delay }); } }); } if (Array.isArray(message)) { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.messages = __spread(__classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.messages, message); } else { __classPrivateFieldGet(_this, _cache)[__classPrivateFieldGet(_this, _errorKey)].data.messages.push(message); } }, }; _notifyWarning.set(this, function (args) { var _a; var message = args.message, delay = args.delay, title = args.title; if (Array.isArray(message)) { __classPrivateFieldGet(_this, _buildToastMultiMesssage).call(_this, 'warning', message, delay, title); } else { var content = message || _this.translate('Warning'); _this.toastr.warning(content, title, { enableHtml: true, timeOut: delay || ((_a = _this.configuration) === null || _a === void 0 ? void 0 : _a.timeDelay) || 3000, closeButton: true, }); } }); _notifyError.set(this, function (args) { var _a; var message = args.message, delay = args.delay, title = args.title; if (Array.isArray(message)) { __classPrivateFieldGet(_this, _buildToastMultiMesssage).call(_this, 'error', message, delay, title); } else { var content = message || _this.translate('Error'); _this.toastr.error(content, title, { enableHtml: true, timeOut: delay || ((_a = _this.configuration) === null || _a === void 0 ? void 0 : _a.timeDelay) || 3000, closeButton: true, }); } }); _buildToastMultiMesssage.set(this, function (type, messages, delay, title) { var _a, _b; /** số lượng item hiển thị mặc định */ var showNum = 2; var id = "sd-notify-ckb-" + uuid.v4(); var messageLength = messages.length; var messageRests = messages.splice(showNum); var messageContainer = "<ul class='sd-notify__list'>{0}{1}</ul>"; var messageTemp = "<li class='sd-notify__item'>- {0}</li>"; var contentRest = ''; if (messageRests === null || messageRests === void 0 ? void 0 : messageRests.length) { contentRest = "<input id='" + id + "' class='cdk-visually-hidden sd-notify__checkbox' type='checkbox' />\n <label class='sd-notify__text sd-notify__text--show' for='" + id + "'>" + _this.translate('Show more') + "</label>\n <div class='sd-notify__item--rest'>\n " + messageRests.map(function (m) { return String.format(messageTemp, m); }).join('') + "\n </div>\n <label class='sd-notify__text sd-notify__text--less' for='" + id + "'>" + _this.translate('Show less') + "</label>"; } var content = String.format(messageContainer, messages.map(function (m) { return String.format(messageTemp, m); }).join(''), contentRest); var toast; // khi truyền message html sẽ bị sanitize nên phải truyền innerHTML khi toast hiện lên // @see https://github.com/scttcper/ngx-toastr/blob/v12.1.0/src/lib/toastr/toastr.service.ts#L271 switch (type) { case 'error': toast = _this.toastr.error(content, (title || _this.translate('Error')) + " (" + messageLength + ")", { enableHtml: true, timeOut: delay || ((_a = _this.configuration) === null || _a === void 0 ? void 0 : _a.timeDelay) || 3000, messageClass: "toast-message toast-message-" + id, closeButton: true, tapToDismiss: false }); break; case 'warning': toast = _this.toastr.warning(content, (title || _this.translate('Warning')) + " (" + messageLength + ")", { enableHtml: true, timeOut: delay || ((_b = _this.configuration) === null || _b === void 0 ? void 0 : _b.timeDelay) || 3000, messageClass: "toast-message toast-message-" + id, closeButton: true, tapToDismiss: false }); break; } if (toast) { toast.onShown .pipe(operators.takeUntil(toast.onHidden)) .subscribe(function () { var messageEle = document.querySelector(".toast-message-" + id); messageEle.innerHTML = content; }); } }); this.handle = { error: function (err) { if (typeof err === 'string') { _this.notify.warning(err); } else if (typeof err === 'object') { var message = (err === null || err === void 0 ? void 0 : err.error) || (err === null || err === void 0 ? void 0 : err.message) || (err === null || err === void 0 ? void 0 : err.ExceptionMessage) || (err === null || err === void 0 ? void 0 : err.Message) || 'Unknown error'; if (typeof err.json === 'function') { err = err.json(); if (err) { message = (err === null || err === void 0 ? void 0 : err.error) || (err === null || err === void 0 ? void 0 : err.message) || (err === null || err === void 0 ? void 0 : err.ExceptionMessage) || (err === null || err === void 0 ? void 0 : err.Message) || 'Unknown error'; } } _this.notify.warning(message); } else { _this.notify.warning('Unknown error'); } }, }; this.confirm = function (message, option) { if (option === void 0) { option = {}; } var dialogRef = _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { title: (option === null || option === void 0 ? void 0 : option.title) || _this.translate('Confirm'), message: message, yesTitle: (option === null || option === void 0 ? void 0 : option.yesTitle) || _this.translate('Yes'), noTitle: (option === null || option === void 0 ? void 0 : option.noTitle) || _this.translate('No'), noButtonColor: (option === null || option === void 0 ? void 0 : option.noButtonColor) || 'secondary', yesButtonColor: (option === null || option === void 0 ? void 0 : option.yesButtonColor) || 'primary', }, }); return new Promise(function (resolve, reject) { dialogRef.afterClosed().subscribe(function (result) { if (result) { if (result === 'ACCEPT') { resolve(null); } else if (result === 'CANCEL') { reject(result); } else { resolve(null); } } }); }); }; this.confirmDelete = function () { return _this.confirm(_this.translate('Delete record(s)')); }; this.confirmApprove = function () { return _this.confirm(_this.translate('Approve record(s)')); }; this.confirmWithInput = function (title, option) { if (option === void 0) { option = {}; } var dialogRef = _this.dialog.open(DialogConfirmComponent, { width: '400px', data: { title: title || _this.translate('Confirm'), message: option === null || option === void 0 ? void 0 : option.message, yesTitle: (option === null || option === void 0 ? void 0 : option.yesTitle) || _this.translate('Yes'), noTitle: (option === null || option === void 0 ? void 0 : option.noTitle) || _this.translate('No'), noButtonColor: (option === null || option === void 0 ? void 0 : option.noButtonColor) || 'secondary', yesButtonColor: (option === null || option === void 0 ? void 0 : option.yesButtonColor) || 'primary', input: { maxlength: (option === null || option === void 0 ? void 0 : option.maxlength) || 255, required: option === null || option === void 0 ? void 0 : option.required, defaultValue: (option === null || option === void 0 ? void 0 : option.defaultValue) || '' }, }, }); return new Promise(function (resolve, reject) { dialogRef.afterClosed().subscribe(function (result) { if (result) { if (result === 'ACCEPT') { resolve(result); } else if (result === 'CANCEL') { reject(result); } else { resolve(result); } } }); }); }; this.translate = function (value) { return _this.translateService.translate(value); }; } return SdNotifyService; }()); _delayDuration = new WeakMap(), _warningKey = new WeakMap(), _errorKey = new WeakMap(), _cache = new WeakMap(), _notifyWarning = new WeakMap(), _notifyError = new WeakMap(), _buildToastMultiMesssage = new WeakMap(); SdNotifyService.decorators = [ { type: core.Injectable } ]; SdNotifyService.ctorParameters = function () { return [ { type: dialog.MatDialog }, { type: ngxToastr.ToastrService }, { type: translate.SdTranslateService }, { type: undefined, decorators: [{ type: core.Inject, args: [NOTIFY_CONFIG,] }, { type: core.Optional }] } ]; }; var SdNotifyModule = /** @class */ (function () { function SdNotifyModule() { } return SdNotifyModule; }()); SdNotifyModule.decorators = [ { type: core.NgModule, args: [{ imports: [ common.CommonModule, forms.FormsModule, formField.MatFormFieldModule, input.MatInputModule, icon.MatIconModule, button.MatButtonModule, dialog.MatDialogModule, ngxToastr.ToastrModule.forRoot(), button$1.SdButtonModule, ], declarations: [DialogConfirmComponent], entryComponents: [DialogConfirmComponent], exports: [], providers: [SdNotifyService], },] } ]; /* * Public API Surface of superdev-angular-core */ /** * Generated bundle index. Do not edit. */ exports.DialogConfirmComponent = DialogConfirmComponent; exports.NOTIFY_CONFIG = NOTIFY_CONFIG; exports.SdNotifyModule = SdNotifyModule; exports.SdNotifyService = SdNotifyService; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=sd-angular-core-notify.umd.js.map