git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / DateBetween.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.DateBetween
|
28 |
* @extends Ext.Container
|
29 |
*/
|
30 |
sitools.common.forms.components.DateBetween = Ext.extend(Ext.Container, { |
31 |
//sitools.component.users.SubSelectionParameters.SingleSelection.DateBetween = Ext.extend(Ext.Container, {
|
32 |
regToday : new RegExp("^\{\\$TODAY\}"), |
33 |
initComponent : function () { |
34 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
35 |
//formattage de extraParams :
|
36 |
var extraParams = {};
|
37 |
Ext.each(this.extraParams, function (param) { |
38 |
extraParams[param.name]= param.value; |
39 |
}, this);
|
40 |
|
41 |
|
42 |
this.showTime = extraParams.showTime;
|
43 |
if (Ext.isString(this.showTime)) { |
44 |
this.showTime = extraParams.showTime == "true"; |
45 |
} |
46 |
this.truncateDefaultValue = extraParams.truncateDefaultValue;
|
47 |
if (Ext.isString(this.truncateDefaultValue)) { |
48 |
this.truncateDefaultValue = extraParams.truncateDefaultValue == "true"; |
49 |
} |
50 |
this.format = extraParams.format;
|
51 |
|
52 |
var dateFormat = this.format; |
53 |
|
54 |
var valueFrom = this.getDefaultValue(this.defaultValues[0]) ; |
55 |
var valueTo = this.getDefaultValue(this.defaultValues[1]) ; |
56 |
|
57 |
this.fieldFrom = new Ext.form.DateField({ |
58 |
allowBlank : true, |
59 |
format : dateFormat,
|
60 |
flex : 1, |
61 |
//height : this.height,
|
62 |
value : valueFrom,
|
63 |
showTime : this.showTime, |
64 |
listeners : {
|
65 |
scope : this, |
66 |
change : function (field, newValue, oldValue) { |
67 |
this.fieldTo.setMinValue(newValue);
|
68 |
this.fieldTo.validate();
|
69 |
} |
70 |
} |
71 |
}); |
72 |
this.fieldTo = new Ext.form.DateField({ |
73 |
allowBlank : true, |
74 |
format : dateFormat,
|
75 |
flex : 1, |
76 |
//height : this.height,
|
77 |
value : valueTo,
|
78 |
showTime : this.showTime, |
79 |
minValue : valueFrom
|
80 |
}); |
81 |
Ext.apply(this, {
|
82 |
layout : 'hbox', |
83 |
overCls : 'fieldset-child', |
84 |
stype : "sitoolsFormContainer", |
85 |
|
86 |
items : [this.fieldFrom, this.fieldTo ] |
87 |
}); |
88 |
sitools.common.forms.components.DateBetween.superclass.initComponent.apply( |
89 |
this, arguments); |
90 |
if (!Ext.isEmpty(this.label)) { |
91 |
var labels = this.label.split("|") || []; |
92 |
switch (labels.length) {
|
93 |
case 0 : |
94 |
break;
|
95 |
case 1 : |
96 |
this.items.insert(0, new Ext.Container({ |
97 |
border : false, |
98 |
html : labels[0], |
99 |
width : 100 |
100 |
})); |
101 |
break;
|
102 |
case 2 : |
103 |
this.items.insert(0, new Ext.Container({ |
104 |
border : false, |
105 |
html : labels[0], |
106 |
width : 50 |
107 |
})); |
108 |
this.items.insert(2, new Ext.Container({ |
109 |
border : false, |
110 |
html : labels[1], |
111 |
width : 50, |
112 |
style : {
|
113 |
"padding-left" : "10px" |
114 |
} |
115 |
})); |
116 |
break;
|
117 |
case 3 : |
118 |
this.items.insert(0, new Ext.Container({ |
119 |
border : false, |
120 |
html : labels[0], |
121 |
width : 50 |
122 |
})); |
123 |
this.items.insert(1, new Ext.Container({ |
124 |
border : false, |
125 |
html : labels[1], |
126 |
width : 50, |
127 |
style : {
|
128 |
"padding-left" : "10px" |
129 |
} |
130 |
})); |
131 |
this.items.insert(3, new Ext.Container({ |
132 |
border : false, |
133 |
html : labels[2], |
134 |
width : 50, |
135 |
style : {
|
136 |
"padding-left" : "10px" |
137 |
} |
138 |
})); |
139 |
break;
|
140 |
} |
141 |
} |
142 |
|
143 |
}, |
144 |
|
145 |
/**
|
146 |
* The code of the parameter to notify changed event.
|
147 |
*/
|
148 |
code : null, |
149 |
|
150 |
/**
|
151 |
* The left bound of the period.
|
152 |
*/
|
153 |
fieldFrom : null, |
154 |
|
155 |
/**
|
156 |
* The right bound of the period.
|
157 |
*/
|
158 |
fieldTo : null, |
159 |
|
160 |
notifyValueSelected : function () { |
161 |
this.parent.notifyValueChanged(this.code); |
162 |
}, |
163 |
|
164 |
isValueDefined : function () { |
165 |
if (this.fieldFrom.getValue() && this.fieldTo.getValue()) { |
166 |
return true; |
167 |
} else {
|
168 |
return false; |
169 |
} |
170 |
}, |
171 |
|
172 |
getSelectedValue : function () { |
173 |
return {
|
174 |
from : this.fieldFrom.getValue(), |
175 |
to : this.fieldTo.getValue() |
176 |
}; |
177 |
}, |
178 |
|
179 |
getParameterValue : function () { |
180 |
var value = this.getSelectedValue(); |
181 |
if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) {
|
182 |
return null; |
183 |
} |
184 |
var format = SITOOLS_DATE_FORMAT;
|
185 |
return {
|
186 |
type : this.type, |
187 |
code : this.code, |
188 |
value : value.from.format(format) + "|" + value.to.format(format) |
189 |
}; |
190 |
|
191 |
// return this.type + "|" + this.code + "|" + value.from.format(format) + "|" + value.to.format(format) ;
|
192 |
}, |
193 |
|
194 |
/**
|
195 |
* return a date truncated or not depending on this.truncateDefaultValue
|
196 |
* @param {String} val A string representing date a SITOOLS_DATE_FORMAT or containg {$TODAY}
|
197 |
* @return {Date} the date
|
198 |
*/
|
199 |
getDefaultValue : function (val) { |
200 |
var result;
|
201 |
if (Ext.isEmpty(val)) {
|
202 |
return null; |
203 |
} |
204 |
else {
|
205 |
if (Ext.isDate(Date.parseDate(val, SITOOLS_DATE_FORMAT))) {
|
206 |
result = Date.parseDate(val, SITOOLS_DATE_FORMAT); |
207 |
} |
208 |
else {
|
209 |
if (this.regToday.test(val)) { |
210 |
try {
|
211 |
result = sitools.common.utils.Date.stringWithTodayToDate(val); |
212 |
} |
213 |
catch (err) {
|
214 |
return null; |
215 |
} |
216 |
|
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
if (this.truncateDefaultValue) { |
222 |
return result.clearTime();
|
223 |
} |
224 |
else {
|
225 |
return result;
|
226 |
} |
227 |
}, |
228 |
|
229 |
isValid : function () { |
230 |
return (this.fieldFrom.isValid() && this.fieldTo.isValid()); |
231 |
}, |
232 |
|
233 |
// *** Reset function for RESET button ***//
|
234 |
resetToDefault : function () { |
235 |
this.fieldFrom.reset();
|
236 |
this.fieldTo.reset();
|
237 |
} |
238 |
// **************************************//
|
239 |
|
240 |
}); |
241 |
|