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} thisthis
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
100 this.onTogglePeriod();
103 this.onIncrementMinutes();
106 this.onDecrementMinutes();
115 onClick: function(e) {
122 return this.el.select('.datepicker', true).first();
127 var time = this.pop.select('tbody', true).first();
129 time.dom.innerHTML = '';
144 cls: 'hours-up glyphicon glyphicon-chevron-up'
164 cls: 'minutes-up glyphicon glyphicon-chevron-up'
185 cls: 'timepicker-hour',
200 cls: 'timepicker-minute',
215 cls: 'btn btn-primary period',
237 cls: 'hours-down glyphicon glyphicon-chevron-down'
257 cls: 'minutes-down glyphicon glyphicon-chevron-down'
275 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
282 var hours = this.time.getHours();
283 var minutes = this.time.getMinutes();
304 minutes = '0' + minutes;
307 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
308 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
309 this.pop.select('button', true).first().dom.innerHTML = period;
315 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
317 var cls = ['bottom'];
319 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
326 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
331 this.picker().addClass(cls.join('-'));
335 Roo.each(cls, function(c){
337 _this.picker().setTop(_this.inputEl().getHeight());
341 _this.picker().setTop(0 - _this.picker().getHeight());
346 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
350 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
359 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
365 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
371 this.picker().show();
376 this.fireEvent('show', this, this.date);
381 this.picker().hide();
384 this.fireEvent('hide', this, this.date);
390 this.setValue(this.time.format(this.format));
392 this.fireEvent('select', this, this.date);
397 onMousedown: function(e){
402 onIncrementHours: function()
404 Roo.log('onIncrementHours');
405 this.time = this.time.add(Date.HOUR, 1);
410 onDecrementHours: function()
412 Roo.log('onDecrementHours');
413 this.time = this.time.add(Date.HOUR, -1);
417 onIncrementMinutes: function()
419 Roo.log('onIncrementMinutes');
420 this.time = this.time.add(Date.MINUTE, 1);
424 onDecrementMinutes: function()
426 Roo.log('onDecrementMinutes');
427 this.time = this.time.add(Date.MINUTE, -1);
431 onTogglePeriod: function()
433 Roo.log('onTogglePeriod');
434 this.time = this.time.add(Date.HOUR, 12);
441 Roo.apply(Roo.bootstrap.TimeField, {
471 cls: 'btn btn-info ok',
483 Roo.apply(Roo.bootstrap.TimeField, {
487 cls: 'datepicker dropdown-menu',
491 cls: 'datepicker-time',
495 cls: 'table-condensed',
497 Roo.bootstrap.TimeField.content,
498 Roo.bootstrap.TimeField.footer