Blame view

js/app/views/TimeSelectorUI.js 9.41 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
/**
 * 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
 * @version  $Id: TimeSelectorUI.js 2135 2014-02-25 13:37:18Z elena $
 * @todo Validations 
 */

Ext.define('amdaUI.TimeSelectorUI', 
{
    extend: 'Ext.form.FieldSet',
    requires : 
    [                
        'amdaUI.IntervalUI'
    ],
    
    setTTTab: function(arrayTT) 
    {
de9b2578   Benjamin Renard   Update TimeSelect...
23
        var arrayRec = new Array();
16035364   Benjamin Renard   First commit
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        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;        
de9b2578   Benjamin Renard   Update TimeSelect...
48
        this.timeSrc.setActiveTab(this.activeTab); 
16035364   Benjamin Renard   First commit
49
        
de9b2578   Benjamin Renard   Update TimeSelect...
50
        if (index === 0) this.TTGrid.getStore().loadData(arrayRec);
16035364   Benjamin Renard   First commit
51
52
53
54
55
56
57
    },
    
    addTT : function(newTTName,newTTid)
    {      
        // set the TimeTable radio checked
        var obj = new Object();  
        obj['timesrc_'+this.id] =  amdaModel.AmdaTimeObject.inputTimeSrc[0]; /*'TimeTable'*/
de9b2578   Benjamin Renard   Update TimeSelect...
58
        this.timeSrc.setActiveTab(obj['timesrc_'+this.id]); 
16035364   Benjamin Renard   First commit
59
        
16035364   Benjamin Renard   First commit
60
61
62
63
64
65
66
67
68
69
        // 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);   
        }        
    },
   
de9b2578   Benjamin Renard   Update TimeSelect...
70
71
72
73
74
    getActiveTimeSource: function()
    {
    	return this.timeSrc.getActiveTab().getItemId(); 
    },
    
16035364   Benjamin Renard   First commit
75
76
77
78
79
80
81
82
    initComponent: function() 
    {
        this.activeField = null;
        var store = Ext.create('Ext.data.Store', 
        {
            model: 'amdaModel.TTobject'	
        });

c94de8e9   Benjamin Renard   Fix Multi plot ti...
83
84
        var me = this;
        
16035364   Benjamin Renard   First commit
85
86
        this.TTGrid = Ext.create('Ext.grid.Panel', 
        {
16035364   Benjamin Renard   First commit
87
            itemId: 1, 	    
437c4dbc   Benjamin Renard   First implementat...
88
            store : store,
16035364   Benjamin Renard   First commit
89
90
91
            columns: 
            [ 
                Ext.create('Ext.grid.RowNumberer', { width: 20 } ),
de9b2578   Benjamin Renard   Update TimeSelect...
92
                { header: "Time Table or Catalog Name", dataIndex: 'name', flex:1, sortable : false, menuDisabled: true },
16035364   Benjamin Renard   First commit
93
94
95
96
97
98
99
100
101
                { 
                  menuDisabled: true,  width: 30, renderer: function()
                    {
                        return'<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
                    }
                }
            ],
            listeners : {
                    render : function(o,op) {
c94de8e9   Benjamin Renard   Fix Multi plot ti...
102
103
                    
                    var el = this.getEl();
16035364   Benjamin Renard   First commit
104
105
106
107
                    var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                        ddGroup: 'explorerTree',
                        notifyOver  : function(ddSource, e, data)
                        {
de9b2578   Benjamin Renard   Update TimeSelect...
108
109
110
111
                                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')))
16035364   Benjamin Renard   First commit
112
113
114
115
116
117
118
119
120
121
122
                                {
                                    this.valid = true;
                                    return this.dropAllowed;
                                }
                                this.valid = false;
                                return this.dropNotAllowed;
                        },
                        notifyDrop  : function(ddSource, e, data) 
                        {
                                if (!this.valid) return false;
                                
16035364   Benjamin Renard   First commit
123
124
125
126
127
128
                                	var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
                                	if (!explorerModule)
                                		return false;
                                    var targetModuleId = explorerModule.getPinedModule(); 
                                    var targetModule = myDesktopApp.getLoadedModule(targetModuleId);
                                    if (targetModule)
c94de8e9   Benjamin Renard   Fix Multi plot ti...
129
                                    	targetModule.getUiContent().addTT(data.records[0].get('text'),data.records[0].get('id'), me.getId());
16035364   Benjamin Renard   First commit
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
193
194
                            return true;
                            }
                        });
                        }
                    }
        });		

        this.TTGrid.on('cellclick', function(view, cell, cellIndex, record, row, recordIndex, e)
        {
        	if (cellIndex == 2)
        	    this.TTGrid.getStore().remove(record);
        }, this);

        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('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;
                            
                          var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id);
                          
                          if (module && module.multiSelector) 
                          {
                              var targetWin  = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.interactive_plot.id);
                              targetWin.items.items[0].setTimeFromData({ start : data.records[0].get('globalStart'),
                                                                         stop  : data.records[0].get('globalStop')});      
                          }
                          else 
                          {
                        	  var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
                        	  if (!explorerModule)
                        		  return false;
                              var targetModuleId = explorerModule.getPinedModule();                                
                              var targetModule = myDesktopApp.getLoadedModule(targetModuleId);                              
                              targetModule.getUiContent().setTimeFromData({ start : data.records[0].get('globalStart'),
                                                                            stop  : data.records[0].get('globalStop')});     
                              me.updateDuration();
                          }
                        return true;
                        }
                    });
                  }
                }
                
        });
16035364   Benjamin Renard   First commit
195
        
437c4dbc   Benjamin Renard   First implementat...
196
        this.timeSrc = new Ext.tab.Panel(
16035364   Benjamin Renard   First commit
197
            {
437c4dbc   Benjamin Renard   First implementat...
198
199
200
201
            	layout: 'fit',
            	plain: true,
            	bodyStyle: 'background: none',
                items:
16035364   Benjamin Renard   First commit
202
                [
437c4dbc   Benjamin Renard   First implementat...
203
204
205
206
                  {
                	  title: 'Interval',
                	  layout: 'fit',
                	  bodyStyle: 'background: none',
de9b2578   Benjamin Renard   Update TimeSelect...
207
                	  itemId: amdaModel.AmdaTimeObject.inputTimeSrc[1],//'Interval'
437c4dbc   Benjamin Renard   First implementat...
208
209
210
211
212
                	  items: [
                	          this.intervalSel
                	  ]
                  },
                  {
de9b2578   Benjamin Renard   Update TimeSelect...
213
                	  title: 'Time Table or Catalog',
437c4dbc   Benjamin Renard   First implementat...
214
                	  layout: 'fit',
de9b2578   Benjamin Renard   Update TimeSelect...
215
                	  itemId: amdaModel.AmdaTimeObject.inputTimeSrc[0],//'TimeTable'
437c4dbc   Benjamin Renard   First implementat...
216
217
218
                	  items: [
                	          this.TTGrid
                	  ]
437c4dbc   Benjamin Renard   First implementat...
219
                  }
de9b2578   Benjamin Renard   Update TimeSelect...
220
                ]     
16035364   Benjamin Renard   First commit
221
222
223
224
        });
        
        var config = 
        {
27b2a53e   Benjamin Renard   Link tab plot to ...
225
                title: (!this.title) ? 'Time Selection' : this.title,
437c4dbc   Benjamin Renard   First implementat...
226
                layout: 'fit',
16035364   Benjamin Renard   First commit
227
228
                items: 
                [
de9b2578   Benjamin Renard   Update TimeSelect...
229
                    this.timeSrc
16035364   Benjamin Renard   First commit
230
231
232
                ]
        };
	 
27b2a53e   Benjamin Renard   Link tab plot to ...
233
        Ext.apply(this, config);
16035364   Benjamin Renard   First commit
234
235
236
        this.callParent(arguments);
    }
});