Blame view

js/app/views/DownloadUI.js 35.5 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
/**
 * Project   : AMDA-NG
 * Name      : DownloadUI.js
 * @class 	 amdaUI.DownloadUI
 * @extends  Ext.container.Container 
 * @brief    Download Module UI definition (View)
 * @author 	 Myriam
 * @version $Id: DownloadUI.js 2622 2014-11-07 14:50:09Z elena $  
 */
e8805e7f   Elena.Budnik   tooltip for timef...
10

16035364   Benjamin Renard   First commit
11
Ext.define('amdaUI.DownloadUI', {
0cefcae2   Benjamin Renard   il reste click droit
12
13
    extend: 'Ext.container.Container',
    alias: 'widget.panelDownload',
16035364   Benjamin Renard   First commit
14

0cefcae2   Benjamin Renard   il reste click droit
15
16
17
18
    requires: [
        'amdaUI.TimeSelectorUI',
        'amdaUI.ParamArgumentsPlug',
        'amdaUI.SendToSampButtonUI',
533ea933   Benjamin Renard   Show description ...
19
        'amdaUI.DescriptionField',
3ec6bc73   Erdogan Furkan   8950 - Positionne...
20
        'amdaModel.Download',
9abfbee9   Benjamin Renard   Add some frames
21
22
        'amdaModel.DownloadParam',
        'amdaModel.RequestParamObject'
0cefcae2   Benjamin Renard   il reste click droit
23
24
    ],

0cefcae2   Benjamin Renard   il reste click droit
25
26
27
28
29
30
31
32
33
34
35
36
    constructor: function (config) {
        this.init(config);
        this.callParent(arguments);
        // load object into view		 
        if (this.object)
            this.loadObject();
        //
        var paramArgsPlug = this.getPlugin('download-param-arguments-plugin');
        if (paramArgsPlug)
            paramArgsPlug.onApply = this.onApplyParameterArgs;
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
37
    saveRequest: function () {
f569bae5   Benjamin Renard   Save download
38
39
40
41
42
43
44
45
46
47
48
        var me = this;

        if (!this.updateObject()) {
            return;
        }

        var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
        if (!downloadModule) {
            return;
        }

f6539f85   Benjamin Renard   Download - Fix sa...
49
50
51
52
53
        if ((this.object.get('id') != '') && (downloadModule.linkedNode.get('text') == this.object.get('name'))) {
            this.saveProcess(false);
            return;
        }

f569bae5   Benjamin Renard   Save download
54
        downloadModule.linkedNode.isValidName(this.fieldName.getValue(), function (res) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
55
            if (!res) {
f569bae5   Benjamin Renard   Save download
56
57
58
59
60
61
                me.fieldName.validFlag = 'Error during object validation';
                myDesktopApp.errorMsg(me.fieldName.validFlag);
                me.fieldName.validate();
                return;
            }

3ec6bc73   Erdogan Furkan   8950 - Positionne...
62
63
            if (!res.valid) {
                if (res.error) {
f569bae5   Benjamin Renard   Save download
64
                    if (res.error.search('subtree') != -1) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
65
66
67
                        Ext.MessageBox.show({
                            title: 'Warning',
                            msg: res.error + '<br/>Do you want to overwrite it?',
f569bae5   Benjamin Renard   Save download
68
69
                            width: 300,
                            buttons: Ext.MessageBox.OKCANCEL,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
70
                            fn: function (btn) {
f6539f85   Benjamin Renard   Download - Fix sa...
71
72
73
74
                                if (btn == 'cancel') return;
                                this.fieldName.clearInvalid();
                                this.saveProcess(true);
                            },
f569bae5   Benjamin Renard   Save download
75
                            icon: Ext.MessageBox.WARNING,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
76
                            scope: me
f569bae5   Benjamin Renard   Save download
77
78
79
80
81
82
                        });
                        me.fieldName.validFlag = true;
                    }
                    else
                        me.fieldName.validFlag = res.error;
                }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
83
                else {
f569bae5   Benjamin Renard   Save download
84
85
86
87
88
89
90
91
92
93
94
95
96
                    me.fieldName.validFlag = 'Invalid object name';
                    myDesktopApp.errorMsg(me.fieldName.validFlag);
                }
                me.fieldName.validate();
                return;
            }

            me.fieldName.validFlag = true;
            me.fieldName.validate();
            me.saveProcess(false);
        });
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
97
    saveProcess: function (toRename) {
0e540b69   Benjamin Renard   Finalize save of ...
98
99
        var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
        if (this.object.isModified('name')) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
100
            if (this.object.get('id')) {
0e540b69   Benjamin Renard   Finalize save of ...
101
102
                var contextNode = downloadModule.linkedNode.parentNode;
                downloadModule.createLinkedNode();
3ec6bc73   Erdogan Furkan   8950 - Positionne...
103
                downloadModule.linkedNode.set('contextNode', contextNode);
0e540b69   Benjamin Renard   Finalize save of ...
104
105
106
107
                downloadModule.createObject(this.object.getJsonValues());
                var downloadObj = downloadModule.linkedNode.get('object');
                this.object = downloadObj;
                if (toRename) downloadModule.linkedNode.toRename = true;
f569bae5   Benjamin Renard   Save download
108
            }
0e540b69   Benjamin Renard   Finalize save of ...
109
110
111
            downloadModule.linkedNode.create();
        }
        else {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
112
            downloadModule.linkedNode.set('contextNode', downloadModule.contextNode);
0e540b69   Benjamin Renard   Finalize save of ...
113
            downloadModule.linkedNode.update();
f569bae5   Benjamin Renard   Save download
114
115
116
        }
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
117
    addTT: function (newTTName, newTTid) {
0cefcae2   Benjamin Renard   il reste click droit
118
119
120
121
122
123
124
125
126
127
128
        var tabPanel = this.formPanel.down();
        var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab());

        if (downloadSrc === 0) {
            this.timeSelector.addTT(newTTName, newTTid);
        } else {
            // 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 of TT download 
3ec6bc73   Erdogan Furkan   8950 - Positionne...
129
                var r = Ext.create('amdaModel.TTobject', { id: newTTid, name: newTTName });
0cefcae2   Benjamin Renard   il reste click droit
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
                this.TTGrid.store.insert(this.TTGrid.store.getCount(), r);
            }
        }
    },

    addTTs: function (TTarray) {
        // set TTTab	    
        this.timeSelector.setTTTab(TTarray);
    },

    // Add TT in download TT module
    addTTdownload: function (newTTName, newTTid) {
        var tabPanel = this.formPanel.down();
        tabPanel.setActiveTab(1);
        this.addTT(newTTName, newTTid);

    },

    /**
     * Set Start-Stop from parameter info (Local & MyData)
     */
    setTimeFromData: function (obj) {
        if (!obj.start || !obj.stop)
            return;
        var dateStart = new Date(obj.start.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));
        var dateStop = new Date(obj.stop.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));

3ec6bc73   Erdogan Furkan   8950 - Positionne...
157
        this.down('form').getForm().setValues({ startDate: dateStart, stopDate: dateStop });
0cefcae2   Benjamin Renard   il reste click droit
158
159
160
        this.timeSelector.intervalSel.updateDuration();
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
161
    addParameter: function (paramNode, updateTime) {
f569bae5   Benjamin Renard   Save download
162
163
164
165
        if (this.doNotifyDrop(paramNode)) {
            return this.doParamDrop(paramNode);
        }
        return false;
915d6711   Benjamin Renard   DownloadNode now ...
166
167
    },

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
168
    addParam: function (paramId, isLeaf, needArgs, components, predefined_args, info) {
0cefcae2   Benjamin Renard   il reste click droit
169
        // adding the parameter to the  paramGrid	
29dfb596   Benjamin Renard   Rework of ParamAr...
170
171
        var paramObj = amdaModel.RequestParamObject.getEmptyObj();
        paramObj.paramid = paramId;
0cefcae2   Benjamin Renard   il reste click droit
172
173
174
175
176
177
178
179
180
181
182
183
184

        if (components) {
            if (components['index1']) {
                paramObj['dim1-index'] = components['index1'];
                ++paramObj['type'];
            }

            if (components['index2']) {
                paramObj['dim2-index'] = components['index2'];
                ++paramObj['type'];
            }
        }

3ec6bc73   Erdogan Furkan   8950 - Positionne...
185
186
187
        if (predefined_args) {
            paramObj.template_args = predefined_args;
        }
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
188
189
190
191
        
        if(info){
            paramObj.qtip= info;
        }
2fa56f95   Benjamin Renard   Predefined templa...
192

0cefcae2   Benjamin Renard   il reste click droit
193
194
195
196
197
198
199
200
201
        var r = Ext.create('amdaModel.DownloadParam', paramObj);
        var pos = this.paramGrid.store.getCount();
        this.paramGrid.store.insert(pos, r);
        this.paramGrid.getView().refresh();

        if (needArgs)
            this.editParameterArgs(r);
    },

0cefcae2   Benjamin Renard   il reste click droit
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    // parameter name -> alias
    updateConstruct: function (oldval, newval) {
        var index = this.paramGrid.store.findExact('name', oldval);
        if (index != -1) {
            this.paramGrid.getStore().getAt(index).set('name', newval);
            this.paramGrid.getStore().getAt(index).set('text', newval);
        }
    },

    setObject: function (obj) {
        this.object = obj;
        this.loadObject();
    },

    /**
     * update this.object from form
     */
3ec6bc73   Erdogan Furkan   8950 - Positionne...
219
    updateObject: function () {
0cefcae2   Benjamin Renard   il reste click droit
220
221
222
223
224
225
226
227
        // get the basic form
        var tabPanel = this.formPanel.down();
        var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab());
        var basicForm = this.formPanel.getForm();
        var updateStatus = true;
        var values = basicForm.getValues();

        // data download
3ec6bc73   Erdogan Furkan   8950 - Positionne...
228
        if (downloadSrc === 0) {
0cefcae2   Benjamin Renard   il reste click droit
229
230
            var timeformat = values.timeformat;
            var timeSource = this.timeSelector.getActiveTimeSource();
0e540b69   Benjamin Renard   Finalize save of ...
231
            var filestructure = values.filestructure;
0cefcae2   Benjamin Renard   il reste click droit
232
            var sampling = values.sampling ? values.sampling : 600;
fb23b7fe   Benjamin Renard   Save 'used first ...
233
            var refparamSampling = values.refparamSampling == 'on';
0cefcae2   Benjamin Renard   il reste click droit
234
235
236
237
238
239
            var fileprefix = values.fileprefix ? values.fileprefix : '';
            var fileformat = values.fileformat;
            var compression = values.compression;

            var fieldsWithoutName = basicForm.getFields().items;
            Ext.Array.each(fieldsWithoutName, function (item, index, allItems) {
f569bae5   Benjamin Renard   Save download
240
                if ((item.name != 'name') && !item.isValid()) {
0cefcae2   Benjamin Renard   il reste click droit
241
                    if ((timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0]) &&
3ec6bc73   Erdogan Furkan   8950 - Positionne...
242
                        ((item.name == 'startDate') || (item.name == 'stopDate') || (item.name == 'duration'))) {
0cefcae2   Benjamin Renard   il reste click droit
243
244
245
246
247
248
249
250
251
252
                        updateStatus = true;
                    } else {
                        // set update isn't allowed
                        updateStatus = false;
                        return false;
                    }
                }
            }, this);

            if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0] // timeSource  'TimeTable'
3ec6bc73   Erdogan Furkan   8950 - Positionne...
253
                && this.timeSelector.TTGrid.getStore().count() == 0) {
0cefcae2   Benjamin Renard   il reste click droit
254
                myDesktopApp.warningMsg('You\'ve chosen Time Selection `by TimeTable` but no timeTable was added!'
3ec6bc73   Erdogan Furkan   8950 - Positionne...
255
                    + '<br>You must add one or choose Time Selection `by Interval`');
0cefcae2   Benjamin Renard   il reste click droit
256
257
258
                updateStatus = false;
            }

3ec6bc73   Erdogan Furkan   8950 - Positionne...
259
            if (updateStatus && (this.object.params().count() == 0)) {
0e540b69   Benjamin Renard   Finalize save of ...
260
261
262
263
                myDesktopApp.warningMsg('You must define at least one parameter to download');
                updateStatus = false;
            }

3ec6bc73   Erdogan Furkan   8950 - Positionne...
264
            if (updateStatus) {
0cefcae2   Benjamin Renard   il reste click droit
265
266
267
                /// real object update
                // update TimeTable object with the content of form
                basicForm.updateRecord(this.object);
0e540b69   Benjamin Renard   Finalize save of ...
268

0cefcae2   Benjamin Renard   il reste click droit
269
270
271
272
                this.object.set('timesrc', timeSource);
                // set valid intervals into TimeTable object
                if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0])
                    this.object.set('timeTables', this.timeSelector.TTGrid.getStore().data.items);
0e540b69   Benjamin Renard   Finalize save of ...
273
                this.object.set('filestructure', filestructure);
0cefcae2   Benjamin Renard   il reste click droit
274
275
276
277
278
279
280
281
282
                this.object.set('refparamSampling', refparamSampling);
                this.object.set('sampling', sampling);
                this.object.set('fileprefix', fileprefix);
                this.object.set('timeformat', timeformat);
                this.object.set('fileformat', fileformat);
                this.object.set('compression', compression);
            }
        }
        //TT download
3ec6bc73   Erdogan Furkan   8950 - Positionne...
283
284
        else {
            var timeformat = values.timeformatTT ? values.timeformatTT : amdaModel.DownloadConfig.defaultValues.timeformatTT;
0cefcae2   Benjamin Renard   il reste click droit
285
286
            var compression = values.compressionTT;
            var fileformat = values.fileformatTT;
0e540b69   Benjamin Renard   Finalize save of ...
287
288
289
290
291
            if (this.TTGrid.getStore().count() == 0) {
                myDesktopApp.warningMsg('You must define at least one TimeTable or Catalog to download');
                updateStatus = false;
            }
            else if (compression === 'none'
3ec6bc73   Erdogan Furkan   8950 - Positionne...
292
                && this.TTGrid.getStore().count() > 1) {
0cefcae2   Benjamin Renard   il reste click droit
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
                myDesktopApp.warningMsg('You are going to download several time tables -  select the Compression please');
                updateStatus = false;
            }
            this.object.set('timeTables', this.TTGrid.getStore().data.items);
            this.object.set('timeformatTT', timeformat);
            this.object.set('fileformatTT', fileformat);
            this.object.set('compressionTT', compression);
        }

        this.object.set('downloadSrc', downloadSrc);
        // return the update status
        return updateStatus;
    },

    /**
     * load this.object into form
     */
    loadObject: function () {
0cefcae2   Benjamin Renard   il reste click droit
311
312
313
314
        // load object into form	
        this.formPanel.getForm().loadRecord(this.object);
        // set object's TTs into the timeselector
        this.addTTs(this.object.get('timeTables'));
0e540b69   Benjamin Renard   Finalize save of ...
315
316
317
        // set parameters
        this.paramGrid.reconfigure(this.object.params());
        //this.paramGrid.getStore().loadData(this.object.params().data.items);
3ec6bc73   Erdogan Furkan   8950 - Positionne...
318
319
        // select "Parameters" tab
        var tabPanel = this.formPanel.down();
0e540b69   Benjamin Renard   Finalize save of ...
320
        tabPanel.setActiveTab(0);
0cefcae2   Benjamin Renard   il reste click droit
321
322
323
324
325
326
327
328
    },

    /**
     * download method called by 'Download' button to launch the download process
     */
    doDownload: function (sendToSamp, clientId) {
        var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
        if (downloadModule)
3ec6bc73   Erdogan Furkan   8950 - Positionne...
329
            downloadModule.linkedNode.execute({ 'sendToSamp': (sendToSamp == true), 'clientId': clientId });
0cefcae2   Benjamin Renard   il reste click droit
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
    },

    actionItem: function (grid, cell, cellIndex, record, row, recordIndex, e) {

        var isTimeTable = record instanceof amdaModel.TTobject;

        if (cellIndex == 3 || (cellIndex == 2 && isTimeTable))
            grid.getStore().remove(record);
        else if (cellIndex == 2) {
            this.paramGrid.getView().select(row);
            this.editParameterArgs(record);
        }
    },

    editParameterArgs: function (record) {
        var paramArgsPlug = this.getPlugin('download-param-arguments-plugin');
        if (paramArgsPlug)
            paramArgsPlug.show('download-param-arguments-plugin', record);
    },

    onApplyParameterArgs: function (parentUI, paramObject) {
        parentUI.paramGrid.getView().refresh();
    },

    onFileStructureChange: function (combo, newValue, oldValue) {
        if (!this.formPanel)
            return;

fb23b7fe   Benjamin Renard   Save 'used first ...
358
        var refParamCheck = this.formPanel.getForm().findField('refparamSampling');
0cefcae2   Benjamin Renard   il reste click droit
359
360
361
362
363
364
365
        var samplingField = this.formPanel.getForm().findField('sampling');

        if (samplingField && newValue !== oldValue) {
            refParamCheck.setDisabled(newValue == 2);
            samplingField.setDisabled((newValue == 2) || refParamCheck.getValue());
        }
    },
9827d468   Hacene SI HADJ MOHAND   us ok
366
    onTTFileFormatChange: function (combo, newValue, oldValue) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
367
        if (!this.formPanel)
9827d468   Hacene SI HADJ MOHAND   us ok
368
369
370
371
372
            return;

        var refTimeFormatField = this.formPanel.getForm().findField('timeformatTT');

        if (refTimeFormatField && newValue !== oldValue) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
373
374
375
376
377
378
            if (newValue === 'space') {
                refTimeFormatField.setValue('YYYY-MM-DDThh:mm:ss');
                refTimeFormatField.setDisabled(true);
            } else {
                refTimeFormatField.setDisabled(false);
            }
9827d468   Hacene SI HADJ MOHAND   us ok
379
380
        }
    },
0cefcae2   Benjamin Renard   il reste click droit
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

    onRefParamSamplingChange: function (check, newValue, oldValue) {
        if (!this.formPanel)
            return;

        var samplingField = this.formPanel.getForm().findField('sampling');
        var structureCombo = this.formPanel.getForm().findField('filestructure');

        if (samplingField && newValue !== oldValue)
            samplingField.setDisabled((structureCombo.getValue() == 2) || check.getValue());
    },

    onSendVOTableToSamp: function (clientId, sendOpt) {
        var me = sendOpt.scope;
        if (me.updateObject()) {
            me.doDownload(true, clientId);
        }
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
400
401
    doNotifyDrop: function (record) {
        if (record.get('nodeType') == 'localParam' && record.get('notyet')) {
f569bae5   Benjamin Renard   Save download
402
403
404
            return false;
        }
        if (((record.get('nodeType') == 'localParam') ||
3ec6bc73   Erdogan Furkan   8950 - Positionne...
405
406
407
            (record.get('nodeType') == 'remoteParam') ||
            (record.get('nodeType') == 'remoteSimuParam') ||
            (record.get('nodeType') == 'derivedParam') ||
b0f72ee0   Erdogan Furkan   #10557 For now
408
            (record.get('nodeType') == 'specialParam') ||
3ec6bc73   Erdogan Furkan   8950 - Positionne...
409
410
411
412
            (record.get('nodeType') == 'myDataParam') ||
            (record.get('nodeType') == 'alias')) &&
            (record.isLeaf() || record.get('isParameter')) &&
            !record.get('disable')) {
f569bae5   Benjamin Renard   Save download
413
414
415
416
417
418
            return true;
        }

        return false;
    },

3ec6bc73   Erdogan Furkan   8950 - Positionne...
419
    doParamDrop: function (record) {
f569bae5   Benjamin Renard   Save download
420
421
422
        var idToSent;
        var components = null;
        var predefinedArgs = record.get('predefinedArgs');
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
423
424
        var info = record.get('info');

3ec6bc73   Erdogan Furkan   8950 - Positionne...
425
426
        switch (record.get('nodeType')) {
            case 'localParam':
f569bae5   Benjamin Renard   Save download
427
428
429
430
431
432
            case 'remoteParam':
            case 'remoteSimuParam':
                idToSent = record.get('id');
                if (record.get('alias') != "")
                    idToSent = "#" + record.get('alias');
                var component_info = record.get('component_info');
3ec6bc73   Erdogan Furkan   8950 - Positionne...
433
434
                if (component_info && component_info.parentId) {
                    if (component_info.index1 || component_info.index2) {
f569bae5   Benjamin Renard   Save download
435
436
437
438
439
440
441
442
                        idToSent = component_info.parentId;
                        components = [];
                        if (component_info.index1)
                            components['index1'] = component_info.index1;
                        if (component_info.index2)
                            components['index2'] = component_info.index2;
                        predefinedArgs = record.parentNode.get('predefinedArgs');
                    }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
443
                    if (record.get('needsArgs')) {
f569bae5   Benjamin Renard   Save download
444
                        idToSent = component_info.parentId;
3ec6bc73   Erdogan Furkan   8950 - Positionne...
445
                        if (component_info.index1) {
f569bae5   Benjamin Renard   Save download
446
447
448
449
450
451
                            components = [];
                            components['index1'] = component_info.index1;
                        }
                    }
                }
                break;
3ec6bc73   Erdogan Furkan   8950 - Positionne...
452
            case 'alias':
f569bae5   Benjamin Renard   Save download
453
454
                idToSent = "#" + record.get('text');
                break;
3ec6bc73   Erdogan Furkan   8950 - Positionne...
455
456
            case 'derivedParam':
                if (record.modelName == 'amdaModel.DerivedParamComponentNode') {
f569bae5   Benjamin Renard   Save download
457
458
459
460
461
                    paramId = record.get('text');
                    var parentId = paramId.substr(0, paramId.length - 3);
                    idToSent = "ws_" + parentId;
                    var regExp = /\(([\d]+)\)/;
                    var component_index = regExp.exec(paramId);
3ec6bc73   Erdogan Furkan   8950 - Positionne...
462
                    if (component_index) {
f569bae5   Benjamin Renard   Save download
463
464
465
                        components = [];
                        components['index1'] = component_index[1];
                    }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
466
                }
f569bae5   Benjamin Renard   Save download
467
468
469
470
                else {
                    idToSent = "ws_" + record.get('text');
                }
                break;
3ec6bc73   Erdogan Furkan   8950 - Positionne...
471
472
            case 'myDataParam':
                if (record.modelName == 'amdaModel.MyDataParamComponentNode') {
f569bae5   Benjamin Renard   Save download
473
474
475
476
477
                    paramId = record.get('text');
                    var parentId = paramId.substr(0, paramId.length - 3);
                    idToSent = "wsd_" + parentId;
                    var regExp = /\(([\d]+)\)/;
                    var component_index = regExp.exec(paramId);
3ec6bc73   Erdogan Furkan   8950 - Positionne...
478
                    if (component_index) {
f569bae5   Benjamin Renard   Save download
479
480
481
482
483
484
485
486
                        components = [];
                        components['index1'] = component_index[1];
                    }
                }
                else {
                    idToSent = "wsd_" + record.get('text');
                }
                break;
b0f72ee0   Erdogan Furkan   #10557 For now
487
488
489
            case 'specialParam':
                idToSent=record.get('id');
                break;
3ec6bc73   Erdogan Furkan   8950 - Positionne...
490
            default:
f569bae5   Benjamin Renard   Save download
491
492
493
494
495
496
                return false;
        }

        var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
        if (downModule) {
            if (predefinedArgs) {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
497
                downModule.parseTemplatedParam(idToSent, function (param_info) {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
498
                    downModule.addParam(param_info.paramid, record.get('leaf'), record.get('needsArgs'), components, param_info.template_args, info);
f569bae5   Benjamin Renard   Save download
499
500
501
                });
            }
            else {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
502
                downModule.addParam(idToSent, record.get('leaf'), record.get('needsArgs'), components, null,info);
f569bae5   Benjamin Renard   Save download
503
504
505
506
                return true;
            }
        }
        return true;
915d6711   Benjamin Renard   DownloadNode now ...
507
508
    },

0cefcae2   Benjamin Renard   il reste click droit
509
510
511
512
513
    /**
     * Check if changes were made before closing window 
     * @return false
     */
    fclose: function () {
0e540b69   Benjamin Renard   Finalize save of ...
514
        return this.object.isDirty();
0cefcae2   Benjamin Renard   il reste click droit
515
516
517
518
519
    },

    init: function (config) {
        var me = this;

3ec6bc73   Erdogan Furkan   8950 - Positionne...
520
        this.timeSelector = new amdaUI.TimeSelectorUI({ id: 'downloadTimeSelector', flex: 1 });
0cefcae2   Benjamin Renard   il reste click droit
521

f569bae5   Benjamin Renard   Save download
522
523
524
525
        this.fieldName = new Ext.form.field.Text({
            labelAlign: 'left',
            labelWidth: 90,
            fieldLabel: 'Request Name',
3ec6bc73   Erdogan Furkan   8950 - Positionne...
526
527
            name: 'name',
            allowBlank: false,
f569bae5   Benjamin Renard   Save download
528
529
530
531
            stripCharsRe: /(^\s+|\s+$)/g,
            validateOnChange: false,
            validateOnBlur: false,
            validFlag: false,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
532
            validator: function () {
f569bae5   Benjamin Renard   Save download
533
534
535
536
537
                return this.validFlag;
            }
        });

        var downloadCont = this;
0cefcae2   Benjamin Renard   il reste click droit
538
539
        this.paramGrid = Ext.create('Ext.grid.Panel', {
            flex: 2,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
540
            store: Ext.create('Ext.data.Store', { model: 'amdaModel.DownloadParam' }),
0cefcae2   Benjamin Renard   il reste click droit
541
            columns: [
3ec6bc73   Erdogan Furkan   8950 - Positionne...
542
                { xtype: 'rownumberer', width: 20 },
0cefcae2   Benjamin Renard   il reste click droit
543
544
545
546
547
548
549
                {
                    header: "Parameter Name",
                    dataIndex: 'name',
                    flex: 1,
                    sortable: false,
                    menuDisabled: true,
                    renderer: function (val, meta, rec) {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
550
                        meta.tdAttr = 'data-qtip="' + rec.data.qtip + '"';
0cefcae2   Benjamin Renard   il reste click droit
551
552
553
554
555
                        return rec.getParamFullName();
                    }
                },
                {
                    menuDisabled: true, width: 30, renderer: function () {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
556
                        return '<div class="icon-parameters" style="width: 15px; height: 15px;"></div>';
0cefcae2   Benjamin Renard   il reste click droit
557
558
559
560
                    }
                },
                {
                    menuDisabled: true, width: 30, renderer: function () {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
561
                        return '<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
0cefcae2   Benjamin Renard   il reste click droit
562
563
564
565
566
                    }
                }
            ],
            //TODO - BRE - Wait the fix for drag&drop issue
            listeners:
3ec6bc73   Erdogan Furkan   8950 - Positionne...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
            {
                render: function (o, op) {
                    var me = this;
                    var el = me.body.dom;
                    me.dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                        ddGroup: 'explorerTree',
                        notifyEnter: function (ddSource, e, data) { },
                        notifyOver: function (ddSource, e, data) {
                            if (!downloadCont.doNotifyDrop(data.records[0])) {
                                this.valid = false;
                                return this.dropNotAllowed;
                            }
                            this.valid = true;
                            return this.dropAllowed;
                        },
                        notifyDrop: function (ddSource, e, data) {
                            if (!this.valid)
                                return false;
                            return downloadCont.doParamDrop(data.records[0]);
0cefcae2   Benjamin Renard   il reste click droit
586
                        }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
587
588
589
                    });
                }
            }
0cefcae2   Benjamin Renard   il reste click droit
590
591
592
593
594
595
        });

        this.paramGrid.on('cellclick', this.actionItem, this);

        this.TTGrid = Ext.create('Ext.grid.Panel', {
            flex: 2,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
596
            store: Ext.create('Ext.data.Store', { model: 'amdaModel.TTobject' }),
0cefcae2   Benjamin Renard   il reste click droit
597
            columns: [
3ec6bc73   Erdogan Furkan   8950 - Positionne...
598
599
                { xtype: 'rownumberer', width: 20 },
                { header: "TimeTable/Catalog Name", dataIndex: 'name', flex: 1, sortable: false, menuDisabled: true },
0cefcae2   Benjamin Renard   il reste click droit
600
601
602
603
604
605
606
                {
                    menuDisabled: true, width: 30, renderer: function () {
                        return '<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
                    }
                }
            ],
            listeners:
3ec6bc73   Erdogan Furkan   8950 - Positionne...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
            {
                render: function (o, op) {
                    var me = this;
                    var el = me.body.dom;
                    var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                        ddGroup: 'explorerTree',
                        notifyEnter: function (ddSource, e, data) {

                        },
                        notifyOver: function (ddSource, e, data) {
                            var nodeType = data.records[0].get('nodeType');
                            if ((nodeType == 'timeTable' || nodeType == 'sharedtimeTable') ||
                                (nodeType == 'catalog' || 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 downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
                            if (downModule)
                                downModule.getUiContent().addTTdownload(data.records[0].get('text'), data.records[0].get('id'));
                            return true;
0cefcae2   Benjamin Renard   il reste click droit
634
                        }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
635
636
637
                    });
                }
            }
0cefcae2   Benjamin Renard   il reste click droit
638
639
640
641
        });

        this.TTGrid.on('cellclick', this.actionItem, this);

915febd3   Vincent Cephirins   RM7926 - Evol - C...
642
        var storeTimeFormat = new Ext.data.ArrayStore({
0cefcae2   Benjamin Renard   il reste click droit
643
            fields: ['id', 'name', 'qtip'],
0e540b69   Benjamin Renard   Finalize save of ...
644
            data: amdaModel.DownloadConfig.timeformatData
0cefcae2   Benjamin Renard   il reste click droit
645
        });
29a2024c   Erdogan Furkan   10852
646
647
648
649
650
651
652
653
654
655

        var descriptionCase = {
            xtype:'panel',
            resizable:true,
            height: 120,
            margin:'5 0 5 0',
            bodyStyle: {background: '#dfe8f6',padding: '1', },
            border:false, 
            layout:'fit',
            items:[{
533ea933   Benjamin Renard   Show description ...
656
                xtype: 'descriptionfield',
3c6689fd   Erdogan Furkan   TextArea has clic...
657
                height:120,
29a2024c   Erdogan Furkan   10852
658
                name: 'description',
533ea933   Benjamin Renard   Show description ...
659
660
                emptyText:'Description',
                fieldLabel: ''
29a2024c   Erdogan Furkan   10852
661
662
663
            }]
        };

f6539f85   Benjamin Renard   Download - Fix sa...
664
        this.paramPanel = new Ext.container.Container({
0cefcae2   Benjamin Renard   il reste click droit
665
666
667
668
            title: 'Parameters',
            layout: {
                type: 'hbox',
                align: 'stretch',
3ec6bc73   Erdogan Furkan   8950 - Positionne...
669
                defaultMargins: { top: 10, left: 10, bottom: 5, right: 10 }
0cefcae2   Benjamin Renard   il reste click droit
670
671
672
673
674
675
676
677
678
679
            },
            items: [
                {
                    xtype: 'container',
                    flex: 2,
                    layout: {
                        type: 'vbox',
                        align: 'stretch'
                    },
                    items: [
f6539f85   Benjamin Renard   Download - Fix sa...
680
                        this.fieldName,
0cefcae2   Benjamin Renard   il reste click droit
681
682
683
684
                        {
                            xtype: 'splitter',
                            flex: 0.05
                        },
29a2024c   Erdogan Furkan   10852
685
686
                        this.paramGrid,
                        descriptionCase,
0cefcae2   Benjamin Renard   il reste click droit
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
                    ]
                },
                {
                    xtype: 'container',
                    flex: 2,
                    defaults: {
                        xtype: 'combo',
                        labelWidth: 90,
                        queryMode: 'local',
                        editable: false
                    },
                    layout: {
                        type: 'vbox',
                        align: 'stretch'
                    },
                    items: [
                        {
                            fieldLabel: 'Time Format',
                            name: 'timeformat',
                            valueField: 'id',
                            displayField: 'name',
                            queryMode: 'local',
915febd3   Vincent Cephirins   RM7926 - Evol - C...
709
                            store: storeTimeFormat,
0cefcae2   Benjamin Renard   il reste click droit
710
711
712
713
714
715
                            listConfig: {
                                tpl: [
                                    '<tpl for=".">',
                                    '<li class="x-boundlist-item" data-qtip="{qtip}">{name}</li>',
                                    '</tpl>'
                                ]
0e540b69   Benjamin Renard   Finalize save of ...
716
                            }
0cefcae2   Benjamin Renard   il reste click droit
717
718
719
720
                        },
                        {
                            fieldLabel: 'File Structure',
                            name: 'filestructure',
0e540b69   Benjamin Renard   Finalize save of ...
721
                            store: amdaModel.DownloadConfig.filestructureData,
0cefcae2   Benjamin Renard   il reste click droit
722
                            listeners: {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
723
                                change: { fn: this.onFileStructureChange },
0cefcae2   Benjamin Renard   il reste click droit
724
725
726
727
728
729
730
731
732
733
                                scope: this
                            }
                        },
                        {
                            xtype: 'checkbox', boxLabel: 'Header in a separate file',
                            boxLabelAlign: 'before',
                            name: 'separateInfoFile', checked: false

                        },
                        {
76447670   Benjamin Renard   Minor fixes
734
                            xtype: 'checkbox', boxLabel: 'Sampling: use first parameter as reference',
0cefcae2   Benjamin Renard   il reste click droit
735
                            boxLabelAlign: 'before',
fb23b7fe   Benjamin Renard   Save 'used first ...
736
                            name: 'refparamSampling', checked: false, disabled: true,
0cefcae2   Benjamin Renard   il reste click droit
737
                            listeners: {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
738
                                change: { fn: this.onRefParamSamplingChange },
0cefcae2   Benjamin Renard   il reste click droit
739
740
741
742
743
                                scope: this
                            }
                        },
                        {
                            xtype: 'numberfield', name: 'sampling',
76447670   Benjamin Renard   Minor fixes
744
                            fieldLabel: 'Sampling (s.)', value: 600,
0cefcae2   Benjamin Renard   il reste click droit
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
                            hideTrigger: true, editable: true,
                            disabled: true
                        },
                        {
                            xtype: 'checkbox', boxLabel: 'Scientific floating-point formatting',
                            boxLabelAlign: 'before',
                            name: 'scientificformat', checked: false
                        },
                        {
                            xtype: 'textfield', name: 'fileprefix',
                            fieldLabel: 'File Prefix',
                            disabled: false, editable: true
                        },
                        {
                            fieldLabel: 'File Format',
                            name: 'fileformat',
0e540b69   Benjamin Renard   Finalize save of ...
761
                            store: amdaModel.DownloadConfig.fileformatData
0cefcae2   Benjamin Renard   il reste click droit
762
763
764
765
                        },
                        {
                            fieldLabel: 'Compression',
                            name: 'compression',
0e540b69   Benjamin Renard   Finalize save of ...
766
                            store: amdaModel.DownloadConfig.filecompressData
0cefcae2   Benjamin Renard   il reste click droit
767
                        },
0cefcae2   Benjamin Renard   il reste click droit
768
769
770
                        this.timeSelector
                    ]
                }
3ec6bc73   Erdogan Furkan   8950 - Positionne...
771
772
            ]
        });
0cefcae2   Benjamin Renard   il reste click droit
773
774

        this.ttPanel =
3ec6bc73   Erdogan Furkan   8950 - Positionne...
775
776
777
778
779
780
781
782
783
784
        {
            xtype: 'container',
            title: 'Time Tables / Catalogs',
            layout: {
                type: 'hbox',
                align: 'stretch',
                defaultMargins: { top: 10, left: 10, bottom: 5, right: 10 }
            },
            items: [
                this.TTGrid,
0cefcae2   Benjamin Renard   il reste click droit
785
786
                {
                    xtype: 'container',
3ec6bc73   Erdogan Furkan   8950 - Positionne...
787
788
789
790
791
792
793
                    flex: 2,
                    defaults: {
                        xtype: 'combo',
                        labelWidth: 90,
                        queryMode: 'local',
                        editable: false
                    },
0cefcae2   Benjamin Renard   il reste click droit
794
                    layout: {
3ec6bc73   Erdogan Furkan   8950 - Positionne...
795
796
                        type: 'vbox',
                        align: 'stretch'
0cefcae2   Benjamin Renard   il reste click droit
797
                    },
3ec6bc73   Erdogan Furkan   8950 - Positionne...
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
                    items: [{
                        fieldLabel: 'Time Format',
                        name: 'timeformatTT',
                        valueField: 'id',
                        store: storeTimeFormat,
                        displayField: 'name',
                        queryMode: 'local',
                        listConfig: {
                            tpl: [
                                '<tpl for=".">',
                                '<li class="x-boundlist-item" data-qtip="{qtip}">{name}</li>',
                                '</tpl>'
                            ]
                        }
                    },
                    {
                        fieldLabel: 'File Format ',
                        name: 'fileformatTT',
                        store: amdaModel.DownloadConfig.fileformatTTData,
                        listeners: {
                            change: { fn: this.onTTFileFormatChange },
                            scope: this
                        }
                    },
                    {
                        fieldLabel: 'Compression ',
                        name: 'compressionTT',
                        store: amdaModel.DownloadConfig.filecompressTTData
                    },
                    {
                        xtype: 'panel',
                        html: ['<div>',
                            '<p><b>=> Format specifications:</b></p>',
                            '<ul>',
                            '<li><b>Plain text:</b> ASCII tabular file. A comment line starts with "#"</li>',
                            '<li><b>VOTable:</b> <a target="_blank" href="https://www.ivoa.net/documents/VOTable/20130315/PR-VOTable-1.3-20130315.html">Version 1.3</a></li>',
                            '<li><b>HPEvent:</b> <a target="_blank" href="https://spase-group.org/docs/conventions/HDMC-Event-List-Specification-v1.0.4.pdf">Version 1.0</a></li>',
                            '</ul>',
                            '</div>'].join("\n")
                    }
0cefcae2   Benjamin Renard   il reste click droit
838
                    ]
3ec6bc73   Erdogan Furkan   8950 - Positionne...
839
840
841
                }
            ]
        };
0cefcae2   Benjamin Renard   il reste click droit
842
843
844
845

        this.formPanel = new Ext.form.Panel({
            layout: 'fit',
            region: 'center',
3ec6bc73   Erdogan Furkan   8950 - Positionne...
846
            bodyStyle: { background: '#dfe8f6' },
0cefcae2   Benjamin Renard   il reste click droit
847
848
849
850
851
852
            buttonAlign: 'left',
            trackResetOnLoad: true, //reset to the last loaded record
            defaults: {
                border: false
            },
            items: [{
3ec6bc73   Erdogan Furkan   8950 - Positionne...
853
854
855
856
857
858
859
860
861
862
863
                xtype: 'tabpanel',
                activeTab: 0,
                bodyStyle: { background: '#dfe8f6' },
                items: [
                    this.paramPanel,
                    this.ttPanel
                ],
                listeners: {
                    tabchange: function (tabPanel, newCard, oldCard, eOpts) {
                        var saveBtn = this.down('#save-download');
                        saveBtn.setDisabled(newCard != this.paramPanel);
f6539f85   Benjamin Renard   Download - Fix sa...
864
                    },
3ec6bc73   Erdogan Furkan   8950 - Positionne...
865
866
867
868
                    scope: this
                }
            },
            ],
0cefcae2   Benjamin Renard   il reste click droit
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
            fbar: [
                {
                    text: 'Download',
                    scope: this,
                    handler: function (button) {
                        // if the return is true (object had been updated)
                        if (this.updateObject()) {
                            // launch the download process 			        
                            this.doDownload();
                        }
                    }
                },
                {
                    text: 'Reset',
                    scope: this,
                    handler: function () {
0e540b69   Benjamin Renard   Finalize save of ...
885
886
887
888
889
                        var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id);
                        downModule.createLinkedNode();
                        var obj = null;
                        downModule.createObject(obj);
                        this.setObject(downModule.linkedNode.get('object'));
0cefcae2   Benjamin Renard   il reste click droit
890
891
                    }
                },
f569bae5   Benjamin Renard   Save download
892
893
                {
                    text: 'Save',
f6539f85   Benjamin Renard   Download - Fix sa...
894
                    id: 'save-download',
f569bae5   Benjamin Renard   Save download
895
896
897
898
899
                    scope: this,
                    handler: function () {
                        this.saveRequest();
                    }
                },
0cefcae2   Benjamin Renard   il reste click droit
900
901
902
903
904
                '->',
                {
                    xtype: 'sendToSampButton',
                    type: 'votable',
                    onSendToSamp: this.onSendVOTableToSamp,
3ec6bc73   Erdogan Furkan   8950 - Positionne...
905
                    sendOpt: { scope: this }
0cefcae2   Benjamin Renard   il reste click droit
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
                }]
        });

        var myConf = {
            layout: 'border',
            items: [
                this.formPanel,
                {
                    xtype: 'panel',
                    region: 'south',
                    title: 'Information',
                    collapsible: true,
                    collapseMode: 'header',
                    height: 100,
                    autoHide: false,
                    bodyStyle: 'padding:5px',
                    iconCls: 'icon-information',
                    loader: {
                        autoLoad: true,
                        url: helpDir + 'downloadHOWTO'
                    }
                }
            ],
3ec6bc73   Erdogan Furkan   8950 - Positionne...
929
            plugins: [{ ptype: 'paramArgumentsPlugin', pluginId: 'download-param-arguments-plugin' }]
0cefcae2   Benjamin Renard   il reste click droit
930
931
932
933
        };

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