git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / CheckBox.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.CheckBox
|
28 |
* @extends Ext.Container
|
29 |
*/
|
30 |
sitools.common.forms.components.CheckBox = Ext.extend(Ext.Container, { |
31 |
//sitools.component.users.SubSelectionParameters.MultipleSelection.CheckBox = Ext.extend(Ext.Container, {
|
32 |
|
33 |
initComponent : function () { |
34 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
35 |
var items = [];
|
36 |
for (i = 0; i < this.values.length; i++) { |
37 |
value = this.values[i];
|
38 |
items.push({ |
39 |
value : value.value,
|
40 |
boxLabel : value.value,
|
41 |
name : this.code, |
42 |
checked : value.defaultValue,
|
43 |
height : 25 |
44 |
|
45 |
}); |
46 |
} |
47 |
this.cbGroup = new Ext.form.CheckboxGroup ({ |
48 |
allowBlank : true, |
49 |
columns : 3, |
50 |
flex : 1, |
51 |
items : items
|
52 |
}); |
53 |
Ext.apply(this, {
|
54 |
height : this.height, |
55 |
width : this.width, |
56 |
overCls : 'fieldset-child', |
57 |
layout : "hbox", |
58 |
stype : "sitoolsFormContainer", |
59 |
items : [this.cbGroup] |
60 |
}); |
61 |
sitools.common.forms.components.CheckBox.superclass.initComponent.apply(this, arguments); |
62 |
|
63 |
if (!Ext.isEmpty(this.label)) { |
64 |
this.items.insert(0, new Ext.Container({ |
65 |
border : false, |
66 |
html : this.label, |
67 |
width : 100 |
68 |
})); |
69 |
} |
70 |
}, |
71 |
|
72 |
getSelectedValue : function () { |
73 |
var values = this.cbGroup.getValue(); |
74 |
if (values && values.length > 0) { |
75 |
var selectedValues = [];
|
76 |
for (var i = 0; i < values.length; i++) { |
77 |
if (Ext.isString(values[i].value) && ! Ext.isNumber(parseFloat(values[i].value))){
|
78 |
values[i].value = values[i].value; |
79 |
} |
80 |
selectedValues.push(values[i].value); |
81 |
} |
82 |
return selectedValues;
|
83 |
} else {
|
84 |
return null; |
85 |
} |
86 |
}, |
87 |
getParameterValue : function () { |
88 |
var values = this.getSelectedValue(); |
89 |
if (!Ext.isArray(values)) {
|
90 |
return null; |
91 |
} |
92 |
values = values.join("|");
|
93 |
// return this.type + "|" + this.code + "|" + values;
|
94 |
return {
|
95 |
type : this.type, |
96 |
code : this.code, |
97 |
value : values
|
98 |
}; |
99 |
|
100 |
}, |
101 |
|
102 |
// *** Reset function for RESET button ***//
|
103 |
resetToDefault : function () { |
104 |
this.cbGroup.reset();
|
105 |
} |
106 |
// **************************************//
|
107 |
|
108 |
}); |