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);
24 * Fires when this field show.
25 * @param {Roo.bootstrap.DateField} this
26 * @param {Mixed} date The date value
31 * Fires when this field hide.
32 * @param {Roo.bootstrap.DateField} this
33 * @param {Mixed} date The date value
38 * Fires when select a date.
39 * @param {Roo.bootstrap.DateField} this
40 * @param {Mixed} date The date value
46 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
49 * @cfg {String} format
50 * The default time format string which can be overriden for localization support. The format must be
51 * valid according to {@link Date#parseDate} (defaults to 'H:i').
55 onRender: function(ct, position)
58 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
60 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
62 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
64 this.pop = this.picker().select('>.datepicker-time',true).first();
65 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block'
67 this.picker().on('mousedown', this.onMousedown, this);
68 this.picker().on('click', this.onClick, this);
70 this.picker().addClass('datepicker-dropdown');
75 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
76 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
77 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
78 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
79 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
80 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
85 if (!this.picker().isVisible()){
86 if (e.keyCode == 27) // allow escape to hide and re-show picker
99 this.onTogglePeriod();
102 this.onIncrementMinutes();
105 this.onDecrementMinutes();
114 onClick: function(e) {
121 return this.el.select('.datepicker', true).first();
126 var time = this.pop.select('tbody', true).first();
128 time.dom.innerHTML = '';
143 cls: 'hours-up glyphicon glyphicon-chevron-up'
163 cls: 'minutes-up glyphicon glyphicon-chevron-up'
184 cls: 'timepicker-hour',
199 cls: 'timepicker-minute',
214 cls: 'btn btn-primary period',
236 cls: 'hours-down glyphicon glyphicon-chevron-down'
256 cls: 'minutes-down glyphicon glyphicon-chevron-down'
274 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
281 var hours = this.time.getHours();
282 var minutes = this.time.getMinutes();
303 minutes = '0' + minutes;
306 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
307 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
308 this.pop.select('button', true).first().dom.innerHTML = period;
314 this.picker().removeClass(['bottom', 'top']);
316 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
318 * place to the top of element!
322 this.picker().addClass('top');
323 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
328 this.picker().addClass('bottom');
330 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
335 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
341 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
347 this.picker().show();
352 this.fireEvent('show', this, this.date);
357 this.picker().hide();
365 this.setValue(this.time.format(this.format));
367 this.fireEvent('select', this, this.date);
372 onMousedown: function(e){
377 onIncrementHours: function()
379 Roo.log('onIncrementHours');
380 this.time = this.time.add(Date.HOUR, 1);
385 onDecrementHours: function()
387 Roo.log('onDecrementHours');
388 this.time = this.time.add(Date.HOUR, -1);
392 onIncrementMinutes: function()
394 Roo.log('onIncrementMinutes');
395 this.time = this.time.add(Date.MINUTE, 1);
399 onDecrementMinutes: function()
401 Roo.log('onDecrementMinutes');
402 this.time = this.time.add(Date.MINUTE, -1);
406 onTogglePeriod: function()
408 Roo.log('onTogglePeriod');
409 this.time = this.time.add(Date.HOUR, 12);
416 Roo.apply(Roo.bootstrap.TimeField, {
446 cls: 'btn btn-info ok',
458 Roo.apply(Roo.bootstrap.TimeField, {
462 cls: 'datepicker dropdown-menu',
466 cls: 'datepicker-time',
470 cls: 'table-condensed',
472 Roo.bootstrap.TimeField.content,
473 Roo.bootstrap.TimeField.footer