Blame view

js/app/views/PlotComponents/PlotExtendShiftPlug.js 6.82 KB
b74e48d4   Benjamin Renard   Add Extend/Shift ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
  * Project      :  AMDA-NG
  * Name         : PlotExtendShiftPlug.js
  * @plugin 	  amdaPlotComp.PlotZoomPlug
  * @extends 	  Ext.util.Observable 
  * @ptype 	 	  plotExtendShiftPlugin
  * @brief		 Plot Extend/Shift UI (View)
  * @author Benjamin
  * @version $Id: PlotExtendShiftPlug.js
  ********************************************************************************
  *    FT Id     :   Date   : Name - Description
  *******************************************************************************
  *  :          
  */


Ext.define('amdaPlotComp.PlotExtendShiftPlug', {
	extend:  'Ext.util.Observable',
	alias: 'plugin.plotExtendShiftPlugin',
0891da48   Benjamin Renard   Fix some bugs wit...
20
21
    
	id: 'plot-extendshift-plug',
b74e48d4   Benjamin Renard   Add Extend/Shift ...
22
23
	win : null,
	form : null,
b39c9d1d   Benjamin Renard   Fix interactive n...
24
	interactiveId : '',
e3824d6e   Hacene SI HADJ MOHAND   us ok
25
26
                    actionDone :'',
                    durationDone: 0,
b74e48d4   Benjamin Renard   Add Extend/Shift ...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	
	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
 */        
b39c9d1d   Benjamin Renard   Fix interactive n...
44
    show : function(interactiveId) {          
b74e48d4   Benjamin Renard   Add Extend/Shift ...
45
46
47
48
    	if (!this.win)
    	{
    		this.win = new Ext.Window({                
    			id: 'plot-extendshift-win-' + this.hostCmp.ownerCt.getId(), // Plot window ID                                                   
e3824d6e   Hacene SI HADJ MOHAND   us ok
49
    			width: 275,
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
    			height: 120,       
    			x: 0, y: 0,                
    			baseCls:'x-panel',                
    			title: 'Extend / Shift',			                
    			layout: 'fit',			                
    			constrain: true,			                
    			collapsible: true,
    			resizable: false,
    			ghost: false,			                
    			renderTo: this.hostCmp.ownerCt.body,                                 
    			items: this.getFormConfig(),                
    			listeners: {			                      
    				scope: this,			    			                      
    				beforeclose: function() {      
    					this.hostCmp.panelImage.stopZoom();	                    
    					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);
    	}
    	
b39c9d1d   Benjamin Renard   Fix interactive n...
82
    	this.interactiveId = interactiveId;
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
    	this.win.show();
    	this.win.setPosition(0,0);	
    },
    
    close : function() {
    	if (this.win == null)
    		return;
    	this.win.close();
    },
    
    toSec: function(value, unit) {
    	if (value == "")
    		return 0;
    	
    	switch (unit) {
    	case "sec":
    		return value;				
    	case "min":
    		return value * 60;				
    	case "hour":
    		return value * 3600;				 
    	case "day":
    		return value * 86400;				 
    	default:
    		return 0;
    	}		
    },

    executeAction : function(actionType) {
    	var durationField = this.form.getForm().findField('duration');
    	var durationUnitField = this.form.getForm().findField('durationUnit');
    	var duration = this.toSec(durationField.getValue(), durationUnitField.getValue());
    	if (duration) {
e3824d6e   Hacene SI HADJ MOHAND   us ok
116
117
118
119
                                        this.durationDone = duration;
                                        this.actionDone = actionType;
    		this.hostCmp.callInteractivePlot({'action' : actionType, 'interactiveId' : this.interactiveId, 'duration' : duration});
                                        Ext.getCmp('undo-PlotExtendShiftPlug').enable(); 
b74e48d4   Benjamin Renard   Add Extend/Shift ...
120
121
122
123
    	}	
    	else
    		myDesktopApp.errorMsg('No duration defined');	
    },
e3824d6e   Hacene SI HADJ MOHAND   us ok
124
125
126
127
128
129
130
131
132
    undoAction : function(){
        if( this.durationDone){
            this.hostCmp.callInteractivePlot({'action' : this.actionDone , 'interactiveId' : this.interactiveId, 'duration' : -this.durationDone});
             Ext.getCmp('undo-PlotExtendShiftPlug').disable(); 
        }
        else
    		myDesktopApp.errorMsg('No duration defined');
        
    },
b74e48d4   Benjamin Renard   Add Extend/Shift ...
133
134
135
136
137
138
139
    
/**
 *        Main form
 */
    getFormConfig: function(){
    	this.form = new Ext.form.FormPanel( {	    	
    		frame: true,		
e3824d6e   Hacene SI HADJ MOHAND   us ok
140
    		width: 275,		
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
    		height: 120,	    	
    		layout: {
			    type: 'vbox',
			    pack: 'start',
			    align: 'stretch'
			},	    	
    		fieldDefaults: {		  
    			labelWidth: 60		
    		},		
    		items: [
    		        {
    		        	xtype: 'fieldcontainer',
    		        	layout: 'hbox',
    		        	fieldLabel: 'Duration to apply to the interval',
    		        	labelAlign: 'top',
    		        	bodyStyle: {background : '#dfe8f6'},
    		        	border: false,
    		        	items: [
    		        	        {
    		        	        	xtype: 'numberfield',
    		        	        	hideTrigger: true,
    		        	        	name: 'duration',
    		        	        	//   minValue: 0,
    		        	        	width: 150
    		        	        },
    		        	        {
    		        	        	xtype: 'splitter',
    		        	        	width: 5
    		        	        },
    		        	        {
    		        	        	xtype:'combo',
    		        	        	name: 'durationUnit',
    		        	        	store:[
    		        	        	       'sec',
    		        	        	       'min',
    		        	        	       'hour',
    		        	        	       'day'
    		        	        	], 
    		        	        	editable: false,
    		        	        	width: 60,
    		        	        	value: 'sec',
    		        	        	triggerAction: 'all'
    		        	        }
    		        	]
    		        }
    		],
    		buttons: [
e3824d6e   Hacene SI HADJ MOHAND   us ok
188
                    
b74e48d4   Benjamin Renard   Add Extend/Shift ...
189
190
191
192
193
194
195
    		          {
    		        	  text: 'Extend/Shrink',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  this.executeAction('extend');
    		        	  }
    		          },
e3824d6e   Hacene SI HADJ MOHAND   us ok
196
                                                '-',
b74e48d4   Benjamin Renard   Add Extend/Shift ...
197
198
199
200
201
202
    		          {
    		        	  text: 'Shift',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  this.executeAction('shift');
    		        	  }
e3824d6e   Hacene SI HADJ MOHAND   us ok
203
204
205
206
207
208
209
210
211
212
    		          },
                                                '-',
                                                    {
    		        	  text: 'Undo',
                                                             id:'undo-PlotExtendShiftPlug',
    		        	  scope : this,
                                                              disabled : true,
    		        	  handler: function(bt,event) {
    		        		  this.undoAction();
    		        	  }
b74e48d4   Benjamin Renard   Add Extend/Shift ...
213
214
215
216
217
    		          }
    		]
    	});   
    	return this.form;   
    }    
b39c9d1d   Benjamin Renard   Fix interactive n...
218
});