git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / Radio.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 "../ComponentFactory.js"
|
22 |
*/
|
23 |
Ext.ns('sitools.common.forms.components');
|
24 |
|
25 |
/**
|
26 |
* @requires sitools.common.forms.ComponentFactory
|
27 |
* @class sitools.common.forms.components.Radio
|
28 |
* @extends Ext.Container
|
29 |
*/
|
30 |
sitools.common.forms.components.Radio = Ext.extend(Ext.Container, { |
31 |
//sitools.component.users.SubSelectionParameters.SingleSelection.Radio = Ext.extend(Ext.Container, {
|
32 |
|
33 |
initComponent : function () { |
34 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
35 |
var value;
|
36 |
var items = [];
|
37 |
for (i = 0; i < this.values.length; i++) { |
38 |
value = this.values[i];
|
39 |
items.push({ |
40 |
value : value.value,
|
41 |
boxLabel : value.value,
|
42 |
name : this.code[0], |
43 |
checked : value.defaultValue
|
44 |
}); |
45 |
} |
46 |
|
47 |
this.radioGroup = new Ext.form.RadioGroup({ |
48 |
allowBlank : true, |
49 |
//height : this.height,
|
50 |
items : items,
|
51 |
flex : 1, |
52 |
/**
|
53 |
* The code of the parameter to notify changed event.
|
54 |
*/
|
55 |
code : this.code[0], |
56 |
listeners : {
|
57 |
scope : this, |
58 |
change : function () { |
59 |
this.form.fireEvent('componentChanged', this.form, this); |
60 |
} |
61 |
} |
62 |
|
63 |
|
64 |
}); |
65 |
Ext.apply(this, {
|
66 |
layout : "hbox", |
67 |
stype : "sitoolsFormContainer", |
68 |
overCls : 'fieldset-child', |
69 |
items : [this.radioGroup] |
70 |
}); |
71 |
sitools.common.forms.components.Radio.superclass.initComponent.apply(this,
|
72 |
arguments);
|
73 |
if (!Ext.isEmpty(this.label)) { |
74 |
this.items.insert(0, new Ext.Container({ |
75 |
border : false, |
76 |
html : this.label, |
77 |
width : 100 |
78 |
})); |
79 |
} |
80 |
|
81 |
}, |
82 |
|
83 |
/* notifyValueChanged : function () {
|
84 |
this.parent.notifyValueChanged(this.code);
|
85 |
},
|
86 |
*/
|
87 |
isValueDefined : function () { |
88 |
if (this.radioGroup.getValue()) { |
89 |
return true; |
90 |
} else {
|
91 |
return false; |
92 |
} |
93 |
}, |
94 |
|
95 |
getSelectedValue : function () { |
96 |
if (this.radioGroup.getValue()) { |
97 |
return this.radioGroup.getValue().value; |
98 |
} else {
|
99 |
return null; |
100 |
} |
101 |
}, |
102 |
getParameterValue : function () { |
103 |
var value = this.getSelectedValue(); |
104 |
if (Ext.isEmpty(value)) {
|
105 |
return null; |
106 |
} |
107 |
// if (Ext.isString(value) && ! Ext.isNumber(parseFloat(value))){
|
108 |
// value = "\"" + value + "\"";
|
109 |
// }
|
110 |
return {
|
111 |
type : this.type, |
112 |
code : this.code, |
113 |
value : value
|
114 |
}; |
115 |
}, |
116 |
|
117 |
// *** Reset function for RESET button ***//
|
118 |
resetToDefault : function () { |
119 |
this.radioGroup.reset();
|
120 |
} |
121 |
// ***************************************//
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
}); |