Blame view

js/app/views/PlotComponents/PlotExtendShiftPlug.js 5.69 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 : '',
b74e48d4   Benjamin Renard   Add Extend/Shift ...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	
	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...
42
    show : function(interactiveId) {          
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
    	if (!this.win)
    	{
    		this.win = new Ext.Window({                
    			id: 'plot-extendshift-win-' + this.hostCmp.ownerCt.getId(), // Plot window ID                                                   
    			width: 230,
    			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...
80
    	this.interactiveId = interactiveId;
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
    	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) {
b39c9d1d   Benjamin Renard   Fix interactive n...
114
    		this.hostCmp.callInteractivePlot({'action' : actionType, 'interactiveId' : this.interactiveId, 'duration' : duration});	                								   
b74e48d4   Benjamin Renard   Add Extend/Shift ...
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
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
188
189
190
191
192
    	}	
    	else
    		myDesktopApp.errorMsg('No duration defined');	
    },
    
/**
 *        Main form
 */
    getFormConfig: function(){
    	this.form = new Ext.form.FormPanel( {	    	
    		frame: true,		
    		width: 230,		
    		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: [
    		          {
    		        	  text: 'Extend/Shrink',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  this.executeAction('extend');
    		        	  }
    		          },
    		          '->',
    		          {
    		        	  text: 'Shift',
    		        	  scope : this,
    		        	  handler: function(bt,event) {
    		        		  this.executeAction('shift');
    		        	  }
    		          }
    		]
    	});   
    	return this.form;   
    }    
b39c9d1d   Benjamin Renard   Fix interactive n...
193
});