confirm.component.js
8.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"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