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} this
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
99 this.onTogglePeriod();
102 this.onIncrementMinutes();
105 this.onDecrementMinutes();
114 onClick: function(e) {
121 return this.el.select('.datepicker', true).first();
126 var time = this.pop.select('tbody', true).first();
128 time.dom.innerHTML = '';
143 cls: 'hours-up glyphicon glyphicon-chevron-up'
163 cls: 'minutes-up glyphicon glyphicon-chevron-up'
184 cls: 'timepicker-hour',
199 cls: 'timepicker-minute',
214 cls: 'btn btn-primary period',
236 cls: 'hours-down glyphicon glyphicon-chevron-down'
256 cls: 'minutes-down glyphicon glyphicon-chevron-down'
274 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
281 var hours = this.time.getHours();
282 var minutes = this.time.getMinutes();
303 minutes = '0' + minutes;
306 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
307 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
308 this.pop.select('button', true).first().dom.innerHTML = period;
314 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
316 var cls = ['bottom'];
318 Roo.log('run!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1');
319 Roo.log(Roo.lib.Dom.getViewWidth());
320 Roo.log(Roo.get(document.body).getScroll());
321 Roo.log(this.inputEl().getLeft());
322 Roo.log(this.picker().getWidth());
324 Roo.log(this.el.getLeft());
325 Roo.log(this.inputEl());
326 Roo.log(this.inputEl().getLeft());
327 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
334 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
339 this.picker().addClass(cls.join('-'));
341 Roo.each(cls, function(c){
343 this.picker().setTop(this.inputEl().getHeight());
347 this.picker().setTop(0 - this.picker().getHeight());
352 this.picker().setLeft(this.inputEl().getLeft() - this.el.getLeft());
356 this.picker().setLeft(this.inputEl().getLeft() - this.el.getLeft());
361 // this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
362 // this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
367 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
373 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
379 this.picker().show();
384 this.fireEvent('show', this, this.date);
389 this.picker().hide();
392 this.fireEvent('hide', this, this.date);
398 this.setValue(this.time.format(this.format));
400 this.fireEvent('select', this, this.date);
405 onMousedown: function(e){
410 onIncrementHours: function()
412 Roo.log('onIncrementHours');
413 this.time = this.time.add(Date.HOUR, 1);
418 onDecrementHours: function()
420 Roo.log('onDecrementHours');
421 this.time = this.time.add(Date.HOUR, -1);
425 onIncrementMinutes: function()
427 Roo.log('onIncrementMinutes');
428 this.time = this.time.add(Date.MINUTE, 1);
432 onDecrementMinutes: function()
434 Roo.log('onDecrementMinutes');
435 this.time = this.time.add(Date.MINUTE, -1);
439 onTogglePeriod: function()
441 Roo.log('onTogglePeriod');
442 this.time = this.time.add(Date.HOUR, 12);
449 Roo.apply(Roo.bootstrap.TimeField, {
479 cls: 'btn btn-info ok',
491 Roo.apply(Roo.bootstrap.TimeField, {
495 cls: 'datepicker dropdown-menu',
499 cls: 'datepicker-time',
503 cls: 'table-condensed',
505 Roo.bootstrap.TimeField.content,
506 Roo.bootstrap.TimeField.footer