Blame view

js/app/views/ParamArgumentsPlug.js 3.92 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
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
/**
  * 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,
	paramArgs: null,
	paramId: '',
	
	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;                 
	},

/**
 *  creation of the window
 */        
    show : function(paramId, crtArgsValues) {          
    	if (!this.win)
    	{
    		this.win = new Ext.Window({                
    			id: 'param-comp-win',                                                 
    			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,                                 
    			items: this.getFormConfig(),  
    			listeners: {			                      
    				scope: this,			    			                      
    				beforeclose: function() {      
    					Ext.PluginManager.unregister(this);                                                                   
    				}     
    			},
    			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);
    				}
    			}
    		});
                        
    		this.win.on('destroy', this.onDestroy, this);
    		
    		Ext.PluginManager.register(this);
    	}
    	
    	this.win.setTitle('Arguments for ' + paramId);
    	
    	this.paramId = paramId;
    	this.paramArgs.editParameter(paramId, crtArgsValues, this.hostCmp);
    	
    	this.win.show();
    },
    
    close : function() {
    	if (this.win == null)
    		return;
    	this.win.close();
    },
    
/**
 *        Main form
 */
    getFormConfig: function(){
    	this.paramArgs = Ext.create('amdaUI.ParamArgumentsUI', {
    	});
    	
    	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: [
    		        this.paramArgs 
    		],
    		buttons: [
    		          {
    		        	  text: 'Apply',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  if (me.paramArgs) {
    		        			  if (me.onApply)
    		        				  me.onApply(this.hostCmp, me.paramId, me.paramArgs.getValues());
    		        		  }
    		        	  }
    		          },
    		          {
    		        	  text: 'Reset',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  if (me.paramArgs)
    		        			  me.paramArgs.resetValues();
    		        	  }
    		          }
    		]
    	});   
    	return this.form;   
    }    
});