Blame view

js/app/models/Download.js 4.68 KB
16035364   Benjamin Renard   First commit
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
/**
 * Project      : AMDA-NG
 * Name         : Download.js
 * Description  : Download Request Business Object Definition
 * @class amdaModel.Download
 * @extends amdaModel.AmdaObject 
 * 
 * @author myriam
 * @version $Id: Download.js 2068 2014-02-06 11:27:38Z elena $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :15/12/2011: myriam – creation 
 */
 
 		
Ext.define('amdaModel.Download', {
		extend: 'amdaModel.AmdaTimeObject',
    
    fields : [
	      {name: 'type', type: 'string', defaultValue: 'Download'},
	      {name: 'downloadSrc', type: 'string'},
	      {name: 'list', defaultValue: null },    // array of parameters	  
	      {name: 'timeformat', type: 'string'},
	      {name: 'timeformatTT', type: 'string'},
16035364   Benjamin Renard   First commit
26
	      {name: 'structure', type: 'string'},
9cb1f3cd   Benjamin Renard   Update download i...
27
	      {name: 'refparamSampling', type: 'boolean', defaultValue: false},
16035364   Benjamin Renard   First commit
28
	      {name: 'sampling', type: 'int', defaultValue: '600'},
3604e40f   Benjamin Renard   "File Name" repla...
29
	      {name: 'fileprefix', type: 'string'},
16035364   Benjamin Renard   First commit
30
31
32
33
34
35
	      {name: 'fileformat', type: 'string'},
	      {name: 'fileformatTT', type: 'string'},
	      {name: 'compression', type: 'string'},
	      {name: 'compressionTT', type: 'string'}
	],
	
3604e40f   Benjamin Renard   "File Name" repla...
36
	propertiesToCopy : 'id,name,downloadSrc,refparamSampling,sampling,list,timeformat,timeformatTT,structure,fileprefix,fileformat,fileformatTT,compression,compressionTT',
16035364   Benjamin Renard   First commit
37
38
39
40
41
42
43
44
45
46

	getJsonValues : function(){

        var myValues  = new Object();       
        myValues.nodeType =  'download';//amdaModel.DownloadNode.nodeType;
        myValues.type = this.get('type');
        myValues.downloadSrc = this.get('downloadSrc');
//Data download	 
	if (myValues.downloadSrc === '0') {	 // Data download 
	  myValues.structure = this.get('structure');
9cb1f3cd   Benjamin Renard   Update download i...
47
	  myValues.refparamSampling = this.get('refparamSampling');
16035364   Benjamin Renard   First commit
48
	  myValues.sampling = this.get('sampling');
3604e40f   Benjamin Renard   "File Name" repla...
49
	  myValues.fileprefix = this.get('fileprefix');
16035364   Benjamin Renard   First commit
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
	   
	  myValues.timesrc =  this.get('timesrc');
	  // if there's at least one timeTable in case of Download data
      if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){
         // get complete timeTables collection
         var timeTables = this.get('timeTables');
         // init an empty array for timeTables
         myValues.timeTables=[];
         // for each interval record
         Ext.Array.each(timeTables, function(item, index, all){
            // get Json simplified value
            if (!item.$className) {
        		myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id};
        	}
            // get Json simplified value 
            else {
                myValues.timeTables[index] = item.getJsonValues();
        	}     
	     });            
	  } else {
	      myValues.startDate = this.get('startDate');
              myValues.stopDate = this.get('stopDate');
	      myValues.durationDay = this.get('durationDay');
	      myValues.durationHour = this.get('durationHour');
	      myValues.durationMin = this.get('durationMin');
	      myValues.durationSec = this.get('durationSec');
	  } 
          
      // if there's at least one parameter
      if (this.get('list') && this.get('list').length) {
        var list = this.get('list');
        myValues.list=[];
         	
  		Ext.each(list, function(item, index){                 
            myValues.list[index]=item.get('name');
        });
16035364   Benjamin Renard   First commit
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
      }  
      myValues.fileformat = this.get('fileformat');
      myValues.timeformat = this.get('timeformat');
      myValues.compression = this.get('compression');
	}
	else if (myValues.downloadSrc === '1'){ // TT download
		// if there's at least one timeTable
        if (this.get('timeTables') && this.get('timeTables').length) {
        	var list = this.get('timeTables');
        	myValues.list=[];
       	
        	Ext.each(list, function(item, index){                 
                myValues.list[index]=item.get('id');
            });  
        }
        myValues.fileformat = this.get('fileformatTT');
        myValues.timeformat = this.get('timeformatTT');
        myValues.compression = this.get('compressionTT');
	}
	else { // fits images download
	   myValues.list=[];
	   if (this.get('list') && this.get('list').length)
       	 Ext.each(this.get('list'), function(item, index){  
       		 var image = new Object();
       		 image.name = item['name'];
       		 image.url  = item['url'];
       		 myValues.list[index] = image;
            });
		myValues.compression = this.get('compression');
	}

        myValues.leaf = true;
     //   myValues.nodeType = amdaModel.PlotNode.nodeType;
        return myValues;
	}
      
9cb1f3cd   Benjamin Renard   Update download i...
122
});