Blame view

js/app/views/TimeSelectorUI.js 7.62 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/**
 * Project   : AMDA-NG
 * Name      : TimeSelectorUI.js
 * @class      amdaUI.TimeSelectorUI
 * @extends    Ext.form.FieldSet
 * @brief    common component to select Time in searchModule, plotModule
 * 					and downloadModule
 * @author 	 Myriam
a0f13ed1   Elena.Budnik   small format + ti...
9
 * @version  $Id: TimeSelectorUI.js 2135 2014-02-25 13:37:18Z elena $ 
16035364   Benjamin Renard   First commit
10
11
 */

a0f13ed1   Elena.Budnik   small format + ti...
12
Ext.define('amdaUI.TimeSelectorUI', {
d341347d   Elena.Budnik   Plot Mgr ameliora...
13
	extend: 'Ext.form.Panel',
a0f13ed1   Elena.Budnik   small format + ti...
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
	
	requires : [ 'amdaUI.IntervalUI' ],
	
	setTTTab: function(arrayTT) {
		var arrayRec = new Array();
		var index = 1;
		if (arrayTT){
			index = 0;            
			Ext.Array.each(arrayTT,function(item,index,all){
				// adding the time table to the TTGrid
				if (!item.$className){
					//json case
					var r = Ext.create('amdaModel.TTobject', { id: item.id, name: item.timeTableName });
					arrayRec.push(r);
				}
				else
					//TTobject case
					arrayRec.push(item);
			});
		}          
		this.activeTab = amdaModel.AmdaTimeObject.inputTimeSrc[index];
		
		// name of RadioGroup in every TimeSelector object should be UNIQUE: 
		// RadioManager is a singleton working with getByName !!!!!	
		var obj = new Object();  	 
		obj['timesrc_' + this.id] =  this.activeTab;        
		this.timeSrc.setActiveTab(this.activeTab); 
		
		if (index === 0) this.TTGrid.getStore().loadData(arrayRec);
	},
16035364   Benjamin Renard   First commit
44
    
3919a5df   furkan   #10178 - Should b...
45
46
47
48
49
	timeFormat : function(time){
		return time.substring(0,4) +'/'+ time.substring(5,7)+'/'+time.substring(8,10)
				+' '+time.substring(11,19)+'.000';
	},

a0f13ed1   Elena.Budnik   small format + ti...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
	addTT : function(newTTName,newTTid) {      
		// set the TimeTable radio checked
		var obj = new Object();  
		obj['timesrc_'+this.id] =  amdaModel.AmdaTimeObject.inputTimeSrc[0]; /*'TimeTable'*/
		this.timeSrc.setActiveTab(obj['timesrc_'+this.id]); 
		
		// search for an existing record in store with this unique name
		var existingIndex = this.TTGrid.store.findExact( 'name', newTTName);
		// if no corresponding TT found
		if (existingIndex == -1){
			// adding the time table to the TTGrid  
			var r = Ext.create('amdaModel.TTobject', { id: newTTid, name: newTTName });
			this.TTGrid.store.insert(this.TTGrid.store.getCount(),r);   
		}        
	},
16035364   Benjamin Renard   First commit
65
   
a0f13ed1   Elena.Budnik   small format + ti...
66
67
68
	getActiveTimeSource: function() {
		return this.timeSrc.getActiveTab().getItemId(); 
	},
46bd4591   Hacene SI HADJ MOHAND   us ok
69
70
71
                   setActiveTimeSource : function (timeSrcIndex){
                    this.timeSrc.setActiveTab(timeSrcIndex);
                 },
bab40211   Benjamin Renard   Test time selecti...
72
73
74
75
76
77
78
79
80
81
82
83
84
85

        isValid: function(acceptEmptyTTList = true) {
            if (this.getActiveTimeSource() === amdaModel.AmdaTimeObject.inputTimeSrc[0]) {
                //TimeTables
                if (acceptEmptyTTList)
                    return true;
                return (this.TTGrid.getStore().count() > 0);
            }
            else {
                //Interval
                return this.intervalSel.isValid();
            }
            return true;
        },
de9b2578   Benjamin Renard   Update TimeSelect...
86
    
a0f13ed1   Elena.Budnik   small format + ti...
87
88
89
90
91
92
	initComponent: function() {
		this.activeField = null;
		var store = Ext.create('Ext.data.Store', 
		{
			model: 'amdaModel.TTobject'	
		});
16035364   Benjamin Renard   First commit
93

a0f13ed1   Elena.Budnik   small format + ti...
94
		var me = this;
c94de8e9   Benjamin Renard   Fix Multi plot ti...
95
        
a0f13ed1   Elena.Budnik   small format + ti...
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
		this.TTGrid = Ext.create('Ext.grid.Panel', 
		{
			itemId: 1, 	    
			store : store,
			columns: 
			[ 
				Ext.create('Ext.grid.RowNumberer', { width: 20 } ),
				{ header: "Time Table or Catalog Name", dataIndex: 'name', flex:1, sortable : false, menuDisabled: true },
				{ 
					menuDisabled: true,  width: 30, renderer: function()
					{
						return'<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
					}
				}
			],
			listeners : {
				render : function(o,op) {
					var el = this.getEl();
					var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
						ddGroup: 'explorerTree',
						notifyOver  : function(ddSource, e, data)
						{
							if ((data.records[0].get('nodeType') == 'timeTable' || 
								data.records[0].get('nodeType') == 'sharedtimeTable' ||
								data.records[0].get('nodeType') == 'catalog' ||
								data.records[0].get('nodeType') == 'sharedcatalog') && (data.records[0].get('leaf')))
							{
								this.valid = true;
								return this.dropAllowed;
							}
							this.valid = false;
							return this.dropNotAllowed;
						},
						notifyDrop  : function(ddSource, e, data) 
						{
							if (!this.valid) return false;
							
							var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
							if (!explorerModule)
								return false;
							var targetModuleId = explorerModule.getPinedModule(); 
							var targetModule = myDesktopApp.getLoadedModule(targetModuleId);
							if (targetModule)
								targetModule.getUiContent().addTT(data.records[0].get('text'),data.records[0].get('id'), me.getId());
							return true;
						}
					});
				}
			}
		}); 
16035364   Benjamin Renard   First commit
146

a0f13ed1   Elena.Budnik   small format + ti...
147
148
149
150
151
		this.TTGrid.on('cellclick', function(view, cell, cellIndex, record, row, recordIndex, e)
		{
			if (cellIndex == 2)
			this.TTGrid.getStore().remove(record);
		}, this);
3919a5df   furkan   #10178 - Should b...
152
		const self = this;
a0f13ed1   Elena.Budnik   small format + ti...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
		this.intervalSel = Ext.create('amdaUI.IntervalUI', 
		{
			itemId: 2,
			listeners : 
			{
				render : function(o,op) 
				{
					var me = this;
					var el = me.getEl(); 
					var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
						ddGroup: 'explorerTree',
						notifyOver  : function(ddSource, e, data) 
						{  
							if ((data.records[0].get('globalStart') != null) && (data.records[0].get('globalStop') != null) 
73beb15b   furkan   #10178 First Step
167
168
169
								 && data.records[0].get('globalStart') != 'depending on mission' &&  data.records[0].get('isParameter')  
								 || data.records[0].get('nodeType') == 'timeTable' || data.records[0].get('nodeType') == 'sharedtimeTable'
								 || data.records[0].get('nodeType') == 'catalog' || data.records[0].get('nodeType') == 'sharedcatalog'  )
a0f13ed1   Elena.Budnik   small format + ti...
170
171
172
173
174
175
176
177
178
179
180
181
						//	if ((data.records[0].get('nodeType') == 'myDataParam' || data.records[0].get('nodeType') == 'localParam')
						//		&&  data.records[0].get('isParameter'))
							{
								this.valid = true;
								return this.dropAllowed;
							}
							this.valid = false;
							return this.dropNotAllowed;
						},
						notifyDrop  : function(ddSource, e, data)
						{
							if (!this.valid) return false;
73beb15b   furkan   #10178 First Step
182
183
184
185
186
187
188
189
190

							var surveyStart = "";
							var surveyStop = "";

							if( !data.records[0].get('isParameter')  && data.records[0].get('nodeType') == 'timeTable' 
								|| data.records[0].get('nodeType') == 'sharedtimeTable'|| data.records[0].get('nodeType') == 'catalog' 
								|| data.records[0].get('nodeType') == 'sharedcatalog')
							{
								AmdaAction.getObject(data.records[0].get('id'), data.records[0].get('nodeType'),  function (result, remoteEvent) {
3919a5df   furkan   #10178 - Should b...
191
192
193
194
195
									surveyStart = self.timeFormat(result['surveyStart']);
									surveyStop = self.timeFormat(result['surveyStop']);

									me.setStartTime(surveyStart);
									me.setStopTime(surveyStop);
73beb15b   furkan   #10178 First Step
196
197
198
199
								}, this);
								return true;
							}
							else{
3919a5df   furkan   #10178 - Should b...
200
201
								surveyStart = self.timeFormat(data.records[0].get('globalStart'));
								surveyStop = self.timeFormat(data.records[0].get('globalStop'));
3919a5df   furkan   #10178 - Should b...
202
203
204

								me.setStartTime(surveyStart);
								me.setStopTime(surveyStop);
73beb15b   furkan   #10178 First Step
205
206
207
								return true;

							}
a0f13ed1   Elena.Budnik   small format + ti...
208
209
210
211
212
						}
					});
				}
			}                
		});
16035364   Benjamin Renard   First commit
213
        
a0f13ed1   Elena.Budnik   small format + ti...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
		this.timeSrc = new Ext.tab.Panel(
		{
			layout: 'fit',
			plain: true,
			bodyStyle: 'background: none',
			items: [
			{
				title: 'Interval',
				layout: 'fit',
				bodyStyle: 'background: none',
				itemId: amdaModel.AmdaTimeObject.inputTimeSrc[1],//'Interval'
				items: [ this.intervalSel ]
			},
			{
				title: 'Time Table or Catalog',
				layout: 'fit',
				itemId: amdaModel.AmdaTimeObject.inputTimeSrc[0],//'TimeTable'
				items: [ this.TTGrid ]
			}]     
		});
16035364   Benjamin Renard   First commit
234
        
a0f13ed1   Elena.Budnik   small format + ti...
235
236
237
238
		var config = 
		{
			title: (!this.title) ? 'Time Selection' : this.title,
			layout: 'fit',
d341347d   Elena.Budnik   Plot Mgr ameliora...
239
			bodyStyle: { background : '#dfe8f6' },
a0f13ed1   Elena.Budnik   small format + ti...
240
241
			items: [ this.timeSrc ]
		};
16035364   Benjamin Renard   First commit
242
	 
a0f13ed1   Elena.Budnik   small format + ti...
243
244
245
		Ext.apply(this, config);
		this.callParent(arguments);
	}
16035364   Benjamin Renard   First commit
246
});