UNPKG

@schoolbelle/common

Version:

447 lines (436 loc) 17 kB
import { debounceTime, filter, take, tap, switchMap } from 'rxjs/operators'; import { fromEvent, merge, Subscription, of } from 'rxjs'; import { __extends, __spread } from 'tslib'; import { Component, Input, EventEmitter, Injectable, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { BsModalRef, BsModalService, ModalModule } from 'ngx-bootstrap/modal'; import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogAbstractComponent = /** @class */ (function () { function DialogAbstractComponent(modalRef) { this.modalRef = modalRef; this.subscription = new Subscription(); this.action = new EventEmitter(); } /** * @return {?} */ DialogAbstractComponent.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; this.subscription.add(merge(fromEvent(document, 'keydown'), fromEvent(document, 'keypress')) .pipe(debounceTime(0), filter((/** * @param {?} e * @return {?} */ function (e) { return e.which === 13; }))) .subscribe((/** * @param {?} e * @return {?} */ function (e) { _this.enter(); }))); }; /** * @return {?} */ DialogAbstractComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.subscription.unsubscribe(); }; /** * @return {?} */ DialogAbstractComponent.prototype.enter = /** * @return {?} */ function () { }; /** * @param {?=} result * @return {?} */ DialogAbstractComponent.prototype.ok = /** * @param {?=} result * @return {?} */ function (result) { if (result === void 0) { result = true; } this.modalRef.hide(); this.action.emit(result); }; /** * @return {?} */ DialogAbstractComponent.prototype.cancel = /** * @return {?} */ function () { this.modalRef.hide(); this.action.emit(false); }; DialogAbstractComponent.decorators = [ { type: Component, args: [{ template: '' }] } ]; /** @nocollapse */ DialogAbstractComponent.ctorParameters = function () { return [ { type: BsModalRef } ]; }; DialogAbstractComponent.propDecorators = { title: [{ type: Input }], message: [{ type: Input }] }; return DialogAbstractComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogConfirmComponent = /** @class */ (function (_super) { __extends(DialogConfirmComponent, _super); function DialogConfirmComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.showNeverShowItAgainCheckbox = false; _this.neverShowItAgain = false; return _this; } /** * @return {?} */ DialogConfirmComponent.prototype.enter = /** * @return {?} */ function () { this.ok(); }; DialogConfirmComponent.decorators = [ { type: Component, args: [{ selector: 'dialog-confirm', template: "<div *ngIf=\"title\" class=\"modal-header d-block\" [innerHTML]=\"title\"></div>\n<div *ngIf=\"message\" class=\"modal-body\" [innerHTML]=\"message\"></div>\n<div class=\"modal-footer justify-content-start border-top-0\">\n <label *ngIf=\"showNeverShowItAgainCheckbox\" class=\"custom-control custom-checkbox\">\n <input type=\"checkbox\" class=\"custom-control-input\" [(ngModel)]=\"neverShowItAgain\">\n <p class=\"custom-control-label\" i18n>See no more.</p>\n </label> \n <button type=\"button\" class=\"btn btn-outline-secondary ml-auto\" (click)=\"modalRef.hide(); action.emit(false)\" i18n>No</button>\n <button type=\"button\" class=\"btn btn-primary\" (click)=\"modalRef.hide(); action.emit(true)\" i18n>Yes</button>\n</div>\n" }] } ]; return DialogConfirmComponent; }(DialogAbstractComponent)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogAlertComponent = /** @class */ (function (_super) { __extends(DialogAlertComponent, _super); function DialogAlertComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.showNeverShowItAgainCheckbox = false; _this.neverShowItAgain = false; return _this; } /** * @return {?} */ DialogAlertComponent.prototype.enter = /** * @return {?} */ function () { this.ok(); }; DialogAlertComponent.decorators = [ { type: Component, args: [{ selector: 'dialog-alert', template: "<div *ngIf=\"title\" class=\"modal-header\" [innerHTML]=\"title\"></div>\n<div *ngIf=\"message\" class=\"modal-body\" [innerHTML]=\"message\"></div>\n<div class=\"modal-footer justify-content-start border-top-0\">\n <label *ngIf=\"showNeverShowItAgainCheckbox\" class=\"custom-control custom-checkbox\">\n <input type=\"checkbox\" class=\"custom-control-input\" [(ngModel)]=\"neverShowItAgain\">\n <p class=\"custom-control-label\" i18n>See no more.</p>\n </label> \n <button type=\"button\" class=\"btn btn-secondary ml-auto\" (click)=\"modalRef.hide(); action.emit(true)\" i18n>Ok</button>\n</div>\n\n" }] } ]; return DialogAlertComponent; }(DialogAbstractComponent)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogSelectComponent = /** @class */ (function (_super) { __extends(DialogSelectComponent, _super); function DialogSelectComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.selections = []; return _this; } /** * @param {?} i * @return {?} */ DialogSelectComponent.prototype.select = /** * @param {?} i * @return {?} */ function (i) { this.modalRef.hide(); this.action.emit(i); }; DialogSelectComponent.decorators = [ { type: Component, args: [{ selector: 'dialog-select', template: "<div *ngIf=\"title\" class=\"modal-header\" [innerHTML]=\"title\"></div>\n<div class=\"modal-body\">\n <button class=\"btn btn-block btn-secondary\" *ngFor=\"let selection of selections; let i = index;\" (click)=\"select(i)\" [innerHTML]=\"selection.html || selection\" [ngClass]=\"selection.class || ''\"></button>\n <button type=\"button\" class=\"btn btn-block btn-outline-secondary\" (click)=\"cancel()\" i18n>Cancel</button>\n</div>\n" }] } ]; DialogSelectComponent.propDecorators = { selections: [{ type: Input }] }; return DialogSelectComponent; }(DialogAbstractComponent)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogPromptComponent = /** @class */ (function (_super) { __extends(DialogPromptComponent, _super); function DialogPromptComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.validators = []; return _this; } /** * @return {?} */ DialogPromptComponent.prototype.ngOnInit = /** * @return {?} */ function () { _super.prototype.ngOnInit.call(this); this.input = new FormControl('', this.validators); }; /** * @return {?} */ DialogPromptComponent.prototype.enter = /** * @return {?} */ function () { if (!this.input.invalid) this.ok(this.input.value); }; DialogPromptComponent.decorators = [ { type: Component, args: [{ selector: 'dialog-prompt', template: "<div *ngIf=\"title\" class=\"modal-header\" [innerHTML]=\"title\"></div>\n<div *ngIf=\"message\" class=\"modal-body\">\n <p [innerHTML]=\"message\"></p>\n <div class=\"px-3\">\n <input class=\"form-control text-center\" \n [ngClass]=\"{'is-invalid':input.dirty && input.invalid}\"\n [formControl]=\"input\" [type]=\"type\" placeholder=\"\" autofocus (keyup.enter)=\"ok(input.value)\">\n </div>\n</div>\n<div class=\"modal-footer justify-content-start border-top-0\">\n <button type=\"button\" class=\"btn btn-outline-secondary ml-auto\" (click)=\"cancel()\" i18n>Cancel</button>\n <button type=\"button\" class=\"btn btn-primary\" \n [ngClass]=\"{\n 'btn-primary':!input.invalid,\n 'btn-secondary':input.invalid\n }\"\n [disabled]=\"input.invalid\" \n (click)=\"ok(input.value)\" i18n>Ok</button>\n</div>\n" }] } ]; DialogPromptComponent.propDecorators = { type: [{ type: Input }] }; return DialogPromptComponent; }(DialogAbstractComponent)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogService = /** @class */ (function () { function DialogService(modalService) { this.modalService = modalService; this.neverShowItAgainList = []; } /** * @param {?=} title * @param {?=} message * @param {?=} showNeverShowItAgainCheckbox * @param {?=} options * @return {?} */ DialogService.prototype.confirm = /** * @param {?=} title * @param {?=} message * @param {?=} showNeverShowItAgainCheckbox * @param {?=} options * @return {?} */ function (title, message, showNeverShowItAgainCheckbox, options) { var _this = this; if (title === void 0) { title = ''; } if (message === void 0) { message = ''; } if (showNeverShowItAgainCheckbox === void 0) { showNeverShowItAgainCheckbox = false; } if (options === void 0) { options = {}; } return of(null).pipe(switchMap((/** * @return {?} */ function () { /** @type {?} */ var dialogKey = title + "|" + message; if (_this.neverShowItAgainList.includes(dialogKey)) return of(true); /** @type {?} */ var modalRef = _this.modalService.show(DialogConfirmComponent, Object.assign({}, options, { backdrop: 'static', initialState: { title: title, message: message, showNeverShowItAgainCheckbox: showNeverShowItAgainCheckbox } })); return (/** @type {?} */ (modalRef.content.action.pipe(take(1), tap((/** * @return {?} */ function () { if (modalRef.content.neverShowItAgain === true) _this.neverShowItAgainList.push(dialogKey); }))))); }))); }; /** * @param {?=} title * @param {?=} message * @param {?=} showNeverShowItAgainCheckbox * @param {?=} options * @return {?} */ DialogService.prototype.alert = /** * @param {?=} title * @param {?=} message * @param {?=} showNeverShowItAgainCheckbox * @param {?=} options * @return {?} */ function (title, message, showNeverShowItAgainCheckbox, options) { var _this = this; if (title === void 0) { title = ''; } if (message === void 0) { message = ''; } if (showNeverShowItAgainCheckbox === void 0) { showNeverShowItAgainCheckbox = false; } if (options === void 0) { options = {}; } return of(null).pipe(switchMap((/** * @return {?} */ function () { /** @type {?} */ var dialogKey = title + "|" + message; if (_this.neverShowItAgainList.includes(dialogKey)) return of(true); /** @type {?} */ var modalRef = _this.modalService.show(DialogAlertComponent, Object.assign({}, options, { backdrop: 'static', initialState: { title: title, message: message, showNeverShowItAgainCheckbox: showNeverShowItAgainCheckbox } })); return modalRef.content.action.pipe(take(1), tap((/** * @return {?} */ function () { if (modalRef.content.neverShowItAgain === true) _this.neverShowItAgainList.push(dialogKey); }))); }))); }; /** * @param {?=} title * @param {?=} selections * @param {?=} options * @return {?} */ DialogService.prototype.select = /** * @param {?=} title * @param {?=} selections * @param {?=} options * @return {?} */ function (title, selections, options) { var _this = this; if (title === void 0) { title = ''; } if (options === void 0) { options = {}; } return of(null).pipe(switchMap((/** * @return {?} */ function () { /** @type {?} */ var modalRef = _this.modalService.show(DialogSelectComponent, Object.assign({}, options, { backdrop: 'static', initialState: { title: title, selections: selections } })); return modalRef.content.action.pipe(take(1)); }))); }; /** * @param {?=} title * @param {?=} message * @param {?=} type * @param {?=} validators * @param {?=} options * @return {?} */ DialogService.prototype.prompt = /** * @param {?=} title * @param {?=} message * @param {?=} type * @param {?=} validators * @param {?=} options * @return {?} */ function (title, message, type, validators, options) { var _this = this; if (title === void 0) { title = ''; } if (message === void 0) { message = ''; } if (validators === void 0) { validators = []; } if (options === void 0) { options = {}; } return of(null).pipe(switchMap((/** * @return {?} */ function () { /** @type {?} */ var modalRef = _this.modalService.show(DialogPromptComponent, Object.assign({}, options, { backdrop: 'static', initialState: { title: title, message: message, type: type, validators: validators } })); return (/** @type {?} */ (modalRef.content.action.pipe(take(1)))); }))); }; DialogService.decorators = [ { type: Injectable } ]; /** @nocollapse */ DialogService.ctorParameters = function () { return [ { type: BsModalService } ]; }; return DialogService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DialogModule = /** @class */ (function () { function DialogModule() { } /** * @return {?} */ DialogModule.forRoot = /** * @return {?} */ function () { return { ngModule: DialogModule, providers: __spread([ DialogService ], ModalModule.forRoot().providers) }; }; DialogModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule, ModalModule.forRoot(), FormsModule, ReactiveFormsModule, ], entryComponents: [ DialogConfirmComponent, DialogAlertComponent, DialogSelectComponent, DialogPromptComponent, ], declarations: [ DialogAbstractComponent, DialogConfirmComponent, DialogAlertComponent, DialogSelectComponent, DialogPromptComponent, ], },] } ]; return DialogModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { DialogService, DialogModule, DialogAbstractComponent as ɵb, DialogAlertComponent as ɵc, DialogConfirmComponent as ɵa, DialogPromptComponent as ɵe, DialogSelectComponent as ɵd }; //# sourceMappingURL=schoolbelle-common-dialog.js.map