-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathTaskItem.js
More file actions
123 lines (108 loc) · 4.1 KB
/
TaskItem.js
File metadata and controls
123 lines (108 loc) · 4.1 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
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : TaskItem.js
* Author : Black Logic
* Note : Render and load task item
* License : GNU GPLv3 with Visual Python special exception
* Date : 2021. 09. 13
* Change Date :
*/
//============================================================================
// [CLASS] TaskItem
//============================================================================
define([
'../com/com_Const',
'../com/com_String',
'../com/component/Component',
], function(com_Const, com_String, Component) {
'use strict';
//========================================================================
// Declare class
//========================================================================
/**
* TaskItem
*/
class TaskItem extends Component{
_init() {
// set taskitem to component
this.state.task.setTaskItem(this);
}
_bindEvent() {
let that = this;
// click event - emphasize TaskItem & open/hide PopupComponent
$(this.wrapSelector()).on('click', function(evt) {
let isOpen = $(that.wrapSelector()).hasClass('vp-focus');
if (isOpen) {
// hide task if it's already opened
// open task
that.state.task.hide();
} else {
// open task
$('#vp_wrapper').trigger({
type: 'open_option_page',
component: that.state.task
});
}
});
// remove click event
$(this.wrapSelector('.vp-menu-task-remove')).on('click', function(evt) {
$('#vp_wrapper').trigger({
type: 'remove_option_page',
component: that.state.task
});
});
}
_getOptionInfo() {
let task = this.state.task;
let info = {};
if (task && task.state && task.config) {
let { id, name } = task;
let { desc, apps }= task.config;
info = {
id: id,
title: name,
desc: desc,
icon: 'apps/apps_white.svg'
};
if (apps) {
info.icon = apps.icon;
}
}
return info;
}
template() {
let { title, icon, desc } = this._getOptionInfo();
let page = new com_String();
page.appendFormatLine('<div class="{0} vp-no-selection" title="{1}">', 'vp-menu-task-item', desc);
// page.appendFormatLine('<img class="vp-menu-task-icon" src="/nbextensions/visualpython/img/{0}">', icon);
page.appendFormatLine('<span>{0}</span>', title);
// LAB: img to url
// page.appendFormatLine('<img class="vp-menu-task-remove" title="{0}" src="{1}">', 'Close task', com_Const.IMAGE_PATH + 'close_small.svg');
page.appendFormatLine('<div class="vp-menu-task-remove vp-icon-close-small" title="{0}"></div>', 'Close task');
page.appendLine('</div>');
return page.toString();
}
render() {
super.render();
// emphasize it if its task is visible
if (!this.state.task.isHidden()) {
this.$target.find('.vp-menu-task-item').removeClass('vp-focus');
$(this.wrapSelector()).addClass('vp-focus');
}
}
focusItem() {
this.$target.find('.vp-menu-task-item').removeClass('vp-focus');
$(this.wrapSelector()).addClass('vp-focus');
}
blurItem() {
// hide task if it's already opened
$(this.wrapSelector()).removeClass('vp-focus');
}
removeItem() {
$(this.wrapSelector()).remove();
}
}
return TaskItem;
});
/* End of file */