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);
23 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
26 * @cfg {String} format
27 * The default time format string which can be overriden for localization support. The format must be
28 * valid according to {@link Date#parseDate} (defaults to 'H:i').
35 return new Date(Date.UTC.apply(Date, arguments));
40 return new Date(Date.UTC.apply(Date, arguments));
45 var today = new Date();
46 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
49 UTCTodayTime: function()
51 var today = new Date();
52 return this.UTCTime(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), today.getUTCHours(), today.getUTCMinutes());
56 var d = this.getUTCDate();
57 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
60 getUTCDate: function() {
64 setDate: function(d) {
65 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
68 setUTCDate: function(d) {
70 this.setValue(this.formatDate(this.date));
73 onRender: function(ct, position)
76 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
78 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
80 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
82 this.pop = this.picker().select('>.datepicker-time',true).first();
83 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block'
85 this.picker().on('mousedown', this.onMousedown, this);
87 this.picker().addClass('datepicker-dropdown');
92 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
93 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
94 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
95 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
96 this.pop.select('button', true).first().on('click', this.onTogglePeriod, this);
102 return this.el.select('.datepicker', true).first();
107 var time = this.pop.select('tbody', true).first();
109 time.dom.innerHTML = '';
124 cls: 'hours-up glyphicon glyphicon-chevron-up'
144 cls: 'minutes-up glyphicon glyphicon-chevron-up'
165 cls: 'timepicker-hour',
180 cls: 'timepicker-minute',
195 cls: 'btn btn-primary',
217 cls: 'hours-down glyphicon glyphicon-chevron-down'
237 cls: 'minutes-down glyphicon glyphicon-chevron-down'
255 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
262 var hours = this.time.getHours();
263 var minutes = this.time.getMinutes();
284 minutes = '0' + minutes;
287 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
288 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
289 this.pop.select('button', true).first().dom.innerHTML = period;
295 this.picker().removeClass(['bottom', 'top']);
297 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
299 * place to the top of element!
303 this.picker().addClass('top');
304 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
309 this.picker().addClass('bottom');
311 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
316 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
322 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
328 this.picker().show();
336 this.picker().hide();
339 this.setValue(this.time.format(this.format));
343 onMousedown: function(e){
348 onIncrementHours: function()
350 Roo.log('onIncrementHours');
351 this.time = this.time.add(Date.HOUR, 1);
356 onDecrementHours: function()
358 Roo.log('onDecrementHours');
359 this.time = this.time.add(Date.HOUR, -1);
363 onIncrementMinutes: function()
365 Roo.log('onIncrementMinutes');
366 this.time = this.time.add(Date.MINUTE, 1);
370 onDecrementMinutes: function()
372 Roo.log('onDecrementMinutes');
373 this.time = this.time.add(Date.MINUTE, -1);
377 onTogglePeriod: function()
379 Roo.log('onTogglePeriod');
380 this.time = this.time.add(Date.HOUR, 12);
387 Roo.apply(Roo.bootstrap.TimeField, {
417 cls: 'btn btn-info glyphicon glyphicon-ok'
428 Roo.apply(Roo.bootstrap.TimeField, {
432 cls: 'datepicker dropdown-menu',
436 cls: 'datepicker-time',
440 cls: 'table-condensed',
442 Roo.bootstrap.TimeField.content,
443 Roo.bootstrap.TimeField.footer