-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathvpMultiButtonModal.js
More file actions
96 lines (85 loc) · 3.45 KB
/
vpMultiButtonModal.js
File metadata and controls
96 lines (85 loc) · 3.45 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
define([
'require'
, 'jquery'
, 'nbextensions/visualpython/src/common/vpCommon'
, 'nbextensions/visualpython/src/common/constant'
, 'nbextensions/visualpython/src/common/StringBuilder'
, 'nbextensions/visualpython/src/common/component/vpComComponent'
], function (requirejs, $, vpCommon, vpConst, sb, vpComComponent) {
/**
* @class vpMultiButtonModal 다중버튼 모달(최소 1개 버튼 바인딩)
* @constructor
*/
var vpMultiButtonModal = function() {
this.setUUID();
this._buttons = new Array();
this._buttons.push("OK");
this._message = "";
};
vpMultiButtonModal.prototype = Object.create(vpComComponent.vpComComponent.prototype);
/**
* 버튼들 설정
* @param {Array} buttons 버튼들. 최소 1개 버튼 바인딩
*/
vpMultiButtonModal.prototype.setButtons = function(buttons = new Array()) {
if (buttons.length == 0) {
buttons.push("OK");
}
this._buttons = buttons;
}
/**
* 메시지 설정
* @param {String} message 모달 메시지 설정
*/
vpMultiButtonModal.prototype.setMessage = function(message = "") {
this._message = message;
}
/**
* 모달 태그 오픈
* @param {function} closeCallback 종료 콜백함수
*/
vpMultiButtonModal.prototype.openModal = function(closeCallback) {
var sbTagString = new sb.StringBuilder();
var that = this;
sbTagString.appendFormatLine("<div id='vp_multiButtonModal' class='{0}'>", that._UUID);
sbTagString.appendLine("<div class='vp-multi-button-modal-box'>");
sbTagString.appendLine("<div class='vp-multi-button-modal-message'>");
sbTagString.appendFormatLine("<span>{0}</span>", that._message);
sbTagString.appendLine("</div>");
sbTagString.appendLine("<div class='vp-multi-button-modal-buttons'>");
for (var idx = 0; idx < that._buttons.length; idx++) {
sbTagString.appendFormatLine("<input class='vp-modal-button' type='button' value='{0}' />", that._buttons[idx]);
}
sbTagString.appendLine("</div>");
sbTagString.appendLine("</div>");
sbTagString.appendLine("</div>");
$(document).on(vpCommon.formatString("click.{0}", that._UUID), vpCommon.formatString(".{0} .{1}", that._UUID, "vp-modal-button"), function() {
$(document).unbind(vpCommon.formatString(".{0}", that._UUID));
if (typeof closeCallback == "function")
closeCallback($(this).index());
$(vpCommon.formatString(".{0}", that._UUID)).remove();
});
/** esc shortcut add */
$(document).bind(vpCommon.formatString('keydown.{0}', that._UUID), function(event) {
that.handleEscToExit(event);
});
$(sbTagString.toString()).appendTo("body");
}
/**
* ESC키로 창 닫기
* @param {Event} event
*/
vpMultiButtonModal.prototype.handleEscToExit = function(event) {
var keyCode = event.keyCode ? event.keyCode : event.which;
// esc
if (keyCode == 27) {
console.log('esc from modal', this._UUID);
$(document).unbind(vpCommon.formatString(".{0}", this._UUID));
$(vpCommon.formatString(".{0}", this._UUID)).remove();
$(vpCommon.formatString("keydown.{0}", this._UUID), this.handleEscToExit);
}
}
return {
vpMultiButtonModal: vpMultiButtonModal
}
});