Project

General

Profile

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

git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / NumberFieldUser.js @ 2830ca05

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
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
* 
11
* SITools2 is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
***************************************/
19
/*global Ext, sitools*/
20
/*
21
 * @include "../AbstractComponentsWithUnit.js"
22
 * @include "../ComponentFactory.js"
23
 */
24
Ext.ns('sitools.common.forms.components');
25

    
26
/**
27
 * A number Field form component. 
28
 * @cfg {string} parameterId Id of the future component.
29
 * @cfg {Array} code Array of string representing columns alias attached to this component
30
 * @cfg {string} type Defines wich unique type of component it is.
31
 * @cfg {string} label The label of the form component.
32
 * @cfg {numeric} height height of the future component.
33
 * @cfg {numeric} widthBox width of the future component.
34
 * @cfg {string} valueSelection "S" for specific Selection, "D" for data selection.
35
 * @cfg {string} dataUrl the url to request the data in case of valueSelection == "D".
36
 * @cfg {boolean} autoComplete for TEXTFIELD, autoComplete configuration of future Ext.form.Textfield.
37
 * @cfg {string} formId The form id that contains this component.
38
 * @cfg {string} dimensionId The sitools units dimension id.
39
 * @cfg {string} css An optional css to add to this component.
40
 * @cfg {Array} defaultValues Array of default values.
41
 * @cfg {} datasetCm the dataset ColumnModel object
42
 * @requires sitools.common.forms.ComponentFactory
43
 * @class sitools.common.forms.components.NumberField
44
 * @extends sitools.common.forms.AbstractWithUnit
45
 */
46
sitools.common.forms.components.NumberField = Ext.extend(sitools.common.forms.AbstractWithUnit, {
47
//sitools.component.users.SubSelectionParameters.SingleSelection.NumberFieldUser = Ext.extend(sitools.common.forms.AbstractWithUnit, {
48

    
49
    /**
50
         * The numeric field
51
         */
52
    field : null,
53

    
54
    initComponent : function () {
55
        this.context = new sitools.common.forms.ComponentFactory(this.context);
56
        
57
                
58
        var extraParams = {};
59
        Ext.each(this.extraParams, function (param) {
60
            extraParams[param.name]= param.value;
61
        }, this);
62
        
63
        this.extraParams = extraParams;
64
            
65
            var unit = this.getUnitComponent();
66
        
67
            this.field = new Ext.form.NumberField({
68
                allowBlank : true,
69
                flex : 1,
70
                //height : this.height,
71
                value : this.defaultValues[0],
72
                decimalPrecision : 20
73
            });
74
            var items = [this.field];
75
        
76
        if (!Ext.isEmpty(unit)) {
77
                items.push(unit);
78
        }
79
            
80
            Ext.apply(this, {
81
                layout : 'hbox',
82
                stype : "sitoolsFormContainer",
83
                overCls : 'fieldset-child',
84
                        defaults : {
85
                        xtype : 'container',
86
                        autoEl : 'div'
87
                },
88
                items : items
89
            });
90
            sitools.common.forms.components.NumberField.superclass.initComponent.apply(
91
                    this, arguments);
92
               if (!Ext.isEmpty(this.label)) {
93
                    this.items.insert(0, new Ext.Container({
94
                    border : false,
95
                    html : this.label,
96
                    width : 100
97
                }));
98
            }
99

    
100
    },
101

    
102
    /**
103
     * Notify the parent of any change
104
     * @method
105
     */
106
    notifyValueSelected : function () {
107
            this.parent.notifyValueChanged(this.code);
108
    },
109

    
110
    /**
111
     * Return if the value is defined.
112
     * @method
113
     * @return {Boolean} 
114
     */
115
    isValueDefined : function () {
116
            if (this.fieldFrom.getValue()) {
117
                    return true;
118
            } else {
119
                    return false;
120
            }
121
    },
122

    
123
    /**
124
     * Get the selected Value
125
     * @return {Numeric} the selected Value
126
     */
127
    getSelectedValue : function () {
128
            return this.field.getValue();
129
    },
130
    
131
    /**
132
     * Returns the value to request corresponding to the Filter API.
133
     * @return {String} parameter filter value
134
     */
135
    getParameterValue : function () {
136
            var value = this.getSelectedValue();
137
            if (Ext.isEmpty(value) || Ext.isEmpty(value)) {
138
                    return null;
139
            }
140
            var result = this.type + "|" + this.code + "|" + value;
141
            if (!Ext.isEmpty(this.userDimension) && !Ext.isEmpty(this.userUnit)){
142
                    result += "|" + this.userDimension + "|" + this.userUnit;
143
            }
144
                   return {
145
                    type : this.type, 
146
                    code : this.code, 
147
                    value : value, 
148
                    userDimension : this.userDimension, 
149
                    userUnit : this.userUnit
150
            };
151
    },
152

    
153
    //  *** Reset function for RESET button ***//
154
    resetToDefault : function () {
155
        this.field.reset();
156
    },
157
    //
158

    
159
});