-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodal.js
executable file
·69 lines (63 loc) · 2.61 KB
/
modal.js
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
class Modal {
constructor(params) {
this.id = params.id ? params.id : 'modal-' + Math.floor(Math.random() * 101);
this.header = params.header ? params.header : '';
this.body = params.body ? params.body : '';
this.footer = params.footer ? params.footer : '';
this.size = params.size === 'big' ? 'modal-lg' : 'modal-sm';
}
set(params) {
if (params.header) {
this.header = params.header;
}
}
render() {
return `
<div class="modal fade" id="${this.id}" tabindex="-1" role="dialog" aria-labelledby="${this.header}" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered ${this.size}" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="${this.header}">${this.header}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
${this.renderedBody}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
${this.renderedFooter}
</div>
</div>
</div>
</div>`
}
show() {
if (typeof this.body === 'object' && this.body instanceof Form) {
this.renderedBody = this.body.renderElements();
this.renderedFooter = this.body.renderActions();
}else if (typeof this.body === 'object' && this.body instanceof Grid) {
this.renderedBody = this.body.render();
this.renderedFooter = this.footer;
} else {
this.renderedBody = this.body;
this.renderedFooter = this.footer;
}
let html = this.render();
$('body').append(html);
$('#' + this.id).modal('show');
$('#' + this.id).on('hidden.bs.modal', function (e) {
$('#' + this.id).modal('dispose');
$('#' + this.id).remove();
});
if (typeof this.body === 'object' && this.body instanceof Form) {
this.body.init();
}else if (typeof this.body === 'object' && this.body instanceof Grid) {
// this.body.load();
}
}
hide() {
$('#' + this.id).modal('hide');
}
}