AmdaNode.js
5.5 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* Project : AMDA-NG4
* Name : AmdaNode.js
* @class amdaModel.AmdaNode
* @extends Ext.data.Model
* @brief Generic Model of Node for AMDA project
* @author CDA
* @version $Id: AmdaNode.js 2544 2014-10-03 10:21:56Z elena $
* @todo
*******************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
* : :08/06/2011: CDA - Migration extjs4
*/
Ext.define('amdaModel.AmdaNode', {
extend: 'Ext.data.TreeModel',
requires: ['amdaReader.ExplorerReader'],
fields: [
{name: 'leaf', type: 'boolean'},
{name: 'nodeType',type:'string'},
{name: 'id', type: 'string'},
{name:'text',type: 'string'},
{name:'info',type: 'string'},
{name: 'help', type: 'string', defaultValue: ''},
{name:'rootNode', persist: false},
{name: 'ownerTreeId', persist: false},
{name: 'ownerTree', persist: false},
{name: 'checked', defaultValue: null, persist: false}
],
statics : {
NEW_DIR_NAME : 'new Folder',
MULTI_PREFIX : 'mult'
},
/**
* @cfg proxy used to load nodes
*/
proxy: {
type: 'direct',
// directFn: AmdaAction.getTree,
api :
{
read: AmdaAction.getTree,
update: AmdaAction.saveTree,
create: AmdaAction.saveTree,
destroy: AmdaAction.doNothing
},
paramsAsHash : true,
reader: {
type: 'explorer'
}
},
/**
* Abstract getter of complete array of item context menu
* @return {Ext.Array} the complete array of item context menu
*/
getAllContextMenuItems: Ext.emptyFn,
/**
* Abstract method call on click on item of context menu
*/
onMenuItemClick: Ext.emptyFn,
/**
* Abstract Update Data method
*/
update : Ext.emptyFn,
/**
* Abstract Rename Data method
*/
rename : Ext.emptyFn,
/**
* Abstract Rename D&D Data method
*/
renameDD : Ext.emptyFn,
/**
* Abstract Create Data method
*/
create : Ext.emptyFn,
/**
* filtering method of context menu
* @param {String} itemKind the kind of right clicked node
* @return {Ext.Array} the Array of filtered item menu
*/
getFilteredContextMenu : function(itemKind) {
var menuitems = this.getAllContextMenuItems();
if (menuitems && menuitems.length){
for ( var i = 0; i < menuitems.length; i++) {
var currentItem = menuitems[i];
var myItemKind = Ext.util.Format.substr(currentItem.fnId, 0, 4);
if (myItemKind === itemKind) {
currentItem.hidden = false;
}
else {
currentItem.hidden = true;
}
}
return menuitems;
} else {
return null;
}
},
getMultiContextMenu : function(){
var menuitems = this.getMultiContextMenuItems();
if (menuitems && menuitems.length){
return menuitems;
} else {
return null;
}
},
/**
* get the kind of this node
* @returns itemKind string
*/
getNodeKind : function() {
var itemKind;
// if id of this node have root subcategory suffix
if (this.id && Ext.util.Format.substr(this.id, -(amdaUI.ExplorerUI.ROOT_SUFFIX.length), this.id.length) === amdaUI.ExplorerUI.ROOT_SUFFIX ) {
itemKind = amdaUI.ExplorerUI.ITEM_KIND_ROOT;
}
// if this node is a leaf and have no child
else if (this.isLeaf()) {
itemKind = amdaUI.ExplorerUI.ITEM_KIND_LEAF;
}
else if (this.get('isParameter')) {
itemKind = amdaUI.ExplorerUI.ITEM_KIND_PARA;
}
// other case
else {
itemKind = amdaUI.ExplorerUI.ITEM_KIND_DIRE;
}
return itemKind;
},
/**
* Getter on context menu of this node
* @returns {Ext.menu.Menu} the contextMenu of this node
*/
getContextMenuItems : function() {
// set the node kind
var itemKind = this.getNodeKind();
// filter the global context menu by node kind
var menuItems = this.getFilteredContextMenu(itemKind);
// return the context menu for this node
return menuItems;
},
getContextMenuMultiItems : function() {
return this.getMultiContextMenu();
},
/**
* Method to retrieve the root node corresponding to the nodeType of this node
* @return {amdaModel.AmdaNode} the root node of category of this node
*/
getRootNode : function() {
if (!this.get('rootNode')) {
// if this node is the root of its category
if(this.getNodeKind() == amdaUI.ExplorerUI.ITEM_KIND_ROOT) {
this.set('rootNode',this);
} else {
// get resources tree panel
var tree = this.myGetOwnerTree();
var treeRoot = tree.getRootNode();
var rootNodeId = this.get('nodeType')+amdaUI.ExplorerUI.ROOT_SUFFIX;
this.set('rootNode',treeRoot.findChild( 'id', rootNodeId, true));
}
}
return this.get('rootNode');
},
/**
* getter on ownerTree (use ownerTreeId property)
* @return {Ext.tree.Panel} the tree which contains this node
*/
myGetOwnerTree : function() {
if (!this.get('ownerTree')) {
this.set('ownerTree',Ext.getCmp(this.get('ownerTreeId')));
}
return this.get('ownerTree');
}
});