Blame view

js/app/views/ParamArgumentsPlug.js 4.96 KB
7ac3ce50   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
  * Project      :  AMDA-NG
  * Name         : ParamArgumentsPlug.js
  * @plugin 	  amdaUI.ParamArgumentsPlug
  * @extends 	  Ext.util.Observable 
  * @ptype 	 	  paramArgumentsPlugin
  * @brief		 Plugin to select arguments of a parameter
  * @author Benjamin
  * @version $Id: ParamArgumentsPlug.js
  ********************************************************************************
  *    FT Id     :   Date   : Name - Description
  *******************************************************************************
  *  :          
  */


Ext.define('amdaUI.ParamArgumentsPlug', {
	extend:  'Ext.util.Observable',
	alias: 'plugin.paramArgumentsPlugin',
        
	win : null,
	form : null,
bb6e93d9   Benjamin Renard   Implement templat...
23
	paramObject: null,
7ac3ce50   Benjamin Renard   First implementat...
24
	paramArgs: null,
7ac3ce50   Benjamin Renard   First implementat...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	
	onApply: null,
	
	requires: [
	           'amdaUI.ParamArgumentsUI'
    ],
	
	constructor: function(config) {            
		Ext.apply(this, config);            
        this.callParent(arguments);
	},
	
	onDestroy : function() {          
        this.win = null;
    },
 
	init: function(cmp) {          
		this.hostCmp = cmp;                 
	},
690e0a87   Benjamin Renard   Add sum in table ...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	
	computeHeight: function() {
		if (!this.paramArgs)
			return 0;
		var maxPos = 0;
		this.paramArgs.items.each(function(item) {
			if (!item.isVisible())
				return;
			var crtPos = item.getPosition(true);
			if (maxPos < crtPos[1] + item.getHeight())
				maxPos = crtPos[1] + item.getHeight();
		});
		return maxPos + 75;
	},
7ac3ce50   Benjamin Renard   First implementat...
58
59
60
61

/**
 *  creation of the window
 */        
e13ef068   Benjamin Renard   Compute window he...
62
63
64
    show : function(prefixId, paramRequestObject) {
    	var me = this;
    	
7ac3ce50   Benjamin Renard   First implementat...
65
66
    	if (!this.win)
    	{
bb6e93d9   Benjamin Renard   Implement templat...
67
68
    		this.win = new Ext.Window({
    			id: prefixId + '-param-arg-win',
7ac3ce50   Benjamin Renard   First implementat...
69
70
71
72
73
74
75
76
77
78
79
    			width: 200,
    			height: 150,       
    			x: 0, y: 0,                
    			baseCls:'x-panel',                
    			title: '',			                
    			layout: 'fit',			                
    			constrain: true,			                
    			collapsible: true,
    			resizable: false,
    			ghost: false,			                
    			renderTo: this.hostCmp.ownerCt.body,                                 
bb6e93d9   Benjamin Renard   Implement templat...
80
81
    			items: this.getFormConfig(),
    			closeAction: 'hide',
7ac3ce50   Benjamin Renard   First implementat...
82
83
    			listeners: {			                      
    				scope: this,			    			                      
33ce72a7   Benjamin Renard   Do not show argum...
84
85
    				beforeclose: function() {
    					this.hostCmp.setDisabled(false);
7ac3ce50   Benjamin Renard   First implementat...
86
    					Ext.PluginManager.unregister(this);                                                                   
e13ef068   Benjamin Renard   Compute window he...
87
88
89
90
    				}  ,
    				show: function() {
    					me.win.setHeight(me.computeHeight());
    				}
7ac3ce50   Benjamin Renard   First implementat...
91
92
93
94
95
96
97
98
99
    			},
    			getConstrainVector: function(constrainTo){
    				var me = this;
    				if (me.constrain || me.constrainHeader) {
    					constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent();
    					return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo);
    				}
    			}
    		});
bb6e93d9   Benjamin Renard   Implement templat...
100
    		
7ac3ce50   Benjamin Renard   First implementat...
101
102
103
104
105
    		this.win.on('destroy', this.onDestroy, this);
    		
    		Ext.PluginManager.register(this);
    	}
    	
bb6e93d9   Benjamin Renard   Implement templat...
106
    	this.win.setTitle('Arguments for ' + paramRequestObject.get('paramid'));
7ac3ce50   Benjamin Renard   First implementat...
107
    	
bb6e93d9   Benjamin Renard   Implement templat...
108
109
110
    	//Work with a clone of the request para object.
    	this.paramObject = paramRequestObject;
    	var workingParamObject = this.paramObject.copy();
bb6e93d9   Benjamin Renard   Implement templat...
111
    	this.paramArgs.editParameter(workingParamObject, this.hostCmp, function() {
690e0a87   Benjamin Renard   Add sum in table ...
112
    		me.win.setHeight(me.computeHeight());
bb6e93d9   Benjamin Renard   Implement templat...
113
    	});
7ac3ce50   Benjamin Renard   First implementat...
114
    	
33ce72a7   Benjamin Renard   Do not show argum...
115
    	this.hostCmp.setDisabled(true);
7ac3ce50   Benjamin Renard   First implementat...
116
117
118
119
120
121
122
123
124
    	this.win.show();
    },
    
    close : function() {
    	if (this.win == null)
    		return;
    	this.win.close();
    },
    
690e0a87   Benjamin Renard   Add sum in table ...
125
126
127
128
129
    onModifyHeight : function(pluginOwner) {
    	if (pluginOwner && pluginOwner.win)
    		pluginOwner.win.setHeight(pluginOwner.computeHeight());
    },
    
7ac3ce50   Benjamin Renard   First implementat...
130
131
132
133
134
135
136
/**
 *        Main form
 */
    getFormConfig: function(){
    	this.paramArgs = Ext.create('amdaUI.ParamArgumentsUI', {
    	});
    	
690e0a87   Benjamin Renard   Add sum in table ...
137
138
139
    	this.paramArgs.onModifyHeight = this.onModifyHeight;
    	this.paramArgs.pluginOwner = this;
    	
7ac3ce50   Benjamin Renard   First implementat...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    	var me = this;
    	this.form = new Ext.form.FormPanel( {	    	
    		frame: true,		
    		width: 230,		
    		height: 120,	    	
    		layout: {
			    type: 'vbox',
			    pack: 'start',
			    align: 'stretch'
			},	    	
    		fieldDefaults: {		  
    			labelWidth: 60		
    		},		
    		items: [
bb6e93d9   Benjamin Renard   Implement templat...
154
    		        me.paramArgs 
7ac3ce50   Benjamin Renard   First implementat...
155
156
157
158
159
160
    		],
    		buttons: [
    		          {
    		        	  text: 'Apply',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
bb6e93d9   Benjamin Renard   Implement templat...
161
162
    		        		  //Set modification
    		        		  if (me.paramObject)
63ac7745   Benjamin Renard   Support component...
163
    		        			  me.paramObject.data = me.paramArgs.paramRequestObject.data;
bb6e93d9   Benjamin Renard   Implement templat...
164
165
    		        		  if (me.onApply)
    		        			  me.onApply(me.hostCmp, me.paramArgs.paramRequestObject);
33ce72a7   Benjamin Renard   Do not show argum...
166
    		        		  me.close();
7ac3ce50   Benjamin Renard   First implementat...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
    		        	  }
    		          },
    		          {
    		        	  text: 'Reset',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  if (me.paramArgs)
    		        			  me.paramArgs.resetValues();
    		        	  }
    		          }
    		]
    	});   
    	return this.form;   
    }    
});