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 return Roo.bootstrap.TimeField.superclass.getAutoCreate.call(this);
62 onRender: function(ct, position)
65 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
67 this.pickerEl = Roo.get(document.body).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('.hours-up', true).first().on('click', this.onIncrementHours, this);
83 this.pop.select('.hours-down', true).first().on('click', this.onDecrementHours, this);
84 this.pop.select('.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
85 this.pop.select('.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.pickerEl;
134 var time = this.pop.select('tbody', true).first();
136 time.dom.innerHTML = '';
151 cls: 'hours-up fa fas fa-chevron-up'
171 cls: 'minutes-up fa fas fa-chevron-up'
192 cls: 'timepicker-hour',
207 cls: 'timepicker-minute',
222 cls: 'btn btn-primary period',
244 cls: 'hours-down fa fas fa-chevron-down'
264 cls: 'minutes-down fa fas fa-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
337 //this.picker().setXY(20000,20000);
338 this.picker().addClass(cls.join('-'));
342 Roo.each(cls, function(c){
347 _this.picker().alignTo(_this.inputEl(), "tr-br", [0, 10], false);
348 //_this.picker().setTop(_this.inputEl().getHeight());
352 _this.picker().alignTo(_this.inputEl(), "br-tr", [0, 10], false);
354 //_this.picker().setTop(0 - _this.picker().getHeight());
359 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
363 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
373 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
379 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
385 this.picker().show();
390 this.fireEvent('show', this, this.date);
395 this.picker().hide();
398 this.fireEvent('hide', this, this.date);
404 this.setValue(this.time.format(this.format));
406 this.fireEvent('select', this, this.date);
411 onMousedown: function(e){
416 onIncrementHours: function()
418 Roo.log('onIncrementHours');
419 this.time = this.time.add(Date.HOUR, 1);
424 onDecrementHours: function()
426 Roo.log('onDecrementHours');
427 this.time = this.time.add(Date.HOUR, -1);
431 onIncrementMinutes: function()
433 Roo.log('onIncrementMinutes');
434 this.time = this.time.add(Date.MINUTE, 1);
438 onDecrementMinutes: function()
440 Roo.log('onDecrementMinutes');
441 this.time = this.time.add(Date.MINUTE, -1);
445 onTogglePeriod: function()
447 Roo.log('onTogglePeriod');
448 this.time = this.time.add(Date.HOUR, 12);
456 Roo.apply(Roo.bootstrap.TimeField, {
460 cls: 'datepicker dropdown-menu',
464 cls: 'datepicker-time',
468 cls: 'table-condensed',
497 cls: 'btn btn-info ok',