9 * @class Roo.bootstrap.form.TimeField
10 * @extends Roo.bootstrap.form.Input
11 * Bootstrap DateField class
12 * @cfg {Number} minuteStep the minutes is always the multiple of a fixed number, default 1
16 * Create a new TimeField
17 * @param {Object} config The config object
20 Roo.bootstrap.form.TimeField = function(config){
21 Roo.bootstrap.form.TimeField.superclass.constructor.call(this, config);
25 * Fires when this field show.
26 * @param {Roo.bootstrap.form.DateField} thisthis
27 * @param {Mixed} date The date value
32 * Fires when this field hide.
33 * @param {Roo.bootstrap.form.DateField} this
34 * @param {Mixed} date The date value
39 * Fires when select a date.
40 * @param {Roo.bootstrap.form.DateField} this
41 * @param {Mixed} date The date value
47 Roo.extend(Roo.bootstrap.form.TimeField, Roo.bootstrap.form.Input, {
50 * @cfg {String} format
51 * The default time format string which can be overriden for localization support. The format must be
52 * valid according to {@link Date#parseDate} (defaults to 'H:i').
57 getAutoCreate : function()
59 this.after = '<i class="fa far fa-clock"></i>';
60 return Roo.bootstrap.form.TimeField.superclass.getAutoCreate.call(this);
64 onRender: function(ct, position)
67 Roo.bootstrap.form.TimeField.superclass.onRender.call(this, ct, position);
69 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.TimeField.template);
71 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
73 this.pop = this.picker().select('>.datepicker-time',true).first();
74 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
76 this.picker().on('mousedown', this.onMousedown, this);
77 this.picker().on('click', this.onClick, this);
79 this.picker().addClass('datepicker-dropdown');
84 this.pop.select('.hours-up', true).first().on('click', this.onIncrementHours, this);
85 this.pop.select('.hours-down', true).first().on('click', this.onDecrementHours, this);
86 this.pop.select('.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
87 this.pop.select('.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
88 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
89 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
94 if (!this.picker().isVisible()){
95 if (e.keyCode == 27) { // allow escape to hide and re-show picker
109 this.onTogglePeriod();
112 this.onIncrementMinutes();
115 this.onDecrementMinutes();
124 onClick: function(e) {
131 return this.pickerEl;
136 var time = this.pop.select('tbody', true).first();
138 time.dom.innerHTML = '';
153 cls: 'hours-up fa fas fa-chevron-up'
173 cls: 'minutes-up fa fas fa-chevron-up'
194 cls: 'timepicker-hour',
209 cls: 'timepicker-minute',
224 cls: 'btn btn-primary period',
246 cls: 'hours-down fa fas fa-chevron-down'
266 cls: 'minutes-down fa fas fa-chevron-down'
284 if(typeof(this.time) === 'undefined') {
285 var now = new Date();
286 var oldMinute = parseInt(now.format('i'));
287 var newMinute = Math.round(parseInt(now.format('i')) / this.minuteStep) * this.minuteStep;
291 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
298 var hours = this.time.getHours();
299 var minutes = this.time.getMinutes();
320 minutes = '0' + minutes;
323 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
324 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
325 this.pop.select('button', true).first().dom.innerHTML = period;
331 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
333 var cls = ['bottom'];
335 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
342 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
346 //this.picker().setXY(20000,20000);
347 this.picker().addClass(cls.join('-'));
351 Roo.each(cls, function(c){
356 _this.picker().alignTo(_this.inputEl(), "tr-br", [0, 10], false);
357 //_this.picker().setTop(_this.inputEl().getHeight());
361 _this.picker().alignTo(_this.inputEl(), "br-tr", [0, 10], false);
363 //_this.picker().setTop(0 - _this.picker().getHeight());
368 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
372 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
382 Roo.bootstrap.form.TimeField.superclass.onFocus.call(this);
388 Roo.bootstrap.form.TimeField.superclass.onBlur.call(this);
394 this.picker().show();
399 this.fireEvent('show', this, this.date);
404 this.picker().hide();
407 this.fireEvent('hide', this, this.date);
413 this.setValue(this.time.format(this.format));
415 this.fireEvent('select', this, this.date);
420 onMousedown: function(e){
425 onIncrementHours: function()
427 Roo.log('onIncrementHours');
428 this.time = this.time.add(Date.HOUR, 1);
433 onDecrementHours: function()
435 Roo.log('onDecrementHours');
436 this.time = this.time.add(Date.HOUR, -1);
440 onIncrementMinutes: function()
442 Roo.log('onIncrementMinutes');
443 var minutesToAdd = Math.round((parseInt(this.time.format('i')) + this.minuteStep) / this.minuteStep) * this.minuteStep - parseInt(this.time.format('i'));
444 this.time = this.time.add(Date.MINUTE, minutesToAdd);
448 onDecrementMinutes: function()
450 Roo.log('onDecrementMinutes');
451 var minutesToSubtract = parseInt(this.time.format('i')) - Math.round((parseInt(this.time.format('i')) - this.minuteStep) / this.minuteStep) * this.minuteStep;
452 this.time = this.time.add(Date.MINUTE, -1 * minutesToSubtract);
456 onTogglePeriod: function()
458 Roo.log('onTogglePeriod');
459 this.time = this.time.add(Date.HOUR, 12);
467 Roo.apply(Roo.bootstrap.form.TimeField, {
471 cls: 'datepicker dropdown-menu',
475 cls: 'datepicker-time',
479 cls: 'table-condensed',
508 cls: 'btn btn-info ok',