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:s').
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.picker().on('mousedown', this.onMousedown, this);
129 this.picker().on('click', this.onClick, this);
131 this.picker().addClass('datepicker-dropdown');
133 // this.startViewMode = this.viewMode;
135 // this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
137 // this.setStartDate(this.startDate);
138 // this.setEndDate(this.endDate);
140 // this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
143 // this.fillMonths();
148 // if(this.showTime){
150 // var dayFoot = this.picker().select('>.datepicker-days tfoot th', true).first();
151 // var timeFoot = this.picker().select('>.datepicker-time tfoot th', true).first();
153 // var dayFootIcon = this.picker().select('>.datepicker-days tfoot span.picker-switch-icon', true).first();
154 // var timeFootIcon = this.picker().select('>.datepicker-time tfoot span.picker-switch-icon', true).first();
156 // timeFoot.addClass('switch-calendar');
157 // dayFoot.addClass('switch-time');
159 // timeFootIcon.addClass('switch-calendar');
160 // timeFootIcon.addClass('glyphicon-calendar');
162 // dayFootIcon.addClass('switch-time');
163 // dayFootIcon.addClass('glyphicon-time');
165 var hours_up = this.picker().select('>.datepicker-time span.hours-up', true).first();
166 var hours_down = this.picker().select('>.datepicker-time span.hours-down', true).first();
167 var minutes_up = this.picker().select('>.datepicker-time span.minutes-up', true).first();
168 var minutes_down = this.picker().select('>.datepicker-time span.minutes-down', true).first();
170 var period = this.picker().select('>.datepicker-time button', true).first();
172 hours_up.on('click', this.onIncrementHours, hours_up);
173 hours_down.on('click', this.onDecrementHours, hours_down);
174 minutes_up.on('click', this.onIncrementMinutes, minutes_up);
175 minutes_down.on('click', this.onDecrementMinutes, minutes_down);
177 period.on('click', this.onTogglePeriod, period);
180 // Roo.each(this.picker().select('tfoot th', true).elements, function(v){
185 // if(this.isInline) {
192 return this.el.select('.datepicker', true).first();
197 var time = this.picker().select('>.datepicker-time tbody', true).first();
199 time.dom.innerHTML = '';
214 cls: 'hours-up glyphicon glyphicon-chevron-up'
234 cls: 'minutes-up glyphicon glyphicon-chevron-up'
255 cls: 'timepicker-hour',
270 cls: 'timepicker-minute',
285 cls: 'btn btn-primary',
307 cls: 'hours-down glyphicon glyphicon-chevron-down'
327 cls: 'minutes-down glyphicon glyphicon-chevron-down'
345 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
353 Roo.log(this.time.getHours());
354 Roo.log(this.time.get());
358 // showMode: function(dir) {
360 // this.viewMode = Math.max(this.minViewMode, Math.min(3, this.viewMode + dir));
363 // Roo.each(this.picker().select('>div',true).elements, function(v){
364 // v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
367 // this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
373 // if(this.isInline) return;
375 this.picker().removeClass(['bottom', 'top']);
377 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
379 * place to the top of element!
383 this.picker().addClass('top');
384 this.picker().setTop(0 - this.picker().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
389 this.picker().addClass('bottom');
391 this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft() - this.el.getLeft());
394 // parseDate : function(value){
395 // if(!value || value instanceof Date){
398 // var v = Date.parseDate(value, this.format);
399 // if (!v && this.useIso) {
400 // v = Date.parseDate(value, 'Y-m-d');
402 // if(!v && this.altFormats){
403 // if(!this.altFormatsArray){
404 // this.altFormatsArray = this.altFormats.split("|");
406 // for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
407 // v = Date.parseDate(value, this.altFormatsArray[i]);
413 // formatDate : function(date, fmt){
414 // return (!date || !(date instanceof Date)) ?
415 // date : date.dateFormat(fmt || this.format);
420 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
426 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
432 this.picker().show();
439 this.picker().hide();
443 onMousedown: function(e){
448 // keyup: function(e){
449 // Roo.bootstrap.DateField.superclass.keyup.call(this);
454 // fireKey: function(e){
455 // if (!this.picker().isVisible()){
456 // if (e.keyCode == 27) // allow escape to hide and re-show picker
460 // var dateChanged = false,
462 // newDate, newViewDate;
463 // switch(e.keyCode){
464 // case 27: // escape
466 // e.preventDefault();
470 // if (!this.keyboardNavigation) break;
471 // dir = e.keyCode == 37 ? -1 : 1;
474 // newDate = this.moveYear(this.date, dir);
475 // newViewDate = this.moveYear(this.viewDate, dir);
476 // } else if (e.shiftKey){
477 // newDate = this.moveMonth(this.date, dir);
478 // newViewDate = this.moveMonth(this.viewDate, dir);
480 // newDate = new Date(this.date);
481 // newDate.setUTCDate(this.date.getUTCDate() + dir);
482 // newViewDate = new Date(this.viewDate);
483 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
485 // if (this.dateWithinRange(newDate)){
486 // this.date = newDate;
487 // this.viewDate = newViewDate;
488 // this.setValue(this.formatDate(this.date));
490 // e.preventDefault();
491 // dateChanged = true;
496 // if (!this.keyboardNavigation) break;
497 // dir = e.keyCode == 38 ? -1 : 1;
499 // newDate = this.moveYear(this.date, dir);
500 // newViewDate = this.moveYear(this.viewDate, dir);
501 // } else if (e.shiftKey){
502 // newDate = this.moveMonth(this.date, dir);
503 // newViewDate = this.moveMonth(this.viewDate, dir);
505 // newDate = new Date(this.date);
506 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
507 // newViewDate = new Date(this.viewDate);
508 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
510 // if (this.dateWithinRange(newDate)){
511 // this.date = newDate;
512 // this.viewDate = newViewDate;
513 // this.setValue(this.formatDate(this.date));
515 // e.preventDefault();
516 // dateChanged = true;
520 // this.setValue(this.formatDate(this.date));
522 // e.preventDefault();
525 // this.setValue(this.formatDate(this.date));
532 onClick: function(e) {
536 var target = e.getTarget();
538 // if(target.nodeName.toLowerCase() === 'i'){
539 // target = Roo.get(target).dom.parentNode;
542 var nodeName = target.nodeName.trim();
543 var className = target.className.trim();
544 var html = target.innerHTML;
549 Roo.log('className');
556 // switch(nodeName.toLowerCase()) {
558 // switch(className) {
564 // var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
565 // switch(this.viewMode){
567 // this.viewDate = this.moveMonth(this.viewDate, dir);
571 // this.viewDate = this.moveYear(this.viewDate, dir);
577 // var date = new Date();
578 // this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
580 // this.setValue(this.formatDate(this.date));
583 // case 'switch-time':
584 // this.showMode(-1);
587 // case 'switch-calendar':
594 // if (className.indexOf('disabled') === -1) {
595 // this.viewDate.setUTCDate(1);
596 // if (className.indexOf('month') !== -1) {
597 // this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
598 // } else if(className.indexOf('picker-switch-icon') !== -1){
599 // if(className.indexOf('switch-time') !== -1){
600 // this.showMode(-1);
610 // var year = parseInt(html, 10) || 0;
611 // this.viewDate.setUTCFullYear(year);
614 // this.showMode(-1);
620 // if (className.indexOf('day') !== -1 && className.indexOf('disabled') === -1){
621 // var day = parseInt(html, 10) || 1;
622 // var year = this.viewDate.getUTCFullYear(),
623 // month = this.viewDate.getUTCMonth();
625 // if (className.indexOf('old') !== -1) {
632 // } else if (className.indexOf('new') !== -1) {
633 // if (month == 11) {
640 // this.date = this.UTCDate(year, month, day,0,0,0,0);
641 // this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
643 // this.setValue(this.formatDate(this.date));
650 // setStartDate: function(startDate){
651 // this.startDate = startDate || -Infinity;
652 // if (this.startDate !== -Infinity) {
653 // this.startDate = this.parseDate(this.startDate);
656 // this.updateNavArrows();
659 // setEndDate: function(endDate){
660 // this.endDate = endDate || Infinity;
661 // if (this.endDate !== Infinity) {
662 // this.endDate = this.parseDate(this.endDate);
665 // this.updateNavArrows();
668 // setDaysOfWeekDisabled: function(daysOfWeekDisabled){
669 // this.daysOfWeekDisabled = daysOfWeekDisabled || [];
670 // if (typeof(this.daysOfWeekDisabled) !== 'object') {
671 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
673 // this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
674 // return parseInt(d, 10);
677 // this.updateNavArrows();
680 // updateNavArrows: function() {
681 // var d = new Date(this.viewDate),
682 // year = d.getUTCFullYear(),
683 // month = d.getUTCMonth();
685 // Roo.each(this.picker().select('.prev', true).elements, function(v){
687 // switch (this.viewMode) {
690 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
696 // if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
703 // Roo.each(this.picker().select('.next', true).elements, function(v){
705 // switch (this.viewMode) {
708 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
714 // if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
722 // moveMonth: function(date, dir){
723 // if (!dir) return date;
724 // var new_date = new Date(date.valueOf()),
725 // day = new_date.getUTCDate(),
726 // month = new_date.getUTCMonth(),
727 // mag = Math.abs(dir),
729 // dir = dir > 0 ? 1 : -1;
732 // // If going back one month, make sure month is not current month
733 // // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
735 // return new_date.getUTCMonth() == month;
737 // // If going forward one month, make sure month is as expected
738 // // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
740 // return new_date.getUTCMonth() != new_month;
742 // new_month = month + dir;
743 // new_date.setUTCMonth(new_month);
744 // // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
745 // if (new_month < 0 || new_month > 11)
746 // new_month = (new_month + 12) % 12;
748 // // For magnitudes >1, move one month at a time...
749 // for (var i=0; i<mag; i++)
750 // // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
751 // new_date = this.moveMonth(new_date, dir);
752 // // ...then reset the day, keeping it in the new month
753 // new_month = new_date.getUTCMonth();
754 // new_date.setUTCDate(day);
755 // test = function(){
756 // return new_month != new_date.getUTCMonth();
759 // // Common date-resetting loop -- if date is beyond end of month, make it
762 // new_date.setUTCDate(--day);
763 // new_date.setUTCMonth(new_month);
768 // moveYear: function(date, dir){
769 // return this.moveMonth(date, dir*12);
772 // dateWithinRange: function(date){
773 // return date >= this.startDate && date <= this.endDate;
776 // remove: function() {
777 // this.picker().remove();
780 onIncrementHours: function()
782 Roo.log('onIncrementHours');
785 onDecrementHours: function()
787 Roo.log('onDecrementHours');
790 onIncrementMinutes: function()
792 Roo.log('onIncrementMinutes');
795 onDecrementMinutes: function()
797 Roo.log('onDecrementMinutes');
800 onTogglePeriod: function()
802 Roo.log('onTogglePeriod');
808 Roo.apply(Roo.bootstrap.TimeField, {
826 Roo.apply(Roo.bootstrap.TimeField, {
830 cls: 'datepicker dropdown-menu',
834 cls: 'datepicker-time',
838 cls: 'table-condensed',
840 Roo.bootstrap.DateField.content