9 * @class Roo.bootstrap.TimeField
10 * @extends Roo.bootstrap.Input
11 * Bootstrap DateField class
15 * Create a new TimeField
16 * @param {Object} config The config object
19 Roo.bootstrap.TimeField = function(config){
20 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
23 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
26 * @cfg {String} format
27 * The default time format string which can be overriden for localization support. The format must be
28 * valid according to {@link Date#parseDate} (defaults to 'H:i').
35 return new Date(Date.UTC.apply(Date, arguments));
40 return new Date(Date.UTC.apply(Date, arguments));
45 var today = new Date();
46 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
49 UTCTodayTime: function()
51 var today = new Date();
52 return this.UTCTime(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), today.getUTCHours(), today.getUTCMinutes());
56 var d = this.getUTCDate();
57 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
60 getUTCDate: function() {
64 setDate: function(d) {
65 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
68 setUTCDate: function(d) {
70 this.setValue(this.formatDate(this.date));
73 onRender: function(ct, position)
76 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
78 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
80 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
82 this.pop = this.picker().select('>.datepicker-time',true).first();
83 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block'
85 this.picker().on('mousedown', this.onMousedown, this);
86 this.picker().on('click', this.onClick, this);
88 this.picker().addClass('datepicker-dropdown');
93 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
94 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
95 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
96 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
97 this.pop.select('button', true).first().on('click', this.onTogglePeriod, this);
103 return this.el.select('.datepicker', true).first();
108 var time = this.pop.select('tbody', true).first();
110 time.dom.innerHTML = '';
125 cls: 'hours-up glyphicon glyphicon-chevron-up'
145 cls: 'minutes-up glyphicon glyphicon-chevron-up'
166 cls: 'timepicker-hour',
181 cls: 'timepicker-minute',
196 cls: 'btn btn-primary',
218 cls: 'hours-down glyphicon glyphicon-chevron-down'
238 cls: 'minutes-down glyphicon glyphicon-chevron-down'
256 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
263 var hours = this.time.getHours();
264 var minutes = this.time.getMinutes();
285 minutes = '0' + minutes;
288 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
289 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
290 this.pop.select('button', true).first().dom.innerHTML = period;
296 this.picker().removeClass(['bottom', 'top']);
298 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
300 * place to the top of element!
304 this.picker().addClass('top');
305 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
310 this.picker().addClass('bottom');
312 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
317 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
323 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
329 this.picker().show();
337 this.picker().hide();
340 this.setValue(this.time.format(this.format));
344 onMousedown: function(e){
349 onIncrementHours: function()
351 Roo.log('onIncrementHours');
352 this.time = this.time.add(Date.HOUR, 1);
357 onDecrementHours: function()
359 Roo.log('onDecrementHours');
360 this.time = this.time.add(Date.HOUR, -1);
364 onIncrementMinutes: function()
366 Roo.log('onIncrementMinutes');
367 this.time = this.time.add(Date.MINUTE, 1);
371 onDecrementMinutes: function()
373 Roo.log('onDecrementMinutes');
374 this.time = this.time.add(Date.MINUTE, -1);
378 onTogglePeriod: function()
380 Roo.log('onTogglePeriod');
381 this.time = this.time.add(Date.HOUR, 12);
388 Roo.apply(Roo.bootstrap.TimeField, {
406 Roo.apply(Roo.bootstrap.TimeField, {
410 cls: 'datepicker dropdown-menu',
414 cls: 'datepicker-time',
418 cls: 'table-condensed',
420 Roo.bootstrap.DateField.content