Commit ecced9f7f8d957068196caf801490c31f517d61d

Authored by Elena.Budnik
1 parent a21497cc

redmine #5395 and #5410

Showing 1 changed file with 200 additions and 198 deletions   Show diff stats
js/app/views/IntervalUI.js
... ... @@ -7,9 +7,6 @@
7 7 * @author Benjamin
8 8 * @version $Id: IntervalUI.js 2077 2014-02-11 11:33:36Z elena $
9 9 * @todo Validations
10   - *****************************************************************************
11   - * FT Id : Date : Name - Description
12   - ******************************************************************************
13 10 */
14 11  
15 12 /**
... ... @@ -17,10 +14,10 @@ config:
17 14 - durationLimit: The maximum value of the duration days field (9999 by default).
18 15 */
19 16 Ext.define('amdaUI.IntervalUI', {
20   - extend: 'Ext.container.Container',
  17 + extend: 'Ext.container.Container',
21 18  
22   - alias: 'widget.intervalSelector',
23   - activeField : null,
  19 + alias: 'widget.intervalSelector',
  20 + activeField : null,
24 21  
25 22 constructor: function(config) {
26 23 this.init(config);
... ... @@ -28,31 +25,31 @@ Ext.define('amdaUI.IntervalUI', {
28 25 },
29 26  
30 27 /**
31   - Set the start and stop date, and update the duration field.
32   - - startDate: A Extjs Date object representing the new start time.
33   - - stopDate: A Extjs Date object representing the new stop time.
34   - - return: None.
  28 + Set the start and stop date, and update the duration field.
  29 + - startDate: A Extjs Date object representing the new start time.
  30 + - stopDate: A Extjs Date object representing the new stop time.
  31 + - return: None.
35 32 */
36 33 setInterval : function(startDate,stopDate)
37 34 {
38 35 // get the search form
39   - var form = this.findParentByType('form').getForm();
40   - // get start field
41   - var startField = form.findField('startDate');
42   - // get stop field
43   - var stopField = form.findField('stopDate');
  36 + var form = this.findParentByType('form').getForm();
  37 + // get start field
  38 + var startField = form.findField('startDate');
  39 + // get stop field
  40 + var stopField = form.findField('stopDate');
44 41  
45   - if (startField != null)
46   - startField.setValue(startDate);
  42 + if (startField != null)
  43 + startField.setValue(startDate);
47 44  
48   - if (stopField != null)
49   - stopField.setValue(stopDate);
  45 + if (stopField != null)
  46 + stopField.setValue(stopDate);
50 47  
51   - this.updateDuration();
  48 + this.updateDuration();
52 49 },
53 50  
54   - /**
55   - Set the limits values of both startField and stopField date fields.
  51 + /**
  52 + Set the limits values of both startField and stopField date fields.
56 53 */
57 54 setLimits: function(minValue, maxValue) {
58 55 var form = this.findParentByType('form').getForm();
... ... @@ -71,31 +68,33 @@ Ext.define('amdaUI.IntervalUI', {
71 68  
72 69 this.updateDuration();
73 70 },
74   - setStartTime: function(startTime) {
75   - var form = this.findParentByType('form').getForm();
76   - var startField = form.findField('startDate');
77   - startField.setValue(startTime);
78   - this.updateDuration();
79   - },
80   - setStopTime: function(stopTime) {
81   - var form = this.findParentByType('form').getForm();
82   - var stopField = form.findField('stopDate');
83   - stopField.setValue(stopTime);
84   - this.updateDuration();
85   - },
  71 +
  72 + setStartTime: function(startTime) {
  73 + var form = this.findParentByType('form').getForm();
  74 + var startField = form.findField('startDate');
  75 + startField.setValue(startTime);
  76 + this.updateDuration();
  77 + },
  78 +
  79 + setStopTime: function(stopTime) {
  80 + var form = this.findParentByType('form').getForm();
  81 + var stopField = form.findField('stopDate');
  82 + stopField.setValue(stopTime);
  83 + this.updateDuration();
  84 + },
86 85  
87   - /**
  86 + /**
88 87 Get the start time field value.
89 88 - return: A Extjs Date object representing the start time (null if the date is not valid).
90 89 */
91 90 getStartTime : function()
92 91 {
93 92 // get the search form
94   - var form = this.findParentByType('form').getForm();
95   - // get start field
96   - var startField = form.findField('startDate');
  93 + var form = this.findParentByType('form').getForm();
  94 + // get start field
  95 + var startField = form.findField('startDate');
97 96  
98   - return startField.getValue();
  97 + return startField.getValue();
99 98 },
100 99  
101 100 /**
... ... @@ -105,123 +104,128 @@ Ext.define('amdaUI.IntervalUI', {
105 104 getStopTime : function()
106 105 {
107 106 // get the search form
108   - var form = this.findParentByType('form').getForm();
109   - // get stop field
110   - var stopField = form.findField('stopDate');
  107 + var form = this.findParentByType('form').getForm();
  108 + // get stop field
  109 + var stopField = form.findField('stopDate');
111 110  
112   - return stopField.getValue();
  111 + return stopField.getValue();
113 112 },
114 113  
115 114 /*
116 115 #### Private methods from here ####
117 116 */
  117 + updateDuration: function() {
  118 + // get the search form
  119 + var form = this.findParentByType('form').getForm();
  120 + // get start value
  121 + var start = this.getStartTime();
  122 + // get stop value
  123 + var stop = this.getStopTime();
  124 + // if duration computable
  125 + if (stop != null && start != null) {
  126 + // compute offset
  127 + var zoneOffset = stop.getTimezoneOffset() - start.getTimezoneOffset();
  128 + // compute duration
  129 + var diff = stop - start - zoneOffset*60000;
  130 +
  131 + var durationDays = Math.floor(diff/86400000);
  132 + // set all duration values
  133 + form.findField('durationDay').setValue(durationDays);
  134 + form.findField('durationHour').setValue(Math.floor(diff/3600000 % 24));
  135 + form.findField('durationMin').setValue(Math.floor(diff/60000 % 60));
  136 + form.findField('durationSec').setValue(Math.floor(diff/1000 % 60));
  137 +
  138 + if (durationDays > this.durationLimit) {
  139 + form.findField('durationDay').markInvalid('Maximum interval is ' + this.durationLimit + ' days!');
  140 + }
  141 + } else {
  142 + form.findField('durationDay').setValue('');
  143 + form.findField('durationHour').setValue('');
  144 + form.findField('durationMin').setValue('');
  145 + form.findField('durationSec').setValue('');
  146 + }
  147 + },
118 148  
119   - updateDuration: function() {
120   - // get the search form
121   - var form = this.findParentByType('form').getForm();
122   - // get start value
123   - var start = this.getStartTime();
124   - // get stop value
125   - var stop = this.getStopTime();
126   - // if duration computable
127   - if (stop != null && start != null) {
128   - // compute offset
129   - var zoneOffset = stop.getTimezoneOffset() - start.getTimezoneOffset();
130   - // compute duration
131   - var diff = stop - start - zoneOffset*60000;
132   -
133   - var durationDays = Math.floor(diff/86400000);
134   - // set all duration values
135   - form.findField('durationDay').setValue(durationDays);
136   - form.findField('durationHour').setValue(Math.floor(diff/3600000 % 24));
137   - form.findField('durationMin').setValue(Math.floor(diff/60000 % 60));
138   - form.findField('durationSec').setValue(Math.floor(diff/1000 % 60));
139   -
140   - if (durationDays > this.durationLimit) {
141   - form.findField('durationDay').markInvalid('Maximum interval is ' + this.durationLimit + ' days!');
142   - }
143   - } else {
144   - form.findField('durationDay').setValue('');
145   - form.findField('durationHour').setValue('');
146   - form.findField('durationMin').setValue('');
147   - form.findField('durationSec').setValue('');
148   - }
149   - },
150   -
151   - isValidDuration: function(){
152   - var form = this.findParentByType('form').getForm();
153   - return (
154   - form.findField('durationDay').isValid() &&
155   - form.findField('durationHour').isValid() &&
156   - form.findField('durationMin').isValid() &&
157   - form.findField('durationSec').isValid()
158   - );
159   - },
160   -
161   - updateStop: function() {
162   - var form = this.findParentByType('form').getForm();
163   - var start = form.findField('startDate').getValue();
164   -
165   - var d = form.findField('durationDay').getValue();
166   - var h = form.findField('durationHour').getValue();
167   - var m = form.findField('durationMin').getValue();
168   - var s = form.findField('durationSec').getValue();
169   - var duration = (d?d:0)*86400 + (h?h:0)*3600 + (m?m:0)*60 + (s?s:0)
  149 + isValidDuration: function(){
  150 + var form = this.findParentByType('form').getForm();
  151 + return (
  152 + form.findField('durationDay').isValid() &&
  153 + form.findField('durationHour').isValid() &&
  154 + form.findField('durationMin').isValid() &&
  155 + form.findField('durationSec').isValid()
  156 + );
  157 + },
170 158  
171   - form.findField('stopDate').setValue(Ext.Date.add(start, Ext.Date.SECOND, duration));
172   - },
  159 + updateStop: function() {
  160 + var form = this.findParentByType('form').getForm();
  161 + var start = form.findField('startDate').getValue();
  162 +
  163 + var d = form.findField('durationDay').getValue();
  164 + var h = form.findField('durationHour').getValue();
  165 + var m = form.findField('durationMin').getValue();
  166 + var s = form.findField('durationSec').getValue();
  167 + var duration = (d?d:0)*86400 + (h?h:0)*3600 + (m?m:0)*60 + (s?s:0)
  168 + var stop = Ext.Date.add(start, Ext.Date.SECOND, duration);
  169 +
  170 + if (Ext.Date.isDST(stop) && !Ext.Date.isDST(start))
  171 + stop = Ext.Date.add(start, Ext.Date.SECOND, duration-3600);
  172 +
  173 + if (!Ext.Date.isDST(stop) && Ext.Date.isDST(start))
  174 + stop = Ext.Date.add(start, Ext.Date.SECOND, duration+3600);
  175 +
  176 + form.findField('stopDate').setValue(stop);
  177 + },
173 178  
174 179 onChangeStartField : function(field, newValue, oldValue)
175 180 {
176   - if (field.isValid()) {
177   - // get the search form
178   - var form = this.findParentByType('form').getForm();
179   - // set to the stop datefield the newValue as minValue
180   - form.findField('stopDate').setMinValue(newValue);
181   - // if it's a user modification
182   - if (this.activeField == 'start') {
183   - // launch the update of duration fields
184   - this.updateDuration();
185   - }
186   - }
  181 + if (field.isValid()) {
  182 + // get the search form
  183 + var form = this.findParentByType('form').getForm();
  184 + // set to the stop datefield the newValue as minValue
  185 + form.findField('stopDate').setMinValue(newValue);
  186 + // if it's a user modification
  187 + if (this.activeField == 'start') {
  188 + // launch the update of duration fields
  189 + this.updateDuration();
  190 + }
  191 + }
187 192 },
188 193  
189   - onChangeStopField: function(field, newValue, oldValue){
190   - if (field.isValid() && this.activeField == 'stop') {
191   - // launch the update of duration fields
192   - this.updateDuration();
193   - }
194   - },
  194 + onChangeStopField: function(field, newValue, oldValue)
  195 + {
  196 + if (field.isValid() && this.activeField == 'stop') {
  197 + // launch the update of duration fields
  198 + this.updateDuration();
  199 + }
  200 + },
195 201  
196 202 getDateField : function(fieldName,fieldText,fieldId,onChangeField)
197 203 {
198 204 return {
199 205 layout: {type: 'hbox', align: 'middle'},
200   - items: [
201   - {
202   - xtype: 'datefield',
203   - name: fieldName,
204   - emptyText: 'YYYY/MM/DD hh:mm:ss',
205   - tip: 'Date formated as YYYY/MM/DD hh:mm:ss',
206   - format: 'Y/m/d H:i:s',
207   - enforceMaxLength: true,
208   - maxLength: 19,
209   - fieldLabel: fieldText,
210   - labelAlign: 'left',
211   - labelWidth: 60,
212   - listeners: {
213   - change: onChangeField,
214   - focus: function(field) {
215   - this.activeField = fieldId;
216   - },
217   - render: function(c) {
218   - Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip });
219   - },
220   - scope : this
221   - }
222   - }
223   - ]
224   - };
  206 + items: [{
  207 + xtype: 'datefield',
  208 + name: fieldName,
  209 + emptyText: 'YYYY/MM/DD hh:mm:ss',
  210 + tip: 'Date formated as YYYY/MM/DD hh:mm:ss',
  211 + format: 'Y/m/d H:i:s',
  212 + enforceMaxLength: true,
  213 + maxLength: 19,
  214 + fieldLabel: fieldText,
  215 + labelAlign: 'left',
  216 + labelWidth: 60,
  217 + listeners: {
  218 + change: onChangeField,
  219 + focus: function(field) {
  220 + this.activeField = fieldId;
  221 + },
  222 + render: function(c) {
  223 + Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip });
  224 + },
  225 + scope : this
  226 + }
  227 + }]
  228 + };
225 229 },
226 230  
227 231 getStartField : function()
... ... @@ -231,71 +235,69 @@ Ext.define('amdaUI.IntervalUI', {
231 235  
232 236 getStopField : function()
233 237 {
234   - return this.getDateField('stopDate','Stop Time','stop',this.onChangeStopField);
  238 + return this.getDateField('stopDate','Stop Time','stop', this.onChangeStopField);
235 239 },
236 240  
237 241 getDurationField : function()
238 242 {
239   - return {
240   - layout: {type: 'hbox', align: 'middle'},
241   - margin: 0,
242   - defaults: {
243   - xtype: 'numberfield',
244   - minValue: 0,
245   - maxLength: 2,
246   - enforceMaxLength: true,
247   - decimalPrecision: 0,
248   - allowExponential: false,
249   - autoStripChars: true,
250   - hideTrigger: true,
251   - labelAlign: 'left',
252   - width: 32,
253   - margin: '0 5 0 0',
254   - listeners: {
255   - change: function(field, newValue, oldValue) {
256   - var form = this.findParentByType('form').getForm();
257   - var start = form.findField('startDate').getValue();
258   - if (this.isValidDuration() && start!=null && this.activeField == 'duration') {
259   - this.updateStop();
260   - }
261   - },
262   - focus: function(field) {
263   - this.activeField = 'duration';
264   - },
265   - render: function(c) {
266   - Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip });
267   - },
268   - scope : this
269   - }
270   - },
271   - items:[
272   - { name: 'durationDay', emptyText: 'Days', tip: 'Days', maxValue: 36500, maxLength: 5, fieldLabel: 'Duration', labelWidth: 60, width: 110, },
273   - { name: 'durationHour', emptyText: 'Hrs', tip: 'Hours', maxValue: 23},
274   - { name: 'durationMin', emptyText: 'Mins', tip: 'Minutes', maxValue: 59},
275   - { name: 'durationSec', emptyText: 'Secs', tip: 'Seconds', maxValue: 59}
276   - ]
277   - };
  243 + return {
  244 + layout: {type: 'hbox', align: 'middle'},
  245 + margin: 0,
  246 + defaults: {
  247 + xtype: 'numberfield',
  248 + minValue: 0,
  249 + maxLength: 2,
  250 + enforceMaxLength: true,
  251 + decimalPrecision: 0,
  252 + allowExponential: false,
  253 + autoStripChars: true,
  254 + hideTrigger: true,
  255 + labelAlign: 'left',
  256 + width: 32,
  257 + margin: '0 5 0 0',
  258 + listeners: {
  259 + change: function(field, newValue, oldValue) {
  260 + var form = this.findParentByType('form').getForm();
  261 + var start = form.findField('startDate').getValue();
  262 + if (this.isValidDuration() && start!=null && this.activeField == 'duration') {
  263 + this.updateStop();
  264 + }
  265 + },
  266 + focus: function(field) {
  267 + this.activeField = 'duration';
  268 + },
  269 + render: function(c) {
  270 + Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip });
  271 + },
  272 + scope : this
  273 + }
  274 + },
  275 + items:[
  276 + { name: 'durationDay', emptyText: 'Days', tip: 'Days', maxValue: 73000, maxLength: 5, fieldLabel: 'Duration', labelWidth: 60, width: 110},
  277 + { name: 'durationHour', emptyText: 'Hrs', tip: 'Hours', maxValue: 23},
  278 + { name: 'durationMin', emptyText: 'Mins', tip: 'Minutes', maxValue: 59},
  279 + { name: 'durationSec', emptyText: 'Secs', tip: 'Seconds', maxValue: 59}
  280 + ]
  281 + };
278 282 },
279 283  
280   - init : function(config) {
281   - this.durationLimit = config.durationLimit == null ? 36500 : config.durationLimit; // Set duration limit to 100 years by default
282   -
283   - var me = this;
284   -
285   - var myConf = {
286   - border: false,
287   - plain: true,
288   - flex: 1,
289   - layout: 'anchor',
290   - defaults: { margin: '0 0 5 0', xtype : 'container'},
291   -
292   - items: [
293   - me.getStartField(),
294   - me.getStopField(),
295   - me.getDurationField()
296   - ]
297   - };
298   -
299   - Ext.apply (this , Ext.apply (arguments, myConf));
  284 + init : function(config)
  285 + {
  286 + this.durationLimit = config.durationLimit == null ? 73000 : config.durationLimit; // Set duration limit to 200 years by default
  287 +
  288 + var me = this;
  289 + var myConf = {
  290 + border: false,
  291 + plain: true,
  292 + flex: 1,
  293 + layout: 'anchor',
  294 + defaults: { margin: '0 0 5 0', xtype : 'container'},
  295 + items: [
  296 + me.getStartField(),
  297 + me.getStopField(),
  298 + me.getDurationField()
  299 + ]
  300 + };
  301 + Ext.apply (this, Ext.apply(arguments, myConf));
300 302 }
301 303 });
... ...