-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree-example.html
executable file
·180 lines (151 loc) · 4.38 KB
/
tree-example.html
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
<html>
<head>
<title>Stores</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<style>
body{
background-color:#aeaeae;
}
#container{
background-color:#ccc;
}
</style>
<style type="text/css">
.emplWrap {
border: 1px #999999 solid;
margin : 3px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background-color: #ffffcc;
padding-bottom: 3px;
}
.emplSelected {
border: 1px #66ff66 solid;
background-color: #ccffcc;
cursor: pointer;
}
.emplOver {
border: 1px #9999ff solid;
background-color: #ccccff;
cursor: pointer;
}
.emplName {
font-weight: bold;
margin-left: 5px;
font-size: 14px;
text-decoration: underline;
color: #333333;
}
.title {
margin-left: 5px;
font-weight: bold;
} </style>
<script src="extjs/adapter/ext/ext-base.js"></script>
<script src="extjs/ext-all-debug.js"></script>
<script>
Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
var rootNode = {
text : 'Root Node',
expanded : true, // expands node immediately
children : [
{
text : 'Child 1',
leaf : true // endpoint, changes UI behavior
},
{
text: 'Child 2',
leaf: true
},
{
text: 'Child 3',
children: [
{
text: 'Grand child 1',
children: [
{
text: 'Grand grand child',
leaf: true
}
]
}
]
}
]
};
Ext.onReady(function () {
new Ext.Window({
height : 200,
width : 200,
layout : 'fit',
border : false,
title : 'Our first tree',
items : {
xtype: 'treepanel',
id: 'treepanel',
autoScroll: true,
root: rootNode,
listeners: {
contextmenu: onCtxMenu
}
}
}).show();
});
var buildCtxMenu = function() {
return new Ext.menu.Menu({
items: [
{
itemId: 'add', // similar to component id except local to Component Container and not in ComponentMgr
handler : Ext.emptyFn
},
{
itemId : 'edit',
handler : Ext.emptyFn,
scope : Ext.emptyFn
},
{
itemId: 'delete',
handler : Ext.emptyFn
}
]
});
};
var onCtxMenu = function(node, evtObj) {
node.select();
evtObj.stopEvent();
if (! this.ctxMenu) {
this.ctxMenu = buildCtxMenu();
}
var ctxMenu = this.ctxMenu;
var addItem = ctxMenu.getComponent('add');
var editItem = ctxMenu.getComponent('edit');
var deleteItem = ctxMenu.getComponent('delete');
if (node.id =='myCompany') {
addItem.setText('Add Department');
editItem.setText('Nope, not changing the name');
deleteItem.setTex('Can\'t delete a company, silly');
addItem.enable();
deleteItem.disable();
editItem.disable();
} else if (! node.leaf) {
addItem.setText('Add Employee');
deleteItem.setText('Delete Department');
editItem.setText('Edit Department');
addItem.enable();
editItem.enable();
deleteItem.enable();
} else {
addItem.setText('Can\'t Add Employee');
editItem.setText('Edit Employee');
deleteItem.setText('Delete Employee');
addItem.disable();
editItem.enable();
deleteItem.enable();
}
ctxMenu.showAt(evtObj.getXY());
};
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>