-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathMenuItem.js
More file actions
177 lines (162 loc) · 6.2 KB
/
MenuItem.js
File metadata and controls
177 lines (162 loc) · 6.2 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
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : MenuItem.js
* Author : Black Logic
* Note : Render and load menu item
* License : GNU GPLv3 with Visual Python special exception
* Date : 2021. 09. 13
* Change Date :
*/
//============================================================================
// [CLASS] MenuItem
//============================================================================
define([
'../com/com_Const',
'../com/com_String',
'../com/component/Component',
'../board/Block'
], function(com_Const, com_String, Component, Block) {
'use strict';
//========================================================================
// Declare class
//========================================================================
/**
* MenuItem
*/
class MenuItem extends Component{
constructor($target, state) {
super($target, state);
}
_getMenuGroupRootType(idx=1) {
// ex) visualpython - apps - frame
let path = this.state.path;
let pathList = path.split(' - ');
return pathList[idx];
}
_getMenuGroupType() {
// ex) visualpython - apps - frame
let path = this.state.path;
let pathList = path.split(' - ');
return pathList.slice(1, pathList.length - 1).join('-');
}
/**
* Get menu item block's background color
* @param {*} isApps
* @returns
*/
_getColorClass(isApps=false) {
if (isApps) {
// For Apps menu item
var color = this.state.apps.color;
switch(color) {
case 0:
return 'vp-color-preparing';
default:
return 'vp-color-apps' + color;
}
} else {
// return color class
// FIXME: set detailed labels
return this.getColorLabel();
}
}
getColorLabel() {
let root = this._getMenuGroupRootType();
let label = root;
switch(root) {
case 'logic':
let subRoot = this._getMenuGroupRootType(2);
label = 'logic-' + subRoot;
break;
case 'library':
break;
}
return label;
}
_bindEvent() {
var that = this;
$(this.wrapSelector()).on('click', function(evt) {
// click event
$('#vp_wrapper').trigger({
type: 'create_option_page',
blockType: 'task',
menuId: that.state.id,
menuState: {},
afterAction: 'open'
});
});
}
_bindDraggable() {
var that = this;
$(this.wrapSelector()).draggable({
containment: '#vp_wrapper',
appendTo: '.vp-board-body',
revert: true,
cursor: 'move',
connectToSortable: '.vp-board-body',
helper: function() {
let isApps = that.state.apps != undefined;
let helperTag = new com_String();
let colorClass = that.getColorLabel();
helperTag.appendFormatLine('<div class="vp-block vp-draggable-helper {0}" style="z-index: 199;" data-color="{1}" data-menu="{2}">'
, colorClass, colorClass, that.state.id);
helperTag.appendFormatLine('<div class="vp-block-header">{0}</div>', that.state.name);
helperTag.appendLine('</div>');
return helperTag.toString();
},
start: function(event, ui) {
// ui.helper.hide();
$(ui.helper).css('z-index', 200);
},
stop: function(event, ui) {
let position = ui.helper.index();
let leftPosStr = $(ui.helper).css('left');
let leftPos = parseInt(leftPosStr.substr(0, leftPosStr.length - 2));
if (leftPos < 0) {
// out of board
return;
}
$('#vp_wrapper').trigger({
type: 'create_option_page',
blockType: 'block',
menuId: that.state.id,
menuState: {},
position: position
});
}
});
}
template() {
var page = new com_String();
var { id, name, desc, apps } = this.state;
if (apps) {
// render apps menu item
page.appendFormatLine('<div class="vp-menuitem apps {0}" data-menu="{1}" title="{2}">'
, this._getColorClass(true), id, desc);
// LAB: img to url
// page.appendFormatLine('<img src="{0}">', com_Const.IMAGE_PATH + apps.icon);
page.appendFormatLine('<div class="apps-icon {0}"></div>', id);
// Exception for title alignment
if (id === 'stats_studentstTest') {
name = "Student's<br/>t-test";
}
page.appendFormatLine('<div class="vp-menuitem-apps-name">{0}</div>', name);
page.append('</div>');
} else {
// render normal group
page.appendFormatLine('<div class="vp-menuitem {0}" data-menu="{1}" title="{2}">'
, this._getColorClass(), id, desc);
page.appendFormatLine('<span class="vp-menuitem-name">{0}</span>', name);
page.append('</div>');
}
return page.toString();
}
render() {
super.render();
this._bindDraggable();
}
}
return MenuItem;
});
/* End of file */