Blame view

js/app/models/LocalParamNode.js 8.6 KB
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
1
/**
16035364   Benjamin Renard   First commit
2
3
4
5
6
 * Project  : AMDA-NG4
 * Name     : LocalParamNode.js
 * @class   amdaModel.LocalParamNode
 * @extends amdaModel.InteractiveNode
 * @brief   Basic Model of Node corresponding to a amda  parameter
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
7
8
 * @author
 * @version $Id: LocalParamNode.js 2800 2015-02-27 16:23:06Z elena $
16035364   Benjamin Renard   First commit
9
10
 */

a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
11
Ext.define('amdaModel.LocalParamNode',
16035364   Benjamin Renard   First commit
12
13
{
    extend: 'amdaModel.InteractiveNode',
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
14

16035364   Benjamin Renard   First commit
15
16
17
18
    statics:
    {
        nodeType: 'localParam'
    },
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
19
20

    fields:
16035364   Benjamin Renard   First commit
21
22
    [
            {name: 'alias', type:'string', persist: false},
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
23
            {name: 'isParameter', type: 'boolean', persist: false},
16035364   Benjamin Renard   First commit
24
25
            {name: 'notyet', type: 'boolean', defaultValue: false, persist: false},
            {name: 'needsArgs', type: 'boolean', persist: false},
16035364   Benjamin Renard   First commit
26
27
28
29
            {name: 'isSpectra', type: 'boolean', defaultValue: false, persist: false},
            {name: 'isStack', type: 'boolean', defaultValue: true, persist: false},
            {name: 'globalStart', type: 'string', persist: false},
            {name: 'globalStop', type: 'string', persist: false},
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
30
            {name: 'timeRestriction', type: 'boolean', persist: false},
16035364   Benjamin Renard   First commit
31
            {name: 'rank', type: 'integer', persist: false, defaultValue: null}
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
32
33
    ],

16035364   Benjamin Renard   First commit
34
    constructor : function(config)
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
35
    {
16035364   Benjamin Renard   First commit
36
37
38
39
40
        this.callParent(arguments);

        this.set('allowDrop', true);
        this.set('moduleId',myDesktopApp.dynamicModules.param.id);
        this.set('objectDataModel',amdaModel.Parameter.$className);
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
41

16035364   Benjamin Renard   First commit
42
         // if future missions or 'depending on mission'
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
43
44
         if (this.get('globalStart')) {
            var now = Ext.Date.format(new Date(), 'Y/m/d');
16035364   Benjamin Renard   First commit
45
46
47
48
            if ( this.get('globalStart') > now )
                    this.set('cls','predicted');
        }
         // time restriction on parameters
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
49
         if (this.get('timeRestriction')) {
16035364   Benjamin Renard   First commit
50
51
52
53
54
55
56
       //      this.set('cls','predicted');
                var id = this.get('id');
                var bracketPos =  id.indexOf("(");
                if (bracketPos > 0) {
                        id = Ext.String.insert(id, '_restr', bracketPos);
                }
                else {
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
57
                        id += '_restr';
16035364   Benjamin Renard   First commit
58
59
60
                }
             this.set('id', id);
         }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
61
62

        if (this.get('rank')) {
16035364   Benjamin Renard   First commit
63
64
65
            var rank = this.get('rank');
            if (rank == 1) this.set('iconCls', 'icon-mercury');
            if (rank == 2) this.set('iconCls', 'icon-venus');
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
66
            if (rank == 5) this.set('iconCls', 'icon-earth');
16035364   Benjamin Renard   First commit
67
68
            if (rank == 6) this.set('iconCls', 'icon-earth');
            if (rank == 7) this.set('iconCls', 'icon-mars');
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
69
            if (rank == 8) this.set('iconCls', 'icon-jupiter');
16035364   Benjamin Renard   First commit
70
            if (rank == 9) this.set('iconCls', 'icon-saturn');
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
71
            if (rank == 93) this.set('iconCls', 'icon-comet');
16035364   Benjamin Renard   First commit
72
73
74
75
            if (rank == 3) this.set('iconCls', 'icon-sw');
            if (rank == 4) this.set('iconCls', 'icon-sw');
            if (rank >= 99) this.set('iconCls', 'icon-solarsystem');
        }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
76
77
78
79
80
81

        if (this.get('isParameter'))
        {
            if (this.get('leaf')) this.set('iconCls', 'icon-scalar');
            else this.set('iconCls', 'icon-vector');

16035364   Benjamin Renard   First commit
82
83
84
            if (this.get('isStack') || this.get('isSpectra')) this.set('iconCls', 'icon-spectra');
        }
    },
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
85
86

    allMenuItems : function()
16035364   Benjamin Renard   First commit
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    {
        var menuItems =
        [{
            fnId : 'root-collapseAll',
            text : 'Close All',
            hidden : true
        }, {
            fnId : 'dire-collapseAll',
            text : 'Close All',
            hidden : true
        }, {
            fnId : 'para-plotParam',
            text : 'Plot Parameter',
            hidden : true
        }, {
            fnId : 'para-downParam',
            text : 'Download Parameter',
            hidden : true
        },{
            fnId : 'leaf-createAlias',
            text : 'Create/Edit Alias',
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
108
109
            hidden : true
        },{
16035364   Benjamin Renard   First commit
110
111
112
113
114
115
116
117
118
119
120
            fnId : 'leaf-createDerivedParam',
            text : 'Create Derived Parameter',
            hidden : true
        },{
            fnId : 'leaf-plotParam',
            text : 'Plot Parameter',
            hidden : true
        }, {
            fnId : 'leaf-downParam',
            text : 'Download Parameter',
            hidden : true
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
121
122
123
124
		}, {
            fnId : 'dire-epnTap',
            text : 'Display EPN-TAP services',
            hidden : false
16035364   Benjamin Renard   First commit
125
126
127
128
129
        }];

        return menuItems;
    },

a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
130
131

    onMenuItemClick : function(menu, item, evt)
16035364   Benjamin Renard   First commit
132
    {
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
133
        switch (item.fnId)
16035364   Benjamin Renard   First commit
134
135
136
137
138
139
        {
            case 'root-collapseAll':
            case 'dire-collapseAll':
                if(this && !this.isLeaf()) {
                    this.collapse(true);
                }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
140
                break;
16035364   Benjamin Renard   First commit
141
            case 'leaf-plotParam':
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
142
143
            case 'para-plotParam':
                    this.createPlot(this);
16035364   Benjamin Renard   First commit
144
145
                break;
            case 'leaf-downParam':
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
146
147
            case 'para-downParam':
                    this.createDownload(this);
16035364   Benjamin Renard   First commit
148
149
150
                break;
            case 'leaf-createDerivedParam':
                if (!this.get('notyet'))
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
151
152
153
                        this.createLeaf(this);
                else
                    myDesktopApp.warningMsg("Sorry! access to this parameter is restricted");
16035364   Benjamin Renard   First commit
154
                break;
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
155
            case 'leaf-createAlias':
16035364   Benjamin Renard   First commit
156
                if (!this.get('notyet'))
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
157
                        this.createAlias(this);
16035364   Benjamin Renard   First commit
158
159
                else
                   myDesktopApp.warningMsg("Sorry! access to this parameter is restricted");
16035364   Benjamin Renard   First commit
160
                break;
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
161
162
			case 'dire-epnTap':
				this.displayEpnTap();
16035364   Benjamin Renard   First commit
163
164
            default:
                break;
16035364   Benjamin Renard   First commit
165
166
        }
    },
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
167
168
169

	displayEpnTap: function() {
		var target = this.get('iconCls');
44c334be   Nathanael Jourdane   When lauched from...
170
171
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
			module.createWindow({'activeTab': 2, 'epntapTarget': target});
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
172
173
174
175
176
177
		});
	},

   createLeaf: function(node)
   {

16035364   Benjamin Renard   First commit
178
179
180
        // instanciate a Parameter object with the current data in his buidchain
        var param =  Ext.create(this.get('objectDataModel'));//, { buildchain: node.get('alias') ? "#"+node.get('alias') : node.get('id') });
        // instanciate a DerivedParamNode with this param object
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
181
182
        var newNode = Ext.create(amdaModel.DerivedParamNode.$className, {leaf : true, object : param});

16035364   Benjamin Renard   First commit
183
184
       // edit newNode into Parameter Module with node as contextNode
       newNode.editInModule();
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
185

63ac7745   Benjamin Renard   Support component...
186
187
188
189
190
       var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id, true, function(module) {
    	   var paramName;
           var components = null;
           if (node.get('alias')!= "" )
               paramName = "#"+node.get('alias');
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
191
           else
63ac7745   Benjamin Renard   Support component...
192
193
194
195
196
197
198
199
200
201
202
               paramName = node.get('id');
           var component_info = node.get('component_info');
           if (component_info && component_info.parentId) {
        	   //It's a component
        	   paramName = component_info.parentId;
        	   components = [];
        	   if (component_info.index1)
        		   components['index1'] = component_info.index1;
        	   if (component_info.index2)
        		   components['index2'] = component_info.index2;
           }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
203
204

           module.addParam(paramName,true,node.get('needsArgs'),components);
63ac7745   Benjamin Renard   Support component...
205
       });
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
206

16035364   Benjamin Renard   First commit
207
208
    },

a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
209
    createAlias: function(node)
16035364   Benjamin Renard   First commit
210
    {
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
211
        var win = myDesktopApp.desktop.getWindow('alias-win');
16035364   Benjamin Renard   First commit
212
213
214
215
216
217
218
219
220
221
222
223
224
        if (!node.get('needsArgs') && node.get('leaf'))
        {
            if(!win)
            {
                var win = myDesktopApp.desktop.createWindow(
                {
                    border: false,
                    id : 'alias-win',
                    title : 'Create Alias',
                    width : 400,
                    height : 200,
                    layout : 'border',
                    maximizable : false,
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
225
                    items :
16035364   Benjamin Renard   First commit
226
227
228
                    [{
                        xtype : 'alias',
                        region : 'center',
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
229
                        margins :
16035364   Benjamin Renard   First commit
230
231
232
233
234
                        {
                            top: 0,
                            right: 5,
                            bottom: 5,
                            left: 5
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
235
                        },
16035364   Benjamin Renard   First commit
236
237
238
                        paramNode : node,
                        id : 'aliasUI'
                    }]
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
239
                });
16035364   Benjamin Renard   First commit
240
            }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
241
            else
16035364   Benjamin Renard   First commit
242
243
244
            {
    //Set data into Alias Widget
                win.items.items[0].paramNode = node;
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
245
246
247
                win.items.items[0].setAlias(node);
            }
            win.show();
16035364   Benjamin Renard   First commit
248
        }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
249
        else
16035364   Benjamin Renard   First commit
250
251
        {
            var message = 'Sorry, parameter ' + node.get('id') + ' cannot have alias';
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
252
            Ext.Msg.alert('Impossible Create Alias', message);
16035364   Benjamin Renard   First commit
253
254
255
            if (win) win.close();
        }
    },
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
256

16035364   Benjamin Renard   First commit
257
258
259
260
    isParameter : function()
    {
        return this.get('isParameter');
    }
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
261

16035364   Benjamin Renard   First commit
262
});