"use strict"; var __decorate = (this && this.__decorate) || function (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; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var confirm_service_1 = require("./confirm.service"); var ng2_bs3_modal_1 = require("ng2-bs3-modal/ng2-bs3-modal"); var KEY_ESC = 27; var ConfirmComponent = /** @class */ (function () { function ConfirmComponent(confirmService) { this._defaults = { type: 'reset', message: 'Do you want to cancel your changes?', cancelText: 'Cancel', okText: 'OK' }; this.alertshow = false; confirmService.activate = this.activate.bind(this); } ConfirmComponent.prototype._setLabels = function (message, type) { if (message === void 0) { message = this._defaults.message; } if (type === void 0) { type = this._defaults.type; } // this.modalType = type; this.type = type; //this.alertshow = type == 'reset' ? true : false; this.message = message; this.okText = this._defaults.okText; this.cancelText = this._defaults.cancelText; }; ConfirmComponent.prototype.activate = function (message, type) { var _this = this; if (message === void 0) { message = this._defaults.message; } if (type === void 0) { type = this._defaults.type; } this._setLabels(message, type); var promise = new Promise(function (resolve) { _this._show(resolve); }); return promise; }; ConfirmComponent.prototype._show = function (resolve) { var _this = this; document.onkeyup = null; var yesOnClick = function (e) { return resolve(1); }; // 1 for yes var noOnClick = function (e) { return resolve(2); }; // 2 for no var cancelOnClick = function (e) { return resolve(3); }; // 3 for cancel var yesResetClick = function (e) { return resolve(1); }; var noResetClick = function (e) { return resolve(2); }; var yesConfirmClick = function (e) { return resolve(6); }; // yes var noConfirmClick = function (e) { return resolve(7); }; // NO var okAlertClick = function (e) { return resolve(5); }; // for alert message var closeAlertClick = function (e) { return resolve(8); }; // for alert message if (!this._cancelButton || !this._okButton) return; //this._confirmElement.style.opacity = 0; //this._confirmElement.style.zIndex = 9999; this._cancelButton.onclick = (function (e) { e.preventDefault(); if (!cancelOnClick(e)) _this._hideDialog(); }); this._okButton.onclick = (function (e) { e.preventDefault(); if (!yesOnClick(e)) _this._hideDialog(); }); this._noButton.onclick = (function (e) { e.preventDefault(); if (!noOnClick(e)) _this._hideDialog(); }); this._noResetButton.onclick = (function (e) { e.preventDefault(); if (!noResetClick(e)) _this._hideDialog(); }); this._yesResetButton.onclick = (function (e) { e.preventDefault(); if (!yesResetClick(e)) _this._hideDialog(); }); this._noConfirmButton.onclick = (function (e) { e.preventDefault(); if (!noConfirmClick(e)) _this._hideDialog(); }); this._yesConfirmButton.onclick = (function (e) { e.preventDefault(); if (!yesConfirmClick(e)) _this._hideDialog(); }); this._okAlert.onclick = (function (e) { e.preventDefault(); if (!okAlertClick(e)) _this._hideDialog(); }); this._closeAlert.onclick = (function (e) { e.preventDefault(); if (!closeAlertClick(e)) _this._hideDialog(); }); //this._confirmelement.onclick = () => { // this._hidedialog(); // return negativeonclick(null); //}; if (this.type.toString() == "close") { this.closeModal.open('sm'); return; } if (this.type.toString() == "reset") { this.resetModal.open('sm'); return; } if (this.type.toString() == "confirmModel") { this.confirmModel.open('sm'); return; } if (this.type.toString() == "alertMsg") { //setTimeout(this.alertMessageModal.open('sm'), 60000); clearTimeout(this.timer); this.timer = setTimeout(function () { _this.alertMessageModal.open('sm'); }, 500); return; } if (this.type.toString() == "alertMsg2") { this.alertMessageModal.open('sm'); return; } document.onkeyup = function (e) { if (e.which == KEY_ESC) { _this._hideDialog(); return cancelOnClick(null); } }; //this._confirmElement.style.opacity = 1; }; ConfirmComponent.prototype._hideDialog = function () { if (this.type.toString() == "close") { this.closeModal.close(); return; } if (this.type.toString() == "reset") { this.resetModal.close(); return; } if (this.type.toString() == "confirmModel") { this.confirmModel.close(); return; } if (this.type.toString() == "alertMsg") { this.alertMessageModal.close(); return; } if (this.type.toString() == "alertMsg2") { this.alertMessageModal.close(); return; } }; ConfirmComponent.prototype.ngOnInit = function () { //this._confirmElement = document.getElementById('confirmationModal'); this._cancelButton = document.getElementById('cancelButton'); this._okButton = document.getElementById('okButton'); this._noButton = document.getElementById('noButton'); this._yesResetButton = document.getElementById('yesResetButton'); this._noResetButton = document.getElementById('noResetButton'); this._yesConfirmButton = document.getElementById('yesConfirmButton'); this._noConfirmButton = document.getElementById('noConfirmButton'); this._okAlert = document.getElementById('okAlert'); this._closeAlert = document.getElementById('closeAlert'); }; __decorate([ core_1.ViewChild("closeModal"), __metadata("design:type", ng2_bs3_modal_1.ModalComponent) ], ConfirmComponent.prototype, "closeModal", void 0); __decorate([ core_1.ViewChild("confirmModel"), __metadata("design:type", ng2_bs3_modal_1.ModalComponent) ], ConfirmComponent.prototype, "confirmModel", void 0); __decorate([ core_1.ViewChild("resetModal"), __metadata("design:type", ng2_bs3_modal_1.ModalComponent) ], ConfirmComponent.prototype, "resetModal", void 0); __decorate([ core_1.ViewChild("alertMessageModal"), __metadata("design:type", ng2_bs3_modal_1.ModalComponent) ], ConfirmComponent.prototype, "alertMessageModal", void 0); ConfirmComponent = __decorate([ core_1.Component({ selector: 'modal-confirm', templateUrl: './confirm.component.html', }), __metadata("design:paramtypes", [confirm_service_1.ConfirmService]) ], ConfirmComponent); return ConfirmComponent; }()); exports.ConfirmComponent = ConfirmComponent; //# sourceMappingURL=confirm.component.js.map