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();
192 var time = this.pop.select('tbody', true).first();
194 time.dom.innerHTML = '';
209 cls: 'hours-up glyphicon glyphicon-chevron-up'
229 cls: 'minutes-up glyphicon glyphicon-chevron-up'
250 cls: 'timepicker-hour',
265 cls: 'timepicker-minute',
280 cls: 'btn btn-primary',
302 cls: 'hours-down glyphicon glyphicon-chevron-down'
322 cls: 'minutes-down glyphicon glyphicon-chevron-down'
340 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
347 var hours = this.time.getHours();
348 var minutes = this.time.getMinutes();
368 minutes = '0' + minutes;
371 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
372 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
373 this.pop.select('button', true).first().dom.innerHTML = period;
377 // showMode: function(dir) {
379 // this.viewMode = Math.max(this.minViewMode, Math.min(3, this.viewMode + dir));
382 // Roo.each(this.picker().select('>div',true).elements, function(v){
383 // v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
386 // this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
392 // if(this.isInline) return;
394 this.picker().removeClass(['bottom', 'top']);
396 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
398 * place to the top of element!
402 this.picker().addClass('top');
403 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
408 this.picker().addClass('bottom');
410 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
413 // parseDate : function(value){
414 // if(!value || value instanceof Date){
417 // var v = Date.parseDate(value, this.format);
418 // if (!v && this.useIso) {
419 // v = Date.parseDate(value, 'Y-m-d');
421 // if(!v && this.altFormats){
422 // if(!this.altFormatsArray){
423 // this.altFormatsArray = this.altFormats.split("|");
425 // for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
426 // v = Date.parseDate(value, this.altFormatsArray[i]);
432 // formatDate : function(date, fmt){
433 // return (!date || !(date instanceof Date)) ?
434 // date : date.dateFormat(fmt || this.format);
439 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
445 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
451 this.picker().show();
459 this.picker().hide();
464 onMousedown: function(e){
469 // keyup: function(e){
470 // Roo.bootstrap.DateField.superclass.keyup.call(this);
475 // fireKey: function(e){
476 // if (!this.picker().isVisible()){
477 // if (e.keyCode == 27) // allow escape to hide and re-show picker
481 // var dateChanged = false,
483 // newDate, newViewDate;
484 // switch(e.keyCode){
485 // case 27: // escape
487 // e.preventDefault();
491 // if (!this.keyboardNavigation) break;
492 // dir = e.keyCode == 37 ? -1 : 1;
495 // newDate = this.moveYear(this.date, dir);
496 // newViewDate = this.moveYear(this.viewDate, dir);
497 // } else if (e.shiftKey){
498 // newDate = this.moveMonth(this.date, dir);
499 // newViewDate = this.moveMonth(this.viewDate, dir);
501 // newDate = new Date(this.date);
502 // newDate.setUTCDate(this.date.getUTCDate() + dir);
503 // newViewDate = new Date(this.viewDate);
504 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
506 // if (this.dateWithinRange(newDate)){
507 // this.date = newDate;
508 // this.viewDate = newViewDate;
509 // this.setValue(this.formatDate(this.date));
511 // e.preventDefault();
512 // dateChanged = true;
517 // if (!this.keyboardNavigation) break;
518 // dir = e.keyCode == 38 ? -1 : 1;
520 // newDate = this.moveYear(this.date, dir);
521 // newViewDate = this.moveYear(this.viewDate, dir);
522 // } else if (e.shiftKey){
523 // newDate = this.moveMonth(this.date, dir);
524 // newViewDate = this.moveMonth(this.viewDate, dir);
526 // newDate = new Date(this.date);
527 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
528 // newViewDate = new Date(this.viewDate);
529 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
531 // if (this.dateWithinRange(newDate)){
532 // this.date = newDate;
533 // this.viewDate = newViewDate;
534 // this.setValue(this.formatDate(this.date));
536 // e.preventDefault();
537 // dateChanged = true;
541 // this.setValue(this.formatDate(this.date));
543 // e.preventDefault();
546 // this.setValue(this.formatDate(this.date));
553 onClick: function(e) {
557 var target = e.getTarget();
559 // if(target.nodeName.toLowerCase() === 'i'){
560 // target = Roo.get(target).dom.parentNode;
563 var nodeName = target.nodeName.trim();
564 var className = target.className.trim();
565 var html = target.innerHTML;
570 Roo.log('className');
577 // switch(nodeName.toLowerCase()) {
579 // switch(className) {
585 // var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
586 // switch(this.viewMode){
588 // this.viewDate = this.moveMonth(this.viewDate, dir);
592 // this.viewDate = this.moveYear(this.viewDate, dir);
598 // var date = new Date();
599 // this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
601 // this.setValue(this.formatDate(this.date));
604 // case 'switch-time':
605 // this.showMode(-1);
608 // case 'switch-calendar':
615 // if (className.indexOf('disabled') === -1) {
616 // this.viewDate.setUTCDate(1);
617 // if (className.indexOf('month') !== -1) {
618 // this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
619 // } else if(className.indexOf('picker-switch-icon') !== -1){
620 // if(className.indexOf('switch-time') !== -1){
621 // this.showMode(-1);
631 // var year = parseInt(html, 10) || 0;
632 // this.viewDate.setUTCFullYear(year);
635 // this.showMode(-1);
641 // if (className.indexOf('day') !== -1 && className.indexOf('disabled') === -1){
642 // var day = parseInt(html, 10) || 1;
643 // var year = this.viewDate.getUTCFullYear(),
644 // month = this.viewDate.getUTCMonth();
646 // if (className.indexOf('old') !== -1) {
653 // } else if (className.indexOf('new') !== -1) {
654 // if (month == 11) {
661 // this.date = this.UTCDate(year, month, day,0,0,0,0);
662 // this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
664 // this.setValue(this.formatDate(this.date));
671 // setStartDate: function(startDate){
672 // this.startDate = startDate || -Infinity;
673 // if (this.startDate !== -Infinity) {
674 // this.startDate = this.parseDate(this.startDate);
677 // this.updateNavArrows();
680 // setEndDate: function(endDate){
681 // this.endDate = endDate || Infinity;
682 // if (this.endDate !== Infinity) {
683 // this.endDate = this.parseDate(this.endDate);
686 // this.updateNavArrows();
689 // setDaysOfWeekDisabled: function(daysOfWeekDisabled){
690 // this.daysOfWeekDisabled = daysOfWeekDisabled || [];
691 // if (typeof(this.daysOfWeekDisabled) !== 'object') {
692 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
694 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
695 // return parseInt(d, 10);
698 // this.updateNavArrows();
701 // updateNavArrows: function() {
702 // var d = new Date(this.viewDate),
703 // year = d.getUTCFullYear(),
704 // month = d.getUTCMonth();
706 // Roo.each(this.picker().select('.prev', true).elements, function(v){
708 // switch (this.viewMode) {
711 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
717 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
724 // Roo.each(this.picker().select('.next', true).elements, function(v){
726 // switch (this.viewMode) {
729 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
735 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
743 // moveMonth: function(date, dir){
744 // if (!dir) return date;
745 // var new_date = new Date(date.valueOf()),
746 // day = new_date.getUTCDate(),
747 // month = new_date.getUTCMonth(),
748 // mag = Math.abs(dir),
750 // dir = dir > 0 ? 1 : -1;
753 // // If going back one month, make sure month is not current month
754 // // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
756 // return new_date.getUTCMonth() == month;
758 // // If going forward one month, make sure month is as expected
759 // // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
761 // return new_date.getUTCMonth() != new_month;
763 // new_month = month + dir;
764 // new_date.setUTCMonth(new_month);
765 // // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
766 // if (new_month < 0 || new_month > 11)
767 // new_month = (new_month + 12) % 12;
769 // // For magnitudes >1, move one month at a time...
770 // for (var i=0; i<mag; i++)
771 // // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
772 // new_date = this.moveMonth(new_date, dir);
773 // // ...then reset the day, keeping it in the new month
774 // new_month = new_date.getUTCMonth();
775 // new_date.setUTCDate(day);
776 // test = function(){
777 // return new_month != new_date.getUTCMonth();
780 // // Common date-resetting loop -- if date is beyond end of month, make it
783 // new_date.setUTCDate(--day);
784 // new_date.setUTCMonth(new_month);
789 // moveYear: function(date, dir){
790 // return this.moveMonth(date, dir*12);
793 // dateWithinRange: function(date){
794 // return date >= this.startDate && date <= this.endDate;
797 // remove: function() {
798 // this.picker().remove();
801 onIncrementHours: function()
803 Roo.log('onIncrementHours');
804 this.time = this.time.add(Date.HOUR, 1);
809 onDecrementHours: function()
811 Roo.log('onDecrementHours');
812 this.time = this.time.add(Date.HOUR, -1);
816 onIncrementMinutes: function()
818 Roo.log('onIncrementMinutes');
819 this.time = this.time.add(Date.MINUTE, 1);
823 onDecrementMinutes: function()
825 Roo.log('onDecrementMinutes');
826 this.time = this.time.add(Date.MINUTE, -1);
830 onTogglePeriod: function()
832 Roo.log('onTogglePeriod');
833 this.time = this.time.add(Date.HOUR, 12);
840 Roo.apply(Roo.bootstrap.TimeField, {
858 Roo.apply(Roo.bootstrap.TimeField, {
862 cls: 'datepicker dropdown-menu',
866 cls: 'datepicker-time',
870 cls: 'table-condensed',
872 Roo.bootstrap.DateField.content