Blame view

js/app/models/AmdaNode.js 4.79 KB
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
1
/**
16035364   Benjamin Renard   First commit
2
3
4
5
6
7
 * Project  : AMDA-NG4
 * Name     : AmdaNode.js
 * @class   amdaModel.AmdaNode
 * @extends Ext.data.Model
 * @brief   Generic Model of Node for AMDA project
 * @author  CDA
16035364   Benjamin Renard   First commit
8
9
 */
Ext.define('amdaModel.AmdaNode', {
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	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 : {
65ac4a9d   NathanaĆ«l Jourdane   Fix folders debug...
28
		NEW_DIR_NAME : 'new_folder',
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
29
		MULTI_PREFIX : 'mult'
16035364   Benjamin Renard   First commit
30
	},
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
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

	/**
	* @cfg proxy used to load nodes
	*/
	proxy: {
		type: 'direct',
		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();
78c1875c   Elena.Budnik   not show empty co...
88
89
		
		var realmenuitems = 0;
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
90
91
92
93
94
		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) {
78c1875c   Elena.Budnik   not show empty co...
95
						realmenuitems ++;
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
96
97
98
99
100
101
						currentItem.hidden = false;
					}
					else {
						currentItem.hidden = true;
					}
			}
78c1875c   Elena.Budnik   not show empty co...
102
103
104
			if ( realmenuitems == 0 )
				return null;

d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
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
			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;
			}
		else if (this.get('rank')) {
					itemKind = amdaUI.ExplorerUI.ITEM_KIND_MISS;
			}
		// base
dc5a7f83   Elena.Budnik   correction : CAT_...
141
142
		else if (this.id && Ext.util.Format.substr(this.id, -(amdaUI.ExplorerUI.CAT_SUFFIX.length), this.id.length) === amdaUI.ExplorerUI.CAT_SUFFIX ) {
			itemKind = amdaUI.ExplorerUI.ITEM_KIND_BASE;
d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
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
		}
		// 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');
16035364   Benjamin Renard   First commit
188
	},
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
189

d29e2a29   Elena.Budnik   BASE NODE_ITEM_KI...
190
191
192
193
194
195
196
197
198
199
	/**
	* 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');
	}
16035364   Benjamin Renard   First commit
200
201

});