Blame view

js/app/views/UploadPanelUI.js 15.5 KB
16035364   Benjamin Renard   First commit
1
2
3
4
/**
 * Project   : AMDA-NG
 * Name      : UploadUI.js
 * @class    amdaUI.UploadUI
901ba3f3   Elena.Budnik   upload catalog
5
 * @extends  Ext.form.Panel 
16035364   Benjamin Renard   First commit
6
7
8
9
10
11
 * @brief    Upload Panel UI definition (View)
 * @author 	 Elena
 * @version  $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $            
 */

Ext.define('amdaUI.UploadPanelUI', {
901ba3f3   Elena.Budnik   upload catalog
12
13
14
15
16
17
	extend: 'Ext.form.Panel',
	alias: 'widget.panelUpload',
	
	requires : [
		'amdaUI.RemoteSearchPlugin'
	],
16035364   Benjamin Renard   First commit
18
        
901ba3f3   Elena.Budnik   upload catalog
19
20
21
22
23
24
25
26
27
	isFile : true,
	isTimeTable : false,
	tmpNode : null,
						
	constructor: function(config) 
	{  
		this.init(config);
		this.callParent(arguments);  		        
	},
16035364   Benjamin Renard   First commit
28

901ba3f3   Elena.Budnik   upload catalog
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
	/*
	* create MyData linked node and edit in module MyData
	* update myDataParams info if needed
	*/
	getObjectCallback : function(result,remoteEvent)
	{                    
		var t = remoteEvent.getTransaction();
		if (result && !result.error) 
		{
			// set parameter into node
			var me = this;
			myDesktopApp.getLoadedModule(this.tmpNode.get('moduleId'), true, function (module){
				// myData
				if (me.tmpNode.get('nodeType') == amdaModel.MyDataParamNode.nodeType) 
				{		       
					var linkedFile = Ext.create('amdaModel.MyDataNode', {leaf : true, text : me.tmpNode.get('text')});
							
					linkedFile.create(result.mask, result.description, result.maskDesc);
					linkedFile.updateMyDataParam(result.mask,result.maskDesc); 
					
					if (!linkedFile.get('id')) 
						linkedFile.set('id',me.tmpNode.get('text'));   
		
					var paramObj = Ext.create(linkedFile.get('objectDataModel'), result);
					linkedFile.set('object',paramObj);
					me.tmpNode.set('fileObject',paramObj);
				}
				else 
				{
					// Time Table or Catalog
					var paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result);
					
					paramObj.set('fromPlugin',true);
					if (result.intervals) 
					{
						paramObj.set('intervals',result.intervals);
						paramObj.set('nbIntervals',result.intervals.length);
					}
					me.tmpNode.set('object',paramObj);
				}	
				if (module)
				{
					module.setLinkedNode(me.tmpNode); 	      
					module.linkedNode.editInModule();  
				}
			}); 
		} 
		else 
		{	   
			// EXCEPTION : parameter not found !
			myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"+this.tmpNode.get('text')+"' found!");	     
		}
		loadMask.hide();
	},
16035364   Benjamin Renard   First commit
83
        
901ba3f3   Elena.Budnik   upload catalog
84
85
86
87
88
89
90
/*
*  form validation
*  TODO markInvalid()?
*/
	validate : function() 
	{
		var values = this.getForm().getValues();
16035364   Benjamin Renard   First commit
91

901ba3f3   Elena.Budnik   upload catalog
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
		if (values['filesrc'] == 'LOCAL') 
		{
			if (this.isFile) var locFile = this.getForm().findField('localFileName').getValue();
			else if (this.isTimeTable) var locFile = this.getForm().findField('localTTName').getValue();
			else var locFile = this.getForm().findField('localCatName').getValue();
													 	
			if (!locFile) 
			{
				myDesktopApp.warningMsg("Select File to Upload");
				return false;
			}
		}
		else 
		{
			if (!values['remoteFile'] && !values['remoteTT'] && !values['remoteCat']) 
			{
				myDesktopApp.warningMsg("Select File to Upload");
				return false;
			}
		}	     	     
		return true;
	},
16035364   Benjamin Renard   First commit
114
115

        
901ba3f3   Elena.Budnik   upload catalog
116
117
118
119
120
121
122
123
124
125
126
	//TODO proper parsing
	updateFormat: function(value) 
	{    
		var arrayOfStr = value.split('.');
		//TODO use down method?	  
		if (this.isFile) 
		{
			var radios = Ext.getCmp('filefrmt');
			var user_format_obj = radios.getValue();	  
			var user_format = user_format_obj.filefrmt;
		}
45a46271   Elena.Budnik   isTimeTable var
127
		else if (this.isTimeTable)
901ba3f3   Elena.Budnik   upload catalog
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
		{
			var radios = Ext.getCmp('ttfrmt');
			var user_format_obj = radios.getValue();	  
			var user_format = user_format_obj.ttfrmt;
		}
		else
		{
			var radios = Ext.getCmp('catfrmt');
			var user_format_obj = radios.getValue();	  
			var user_format = user_format_obj.catfrmt;
		}
					
		var auto_format = user_format;
		
		//  auto define format in some special cases 
		//TODO name without extention => ASCII?
		if (arrayOfStr.length == 1) auto_format = 'ASCII'; 
		else  
		{
			var suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase();
			if (suffix == 'gz') 
				suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz';
16035364   Benjamin Renard   First commit
150

901ba3f3   Elena.Budnik   upload catalog
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
			switch (suffix)
			{
				case 'cdf' :  auto_format = 'CDF'; break;
				case 'cef.gz' :
				case 'cef' :  auto_format = 'CEF'; break;
				case 'xml' :  auto_format = 'VOT';
				case 'vot' :  auto_format = 'VOT'; break;
				case 'nc'  :  auto_format = 'NC'; break;
				case 'asc' :
				case 'txt' :			 
				default : auto_format = 'ASCII'; 			   
			}
		} 
		// set auto format : case when format was not set by user before   
		if (this.isFile && user_format !== auto_format) {
				user_format_obj.filefrmt = auto_format;    
		} else  if (this.isTimeTable && user_format !== auto_format) {
				user_format_obj.ttfrmt = auto_format;
45a46271   Elena.Budnik   isTimeTable var
169
		} else if (!this.isFile && !this.isTimeTable && user_format !== auto_format) {
901ba3f3   Elena.Budnik   upload catalog
170
171
172
173
174
			user_format_obj.catfrmt = auto_format;
		}
		
		radios.setValue(user_format_obj);
	},
16035364   Benjamin Renard   First commit
175
 
901ba3f3   Elena.Budnik   upload catalog
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
	/*
	* 
	*/
	forceUpload : function (url,format)
	{
		this.getForm().findField('filesrc').setValue('URL');	
		
		switch (format)
		{
			case 'votable' :
						this.getForm().findField('filefrmt').setValue('VOT');
						break;
			case 'cdf' :
						this.getForm().findField('filefrmt').setValue('CDF');
						break;
			default :
						//ToDo Error - unknown format
						return;
	}                
		this.getForm().findField('remoteFile').setValue(url);
		
		this.postUpload();
	},
16035364   Benjamin Renard   First commit
199
        
901ba3f3   Elena.Budnik   upload catalog
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
	/*
	* 
	*/
	postUpload : function()
	{
		// 'global' form containing 'partial' forms				      
		var form = this.getForm();
		
		// special validation 	            
		if(this.validate())
		{						
			form.submit({
				scope: this,
				url: 'php/uploadFile.php',
				waitMsg: 'Uploading your file...',
				success: function(form, o)
				{   
					this.tmpNode = Ext.create(this.nodeType,{leaf : true, text : o.result.file});
					loadMask.show();
					AmdaAction.getUploadedObject(o.result.file, o.result.format, this.tmpNode.get('nodeType'), this.getObjectCallback, this);
				},
				failure: function(form, o) 
				{                    
					loadMask.hide();                       
					myDesktopApp.errorMsg('Error '+o.result.error); 
				}
			});
		}		
	},
16035364   Benjamin Renard   First commit
229
	
901ba3f3   Elena.Budnik   upload catalog
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
	/*
	*  panel config
	*/
	init : function(config) 
	{       
		this.isFile = config.panelType == 'file'? true : false;
		this.isTimeTable = config.panelType == 'timetable'? true : false;
		
		// file / time table / catalog settings	  
		if (this.isFile) 
		{	    
			var title = 'File';
			var items = [
				{ boxLabel: 'ASCII', name: 'filefrmt', inputValue: 'ASCII', checked: true,
					listeners: 
					{
						change: function (cb, nv, ov) {
							if (nv) Ext.getCmp('tf').show();
							else Ext.getCmp('tf').hide();	
						}
					} 
				}, 
			//	{ boxLabel: 'netCDF&nbsp;<img amda_clicktip="ncTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'NC' },
				{ boxLabel: 'CDF&nbsp;<img amda_clicktip="cdfTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', name: 'filefrmt', inputValue: 'CDF' },
			// { boxLabel: 'CEF[GZ]', name: 'filefrmt', inputValue: 'CEF' },
				{ boxLabel: 'VOTable', name: 'filefrmt', inputValue: 'VOT' }];
			var timeFormatId = 'tf';
			this.formatId = 'nsf';
			this.localUploadId = 'form-uploadfile';
			var localUploadName ='localFileName';
			var remoteUploadName ='remoteFile';
			this.remoteUploadId = 'form-uploadurl'; 	 
			this.nodeType = 'amdaModel.MyDataParamNode';
			//TODO load XML	   
			var store = Ext.create('Ext.data.Store', {
				fields: ['value', 'name'],
				data : [
					{"value":"ftp://cdaweb.gsfc.nasa.gov/pub/data/", "name":"CDAWEB/FTP"}/*,		   
					{"value":"ftp://ftp.ngdc.noaa.gov/STP/SOLAR_DATA/", "name":"Solar Data"}*/]
			});	   
		}
		else if (this.isTimeTable)
		{		
			var title = 'Time Table';
			var items = [
				{ boxLabel: 'ASCII', name: 'ttfrmt', inputValue: 'ASCII', checked: true,
						listeners: {
								change: function (cb, nv, ov) {
									if (nv) Ext.getCmp('tf_tt').show(); 
									else Ext.getCmp('tf_tt').hide();  							 						  
								}
						} 
				},
				{ boxLabel: 'VOTable', name: 'ttfrmt', inputValue: 'VOT'}];
						
			var timeFormatId = 'tf_tt'; 
			this.formatId = 'nsf_tt';
			this.localUploadId = 'form-uploadtt';
			var localUploadName ='localTTName';
			var remoteUploadName ='remoteTT';
			this.remoteUploadId = 'form-uploadtturl'; 
			this.nodeType = 'amdaModel.TimeTableNode';
			//TODO load XML		    
			var store = Ext.create('Ext.data.Store', {
					fields: ['value', 'name'],
					data : []
			});
		}
		else 
		{
			var title = 'Catalog';
			var items = [
				{ boxLabel: 'VOTable', name: 'catfrmt', inputValue: 'VOT', checked: true }];
						
			var timeFormatId = 'tf_cat'; 
			this.formatId = 'nsf_cat';
			this.localUploadId = 'form-uploadcat';
			var localUploadName ='localCatName';
			var remoteUploadName ='remoteCat';
			
			this.remoteUploadId = 'form-uploadcaturl'; 
			this.nodeType = 'amdaModel.CatalogNode';
			//TODO load XML		    
			var store = Ext.create('Ext.data.Store', {
					fields: ['value', 'name'],
					data : []
			});
		}
		
		var combo = Ext.create('Ext.form.ComboBox', {
				flex : 4, 
				store: store,
				emptyText: 'Enter Remote Site URL (ftp)',
				queryMode: 'local',
				displayField: 'name',
				valueField: 'value' 
		});
16035364   Benjamin Renard   First commit
327
	    	  
901ba3f3   Elena.Budnik   upload catalog
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
		var fieldcontainer = 
		{ 
			xtype: 'fieldcontainer', 
			fieldLabel: ' ', labelWidth: 0, labelSeparator : '', labelPad : 0,
			layout: 'hbox',		
			items: [
				combo,
				{
					xtype : 'button',
					flex : 1,
					text: 'Browse It',								   
						handler: function()
						{					      
							var form = this.up('form').getForm(); 
							var site = form.getFields().getAt(0).getValue(); 					    
							if (site) 						   
								this.up('form').ownerCt.fireEvent('open', site);
							else 
								myDesktopApp.warningMsg("Please Enter Remote Site URL");				 
						} 
				}]
		};
		
		if (this.isFile) var radioId = 'filefrmt';
		else if (this.isTimeTable) var radioId =	'ttfrmt';
		else var radioId = 'catfrmt';
		
		var fileFormat =  Ext.create('Ext.form.FieldSet', { 			      
			title: 'File Format',			     		     
			items : [{ 
				xtype: 'radiogroup',
				id : radioId, 
				columns: 3,
				cls: 'x-check-group-alt',
				items: items				
			}]
		});
16035364   Benjamin Renard   First commit
365
            
901ba3f3   Elena.Budnik   upload catalog
366
367
368
369
370
371
372
373
374
375
376
377
378
		var Sampling = 
		{ 
			xtype: 'radiogroup',	
			fieldLabel: 'Time Sampling',	
			labelWidth: 90,			  
			cls: 'x-check-group-alt',
			hidden : !this.isFile,
			defaults : {name : 'timesmpl'},
			items: [ 			
				{boxLabel: 'constant', inputValue: 'constant', checked: true},
				{boxLabel: 'variable&nbsp;<img amda_clicktip="variableSampling" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'variable'}	  
			] 		
		};
16035364   Benjamin Renard   First commit
379
	  
901ba3f3   Elena.Budnik   upload catalog
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
		var dayStart = 
		{ 
			xtype: 'checkbox',  
			name : 'doy',
			hidden : true,
			fieldLabel: 'DOY starts from 1',
			inputValue: '1'
		};
			
		var nonStandardFormat = 
		{ 
			xtype: 'fieldcontainer',
			defaultType: 'textfield',
			layout: 'anchor',
			defaults: 
			{
					layout: '100%',
					labelWidth : 150
			}, 
			id : this.formatId, 
			hidden : true,
			items: [  
			{ 
				fieldLabel : 'define time format',	
				name : 'nonstd',				   
				value: 'Y-m-d H:i:s',
				enableKeyEvents: true,
				listeners : 
				{
					keyUp : function() {
						if (this.getValue().indexOf('z') > 0) {
							this.nextSibling().show();
						}                                                 
						if (this.getValue().indexOf('d') > 0) {
							this.nextSibling().hide();
						}                                                 
					}
				}
			},
			dayStart,
			{ 
					fieldLabel : 'define max time length',
					name : 'timelength',
					value: 'auto' 				    
			}],
			listeners : 
			{                                        
				hide : function() {
						this.items.getAt(1).hide();                                                
				}
			}
		};	 
		var isCatalog = !(this.isFile || this.isTimeTable);
16035364   Benjamin Renard   First commit
433

901ba3f3   Elena.Budnik   upload catalog
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
		var timeFormat = Ext.create('Ext.form.FieldSet', { 
			id: timeFormatId, 
			title: 'Time Settings',	
			hidden : isCatalog,
			items : [
			{
				xtype: 'radiogroup',
				fieldLabel: 'Time Format',
				labelWidth: 90,				   
				cls: 'x-check-group-alt',
				defaults : { name : 'timefrmt'},
				items: [						 
				{ boxLabel: 'standard&nbsp;<img amda_clicktip="standardTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'standard', checked: true},     			
				{ boxLabel: 'no&nbsp;<img amda_clicktip="userTimeFormat" style="vertical-align:bottom" src="js/resources/images/16x16/info_mini.png"', inputValue: 'user', 
					listeners: 
					{
						scope : this,
						change: function (cb, nv, ov) {							
						if (nv) 
								Ext.getCmp(this.formatId).show();
						else    
								Ext.getCmp(this.formatId).hide();	
						}
					} 					      
				}] 				      			  	
			},
			nonStandardFormat,
			Sampling ]
		});
	
		var localFile = Ext.create('Ext.form.Panel', {			      
			id: this.localUploadId,
			fileUpload: true,
			hideLabels: true,
			frame: true,			      
			items: [
			{
				xtype: 'fileuploadfield',							     
				emptyText: 'Select Your File',
				width: 300,
				name: localUploadName,  
				buttonText: 'Browse',
				listeners: 
				{
					scope : this,
					change: function (field, value, e) {							
							this.updateFormat(value);	
					} 
				}
			},
			{  
				// it is common setting for Local and Remote files
				xtype : 'hiddenfield',
				name: 'MAX_FILE_SIZE',
				value: myDesktopApp.MAX_UPLOADED_FILE_SIZE // 30MB	 			      
			}] 
		});      
	
		var remoteFile = Ext.create('Ext.form.Panel', {					 
			id: this.remoteUploadId,					 
			hideLabels: true,
			autoHeight: true,					 
			frame: true,
			hidden : true,
			items: [  
				fieldcontainer,
				{ 
					xtype : 'textfield',
					name : remoteUploadName, 
					emptyText: 'Enter Remote File URL (http or ftp)',
					width: 310,
					listeners: 
					{
						scope : this,
						change: function (field, value, e) {							
									this.updateFormat(value);	
						} 
					}
				}]
		});
16035364   Benjamin Renard   First commit
514
                                        
901ba3f3   Elena.Budnik   upload catalog
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
		var uploadForm = Ext.create('Ext.form.FieldSet',{				    			    
			title: 'File Source',			     
			items : [
			{ 
				xtype: 'radiogroup',					 
				cls: 'x-check-group-alt',
				items: [
					{ boxLabel: 'Local', name: 'filesrc', inputValue: 'LOCAL', checked: true,
						listeners: 
						{
							scope : this,
							change: function (cb, nv, ov) {
								if (nv == ov) return;
								var local = Ext.getCmp(this.localUploadId);
								var remote = Ext.getCmp(this.remoteUploadId);
								if (nv) {
										remote.hide();
										local.show();					
								}
								else  {
										local.hide();
										remote.show();									    
								}   
							}
						} 
					},
					{ boxLabel: 'URL', name: 'filesrc', inputValue: 'URL'} ]				
			}]
		});		      
														
		var myConf = 
		{
			title : title,  
			layout: {type: 'vbox', align: 'stretch'},
			bodyStyle: { background : '#dfe8f6'},
			items : [ 
					uploadForm,
					localFile, 
					remoteFile, 			     
					fileFormat,
					timeFormat	
			],
			buttons: [
			{
				text: 'Upload',
				handler: function()
				{
					this.postUpload();
				},
				scope : this
			},
			{
				text: 'Reset',
				handler: function(){				      
					this.up('form').getForm().reset();  
				}
			}], 
			plugins: [{ptype: 'remoteSearchPlugin'}],
			listeners:
			{
				click: 
				{
					element: 'el',
					fn: function(e,t) {	 		 
						var me = t,
						text = me.getAttribute('amda_clicktip');
						if (text) 
						{
							e.preventDefault();
							AmdaAction.getInfo({name : text}, function(res,e) {					    					   
								if (res.success) myDesktopApp.infoMsg(res.result);
							}); 
						}
					}
				}
			}
		};

		Ext.apply (this, Ext.apply(arguments, myConf));	 	  
	}		 
16035364   Benjamin Renard   First commit
595
});