Blame view

js/app/views/TimeTableUI.js 39.9 KB
16035364   Benjamin Renard   First commit
1
2
3
4
/**
 * Project   : AMDA-NG
 * Name      : TimeTableUI.js
 * @class 	 amdaUI.TimeTableUI
70aabdee   elena   catalog draft
5
 * @extends    Ext.container.Container
16035364   Benjamin Renard   First commit
6
7
8
 * @brief	 Time Table Module UI definition (View)
 * @author 	 Myriam
 * @version  $Id: TimeTableUI.js 2075 2014-02-11 11:30:14Z elena $
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaUI.TimeTableUI', {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
12
13
14
15
16
17
18
    extend: 'Ext.container.Container',
    alias: 'widget.panelTimeTable',

    requires: [
        'Ext.ux.grid.FiltersFeature',
        'Ext.ux.grid.filter.DateFilter',
        'Ext.ux.grid.filter.NumericFilter',
3d9f783f   Erdogan Furkan   Some more modific...
19
        'amdaUI.CustomFilters',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
20
21
        'amdaUI.OperationsTT',
        'amdaUI.StatisticalPlug',
533ea933   Benjamin Renard   Show description ...
22
        'amdaUI.DescriptionField',
a5da368d   Erdogan Furkan   #9505 - Done
23
24
        'Ext.grid.plugin.BufferedRenderer',
        'amdaDesktop.AmdaStateProvider'
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
25
26
27
28
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
    ],

    statics: {
        COL_TO_HIDE: 'colToHide'
    },

    status: null,

    constructor: function (config) {
        this.init(config);
        this.callParent(arguments);
        // load object into view
        this.loadObject();
    },

    /**
     * set the current editing object
     * this method will be used on timetable edition when this win is already opened
     */
    setObject: function (object)
    {
        // set object
        this.object = object;

        // load object into view
        this.loadObject();

        // show the default duration column
        this.TTGrid.headerCt.getGridColumns();

        Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function (item, index, all) {
            // if item is the default duration column
a5da368d   Erdogan Furkan   #9505 - Done
57
            if (item.id == amdaUI.TimeTableUI.COL_TO_HIDE + Ext.state.Manager.getProvider().get('tt_duration').toString()) {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
58
59
60
61
                // show this column
                item.show();
            }
        });
16035364   Benjamin Renard   First commit
62
63
        // fire the refresh event (to statistical plugin)
        this.fireEvent("refresh");
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
64
65
66
67
68
69
70
71
        // global event
        myDesktopApp.EventManager.fireEvent("refresh");
    },

    /**
     * load object timetable into this view
     */
    loadObject: function () {
1d7c3a74   Hacene SI HADJ MOHAND   correcting #7320
72
        this.object.set('created', this.convertUTCDateToLocalDate(this.object.get('created')));
16035364   Benjamin Renard   First commit
73
74
        // load object into form
        this.formPanel.getForm().loadRecord(this.object);
0fea5567   Benjamin Renard   First step for re...
75

16035364   Benjamin Renard   First commit
76
        this.status = null;
0fea5567   Benjamin Renard   First step for re...
77

16035364   Benjamin Renard   First commit
78
79
        //
        var me = this;
0fea5567   Benjamin Renard   First step for re...
80

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
81
82
83
84
85
86
87
88
89
        var onAfterInit = function (result, e) {
            if (!result || !result.success)
            {
                if (result.message)
                    myDesktopApp.errorMsg(result.message);
                else
                    myDesktopApp.errorMsg('Unknown error during cache initialisation');
                return;
            }
0fea5567   Benjamin Renard   First step for re...
90

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
91
            me.TTGrid.getSelectionModel().deselectAll();
0fea5567   Benjamin Renard   First step for re...
92

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
93
94
95
            // clear filters
            me.TTGrid.getStore().clearFilter(true);
            me.TTGrid.filters.clearFilters();
0fea5567   Benjamin Renard   First step for re...
96

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
97
98
99
            //clear sort
            me.TTGrid.getStore().sorters.clear();
            //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
0fea5567   Benjamin Renard   First step for re...
100

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
101
102
            //set cache token to the Time Table object
            me.object.set('cacheToken', result.token);
0fea5567   Benjamin Renard   First step for re...
103

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
104
            me.TTGrid.getStore().load();
0fea5567   Benjamin Renard   First step for re...
105

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
106
            me.status = result.status;
0fea5567   Benjamin Renard   First step for re...
107

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
108
109
            //Statistical plugin
            me.fireEvent("refresh");
16035364   Benjamin Renard   First commit
110
        };
0fea5567   Benjamin Renard   First step for re...
111

16035364   Benjamin Renard   First commit
112
113
        if (this.object.get('fromPlugin'))
        {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
            if (this.object.get('objFormat') && this.object.get('objFormat') != '')
            {
                //From uploaded file
                AmdaAction.initObjectCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), false, onAfterInit);
            } else
            {
                //From tmp object (ie Search result)
                AmdaAction.initObjectCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), false, onAfterInit);
            }
        } else if (this.object.get('relatedCatalogId') != '')
        {
            var pathern = this.object.get('relatedCatalogId').split('_')[0];
            catType = '';
            if (pathern == 'cat')
                catType = ' catalog';
            if (pathern == 'sharedcatalog')
                catType = 'sharedcatalog';
            AmdaAction.initObjectCacheFromCatalog(this.object.get('relatedCatalogId'), catType, onAfterInit);
        } else
0fea5567   Benjamin Renard   First step for re...
133
        {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
134
135
136
137
138
139
140
141
142
143
            var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id).linkedNode.data.nodeType;
            if (this.object.get('id') == '')
            {
                //Init empty cache
                AmdaAction.initObjectCache(false, 0, onAfterInit);
            } else
            {
                //From existing TT file
                AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, onAfterInit);
            }
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
144
        }
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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
195
196
197
198
199
    },

    /**
     * update this.object from form
     */
    updateObject: function ()
    {
        this.updateCount();

        // get the basic form
        var basicForm = this.formPanel.getForm();
        var updateStatus = true;

        var fieldsWithoutName = basicForm.getFields().items;
        Ext.Array.each(fieldsWithoutName, function (item, index, allItems) {
            if (item !== this.fieldName) {
                if (!item.isValid()) {
                    // set update isn't allowed
                    updateStatus = false;
                }
            }
        }, this);
        // if the update is allowed
        if (updateStatus) {
            /// real object update
            // update TimeTable object with the content of form
            basicForm.updateRecord(this.object);
        }
        // return the update status
        return updateStatus;
    },

    updateCount: function ()
    {
        this.object.set('nbIntervals', this.TTGrid.getStore().getTotalCount());
        this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
    },

    /*
     * save method called by Save button
     */
    saveProcess: function (toRename, onAfterSave, notDisplayMsg)
    {
        var timeTableModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);

        // if the name has been modified this is a creation
        if (timeTableModule.contextNode && (timeTableModule.contextNode.data.id == 'sharedtimeTable-treeRootNode'))
        {
            timeTableModule.linkedNode = null;
            timeTableModule.createLinkedNode();
            timeTableModule.createObject(this.object.getJsonValues());
            var ttobj = timeTableModule.linkedNode.get('object');
            // synchronisation of objects
            this.object = ttobj;
            timeTableModule.linkedNode.create();
827bddef   Benjamin Renard   Fix save of a fil...
200
        } else if (this.fclose() || this.status && (this.status.nbFiltered > 0)) /*TimeTable object has been modified*/
16035364   Benjamin Renard   First commit
201
        {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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
229
230
231
232
233
234
235
236
237
238
            if (this.object.isModified('name') || this.object.get('fromPlugin'))
            {
                // if object already has an id : it's a 'rename' of an existing TimeTable
                if (this.object.get('id'))
                {
                    // the context Node is the parent node of current edited one
                    var contextNode = timeTableModule.linkedNode.parentNode;
                    // link a new node to the TimeTableModule
                    timeTableModule.createLinkedNode();
                    // set the contextNode
                    timeTableModule.linkedNode.set('contextNode', contextNode);
                    // create a new object linked
                    timeTableModule.createObject(this.object.getJsonValues());

                    var ttobj = timeTableModule.linkedNode.get('object');
                    // synchronisation of objects
                    this.object = ttobj;

                    if (toRename)
                        timeTableModule.linkedNode.toRename = true;
                }
                timeTableModule.linkedNode.create({callback: function ($action) {
                        if (timeTableModule.linkedNode.get('object').get('fromPlugin'))
                            timeTableModule.linkedNode.get('object').set('fromPlugin', false);
                        timeTableModule.linkedNode.update({callback: function () {
                                if (onAfterSave)
                                    onAfterSave();
                            }, scope: this});
                    },
                    scope: this});
            } else {
                //update
                timeTableModule.linkedNode.update({callback: function () {
                        if (onAfterSave)
                            onAfterSave();
                    }, scope: this});
            }
16035364   Benjamin Renard   First commit
239
        }
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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
    },

    /**
     * overwrite metod called by Save button
     */
    overwriteProcess: function (btn)
    {
        if (btn == 'cancel')
            return;

        this.fieldName.clearInvalid();
        this.saveProcess(true);

    },

    addInterval: function (start, stop)
    {
        var row = this.TTGrid.getStore().getTotalCount();
        var me = this;
        this.TTGrid.getSelectionModel().deselectAll();
        AmdaAction.addCacheInterval({'start': start, 'stop': stop, 'index': row}, function (result, e) {
            this.status = result.status;
            if (!this.TTGrid.getStore().loading) {
                this.TTGrid.getStore().reload({
                    callback: function (records, options, success) {
                        me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function () {
                            me.TTGrid.getView().select(row);
                        }, me);
                    }
                });
            }
        }, this);
    },
    generateCAT: function (id)
    {
        if (this.fclose()) {
            Ext.Msg.confirm('Generate CAT', 'Current Time Table has been modified.\nDo you want to save it to include these changes in the generated Catalog ?',
                    function (btn, text) {
                        if (btn == 'yes') {
                            // mark this.closed as true before the call to close() as that will fire the beforeclose event again
                            if (this.object.get('id') == "") {
                                // case of creation of catalog
                                this.saveTT(this.createCAT(this.object.get('id')));
                            } else {
                                // case existing catalog
                                this.saveProcess(false, this.createCAT(this.object.get('id')));
                            }
                            return;
                        }
                    }, this);

        } else {
            this.createCAT(this.object.get('id'));
            return;
        }
    },
    createCAT: function (id)
    {
        Ext.Msg.prompt('Create catalog', 'Enter the number of columns:', function (btn, text) {
            if (btn == 'ok') {
                var catObj = Ext.create('amdaModel.Catalog');
                var catNode = Ext.create('amdaModel.CatalogNode', {leaf: true});
                catObj.set('relatedTimeTableId', id);
                creatDate = new Date(this.object.get('created'));
217e6c35   Hacene SI HADJ MOHAND   affichage oki
304
                date = Ext.Date.format(creatDate, 'Y-m-d\\TH:i:s.u');
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
                descr = 'Generated by CDPP/Amda Time Table Module \n' + 'From Time Table: ' + this.object.get('name') + ' which was generated on: ' + date + '\n';
                catObj.set('description', descr + this.object.get('description'));
                var nbParam = parseInt(text);
                if ((nbParam <= 0) || (nbParam > 100)) {
                    nbParam = 1;
                }
                catObj.set('nbParameters', nbParam);
                catNode.set('object', catObj);
                var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
                var catRootNode = explorerTree.getRootNode().findChild('id', 'catalog-treeRootNode', true);
                amdaModel.InteractiveNode.preloadNodes(catRootNode.getRootNode(),
                        function ()
                        {
                            // edit newNode into Parameter Module with node as contextNode
                            catNode.editInModule();
                        });
            }
        }, this);
    },
    saveTT: function (OnAfterSave)
    {
        if (this.updateObject()) {
            var basicForm = this.formPanel.getForm();
            // if there's at least one record in the store of TTGrid
            if (this.TTGrid.getStore().getTotalCount() > 0) {
                // update TimeTable object which the content of form
                basicForm.updateRecord(this.object);

                var me = this;
                this.checkIntervalsStatusForSave(function () {
                    //Name validation
                    var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
                    if (!ttModule)
                        return;
                    ttModule.linkedNode.isValidName(me.fieldName.getValue(), function (res) {
                        if (!res)
                        {
                            me.fieldName.validFlag = 'Error during object validation';
                            myDesktopApp.errorMsg(me.fieldName.validFlag);
                            me.fieldName.validate();
                            return;
                        }

                        if (!res.valid)
                        {
                            if (res.error)
                            {
                                if (res.error.search('subtree') != -1) {
                                    Ext.MessageBox.show({title: 'Warning',
                                        msg: res.error + '<br/>Do you want to overwrite it?',
                                        width: 300,
                                        buttons: Ext.MessageBox.OKCANCEL,
                                        fn: me.overwriteProcess,
                                        icon: Ext.MessageBox.WARNING,
                                        scope: me
                                    });
                                    me.fieldName.validFlag = true;
                                } else
                                    me.fieldName.validFlag = res.error;
                            } else
                            {
                                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);
                    });
                });
            } else {
                // warning:
                Ext.Msg.alert('No intervals', 'Your time table is invalid, <br>you must have at least one interval');
            }
        }
    },
1d7c3a74   Hacene SI HADJ MOHAND   correcting #7320
384
385

    // Convert UTC date to client local date 
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
386
    convertUTCDateToLocalDate: function (date) {
1d7c3a74   Hacene SI HADJ MOHAND   correcting #7320
387
388
        if (date == null) {
            return date;
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
389
390
        };
         
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
391
392
393
394
395
396
397
398
399
400
401
402
        var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);

        var offset = date.getTimezoneOffset() / 60;
        var hours = date.getHours();

        newDate.setHours(hours - offset);

        return newDate;
    },

    init: function (config)
    {
3d9f783f   Erdogan Furkan   Some more modific...
403
        amdaUI.CustomFilters.init();
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
404
        this.object = config.object;
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422

        this.fieldName = new Ext.form.field.Text({
            fieldLabel: 'Name*',
            allowBlank: false,
            stripCharsRe: /(^\s+|\s+$)/g,
            emptyText: 'Please no spaces!',
            name: 'name',
            anchor: '100%',
            validateOnChange: false,
            validateOnBlur: false,
            validFlag: false,
            validator: function () {
                return this.validFlag;
            }
        });

        this.formPanel = new Ext.form.Panel({
            bodyStyle: {background: '#dfe8f6'},
16035364   Benjamin Renard   First commit
423
424
            id: 'formTimeTable',
            flex: 4,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
425
426
427
428
            model: 'amdaModel.TimeTable',
            trackResetOnLoad: true, // reset to the last loaded record
            border: false,
            fieldDefaults: {labelWidth: 80},
16035364   Benjamin Renard   First commit
429
            items: [
0fea5567   Benjamin Renard   First step for re...
430
                this.fieldName,
16035364   Benjamin Renard   First commit
431
432
433
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
434
                    fieldLabel: 'Creation date',
16035364   Benjamin Renard   First commit
435
436
                    items: [
                        {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
437
                            xtype: 'datefield', width: 180,
0fea5567   Benjamin Renard   First step for re...
438
                            name: 'created', disabled: true,
16035364   Benjamin Renard   First commit
439
440
                            hideTrigger: true, format: 'Y/m/d H:i:s'
                        },
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
441
442
443
444
                        {xtype: 'component', width: 20},
                        {xtype: 'displayfield', value: 'Intervals:', width: 50},
                        {xtype: 'component', width: 8},
                        {xtype: 'textfield', name: 'nbIntervals', disabled: true, width: 70}
0fea5567   Benjamin Renard   First step for re...
445
                    ]
16035364   Benjamin Renard   First commit
446
447
                },
                {
533ea933   Benjamin Renard   Show description ...
448
                    xtype: 'descriptionfield',
3c6689fd   Erdogan Furkan   TextArea has clic...
449
                    height:180,
16035364   Benjamin Renard   First commit
450
                    name: 'description',
16035364   Benjamin Renard   First commit
451
452
453
454
455
456
457
458
459
460
461
                    anchor: '100% 50%'
                },
                {
                    xtype: 'textarea',
                    name: 'history',
                    fieldLabel: 'Operation log',
                    anchor: '100% 30%'
                }
            ]

        });
0fea5567   Benjamin Renard   First step for re...
462

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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
        var store = Ext.create('Ext.data.Store', {
            model: 'amdaModel.Interval',
            autoDestroy: false,
            pageSize: 200,
            buffered: true,
            autoLoad: true,
            purgePageCount: 0,
            remoteSort: true,
            listeners: {
                load: function (store, records) {

                    //  alert('nb of records in store:'+records.length );
                    myDesktopApp.EventManager.fireEvent('refresh');
                    this.TTGrid.getView().refresh();
                    this.TTGrid.getSelectionModel().refresh();
                    this.updateCount();
                    //Statistical plugin
                    this.fireEvent("refresh");
                },
                prefetch: function (store, records, successful, operation, eOpts) {
                    if (operation && (operation.action == 'read'))
                    {
                        if (operation.response && operation.response.result && operation.response.result.success)
                            this.status = operation.response.result.status;
                    }
                },
                remove: function (store) {
                    this.updateCount();
                    //Statistical plugin
                    this.fireEvent("refresh");
                },
                add: function (store) {
                    this.updateCount();
                    //Statistical plugin
                    this.fireEvent("refresh");
                },
                datachanged: function (store) {
                    this.updateCount();
                    //Statistical plugin
                    this.fireEvent("refresh");
                },
                scope: this
            }
        });

        var filters = {
            ftype: 'filters',
            encode: true, // json encode the filter query
            local: false, // defaults to false (remote filte
            filters: [
3d9f783f   Erdogan Furkan   Some more modific...
513
514
515
516
517
518
                {type: 'customnumericfilter', dataIndex: 'durationDay'},
                {type: 'customnumericfilter', dataIndex: 'durationHour'},
                {type: 'customnumericfilter', dataIndex: 'durationMin'},
                {type: 'customnumericfilter', dataIndex: 'durationSec'},
                {type: 'customdatefilter', dataIndex: 'start', dateFormat: 'c'},
                {type: 'customdatefilter', dataIndex: 'stop', dateFormat: 'c'}
16035364   Benjamin Renard   First commit
519
            ]
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
520
        };
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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
        var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
            onEditComplete: function (ed, value, startValue) {
                var me = this,
                        activeColumn = me.getActiveColumn(),
                        context = me.context,
                        record;

                if (activeColumn) {
                    record = context.record;

                    me.setActiveEditor(null);
                    me.setActiveColumn(null);
                    me.setActiveRecord(null);

                    context.value = value;
                    if (!me.validateEdit()) {
                        me.editing = false;
                        return;
                    }

                    // Only update the record if the new value is different than the
                    // startValue. When the view refreshes its el will gain focus
                    if (!record.isEqual(value, startValue)) {
                        var obj = {
                            'cacheId': record.get('cacheId'),
                            'isCatalog': false,
                            'data': {}
                        };
b4c976eb   Hacene SI HADJ MOHAND   pack unpack ne ma...
549
                        obj['data'][activeColumn.dataIndex] = Ext.Date.format(value, 'Y-m-d\\TH:i:s.u');
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
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

                        //context.grid.getSelectionModel().deselectAll();
                        //Interval is modified on the server side
                        me.editing = true;

                        AmdaAction.modifyCacheInterval(obj, function (result, e) {

                            var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
                            if (ttModule)
                                ttModule.getUiContent().status = result.status;
                            if (!context.store.loading) {
                                context.grid.getSelectionModel().deselectAll();
                                context.store.reload({
                                    callback: function (records, options, success) {
                                        context.view.bufferedRenderer.scrollTo(context.rowIdx, true, function () {
                                            me.fireEvent('edit', me, context);
                                            me.editing = false;
                                        }, me);
                                    }
                                });
                            } else {
                                me.editing = false;
                            }
                        }, this);
                    } else
                        me.editing = false;
                }
            }

        });

        this.TTGrid = Ext.create('Ext.grid.Panel', {
            store: store,
            features: [filters],
            columnLines: true,
a5da368d   Erdogan Furkan   #9505 - Done
585
            me:this,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
586
            selModel: {pruneRemoved: false},
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

            countDecimals: function (value) {
                if (Math.floor(value) === value)
                    return 0;
                return value.toString().split(".")[1].length || 0;
            },
            
            dateToString: function (value) {
                ndegits = this.countDecimals(value);
                if (ndegits <= 3) {
                    return  Ext.util.Format.number(value, '0.000');
                } else if (value < 0.1) {
                    return value.toExponential(3);
                } else {
                    return Ext.util.Format.number(value, '0.000000');
                }
            },
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
604
            columns: [
16035364   Benjamin Renard   First commit
605
                {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
606
607
608
609
610
611
612
613
614
615
                    xtype: 'rownumberer',
                    width: 50,
                    renderer: function (value, metaData, record, row, col, store, gridView) {
                        var msg = record.index + 1;
                        if (record.get('isNew') || record.get('isModified'))
                        {
                            msg += ' *';
                            metaData.style = 'font-weight: bold'
                        }
                        return msg;
16035364   Benjamin Renard   First commit
616
617
                    }
                },
0fea5567   Benjamin Renard   First step for re...
618
                {
abde111c   Benjamin Renard   Fix columns size ...
619
                    header: 'Start Time', dataIndex: 'start', width: 145,
217e6c35   Hacene SI HADJ MOHAND   affichage oki
620
                    editor: {xtype: 'datefield', allowBlank: false, hideTrigger: true, format: 'Y-m-d\\TH:i:s.u'},
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
621
                    renderer: function (value) {
16035364   Benjamin Renard   First commit
622
                        if (value != null) {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
623
                            if (Ext.isDate(value)) {
217e6c35   Hacene SI HADJ MOHAND   affichage oki
624
                                return Ext.Date.format(value, 'Y-m-d\\TH:i:s.u');
16035364   Benjamin Renard   First commit
625
                            } else {
217e6c35   Hacene SI HADJ MOHAND   affichage oki
626
                                return Ext.Date.format(new Date(value), 'Y-m-d\\TH:i:s.u');
16035364   Benjamin Renard   First commit
627
628
629
630
631
632
                            }
                        } else {
                            return value;
                        }
                    }
                },
0fea5567   Benjamin Renard   First step for re...
633
                {
abde111c   Benjamin Renard   Fix columns size ...
634
                    header: 'Stop Time', dataIndex: 'stop', width: 145,
217e6c35   Hacene SI HADJ MOHAND   affichage oki
635
                    editor: {xtype: 'datefield', allowBlank: false, hideTrigger: true, format: 'Y-m-d\\TH:i:s.u'},
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
636
                    renderer: function (value) {
16035364   Benjamin Renard   First commit
637
                        if (value != null) {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
638
                            if (Ext.isDate(value)) {
217e6c35   Hacene SI HADJ MOHAND   affichage oki
639
                                return Ext.Date.format(value, 'Y-m-d\\TH:i:s.u');
16035364   Benjamin Renard   First commit
640
                            } else {
217e6c35   Hacene SI HADJ MOHAND   affichage oki
641
                                return Ext.Date.format(new Date(value), 'Y-m-d\\TH:i:s.u');
16035364   Benjamin Renard   First commit
642
643
644
645
646
                            }
                        } else {
                            return value;
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
647
                },
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
648
                {
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
649
                    header: 'Duration (day)', width: 120, dataIndex: 'durationDay',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
650
                    id: amdaUI.TimeTableUI.COL_TO_HIDE + '1',
a5da368d   Erdogan Furkan   #9505 - Done
651
                    hidden: Ext.state.Manager.getProvider().get('tt_duration') != 1 ? true : false,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
652
                    renderer: function (value) {
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
653
                        return this.dateToString(value);
16035364   Benjamin Renard   First commit
654
655
                    },
                    listeners: {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
656
657
                        beforeshow: function () {
                            Ext.Array.each(this.ownerCt.getGridColumns(), function (item, index, all) {
16035364   Benjamin Renard   First commit
658
                                // if item is a column to hide automatically
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
659
                                if (Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE) {
16035364   Benjamin Renard   First commit
660
                                    // if item isn't the column which is being declared and is not hidden
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
661
                                    if (item.id != amdaUI.TimeTableUI.COL_TO_HIDE + '1' && !item.isHidden()) {
16035364   Benjamin Renard   First commit
662
663
664
665
666
667
668
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
669
                },
16035364   Benjamin Renard   First commit
670
                {
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
671
                    header: 'Duration (hour)', width: 120, dataIndex: 'durationHour',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
672
                    id: amdaUI.TimeTableUI.COL_TO_HIDE + '2',
a5da368d   Erdogan Furkan   #9505 - Done
673
                    hidden: Ext.state.Manager.getProvider().get('tt_duration') != 2 ? true : false,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
674
                    renderer: function (value) {
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
675
                        return this.dateToString(value);
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
676
                    },
16035364   Benjamin Renard   First commit
677
                    listeners: {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
678
679
                        beforeshow: function () {
                            Ext.Array.each(this.ownerCt.getGridColumns(), function (item, index, all) {
16035364   Benjamin Renard   First commit
680
                                // if item is a column to hide automatically
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
681
                                if (Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE) {
16035364   Benjamin Renard   First commit
682
                                    // if item isn't the column which is being declared and is not hidden
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
683
                                    if (item.id != amdaUI.TimeTableUI.COL_TO_HIDE + '2' && !item.isHidden()) {
16035364   Benjamin Renard   First commit
684
685
686
687
688
689
690
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
691
                },
16035364   Benjamin Renard   First commit
692
                {
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
693
                    header: 'Duration (min)', width: 120, dataIndex: 'durationMin',
a5da368d   Erdogan Furkan   #9505 - Done
694
                    hidden:Ext.state.Manager.getProvider().get('tt_duration') != 3 ? true : false,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
695
                    id: amdaUI.TimeTableUI.COL_TO_HIDE + '3',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
696
                    renderer: function (value) {
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
697
                        return this.dateToString(value);
16035364   Benjamin Renard   First commit
698
699
                    },
                    listeners: {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
700
701
                        beforeshow: function () {
                            Ext.Array.each(this.ownerCt.getGridColumns(), function (item, index, all) {
16035364   Benjamin Renard   First commit
702
                                // if item is a column to hide automatically
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
703
                                if (Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE) {
16035364   Benjamin Renard   First commit
704
                                    // if item isn't the column which is being declared and is not hidden
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
705
                                    if (item.id != amdaUI.TimeTableUI.COL_TO_HIDE + '3' && !item.isHidden()) {
16035364   Benjamin Renard   First commit
706
707
708
709
710
711
712
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
713
714
715
716
                },
                {
                    header: 'Duration (sec)', width: 120, dataIndex: 'durationSec',
                    id: amdaUI.TimeTableUI.COL_TO_HIDE + '4',
a5da368d   Erdogan Furkan   #9505 - Done
717
                    hidden:Ext.state.Manager.getProvider().get('tt_duration') != 4 ? true : false,
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
718
                    renderer: function (value) {
8ee13af1   Hacene SI HADJ MOHAND   solving 9344
719
                        return Ext.util.Format.number(value, '0.000');
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
                    },
                    listeners: {
                        beforeshow: function () {
                            Ext.Array.each(this.ownerCt.getGridColumns(), function (item, index, all) {
                                // if item is a column to hide automatically
                                if (Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE) {
                                    // if item isn't the column which is being declared and is not hidden
                                    if (item.id != amdaUI.TimeTableUI.COL_TO_HIDE + '4' && !item.isHidden()) {
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
16035364   Benjamin Renard   First commit
735
                }
0fea5567   Benjamin Renard   First step for re...
736
            ],
16035364   Benjamin Renard   First commit
737
738
            frame: true,
            dockedItems: [{
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
                    xtype: 'toolbar',
                    items: [{
                            iconCls: 'icon-add',
                            scope: this,
                            handler: function () {
                                cellEditing.cancelEdit();

                                var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
                                var row = 0;
                                if (selection)
                                    row = store.indexOf(selection) + 1;
                                this.TTGrid.getSelectionModel().deselectAll();

                                var me = this;
                                AmdaAction.addCacheInterval({'index': row}, function (result, e) {
                                    this.status = result.status;
                                    if (!this.TTGrid.getStore().loading) {
                                        this.TTGrid.getStore().reload({
                                            callback: function (records, options, success) {
                                                me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function () {
                                                    me.TTGrid.getView().select(row);
                                                    cellEditing.startEditByPosition({row: row, column: 1});
                                                }, me);
                                            }
                                        });
                                    }
                                }, this);
                            }
                        }, {
                            iconCls: 'icon-delete',
                            disabled: true,
                            itemId: 'delete',
                            scope: this,
                            handler: function () {
                                var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
                                if (selection) {
                                    var rowId = selection.get('cacheId');
                                    this.TTGrid.getSelectionModel().deselectAll();
                                    AmdaAction.removeTTCacheIntervalFromId(rowId, false, function (result, e) {
                                        this.status = result.status;
                                        if (!this.TTGrid.getStore().loading) {
                                            this.TTGrid.getStore().reload();
                                        }
                                    }, this);
                                }
                            }
                        },
                        '->',
                        {
                            text: 'Clear Filters',
                            scope: this,
                            handler: function () {
                                this.TTGrid.getStore().clearFilter(true);
                                this.TTGrid.filters.clearFilters();
                            }
16035364   Benjamin Renard   First commit
794
                        }
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
795
796
797
798
799
800
                    ]
                }],
            plugins: [cellEditing, {ptype: 'bufferedrenderer'}],
            listeners: {
                scope: this,
                edit: function (editor, e) {
16035364   Benjamin Renard   First commit
801
                    if (e.record.get('stop') != null && e.record.get('start') != null) {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
802
803
804
                        e.record.set('durationHour', (e.record.get('stop') - e.record.get('start')) / 3600000.0);
                        e.record.set('durationMin', (e.record.get('stop') - e.record.get('start')) / 60000.0);
                        e.record.set('durationSec', (e.record.get('stop') - e.record.get('start')) / 1000.0);
791d4b0a   Hacene SI HADJ MOHAND   ok cat nok tt
805
                        e.record.set('durationDay', (e.record.get('stop') - e.record.get('start')) / 3600000.0 / 24.0);
16035364   Benjamin Renard   First commit
806
807
808
                        //  send refresh event to statistical plugin
                        this.fireEvent("refresh");
                    }
a5da368d   Erdogan Furkan   #9505 - Done
809
810
811
812
813
814
815
816
                },
                columnschanged:function(ct,eOpts){ // Takes into count the duration changes
                    Ext.Array.each(ct.getGridColumns(), function (item, index, all) {
                        if (Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE && !item.isHidden()) {
                            var durationNumber = parseInt(Ext.util.Format.substr(item.id, amdaUI.TimeTableUI.COL_TO_HIDE.length, amdaUI.TimeTableUI.COL_TO_HIDE.length+1));
                            Ext.state.Manager.getProvider().set('tt_duration', durationNumber);
                        }
                    });
16035364   Benjamin Renard   First commit
817
                }
16035364   Benjamin Renard   First commit
818
            }
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
819
        });
16035364   Benjamin Renard   First commit
820

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
821
822
        this.TTGrid.getSelectionModel().on('selectionchange', function (selModel, selections) {
            this.TTGrid.down('#delete').setDisabled(selections.length === 0);
16035364   Benjamin Renard   First commit
823
        }, this);
0fea5567   Benjamin Renard   First step for re...
824

bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
825
826
827
828
        var myConf = {
            layout: 'border',
            defaults: {layout: 'fit', border: false},
            items: [
16035364   Benjamin Renard   First commit
829
830
831
832
                {
                    xtype: 'form',
                    region: 'center',
                    buttonAlign: 'left',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
833
                    bodyStyle: {background: '#dfe8f6'},
16035364   Benjamin Renard   First commit
834
                    padding: '5 5 5 5',
0fea5567   Benjamin Renard   First step for re...
835
836
                    layout: {type: 'hbox', pack: 'start', align: 'stretch'},
                    items: [
16035364   Benjamin Renard   First commit
837
838
839
840
841
842
843
844
845
846
847
848
                        {
                            xtype: 'container',
                            flex: 3.6,
                            layout: {type: 'vbox', pack: 'start', align: 'stretch'},
                            items: [
                                this.formPanel,
                                {
                                    xtype: 'operationsTT',
                                    parent: this,
                                    flex: 2.5,
                                    id: 'operation'
                                }
0fea5567   Benjamin Renard   First step for re...
849
850
851
                            ]
                        },
                        {
16035364   Benjamin Renard   First commit
852
853
854
                            xtype: 'container',
                            border: false,
                            padding: '0 0 5 15',
0fea5567   Benjamin Renard   First step for re...
855
                            flex: 4,
16035364   Benjamin Renard   First commit
856
                            layout: 'fit',
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
857
                            items: [this.TTGrid]
16035364   Benjamin Renard   First commit
858
859
                        }
                    ],
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
860
                    fbar: [
0fea5567   Benjamin Renard   First step for re...
861
                        {
16035364   Benjamin Renard   First commit
862
863
864
                            xtype: 'button',
                            text: 'Save',
                            width: 65,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
865
                            scope: this,
16035364   Benjamin Renard   First commit
866
                            handler: function () {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
867
868
869
                                this.saveTT();
                            }
                        }, {
16035364   Benjamin Renard   First commit
870
871
872
873
                            xtype: 'button',
                            text: 'Reset',
                            width: 65,
                            scope: this,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
874
875
876
877
878
                            handler: function () {
                                var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
                                ttModule.createLinkedNode();
                                ttModule.createObject();
                                this.setObject(ttModule.getLinkedNode().get('object'));
16035364   Benjamin Renard   First commit
879
                            }
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
880
                        }, {
e1fdab74   Hacene SI HADJ MOHAND   starting
881
882
883
884
                            xtype: 'button',
                            text: 'Generate Catalog',
                            width: 120,
                            scope: this,
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
885
                            handler: function () {
0de794df   Benjamin Renard   Fix typo
886
                                this.generateCAT(this.object.get('id'));
e1fdab74   Hacene SI HADJ MOHAND   starting
887
                            }
0fea5567   Benjamin Renard   First step for re...
888
                        }
16035364   Benjamin Renard   First commit
889
                    ]
0fea5567   Benjamin Renard   First step for re...
890
                },
16035364   Benjamin Renard   First commit
891
                {
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
892
893
894
895
896
897
898
899
900
901
902
903
                    xtype: 'panel', region: 'south',
                    title: 'Information',
                    collapsible: true,
                    collapseMode: 'header',
                    height: 100,
                    autoHide: false,
                    iconCls: 'icon-information',
                    bodyStyle: 'padding:5px',
                    loader: {
                        autoLoad: true,
                        url: helpDir + 'timetableHOWTO'
                    }
16035364   Benjamin Renard   First commit
904
905
                }
            ],
bad1e728   Hacene SI HADJ MOHAND   Ok for time zone
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
            plugins: [{ptype: 'statisticalPlugin'}]
        };

        Ext.apply(this, Ext.apply(arguments, myConf));
    },

    checkIntervalsStatusForSave: function (onStatusOk) {
        if (this.status == null)
            return;

        if (this.status.nbValid <= 0)
        {
            myDesktopApp.errorMsg('Your time table is invalid, <br>you must have at least one valid interval');
            return;
        }

        var msg = '';
        if (this.status.nbInvalid > 0)
            msg += 'There are some invalid intervals. Only valid intervals will be saved!<br/>';
        if (this.status.nbFiltered > 0)
            msg += 'There are some filtered intervals. Filtered intervals will not be saved!<br/>';
        if (msg != '')
        {
            msg += 'Do you want to continue?';
            Ext.Msg.show({
                title: 'Warning!',
                msg: msg,
                buttons: Ext.Msg.OKCANCEL,
                fn: function (btnId) {
                    if (btnId === 'cancel') {
                        // cancel the save action
                    } else {
                        onStatusOk();
                    }
                },
                scope: this,
                icon: Ext.Msg.WARNING
            });
            return;
        }

        onStatusOk();
    },

    /**
     * Check if changes were made before closing window
     * @return true if changes
     */
    fclose: function () {
        if (this.status == null)
            return false;

        var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
        return isDirty;
    }
0fea5567   Benjamin Renard   First step for re...
961
});