Blame view

js/app/views/AliasUI.js 5.61 KB
16035364   Benjamin Renard   First commit
1
2
3
4
/**
 * Project   : AMDA-NG
 * Name      : AliasUI.js
 * @class 	 amdaUI.AliasUI
05ebfb1e   Elena.Budnik   alias, first commit
5
 * @extends  Ext.form.Panel
16035364   Benjamin Renard   First commit
6
7
8
 * @brief	 Alias UI definition (View)
 * @author 	 Myriam
 * @version  $Id: AliasUI.js 966 2012-07-03 14:50:05Z elena $
16035364   Benjamin Renard   First commit
9
 */ 
05ebfb1e   Elena.Budnik   alias, first commit
10

16035364   Benjamin Renard   First commit
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
Ext.define('amdaUI.AliasUI',{
	extend: 'Ext.form.Panel',
	alias: 'widget.alias', 
	
    /**
     * @cfg {String} data models
     * @required
     */
	nodeDataModel : 'amdaModel.AliasNode',
	
 
	setAlias : function(obj) {	  
		var paramValue = obj ? obj.get('id') : null;
		var aliasValue = obj && obj.get('alias') ? obj.get('alias') : null;
		this.parameterField.setValue(paramValue);		
		this.aliasField.setValue(aliasValue);
	},
	
	setAliasJson : function(obj) {	  
		var paramValue = obj ? obj.id : null;
		var aliasValue = obj && obj.alias ? obj.alias : null;
		this.parameterField.setValue(paramValue);
		this.aliasField.setValue(aliasValue);		
	},
	
	setLinkedNode : function (myLinkedNode){
		this.linkedNode = myLinkedNode;		
	},
	
	setParamNode : function (paramNode){
		this.paramNode = paramNode;
		if (this.paramNode.get('alias') && amdaModel.AliasNode.deletedAliases) {
			this.checkDeleted(this.paramNode.get('id'));
		}
	},
  
// check if alias was deleted in this session => set param alias == null	
	checkDeleted : function(paramId) {
		 var itemIndex = -1;
		 Ext.Array.each(amdaModel.AliasNode.deletedAliases,
				function(name, index, item) {
				    if (name === paramId) {
				      itemIndex = index;
				      return false;
				    }
				}
		    );
		 if (itemIndex >= 0) {
			 Ext.Array.erase(amdaModel.AliasNode.deletedAliases, itemIndex, 1);
		 }
	},
	
05ebfb1e   Elena.Budnik   alias, first commit
63
64
	createLinkedNode : function ()
	{
16035364   Benjamin Renard   First commit
65
66
67
68
69
		var newNode = Ext.create(this.nodeDataModel, {
			leaf : true,
			contextNode : this.contextNode
		});		  
	 
05ebfb1e   Elena.Budnik   alias, first commit
70
		this.setLinkedNode(newNode);
16035364   Benjamin Renard   First commit
71
72
	},
	
05ebfb1e   Elena.Budnik   alias, first commit
73
74
	validate : function(alias,param) 
	{     
16035364   Benjamin Renard   First commit
75
76
		var aliasNodeByName = this.linkedNode.get('rootNode').findChild('text', alias);		       
		if (aliasNodeByName) {
05ebfb1e   Elena.Budnik   alias, first commit
77
78
79
80
81
			//TODO process
			var paramId =  aliasNodeByName.get('id').substr(6);
				Ext.Msg.alert('Alias','Alias '+ alias +' already exists for parameter\n' + paramId);
				return false;
		}    
16035364   Benjamin Renard   First commit
82
		
05ebfb1e   Elena.Budnik   alias, first commit
83
		return true;
16035364   Benjamin Renard   First commit
84
85
86
87
88
	}, 
	
	updateConstruct : function(oldval,newval) {
		Ext.Array.each(myDesktopApp.paramModulesID, function(id){
			var targetModule = myDesktopApp.getLoadedModule(id);
5bc01d75   Elena.Budnik   check if window i...
89
			if (targetModule && typeof targetModule.getUiContent() !== "undefined")
16035364   Benjamin Renard   First commit
90
91
92
93
				targetModule.getUiContent().updateConstruct(oldval,newval);
		});			 
	},
		
05ebfb1e   Elena.Budnik   alias, first commit
94
95
96
97
98
99
	saveAlias: function() 
	{  
		if (this.parameterField.value.match(/[a-z,0-9]/gi) == null) {
			Ext.Msg.show({title:'No Parameter', msg: 'Please select parameter to create alias for', 
								icon: Ext.Msg.WARNING, buttons: Ext.Msg.OK});
			return;
16035364   Benjamin Renard   First commit
100
101
102
103
104
105
106
107
		}
		
		var tree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
		var rootNode = tree.getRootNode().findChild('id','alias-treeRootNode',true);
		
		if (!rootNode.isExpanded()) rootNode.expand(false);	   					    						    
		
		if (!this.paramNode.get('alias')) {
05ebfb1e   Elena.Budnik   alias, first commit
108
109
110
			this.createLinkedNode();
			var isNew = true;
		} 
16035364   Benjamin Renard   First commit
111
		else {
05ebfb1e   Elena.Budnik   alias, first commit
112
113
114
115
116
117
118
			var aliasNode = rootNode.findChild('text', this.paramNode.get('alias'));
			if (!aliasNode) {
				//TODO error 
				alert('NOT FOUND');
			}
			this.setLinkedNode(aliasNode);
			var isNew = false;
16035364   Benjamin Renard   First commit
119
120
121
122
123
		}  

		this.linkedNode.set('rootNode', rootNode);
		var alias = this.aliasField.value;
		var param = this.parameterField.value;
05ebfb1e   Elena.Budnik   alias, first commit
124
		var component_info = this.paramNode.get('component_info');
bafc2a52   Elena.Budnik   icon Cls for alias
125
		var iconClass = this.paramNode.get('iconCls');
16035364   Benjamin Renard   First commit
126
127
		// now validation							    
		if (this.validate(alias,param)) {	
05ebfb1e   Elena.Budnik   alias, first commit
128
129
130
131
132
133
134
			if (isNew) {
				if (alias.match(/[a-z,0-9]/gi) == null) {
					Ext.Msg.show({title:'No Alias', msg: 'No alias was created for parameter '+ param, 
							icon: Ext.Msg.WARNING, buttons: Ext.Msg.OK}); 
				}
				else {
					// create alias 
bafc2a52   Elena.Budnik   icon Cls for alias
135
					this.linkedNode.create(alias, param, component_info, iconClass);
05ebfb1e   Elena.Budnik   alias, first commit
136
137
138
139
140
141
142
143
144
145
146
147
148
					this.updateConstruct(param,"#"+alias);
				}
			}   
			else if (alias.match(/[a-z,0-9]/gi) == null) {
				var alias = this.paramNode.get('alias');
				Ext.Msg.confirm('Delete', 'Are you sure you want to delete this alias ?', function(btn, text){
					if (btn == 'yes'){
						// remove alias		                                	
						this.updateConstruct("#"+alias,param);
						this.linkedNode.deleteNode();
					}
				},this);
			}   
16035364   Benjamin Renard   First commit
149
			else {
05ebfb1e   Elena.Budnik   alias, first commit
150
151
152
				// rename alias
				this.linkedNode.renameNode(this.paramNode.get('alias'),alias, param);
				this.updateConstruct("#"+this.paramNode.get('alias'),"#"+alias);
16035364   Benjamin Renard   First commit
153
			}
05ebfb1e   Elena.Budnik   alias, first commit
154
155
156
			// Delete alias from array of deleted aliases
			this.checkDeleted(this.paramNode.get('id'));
			this.paramNode.set('alias',alias);
16035364   Benjamin Renard   First commit
157
158
159
160
161
		}						    						    	  
		var win = myDesktopApp.getDesktop().getWindow('alias-win');
		if (win) win.close();	  
	},
	
05ebfb1e   Elena.Budnik   alias, first commit
162
	initComponent : function (){
16035364   Benjamin Renard   First commit
163
		
05ebfb1e   Elena.Budnik   alias, first commit
164
165
		if (this.initialConfig.paramNode)
			this.setParamNode(this.initialConfig.paramNode);	    	    
16035364   Benjamin Renard   First commit
166
		
05ebfb1e   Elena.Budnik   alias, first commit
167
168
169
170
		this.parameterField = new Ext.form.field.Text({
			fieldLabel: 'AMDA Parameter', name:'param',  labelAlign: 'top', 
			disabled: true, width : '90%', padding : '10px 0 0 10px', allowBlank: false		 
		});
16035364   Benjamin Renard   First commit
171
 
05ebfb1e   Elena.Budnik   alias, first commit
172
173
		this.aliasField = new Ext.form.field.Text({
			fieldLabel: 'Your Alias', padding : '10px 0 0 10px', width : '90%',
14008bfe   Elena.Budnik   alias - no spaces
174
175
			labelWidth: 70, allowBlank: false, stripCharsRe: /(^\s+|\s+$)/g,
			emptyText: 'Please no spaces!' 
05ebfb1e   Elena.Budnik   alias, first commit
176
		});
16035364   Benjamin Renard   First commit
177
	    
05ebfb1e   Elena.Budnik   alias, first commit
178
		this.setAlias(this.paramNode);
16035364   Benjamin Renard   First commit
179
	    	 
05ebfb1e   Elena.Budnik   alias, first commit
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
		var config = {		
			defaultType: 'textfield', 
			bodyStyle: 'background:#ddecfe;',  
			items: [
					this.parameterField,
					this.aliasField
			],
			fbar: [
				{ 
					text: 'Save Alias', 
					scope: this,
					handler: this.saveAlias
				}
			]
		};
		Ext.apply (this , Ext.apply(this.initialConfig, config));
		this.callParent(arguments);
	}  
16035364   Benjamin Renard   First commit
198
});