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').
32 onRender: function(ct, position)
35 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
37 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
39 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
41 this.pop = this.picker().select('>.datepicker-time',true).first();
42 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block'
44 this.picker().on('mousedown', this.onMousedown, this);
45 this.picker().on('click', this.onClick, this);
47 this.picker().addClass('datepicker-dropdown');
52 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
53 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
54 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
55 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
56 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
57 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
62 if (!this.picker().isVisible()){
63 if (e.keyCode == 27) // allow escape to hide and re-show picker
76 this.onTogglePeriod();
79 this.onIncrementMinutes();
82 this.onDecrementMinutes();
91 onClick: function(e) {
98 return this.el.select('.datepicker', true).first();
103 var time = this.pop.select('tbody', true).first();
105 time.dom.innerHTML = '';
120 cls: 'hours-up glyphicon glyphicon-chevron-up'
140 cls: 'minutes-up glyphicon glyphicon-chevron-up'
161 cls: 'timepicker-hour',
176 cls: 'timepicker-minute',
191 cls: 'btn btn-primary period',
213 cls: 'hours-down glyphicon glyphicon-chevron-down'
233 cls: 'minutes-down glyphicon glyphicon-chevron-down'
251 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
258 var hours = this.time.getHours();
259 var minutes = this.time.getMinutes();
280 minutes = '0' + minutes;
283 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
284 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
285 this.pop.select('button', true).first().dom.innerHTML = period;
291 this.picker().removeClass(['bottom', 'top']);
293 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
295 * place to the top of element!
299 this.picker().addClass('top');
300 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
305 this.picker().addClass('bottom');
307 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
312 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
318 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
324 this.picker().show();
332 this.picker().hide();
340 this.setValue(this.time.format(this.format));
343 onMousedown: function(e){
348 onIncrementHours: function()
350 Roo.log('onIncrementHours');
351 this.time = this.time.add(Date.HOUR, 1);
356 onDecrementHours: function()
358 Roo.log('onDecrementHours');
359 this.time = this.time.add(Date.HOUR, -1);
363 onIncrementMinutes: function()
365 Roo.log('onIncrementMinutes');
366 this.time = this.time.add(Date.MINUTE, 1);
370 onDecrementMinutes: function()
372 Roo.log('onDecrementMinutes');
373 this.time = this.time.add(Date.MINUTE, -1);
377 onTogglePeriod: function()
379 Roo.log('onTogglePeriod');
380 this.time = this.time.add(Date.HOUR, 12);
387 Roo.apply(Roo.bootstrap.TimeField, {
417 cls: 'btn btn-info ok',
429 Roo.apply(Roo.bootstrap.TimeField, {
433 cls: 'datepicker dropdown-menu',
437 cls: 'datepicker-time',
441 cls: 'table-condensed',
443 Roo.bootstrap.TimeField.content,
444 Roo.bootstrap.TimeField.footer