Commit 0de2b2fd5782fb16461b267c2444e185b4775b0c
1 parent
26c3b7b1
Exists in
master
and in
111 other branches
fix and improve intervalUI
Showing
2 changed files
with
47 additions
and
43 deletions
Show diff stats
js/app/views/EpnTapUI.js
js/app/views/IntervalUI.js
... | ... | @@ -113,7 +113,6 @@ Ext.define('amdaUI.IntervalUI', { |
113 | 113 | var stop = this.getStopTime(); |
114 | 114 | // if duration computable |
115 | 115 | if (stop != null && start != null) { |
116 | - | |
117 | 116 | // compute offset |
118 | 117 | var zoneOffset = stop.getTimezoneOffset() - start.getTimezoneOffset(); |
119 | 118 | // compute duration |
... | ... | @@ -121,43 +120,43 @@ Ext.define('amdaUI.IntervalUI', { |
121 | 120 | |
122 | 121 | var durationDays = Math.floor(diff/86400000); |
123 | 122 | // set all duration values |
124 | - form.findField('durationDay').setValue(Ext.String.leftPad(durationDays, ('' + this.durationLimit).length, '0')); | |
125 | - form.findField('durationHour').setValue(Ext.String.leftPad(Math.floor(diff/3600000 % 24),2,'0')); | |
126 | - form.findField('durationMin').setValue(Ext.String.leftPad(Math.floor(diff/60000 % 60),2,'0')); | |
127 | - form.findField('durationSec').setValue(Ext.String.leftPad(Math.floor(diff/1000 % 60),2,'0')); | |
123 | + form.findField('durationDay').setValue(durationDays); | |
124 | + form.findField('durationHour').setValue(Math.floor(diff/3600000 % 24)); | |
125 | + form.findField('durationMin').setValue(Math.floor(diff/60000 % 60)); | |
126 | + form.findField('durationSec').setValue(Math.floor(diff/1000 % 60)); | |
128 | 127 | |
129 | 128 | if (durationDays > this.durationLimit) { |
130 | 129 | form.findField('durationDay').markInvalid('Maximum interval is ' + this.durationLimit + ' days!'); |
131 | 130 | } |
131 | + } else { | |
132 | + form.findField('durationDay').setValue(''); | |
133 | + form.findField('durationHour').setValue(''); | |
134 | + form.findField('durationMin').setValue(''); | |
135 | + form.findField('durationSec').setValue(''); | |
132 | 136 | } |
133 | - | |
134 | 137 | }, |
135 | 138 | |
136 | 139 | isValidDuration: function(){ |
137 | - // get the time form | |
138 | 140 | var form = this.findParentByType('form').getForm(); |
139 | - // get global validation status for duration fields | |
140 | 141 | return ( |
141 | - form.findField('durationDay').isValid() && form.findField('durationHour').isValid() | |
142 | - && form.findField('durationMin').isValid() && form.findField('durationSec').isValid() | |
143 | - );// return true if all duration fields are Valid false otherwise | |
142 | + form.findField('durationDay').isValid() && | |
143 | + form.findField('durationHour').isValid() && | |
144 | + form.findField('durationMin').isValid() && | |
145 | + form.findField('durationSec').isValid() | |
146 | + ); | |
144 | 147 | }, |
145 | 148 | |
146 | 149 | updateStop: function() { |
147 | - // get the time form | |
148 | 150 | var form = this.findParentByType('form').getForm(); |
149 | - // get duration value | |
150 | - var duration = parseInt(form.findField('durationDay').getValue(),10)*86400 + | |
151 | - parseInt(form.findField('durationHour').getValue(),10)*3600 + | |
152 | - parseInt(form.findField('durationMin').getValue(),10)*60 + | |
153 | - parseInt(form.findField('durationSec').getValue(),10); | |
154 | - // get start value | |
155 | 151 | var start = form.findField('startDate').getValue(); |
156 | - // compute stop value | |
157 | - var stop = Ext.Date.add(start,Ext.Date.SECOND,duration); | |
158 | - // set stop value into form | |
159 | - form.findField('stopDate').setValue(stop); | |
160 | 152 | |
153 | + var d = form.findField('durationDay').getValue(); | |
154 | + var h = form.findField('durationHour').getValue(); | |
155 | + var m = form.findField('durationMin').getValue(); | |
156 | + var s = form.findField('durationSec').getValue(); | |
157 | + var duration = (d?d:0)*86400 + (h?h:0)*3600 + (m?m:0)*60 + (s?s:0) | |
158 | + | |
159 | + form.findField('stopDate').setValue(Ext.Date.add(start, Ext.Date.SECOND, duration)); | |
161 | 160 | }, |
162 | 161 | |
163 | 162 | onChangeStartField : function(field, newValue, oldValue) |
... | ... | @@ -168,7 +167,7 @@ Ext.define('amdaUI.IntervalUI', { |
168 | 167 | // set to the stop datefield the newValue as minValue |
169 | 168 | form.findField('stopDate').setMinValue(newValue); |
170 | 169 | // if it's a user modification |
171 | - if (oldValue != null && this.activeField == 'start') { | |
170 | + if (this.activeField == 'start') { | |
172 | 171 | // launch the update of duration fields |
173 | 172 | this.updateDuration(); |
174 | 173 | } |
... | ... | @@ -176,7 +175,7 @@ Ext.define('amdaUI.IntervalUI', { |
176 | 175 | }, |
177 | 176 | |
178 | 177 | onChangeStopField: function(field, newValue, oldValue){ |
179 | - if (field.isValid() && oldValue != null && this.activeField == 'stop') { | |
178 | + if (field.isValid() && this.activeField == 'stop') { | |
180 | 179 | // launch the update of duration fields |
181 | 180 | this.updateDuration(); |
182 | 181 | } |
... | ... | @@ -191,6 +190,7 @@ Ext.define('amdaUI.IntervalUI', { |
191 | 190 | xtype: 'datefield', |
192 | 191 | name: fieldName, |
193 | 192 | emptyText: 'YYYY/MM/DD hh:mm:ss', |
193 | + tip: 'Date formated as YYYY/MM/DD hh:mm:ss', | |
194 | 194 | format: 'Y/m/d H:i:s', |
195 | 195 | enforceMaxLength: true, |
196 | 196 | maxLength: 19, |
... | ... | @@ -202,6 +202,9 @@ Ext.define('amdaUI.IntervalUI', { |
202 | 202 | focus: function(field) { |
203 | 203 | this.activeField = fieldId; |
204 | 204 | }, |
205 | + render: function(c) { | |
206 | + Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip }); | |
207 | + }, | |
205 | 208 | scope : this |
206 | 209 | } |
207 | 210 | } |
... | ... | @@ -225,17 +228,22 @@ Ext.define('amdaUI.IntervalUI', { |
225 | 228 | layout: {type: 'hbox', align: 'middle'}, |
226 | 229 | margin: 0, |
227 | 230 | defaults: { |
228 | - xtype: 'textfield', | |
231 | + xtype: 'numberfield', | |
232 | + minValue: 0, | |
233 | + maxLength: 2, | |
234 | + enforceMaxLength: true, | |
235 | + decimalPrecision: 0, | |
236 | + allowExponential: false, | |
237 | + autoStripChars: true, | |
238 | + hideTrigger: true, | |
229 | 239 | labelAlign: 'left', |
230 | - width: 35, | |
240 | + width: 32, | |
231 | 241 | margin: '0 5 0 0', |
232 | - allowBlank: false, maxLength:2, enforceMaxLength : true, | |
233 | - hideTrigger: true, | |
234 | - regex: /^[0-9]([0-9])*$/i, | |
235 | 242 | listeners: { |
236 | - change: function(field, newValue, oldValue){ | |
237 | - if (this.isValidDuration() && oldValue != null && this.activeField == 'duration') { | |
238 | - // launch the update of stop datefield | |
243 | + change: function(field, newValue, oldValue) { | |
244 | + var form = this.findParentByType('form').getForm(); | |
245 | + var start = form.findField('startDate').getValue(); | |
246 | + if (this.isValidDuration() && start!=null && this.activeField == 'duration') { | |
239 | 247 | this.updateStop(); |
240 | 248 | } |
241 | 249 | }, |
... | ... | @@ -243,25 +251,22 @@ Ext.define('amdaUI.IntervalUI', { |
243 | 251 | this.activeField = 'duration'; |
244 | 252 | }, |
245 | 253 | render: function(c) { |
246 | - Ext.create('Ext.tip.ToolTip', { | |
247 | - target: c.getEl(), | |
248 | - html: c.tip | |
249 | - }); | |
254 | + Ext.create('Ext.tip.ToolTip', { target: c.getEl(), html: c.tip }); | |
250 | 255 | }, |
251 | 256 | scope : this |
252 | 257 | } |
253 | 258 | }, |
254 | 259 | items:[ |
255 | - { name: 'durationDay', tip: 'Days', fieldLabel: 'Duration', labelWidth: 60, emptyText: 'Days', width: 100, maxLength: ('' + this.durationLimit).length}, | |
256 | - { name: 'durationHour', tip: 'Hours', emptyText: 'Hrs'}, | |
257 | - { name: 'durationMin', tip: 'Minutes', emptyText: 'Mins'}, | |
258 | - { name: 'durationSec', tip: 'Seconds', emptyText: 'Secs'} | |
260 | + { name: 'durationDay', emptyText: 'Days', tip: 'Days', maxValue: 36500, maxLength: 5, fieldLabel: 'Duration', labelWidth: 60, width: 110, }, | |
261 | + { name: 'durationHour', emptyText: 'Hrs', tip: 'Hours', maxValue: 23}, | |
262 | + { name: 'durationMin', emptyText: 'Mins', tip: 'Minutes', maxValue: 59}, | |
263 | + { name: 'durationSec', emptyText: 'Secs', tip: 'Seconds', maxValue: 59} | |
259 | 264 | ] |
260 | 265 | }; |
261 | 266 | }, |
262 | 267 | |
263 | 268 | init : function(config) { |
264 | - this.durationLimit = config.durationLimit == null ? 9999 : config.durationLimit; // Set duration limit to 9999 by default | |
269 | + this.durationLimit = config.durationLimit == null ? 36500 : config.durationLimit; // Set duration limit to 100 years by default | |
265 | 270 | |
266 | 271 | var me = this; |
267 | 272 | ... | ... |