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 getAutoCreate : function()
57 this.after = '<i class="fa far fa-clock"></i>';
58 Roo.bootstrap.TimeField.superclass.getAutoCreate.call(this);
62 onRender: function(ct, position)
65 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
67 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
69 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
71 this.pop = this.picker().select('>.datepicker-time',true).first();
72 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
74 this.picker().on('mousedown', this.onMousedown, this);
75 this.picker().on('click', this.onClick, this);
77 this.picker().addClass('datepicker-dropdown');
82 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
83 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
84 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
85 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
86 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
87 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
92 if (!this.picker().isVisible()){
93 if (e.keyCode == 27) { // allow escape to hide and re-show picker
107 this.onTogglePeriod();
110 this.onIncrementMinutes();
113 this.onDecrementMinutes();
122 onClick: function(e) {
129 return this.el.select('.datepicker', true).first();
134 var time = this.pop.select('tbody', true).first();
136 time.dom.innerHTML = '';
151 cls: 'hours-up glyphicon glyphicon-chevron-up'
171 cls: 'minutes-up glyphicon glyphicon-chevron-up'
192 cls: 'timepicker-hour',
207 cls: 'timepicker-minute',
222 cls: 'btn btn-primary period',
244 cls: 'hours-down glyphicon glyphicon-chevron-down'
264 cls: 'minutes-down glyphicon glyphicon-chevron-down'
282 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
289 var hours = this.time.getHours();
290 var minutes = this.time.getMinutes();
311 minutes = '0' + minutes;
314 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
315 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
316 this.pop.select('button', true).first().dom.innerHTML = period;
322 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
324 var cls = ['bottom'];
326 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
333 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
338 this.picker().addClass(cls.join('-'));
342 Roo.each(cls, function(c){
344 _this.picker().setTop(_this.inputEl().getHeight());
348 _this.picker().setTop(0 - _this.picker().getHeight());
353 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
357 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
366 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
372 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
378 this.picker().show();
383 this.fireEvent('show', this, this.date);
388 this.picker().hide();
391 this.fireEvent('hide', this, this.date);
397 this.setValue(this.time.format(this.format));
399 this.fireEvent('select', this, this.date);
404 onMousedown: function(e){
409 onIncrementHours: function()
411 Roo.log('onIncrementHours');
412 this.time = this.time.add(Date.HOUR, 1);
417 onDecrementHours: function()
419 Roo.log('onDecrementHours');
420 this.time = this.time.add(Date.HOUR, -1);
424 onIncrementMinutes: function()
426 Roo.log('onIncrementMinutes');
427 this.time = this.time.add(Date.MINUTE, 1);
431 onDecrementMinutes: function()
433 Roo.log('onDecrementMinutes');
434 this.time = this.time.add(Date.MINUTE, -1);
438 onTogglePeriod: function()
440 Roo.log('onTogglePeriod');
441 this.time = this.time.add(Date.HOUR, 12);
448 Roo.apply(Roo.bootstrap.TimeField, {
478 cls: 'btn btn-info ok',
490 Roo.apply(Roo.bootstrap.TimeField, {
494 cls: 'datepicker dropdown-menu',
498 cls: 'datepicker-time',
502 cls: 'table-condensed',
504 Roo.bootstrap.TimeField.content,
505 Roo.bootstrap.TimeField.footer