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.language = this.language || 'en';
79 // this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
80 // this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
82 // this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
83 // this.format = this.format || 'm/d/y';
84 // this.isInline = false;
85 // this.isInput = true;
86 // this.component = this.el.select('.add-on', true).first() || false;
87 // this.component = (this.component && this.component.length === 0) ? false : this.component;
88 // this.hasInput = this.component && this.inputEL().length;
90 // if (typeof(this.minViewMode === 'string')) {
91 // switch (this.minViewMode) {
93 // this.minViewMode = 2;
96 // this.minViewMode = 3;
99 // this.minViewMode = 1;
102 // this.minViewMode = 0;
107 // if (typeof(this.viewMode === 'string')) {
108 // switch (this.viewMode) {
110 // this.viewMode = 2;
113 // this.viewMode = 2;
116 // this.viewMode = 1;
119 // this.viewMode = 0;
124 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
126 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
128 this.pop = this.picker().select('>.datepicker-time',true).first();
129 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block'
131 this.picker().on('mousedown', this.onMousedown, this);
132 this.picker().on('click', this.onClick, this);
134 this.picker().addClass('datepicker-dropdown');
136 // this.startViewMode = this.viewMode;
138 // this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
140 // this.setStartDate(this.startDate);
141 // this.setEndDate(this.endDate);
143 // this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
146 // this.fillMonths();
151 // if(this.showTime){
153 // var dayFoot = this.picker().select('>.datepicker-days tfoot th', true).first();
154 // var timeFoot = this.picker().select('>.datepicker-time tfoot th', true).first();
156 // var dayFootIcon = this.picker().select('>.datepicker-days tfoot span.picker-switch-icon', true).first();
157 // var timeFootIcon = this.picker().select('>.datepicker-time tfoot span.picker-switch-icon', true).first();
159 // timeFoot.addClass('switch-calendar');
160 // dayFoot.addClass('switch-time');
162 // timeFootIcon.addClass('switch-calendar');
163 // timeFootIcon.addClass('glyphicon-calendar');
165 // dayFootIcon.addClass('switch-time');
166 // dayFootIcon.addClass('glyphicon-time');
168 this.pop.select('>span.hours-up', true).first().on('click', this.onIncrementHours, this);
169 this.pop.select('>span.hours-down', true).first().on('click', this.onDecrementHours, this);
170 this.pop.select('>span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
171 this.pop.select('>span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
172 this.pop.select('>button', true).first().on('click', this.onTogglePeriod, this);
175 // Roo.each(this.picker().select('tfoot th', true).elements, function(v){
180 // if(this.isInline) {
187 return this.el.select('.datepicker', true).first();
193 var time = this.pop.select('tbody', true).first();
195 time.dom.innerHTML = '';
210 cls: 'hours-up glyphicon glyphicon-chevron-up'
230 cls: 'minutes-up glyphicon glyphicon-chevron-up'
251 cls: 'timepicker-hour',
266 cls: 'timepicker-minute',
281 cls: 'btn btn-primary',
303 cls: 'hours-down glyphicon glyphicon-chevron-down'
323 cls: 'minutes-down glyphicon glyphicon-chevron-down'
341 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
348 var hours = this.time.getHours();
349 var minutes = this.time.getMinutes();
357 this.pop.select('>.timepicker-hour', true).first().el.dom.innerHTML = hours;
358 this.pop.select('>.timepicker-minute', true).first().el.dom.innerHTML = minutes;
359 this.pop.select('>button', true).first().el.dom.innerHTML = period;
363 // showMode: function(dir) {
365 // this.viewMode = Math.max(this.minViewMode, Math.min(3, this.viewMode + dir));
368 // Roo.each(this.picker().select('>div',true).elements, function(v){
369 // v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
372 // this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
378 // if(this.isInline) return;
380 this.picker().removeClass(['bottom', 'top']);
382 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
384 * place to the top of element!
388 this.picker().addClass('top');
389 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
394 this.picker().addClass('bottom');
396 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
399 // parseDate : function(value){
400 // if(!value || value instanceof Date){
403 // var v = Date.parseDate(value, this.format);
404 // if (!v && this.useIso) {
405 // v = Date.parseDate(value, 'Y-m-d');
407 // if(!v && this.altFormats){
408 // if(!this.altFormatsArray){
409 // this.altFormatsArray = this.altFormats.split("|");
411 // for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
412 // v = Date.parseDate(value, this.altFormatsArray[i]);
418 // formatDate : function(date, fmt){
419 // return (!date || !(date instanceof Date)) ?
420 // date : date.dateFormat(fmt || this.format);
425 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
431 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
437 this.picker().show();
445 this.picker().hide();
450 onMousedown: function(e){
455 // keyup: function(e){
456 // Roo.bootstrap.DateField.superclass.keyup.call(this);
461 // fireKey: function(e){
462 // if (!this.picker().isVisible()){
463 // if (e.keyCode == 27) // allow escape to hide and re-show picker
467 // var dateChanged = false,
469 // newDate, newViewDate;
470 // switch(e.keyCode){
471 // case 27: // escape
473 // e.preventDefault();
477 // if (!this.keyboardNavigation) break;
478 // dir = e.keyCode == 37 ? -1 : 1;
481 // newDate = this.moveYear(this.date, dir);
482 // newViewDate = this.moveYear(this.viewDate, dir);
483 // } else if (e.shiftKey){
484 // newDate = this.moveMonth(this.date, dir);
485 // newViewDate = this.moveMonth(this.viewDate, dir);
487 // newDate = new Date(this.date);
488 // newDate.setUTCDate(this.date.getUTCDate() + dir);
489 // newViewDate = new Date(this.viewDate);
490 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
492 // if (this.dateWithinRange(newDate)){
493 // this.date = newDate;
494 // this.viewDate = newViewDate;
495 // this.setValue(this.formatDate(this.date));
497 // e.preventDefault();
498 // dateChanged = true;
503 // if (!this.keyboardNavigation) break;
504 // dir = e.keyCode == 38 ? -1 : 1;
506 // newDate = this.moveYear(this.date, dir);
507 // newViewDate = this.moveYear(this.viewDate, dir);
508 // } else if (e.shiftKey){
509 // newDate = this.moveMonth(this.date, dir);
510 // newViewDate = this.moveMonth(this.viewDate, dir);
512 // newDate = new Date(this.date);
513 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
514 // newViewDate = new Date(this.viewDate);
515 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
517 // if (this.dateWithinRange(newDate)){
518 // this.date = newDate;
519 // this.viewDate = newViewDate;
520 // this.setValue(this.formatDate(this.date));
522 // e.preventDefault();
523 // dateChanged = true;
527 // this.setValue(this.formatDate(this.date));
529 // e.preventDefault();
532 // this.setValue(this.formatDate(this.date));
539 onClick: function(e) {
543 var target = e.getTarget();
545 // if(target.nodeName.toLowerCase() === 'i'){
546 // target = Roo.get(target).dom.parentNode;
549 var nodeName = target.nodeName.trim();
550 var className = target.className.trim();
551 var html = target.innerHTML;
556 Roo.log('className');
563 // switch(nodeName.toLowerCase()) {
565 // switch(className) {
571 // var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
572 // switch(this.viewMode){
574 // this.viewDate = this.moveMonth(this.viewDate, dir);
578 // this.viewDate = this.moveYear(this.viewDate, dir);
584 // var date = new Date();
585 // this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
587 // this.setValue(this.formatDate(this.date));
590 // case 'switch-time':
591 // this.showMode(-1);
594 // case 'switch-calendar':
601 // if (className.indexOf('disabled') === -1) {
602 // this.viewDate.setUTCDate(1);
603 // if (className.indexOf('month') !== -1) {
604 // this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
605 // } else if(className.indexOf('picker-switch-icon') !== -1){
606 // if(className.indexOf('switch-time') !== -1){
607 // this.showMode(-1);
617 // var year = parseInt(html, 10) || 0;
618 // this.viewDate.setUTCFullYear(year);
621 // this.showMode(-1);
627 // if (className.indexOf('day') !== -1 && className.indexOf('disabled') === -1){
628 // var day = parseInt(html, 10) || 1;
629 // var year = this.viewDate.getUTCFullYear(),
630 // month = this.viewDate.getUTCMonth();
632 // if (className.indexOf('old') !== -1) {
639 // } else if (className.indexOf('new') !== -1) {
640 // if (month == 11) {
647 // this.date = this.UTCDate(year, month, day,0,0,0,0);
648 // this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
650 // this.setValue(this.formatDate(this.date));
657 // setStartDate: function(startDate){
658 // this.startDate = startDate || -Infinity;
659 // if (this.startDate !== -Infinity) {
660 // this.startDate = this.parseDate(this.startDate);
663 // this.updateNavArrows();
666 // setEndDate: function(endDate){
667 // this.endDate = endDate || Infinity;
668 // if (this.endDate !== Infinity) {
669 // this.endDate = this.parseDate(this.endDate);
672 // this.updateNavArrows();
675 // setDaysOfWeekDisabled: function(daysOfWeekDisabled){
676 // this.daysOfWeekDisabled = daysOfWeekDisabled || [];
677 // if (typeof(this.daysOfWeekDisabled) !== 'object') {
678 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
680 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
681 // return parseInt(d, 10);
684 // this.updateNavArrows();
687 // updateNavArrows: function() {
688 // var d = new Date(this.viewDate),
689 // year = d.getUTCFullYear(),
690 // month = d.getUTCMonth();
692 // Roo.each(this.picker().select('.prev', true).elements, function(v){
694 // switch (this.viewMode) {
697 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
703 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
710 // Roo.each(this.picker().select('.next', true).elements, function(v){
712 // switch (this.viewMode) {
715 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
721 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
729 // moveMonth: function(date, dir){
730 // if (!dir) return date;
731 // var new_date = new Date(date.valueOf()),
732 // day = new_date.getUTCDate(),
733 // month = new_date.getUTCMonth(),
734 // mag = Math.abs(dir),
736 // dir = dir > 0 ? 1 : -1;
739 // // If going back one month, make sure month is not current month
740 // // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
742 // return new_date.getUTCMonth() == month;
744 // // If going forward one month, make sure month is as expected
745 // // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
747 // return new_date.getUTCMonth() != new_month;
749 // new_month = month + dir;
750 // new_date.setUTCMonth(new_month);
751 // // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
752 // if (new_month < 0 || new_month > 11)
753 // new_month = (new_month + 12) % 12;
755 // // For magnitudes >1, move one month at a time...
756 // for (var i=0; i<mag; i++)
757 // // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
758 // new_date = this.moveMonth(new_date, dir);
759 // // ...then reset the day, keeping it in the new month
760 // new_month = new_date.getUTCMonth();
761 // new_date.setUTCDate(day);
762 // test = function(){
763 // return new_month != new_date.getUTCMonth();
766 // // Common date-resetting loop -- if date is beyond end of month, make it
769 // new_date.setUTCDate(--day);
770 // new_date.setUTCMonth(new_month);
775 // moveYear: function(date, dir){
776 // return this.moveMonth(date, dir*12);
779 // dateWithinRange: function(date){
780 // return date >= this.startDate && date <= this.endDate;
783 // remove: function() {
784 // this.picker().remove();
787 onIncrementHours: function()
789 Roo.log('onIncrementHours');
792 onDecrementHours: function()
794 Roo.log('onDecrementHours');
797 onIncrementMinutes: function()
799 Roo.log('onIncrementMinutes');
802 onDecrementMinutes: function()
804 Roo.log('onDecrementMinutes');
807 onTogglePeriod: function()
809 Roo.log('onTogglePeriod');
815 Roo.apply(Roo.bootstrap.TimeField, {
833 Roo.apply(Roo.bootstrap.TimeField, {
837 cls: 'datepicker dropdown-menu',
841 cls: 'datepicker-time',
845 cls: 'table-condensed',
847 Roo.bootstrap.DateField.content