Blame view

js/app/models/PlotObjects/MultiplotRequestObject.js 5.15 KB
940afd8d   Benjamin Renard   Introduce multipl...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * Project      : AMDA-NG
 * Name         : MultiplotRequestObject.js
 * @class   amdaPlotObj.MutiplotRequestObject
 * @extends amdaModel.AmdaTimeObject
 * @brief   Multi-Plot Request Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: MultiplotRequestObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :28/02/2020: BRE  - file creation
 */
 
 		
Ext.define('amdaPlotObj.MultiplotRequestObject', {
    extend: 'amdaModel.AmdaTimeObject',
    idProperty: 'id',
6f513d3f   Benjamin Renard   WIP
19
20

    requires: [
c9db9962   Benjamin Renard   WIP
21
22
        'amdaModel.PlotNode',
        'amdaPlotObj.PlotRequestObject'
6f513d3f   Benjamin Renard   WIP
23
    ],
940afd8d   Benjamin Renard   Introduce multipl...
24
25
	
    hasMany: {
6f513d3f   Benjamin Renard   WIP
26
        model : 'amdaModel.PlotNode',
940afd8d   Benjamin Renard   Introduce multipl...
27
28
29
30
31
32
33
34
        name  : 'plots',
        associationKey:'plots'
    },
    
    constructor: function(){
    	var me = this;
    	me.callParent(arguments);
    },
495fc7a3   Benjamin Renard   Adapt plot UI in ...
35
36
37
38
39
40
41
42
43
44
45

    isDirty: function() {
        var dirty = false;
        this.plots().each(function(plotNode) {
            var plotObject = plotNode.get('object');
            if (plotObject && (plotObject.get('id') != '') && plotObject.dirty) {
                dirty = true;
            }
        });
        return dirty;
    },
940afd8d   Benjamin Renard   Introduce multipl...
46
47
    
    createNewPlot: function() {
c9db9962   Benjamin Renard   WIP
48
49
50
51
52
        var plotObject = Ext.create('amdaPlotObj.PlotRequestObject');
        return this.createNewPlotFromObject(plotObject);
    },

    duplicatePlot: function(plotNode) {
9705c573   Benjamin Renard   Duplicate plot
53
        var me = this;
9705c573   Benjamin Renard   Duplicate plot
54
55
56
        var newPlotNode = null;
        this.plots().each(function(node, index) {
            if (node == plotNode) {
9705c573   Benjamin Renard   Duplicate plot
57
58
59
                newPlotNode = Ext.create('amdaModel.PlotNode', {
                    leaf : true
                });
232cf098   Benjamin Renard   Another fix for p...
60
		var data = plotNode.get('object').getJsonValues();
63c16a6c   Benjamin Renard   Fix plot request ...
61
62
                newPlotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', data));
		plotNode.get('object').reject();
5c744625   Benjamin Renard   Synchronize reque...
63
64
                me.plots().remove(plotNode);
                me.plots().insert(index, [newPlotNode]);
9705c573   Benjamin Renard   Duplicate plot
65
            }
c9db9962   Benjamin Renard   WIP
66
        });
9705c573   Benjamin Renard   Duplicate plot
67
        return newPlotNode;
c9db9962   Benjamin Renard   WIP
68
69
    },

d794a307   Benjamin Renard   Fix bug when a pl...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    overwritePlot: function(plotNode, targetPlotNode) {
        var targetIndex = -1;
        this.plots().each(function(node, index) {
            if (node == targetPlotNode) {
                targetIndex = index;
            }
        });
        if (targetIndex < 0) {
            //Target not exists in multiplot node => add it
            this.plots().add(targetPlotNode);
            targetIndex = this.plots().count() - 1;
        }
        var data = plotNode.get('object').getJsonValues();
        data.id = targetPlotNode.get('id');
        targetPlotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', data));
        plotNode.get('object').reject();
        return targetPlotNode;
    },

c9db9962   Benjamin Renard   WIP
89
    createNewPlotFromObject: function(plotObject) {
6f513d3f   Benjamin Renard   WIP
90
        var plotNode = Ext.create('amdaModel.PlotNode', {
9705c573   Benjamin Renard   Duplicate plot
91
            leaf : true
6f513d3f   Benjamin Renard   WIP
92
        });
495fc7a3   Benjamin Renard   Adapt plot UI in ...
93
        plotNode.set('object',plotObject);
6f513d3f   Benjamin Renard   WIP
94
        this.plots().add(plotNode);
495fc7a3   Benjamin Renard   Adapt plot UI in ...
95
        return this.plots().getAt(this.plots().count()-1);
940afd8d   Benjamin Renard   Introduce multipl...
96
97
    },

57e15214   Benjamin Renard   Fix addParameter ...
98
99
100
101
    removePlotByInternalId: function(internalId) {
        var plotNode = this.plots().data.getByKey(internalId);
        if (plotNode)
            this.plots().remove(plotNode);
940afd8d   Benjamin Renard   Introduce multipl...
102
103
    },

4efeb459   Benjamin Renard   First version for...
104
105
106
107
    getJsonValues : function()
    {
        var requestValues  = new Object();

752ba9ab   Benjamin Renard   Fix nodeType for ...
108
        requestValues['nodeType'] = 'multiplot';
4efeb459   Benjamin Renard   First version for...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        requestValues['leaf'] = true;

        requestValues['timesrc'] =  this.get('timesrc');
        // if there's at least one timeTable name into 'timeTables' collection
        if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){
            // get complete timeTables collection
            var timeTables = this.get('timeTables');
            // init an empty array for timeTables
            requestValues['timeTables'] = [];
            // for each interval record
            Ext.Array.each(timeTables, function(item, index, all){
                if (!item.$className) {
                    requestValues['timeTables'][index] = {timeTableName : item.timeTableName, id : item.id};
                }
                // get Json simplified value
                else {
                    requestValues['timeTables'][index] = item.getJsonValues();
                }
            });
        } else {
79a60955   Hacene SI HADJ MOHAND   ms ok affichage ko
129
130
            requestValues['startDate'] =  Ext.Date.format(this.get('startDate'), 'Y-m-d\\TH:i:s.u');	
            requestValues['stopDate'] =  Ext.Date.format(this.get('stopDate'), 'Y-m-d\\TH:i:s.u');	
4efeb459   Benjamin Renard   First version for...
131
132
133
134
            requestValues['durationDay'] = this.get('durationDay');
            requestValues['durationHour'] = this.get('durationHour');
            requestValues['durationMin'] = this.get('durationMin');
            requestValues['durationSec'] = this.get('durationSec');
b852834a   Hacene SI HADJ MOHAND   progress
135
            requestValues['durationMs'] = this.get('durationMs');
4efeb459   Benjamin Renard   First version for...
136
137
138
139
140
141
142
143
144
145
        }

        requestValues['plots'] = [];
        this.plots().each(function(plotNode) {
            if (plotNode.get('object').get('multi-selected')) {
                requestValues['plots'].push(plotNode.get('object').getJsonValues());
            }
        });

        return requestValues;
940afd8d   Benjamin Renard   Introduce multipl...
146
147
    }
});