Project

General

Profile

Download (9.38 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / solar / asynchronous_download_public / Asynchronous_Download_userInterface_sitools2 / resourcePluginParamsPanel.js @ master

1
/*******************************************************************************
2
 * Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 * 
4
 * This file is part of SITools2.
5
 * 
6
 * SITools2 is free software: you can redistribute it and/or modify it under the
7
 * terms of the GNU General Public License as published by the Free Software
8
 * Foundation, either version 3 of the License, or (at your option) any later
9
 * version.
10
 * 
11
 * SITools2 is distributed in the hope that it will be useful, but WITHOUT ANY
12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
 * 
15
 * You should have received a copy of the GNU General Public License along with
16
 * SITools2. If not, see <http://www.gnu.org/licenses/>.
17
 ******************************************************************************/
18
/*global Ext, sitools, i18n, SitoolsDesk */
19

    
20
Ext.namespace('sitools.user.component.dataviews');
21
/**
22
 * @cfg {Ext.menu.menu} contextMenu the contextMenu that call the plugin and will execute onResourceCallClick method
23
 * @cfg {Ext.data.Record} resource the resource record
24
 * @cfg {string} url the base url of the resource
25
 * @cfg {string} methods the methods allowed with the format method1|method2|...|methodN
26
 * @cfg {string} runType the runTypeUserInput defined in the resource
27
 * @cfg {boolean} withSelection true if there was a selection, false otherwise
28
 * @cfg {Array} parameters the parameters
29
 * @class sitools.user.component.dataviews.resourcePluginParamsPanel
30
 * @extends Ext.Window
31
 */
32
sitools.user.component.dataviews.resourcePluginParamsPanel = Ext.extend(Ext.Panel, {
33
//sitools.user.component.livegrid.resourcePluginParamsWindow = Ext.extend(Ext.Window, {
34
    width : "450",
35
    
36
    showMethod : false, 
37
    defaultMethod : "",
38
    showRunType : false, 
39
    initComponent : function () {
40
        var methodsArray = this.methods.split("|");
41
        this.showMethod = methodsArray.length > 1;
42
        this.defaultMethod = methodsArray[0];
43
        
44
        this.methodsStore = new Ext.data.ArrayStore({
45
            fields: ["method"],
46
            idIndex: 0
47
        });
48
    
49
        Ext.each(methodsArray, function (item, index) {
50
            this.methodsStore.add(new Ext.data.Record({
51
                method : item
52
            }));
53
        }, this);
54
        
55
        var formCommonParametersFields = [];
56
        var comboMethod = new Ext.form.ComboBox({                
57
            xtype : 'combo',
58
            mode : 'local',
59
            triggerAction : 'all',
60
            editable : false,
61
            name : 'method',
62
            fieldLabel : i18n.get('label.method'),
63
            width : 100,
64
            store : this.methodsStore,
65
            valueField : 'method',
66
            displayField : 'method',
67
            anchor : "100%",
68
            value : this.defaultMethod,
69
            forceSelection : true
70
        });
71
        this.items = [];
72
        if (this.showMethod) {
73
                        formCommonParametersFields.push(comboMethod);
74
                        this.formParams = new Ext.form.FormPanel({
75
                    padding: 5,
76
        //            title : "Request parameters",
77
                    items : [{
78
                        xtype : 'fieldset',
79
                        title : i18n.get("label.commonParameters"),
80
                        items : formCommonParametersFields
81
                    }]
82
                });
83
                
84
                this.items.push(this.formParams);                        
85
        }
86
        
87
        var userInputParams = [];
88
        this.user = projectGlobal.user || {
89
                        firstName : "public",
90
                        identifier : "public",
91
                        email : "&nbsp;"
92
                        };
93

    
94
        Ext.each(this.resource.parameters, function (value, index) {
95
            if (value.type == "PARAMETER_USER_INPUT" && value.userUpdatable) {
96
                if(value.name == "Email" && this.user.identifier != "public"){
97
                        //if user is not public donnot show email input field
98
                }else{
99
                        var item = this.buildFormItemFromParam(value);
100
                        userInputParams.push(item);
101
                        if (value.name == "runTypeUserInput") {
102
                                this.showRunType = true;
103
                        }
104

    
105
                }
106
            }
107
        }, this);
108

    
109
        if (!Ext.isEmpty(userInputParams)) {
110
            this.formParamsUserInput = new Ext.form.FormPanel({
111
                padding: 5,
112
                labelWidth : 150, 
113
                items : {
114
                    xtype : 'fieldset',
115
                    title : i18n.get("label.specificParameter"),
116
                    items : userInputParams
117
                }
118
            });  
119
            this.items.push(this.formParamsUserInput);
120
        }
121
        
122
        this.buttons = [{
123
            text : i18n.get('label.submit'),
124
            scope : this,
125
            handler : this.onCall            
126
        }, {
127
            text : i18n.get('label.cancel'),
128
            scope : this,
129
            handler : function () {
130
                this.ownerCt.close();
131
                this.callback.call(undefined, false);
132
            }
133
        }];
134
        sitools.user.component.dataviews.resourcePluginParamsPanel.superclass.initComponent.call(this);
135
    },
136
    
137
    onCall : function () {        
138
        var method;
139
        if (this.showMethod) {
140
                var form = this.formParams.getForm();
141
                method = form.findField("method").getValue();
142
        }
143
        else {
144
                        method = this.defaultMethod;        
145
        }
146
                
147
        var runTypeUserInput;
148
        if (this.showRunType) {
149
                        runTypeUserInput = this.formParamsUserInput.getForm().findField("runTypeUserInput").getValue();
150
        }
151
        else {
152
                        runTypeUserInput = this.runType;
153
        }
154
        var limit;
155

    
156
        var userParameters = {};
157
        if (!Ext.isEmpty(this.formParamsUserInput)) {
158
            var formParams = this.formParamsUserInput.getForm();
159
            Ext.iterate(formParams.getValues(), function (key, value) {
160
                userParameters[key] = value;                
161
            });
162
        }
163
        if(userParameters["Email"] == ""){
164
            Ext.Msg.alert("Email error","Please insert an email address which will be used to inform you with the download link.");
165
            return false;
166
        } 
167
        Ext.each(this.parameters, function (param) {
168
            if (param.type == "PARAMETER_IN_QUERY") {
169
                userParameters[param.name] = param.value;
170
            }
171
        });
172
        
173
        this.contextMenu.onResourceCallClick(this.resource, this.url, method, runTypeUserInput, limit, userParameters, this.postParameter, this.callback);
174
        this.ownerCt.close();
175
    }, 
176
    buildFormItemFromParam : function (value, userInputParams) {
177
                var valueType = value.valueType;
178
        var item = {};
179
        //specific case for boolean
180
        if (valueType.indexOf("xs:boolean") != -1) {
181
            valueType = "xs:enum[true,false]";
182
        }
183
        if (valueType.indexOf("xs:enum") != -1) {
184
                var enumeration = valueType.split("[");
185
                enumeration = enumeration[1].split("]");
186
                enumeration = enumeration[0].split(",");
187

    
188
                        var multiple = false;
189
                        if (valueType.indexOf("xs:enum-multiple") >= 0 || valueType.indexOf("xs:enum-editable-multiple") >= 0) {
190
                                multiple = true;
191
                        }
192
                        
193
                        var storeItems = [];
194
                        for (var i = 0; i < enumeration.length; i++) {
195
                                var tmp = enumeration[i].trim();
196
                                storeItems.push([ tmp, tmp]);
197
                        }
198
                        var store = new Ext.data.ArrayStore({
199
                fields : ['value', 'text'],
200
                data : storeItems, 
201
                valueField : 'value', 
202
                displayField : 'text'
203
            });
204
                        
205
                        if (multiple) {
206
                                item = {
207
                                        store : store,
208
                                        name : value.name, 
209
                                        xtype : "multiselect", 
210
                                        values : value.value, 
211
                                        delimiter : '|', 
212
                                        fieldLabel : value.name, 
213
                                        width : 235, 
214
                                        tooltip : value.description
215
                                };
216
                        }
217
                        else {
218
                                item = {
219
                                        store : store,
220
                                        name : value.name, 
221
                                        xtype : "combo", 
222
                                        value : value.value, 
223
                                        valueField : "value", 
224
                                        displayField : "text", 
225
                                        mode: 'local', 
226
                                        fieldLabel : value.name, 
227
                                        triggerAction : 'all',
228
                                        selectOnFocus : true,
229
                                        editable : false, 
230
                                        anchor : "100%", 
231
                                        tooltip : value.description
232
                                };
233
                        }
234
        }
235
        else {
236
                        item = {
237
                name : value.name,
238
                xtype : 'textfield',
239
                value : value.value,
240
                fieldLabel : value.name,
241
                anchor : "100%", 
242
                                tooltip : value.description
243
            };
244
        }
245
        return item;
246
    }, 
247
    /**
248
     * Method called when trying to show this component with fixed navigation
249
     * 
250
     * @param {sitools.user.component.viewDataDetail} me the dataDetail view
251
     * @param {} config config options
252
     * @returns
253
     */
254
    showMeInFixedNav : function (me, config) {
255
        Ext.apply(config.windowSettings, {
256
            width : config.windowSettings.winWidth || DEFAULT_WIN_WIDTH,
257
            height : config.windowSettings.winHeight || DEFAULT_WIN_HEIGHT
258
        });
259
        SitoolsDesk.openModalWindow(me, config);
260
    }, 
261
    /**
262
     * Method called when trying to show this component with Desktop navigation
263
     * 
264
     * @param {sitools.user.component.viewDataDetail} me the dataDetail view
265
     * @param {} config config options
266
     * @returns
267
     */
268
    showMeInDesktopNav : function (me, config) {
269
        Ext.apply(config.windowSettings, {
270
            width : config.windowSettings.winWidth || DEFAULT_WIN_WIDTH,
271
            height : config.windowSettings.winHeight || DEFAULT_WIN_HEIGHT
272
        });
273
        SitoolsDesk.openModalWindow(me, config);
274
    }
275

    
276
});