Roo/bootstrap/TimeField.js
authorEdward <edward@roojs.com>
Fri, 6 Jun 2014 03:58:41 +0000 (11:58 +0800)
committerEdward <edward@roojs.com>
Fri, 6 Jun 2014 03:58:41 +0000 (11:58 +0800)
roojs-bootstrap.js
roojs-bootstrap-debug.js

Roo/bootstrap/TimeField.js
roojs-bootstrap-debug.js
roojs-bootstrap.js

index fccf2ad..bd0a99b 100644 (file)
@@ -61,80 +61,28 @@ Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input,  {
     fireKey: function(e){
         Roo.log('Fire Key !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
         Roo.log(e.keyCode);
-//        if (!this.picker().isVisible()){
-//            if (e.keyCode == 27) // allow escape to hide and re-show picker
-//                this.show();
-//            return;
-//        }
-//        var dateChanged = false,
-//        dir, day, month,
-//        newDate, newViewDate;
-//        switch(e.keyCode){
-//            case 27: // escape
-//                this.hide();
-//                e.preventDefault();
-//                break;
-//            case 37: // left
-//            case 39: // right
-//                if (!this.keyboardNavigation) break;
-//                dir = e.keyCode == 37 ? -1 : 1;
-//                
-//                if (e.ctrlKey){
-//                    newDate = this.moveYear(this.date, dir);
-//                    newViewDate = this.moveYear(this.viewDate, dir);
-//                } else if (e.shiftKey){
-//                    newDate = this.moveMonth(this.date, dir);
-//                    newViewDate = this.moveMonth(this.viewDate, dir);
-//                } else {
-//                    newDate = new Date(this.date);
-//                    newDate.setUTCDate(this.date.getUTCDate() + dir);
-//                    newViewDate = new Date(this.viewDate);
-//                    newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
-//                }
-//                if (this.dateWithinRange(newDate)){
-//                    this.date = newDate;
-//                    this.viewDate = newViewDate;
-//                    this.setValue(this.formatDate(this.date));
-//                    this.update();
-//                    e.preventDefault();
-//                    dateChanged = true;
-//                }
-//                break;
-//            case 38: // up
-//            case 40: // down
-//                if (!this.keyboardNavigation) break;
-//                dir = e.keyCode == 38 ? -1 : 1;
-//                if (e.ctrlKey){
-//                    newDate = this.moveYear(this.date, dir);
-//                    newViewDate = this.moveYear(this.viewDate, dir);
-//                } else if (e.shiftKey){
-//                    newDate = this.moveMonth(this.date, dir);
-//                    newViewDate = this.moveMonth(this.viewDate, dir);
-//                } else {
-//                    newDate = new Date(this.date);
-//                    newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
-//                    newViewDate = new Date(this.viewDate);
-//                    newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
-//                }
-//                if (this.dateWithinRange(newDate)){
-//                    this.date = newDate;
-//                    this.viewDate = newViewDate;
-//                    this.setValue(this.formatDate(this.date));
-//                    this.update();
-//                    e.preventDefault();
-//                    dateChanged = true;
-//                }
-//                break;
-//            case 13: // enter
-//                this.setValue(this.formatDate(this.date));
-//                this.hide();
-//                e.preventDefault();
-//                break;
-//            case 9: // tab
-//                this.setValue(this.formatDate(this.date));
-//                this.hide();
-//                break;
-//        }
+        if (!this.picker().isVisible()){
+            if (e.keyCode == 27) // allow escape to hide and re-show picker
+                this.show();
+            return;
+        }
+
+        e.preventDefault();
+        
+        switch(e.keyCode){
+            case 27: // escape
+            case 9: // tab
+                this.hide();
+                break;
+            case 37: // left
+            case 39: // right
+            case 38: // up
+            case 40: // down
+                break;
+            case 13: // enter
+                this.setTime();
+                break;
+        }
     },
     
     onClick: function(e) {
index a9cd921..44879b1 100644 (file)
@@ -11857,80 +11857,28 @@ Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input,  {
     fireKey: function(e){
         Roo.log('Fire Key !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
         Roo.log(e.keyCode);
-//        if (!this.picker().isVisible()){
-//            if (e.keyCode == 27) // allow escape to hide and re-show picker
-//                this.show();
-//            return;
-//        }
-//        var dateChanged = false,
-//        dir, day, month,
-//        newDate, newViewDate;
-//        switch(e.keyCode){
-//            case 27: // escape
-//                this.hide();
-//                e.preventDefault();
-//                break;
-//            case 37: // left
-//            case 39: // right
-//                if (!this.keyboardNavigation) break;
-//                dir = e.keyCode == 37 ? -1 : 1;
-//                
-//                if (e.ctrlKey){
-//                    newDate = this.moveYear(this.date, dir);
-//                    newViewDate = this.moveYear(this.viewDate, dir);
-//                } else if (e.shiftKey){
-//                    newDate = this.moveMonth(this.date, dir);
-//                    newViewDate = this.moveMonth(this.viewDate, dir);
-//                } else {
-//                    newDate = new Date(this.date);
-//                    newDate.setUTCDate(this.date.getUTCDate() + dir);
-//                    newViewDate = new Date(this.viewDate);
-//                    newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
-//                }
-//                if (this.dateWithinRange(newDate)){
-//                    this.date = newDate;
-//                    this.viewDate = newViewDate;
-//                    this.setValue(this.formatDate(this.date));
-//                    this.update();
-//                    e.preventDefault();
-//                    dateChanged = true;
-//                }
-//                break;
-//            case 38: // up
-//            case 40: // down
-//                if (!this.keyboardNavigation) break;
-//                dir = e.keyCode == 38 ? -1 : 1;
-//                if (e.ctrlKey){
-//                    newDate = this.moveYear(this.date, dir);
-//                    newViewDate = this.moveYear(this.viewDate, dir);
-//                } else if (e.shiftKey){
-//                    newDate = this.moveMonth(this.date, dir);
-//                    newViewDate = this.moveMonth(this.viewDate, dir);
-//                } else {
-//                    newDate = new Date(this.date);
-//                    newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
-//                    newViewDate = new Date(this.viewDate);
-//                    newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
-//                }
-//                if (this.dateWithinRange(newDate)){
-//                    this.date = newDate;
-//                    this.viewDate = newViewDate;
-//                    this.setValue(this.formatDate(this.date));
-//                    this.update();
-//                    e.preventDefault();
-//                    dateChanged = true;
-//                }
-//                break;
-//            case 13: // enter
-//                this.setValue(this.formatDate(this.date));
-//                this.hide();
-//                e.preventDefault();
-//                break;
-//            case 9: // tab
-//                this.setValue(this.formatDate(this.date));
-//                this.hide();
-//                break;
-//        }
+        if (!this.picker().isVisible()){
+            if (e.keyCode == 27) // allow escape to hide and re-show picker
+                this.show();
+            return;
+        }
+
+        e.preventDefault();
+        
+        switch(e.keyCode){
+            case 27: // escape
+            case 9: // tab
+                this.hide();
+                break;
+            case 37: // left
+            case 39: // right
+            case 38: // up
+            case 40: // down
+                break;
+            case 13: // enter
+                this.setTime();
+                break;
+        }
     },
     
     onClick: function(e) {
index 0d46d1a..dec314c 100644 (file)
@@ -273,7 +273,8 @@ this.update();this.updateNavArrows();},setEndDate:function(A){this.endDate=A||In
 this.update();this.updateNavArrows();},setDaysOfWeekDisabled:function(A){this.daysOfWeekDisabled=A||[];if(typeof(this.daysOfWeekDisabled)!=='object'){this.daysOfWeekDisabled=this.daysOfWeekDisabled.split(/,\s*/);}
 this.daysOfWeekDisabled=this.daysOfWeekDisabled.map(function(d){return parseInt(d,10);});this.update();this.updateNavArrows();},updateNavArrows:function(){var d=new Date(this.viewDate),A=d.getUTCFullYear(),B=d.getUTCMonth();Roo.each(this.picker().select('.prev',true).elements,function(v){v.show();switch(this.viewMode){case 0:if(this.startDate!==-Infinity&&A<=this.startDate.getUTCFullYear()&&B<=this.startDate.getUTCMonth()){v.hide();}break;case 1:case 2:if(this.startDate!==-Infinity&&A<=this.startDate.getUTCFullYear()){v.hide();}break;}});Roo.each(this.picker().select('.next',true).elements,function(v){v.show();switch(this.viewMode){case 0:if(this.endDate!==Infinity&&A>=this.endDate.getUTCFullYear()&&B>=this.endDate.getUTCMonth()){v.hide();}break;case 1:case 2:if(this.endDate!==Infinity&&A>=this.endDate.getUTCFullYear()){v.hide();}break;}})},moveMonth:function(A,B){if(!B)return A;var C=new Date(A.valueOf()),D=C.getUTCDate(),E=C.getUTCMonth(),F=Math.abs(B),G,H;B=B>0?1:-1;if(F==1){H=B==-1?function(){return C.getUTCMonth()==E;}:function(){return C.getUTCMonth()!=G;};G=E+B;C.setUTCMonth(G);if(G<0||G>11)G=(G+12)%12;}else {for(var i=0;i<F;i++)C=this.moveMonth(C,B);G=C.getUTCMonth();C.setUTCDate(D);H=function(){return G!=C.getUTCMonth();};}while(H()){C.setUTCDate(--D);C.setUTCMonth(G);}return C;},moveYear:function(A,B){return this.moveMonth(A,B*12);},dateWithinRange:function(A){return A>=this.startDate&&A<=this.endDate;},remove:function(){this.picker().remove();}});Roo.apply(Roo.bootstrap.DateField,{head:{tag:'thead',cn:[{tag:'tr',cn:[{tag:'th',cls:'prev',html:'<i class="icon-arrow-left"/>'},{tag:'th',cls:'switch',colspan:'5'},{tag:'th',cls:'next',html:'<i class="icon-arrow-right"/>'}]}]},content:{tag:'tbody',cn:[{tag:'tr',cn:[{tag:'td',colspan:'7'}]}]},footer:{tag:'tfoot',cn:[{tag:'tr',cn:[{tag:'th',colspan:'7',cls:'today'}]}]},dates:{en:{days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"],daysMin:["Su","Mo","Tu","We","Th","Fr","Sa","Su"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],today:"Today"}},modes:[{clsName:'days',navFnc:'Month',navStep:1},{clsName:'months',navFnc:'FullYear',navStep:1},{clsName:'years',navFnc:'FullYear',navStep:10}]});Roo.apply(Roo.bootstrap.DateField,{template:{tag:'div',cls:'datepicker dropdown-menu',cn:[{tag:'div',cls:'datepicker-days',cn:[{tag:'table',cls:'table-condensed',cn:[Roo.bootstrap.DateField.head,{tag:'tbody'},Roo.bootstrap.DateField.footer]}]},{tag:'div',cls:'datepicker-months',cn:[{tag:'table',cls:'table-condensed',cn:[Roo.bootstrap.DateField.head,Roo.bootstrap.DateField.content,Roo.bootstrap.DateField.footer]}]},{tag:'div',cls:'datepicker-years',cn:[{tag:'table',cls:'table-condensed',cn:[Roo.bootstrap.DateField.head,Roo.bootstrap.DateField.content,Roo.bootstrap.DateField.footer]}]}]}});
 //Roo/bootstrap/TimeField.js
-Roo.bootstrap.TimeField=function(A){Roo.bootstrap.TimeField.superclass.constructor.call(this,A);};Roo.extend(Roo.bootstrap.TimeField,Roo.bootstrap.Input,{format:"H:i",onRender:function(ct,A){Roo.bootstrap.TimeField.superclass.onRender.call(this,ct,A);this.el.select('>.input-group',true).first().createChild(Roo.bootstrap.TimeField.template);this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay='block';this.pop=this.picker().select('>.datepicker-time',true).first();this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay='block'this.picker().on('mousedown',this.onMousedown,this);this.picker().on('click',this.onClick,this);this.picker().addClass('datepicker-dropdown');this.fillTime();this.update();this.pop.select('span.hours-up',true).first().on('click',this.onIncrementHours,this);this.pop.select('span.hours-down',true).first().on('click',this.onDecrementHours,this);this.pop.select('span.minutes-up',true).first().on('click',this.onIncrementMinutes,this);this.pop.select('span.minutes-down',true).first().on('click',this.onDecrementMinutes,this);this.pop.select('button.period',true).first().on('click',this.onTogglePeriod,this);this.pop.select('button.ok',true).first().on('click',this.setTime,this);},fireKey:function(e){Roo.log('Fire Key !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');Roo.log(e.keyCode);},onClick:function(e){e.stopPropagation();e.preventDefault();},picker:function(){return this.el.select('.datepicker',true).first();},fillTime:function(){var A=this.pop.select('tbody',true).first();A.dom.innerHTML='';A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'hours-up glyphicon glyphicon-chevron-up'}]}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'minutes-up glyphicon glyphicon-chevron-up'}]}]},{tag:'td',cls:'separator'}]});A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'span',cls:'timepicker-hour',html:'00'}]},{tag:'td',cls:'separator',html:':'},{tag:'td',cn:[{tag:'span',cls:'timepicker-minute',html:'00'}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'button',type:'button',cls:'btn btn-primary period',html:'AM'}]}]});A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'hours-down glyphicon glyphicon-chevron-down'}]}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'minutes-down glyphicon glyphicon-chevron-down'}]}]},{tag:'td',cls:'separator'}]});},update:function(){this.time=(typeof(this.time)==='undefined')?new Date():this.time;this.fill();},fill:function(){var A=this.time.getHours();var B=this.time.getMinutes();var C='AM';if(A>11){C='PM';}if(A==0){A=12;}if(A>12){A=A-12;}if(A<10){A='0'+A;}if(B<10){B='0'+B;}
+Roo.bootstrap.TimeField=function(A){Roo.bootstrap.TimeField.superclass.constructor.call(this,A);};Roo.extend(Roo.bootstrap.TimeField,Roo.bootstrap.Input,{format:"H:i",onRender:function(ct,A){Roo.bootstrap.TimeField.superclass.onRender.call(this,ct,A);this.el.select('>.input-group',true).first().createChild(Roo.bootstrap.TimeField.template);this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay='block';this.pop=this.picker().select('>.datepicker-time',true).first();this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay='block'this.picker().on('mousedown',this.onMousedown,this);this.picker().on('click',this.onClick,this);this.picker().addClass('datepicker-dropdown');this.fillTime();this.update();this.pop.select('span.hours-up',true).first().on('click',this.onIncrementHours,this);this.pop.select('span.hours-down',true).first().on('click',this.onDecrementHours,this);this.pop.select('span.minutes-up',true).first().on('click',this.onIncrementMinutes,this);this.pop.select('span.minutes-down',true).first().on('click',this.onDecrementMinutes,this);this.pop.select('button.period',true).first().on('click',this.onTogglePeriod,this);this.pop.select('button.ok',true).first().on('click',this.setTime,this);},fireKey:function(e){Roo.log('Fire Key !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');Roo.log(e.keyCode);if(!this.picker().isVisible()){if(e.keyCode==27)this.show();return;}
+e.preventDefault();switch(e.keyCode){case 27:case 9:this.hide();break;case 37:case 39:case 38:case 40:break;case 13:this.setTime();break;}},onClick:function(e){e.stopPropagation();e.preventDefault();},picker:function(){return this.el.select('.datepicker',true).first();},fillTime:function(){var A=this.pop.select('tbody',true).first();A.dom.innerHTML='';A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'hours-up glyphicon glyphicon-chevron-up'}]}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'minutes-up glyphicon glyphicon-chevron-up'}]}]},{tag:'td',cls:'separator'}]});A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'span',cls:'timepicker-hour',html:'00'}]},{tag:'td',cls:'separator',html:':'},{tag:'td',cn:[{tag:'span',cls:'timepicker-minute',html:'00'}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'button',type:'button',cls:'btn btn-primary period',html:'AM'}]}]});A.createChild({tag:'tr',cn:[{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'hours-down glyphicon glyphicon-chevron-down'}]}]},{tag:'td',cls:'separator'},{tag:'td',cn:[{tag:'a',href:'#',cls:'btn',cn:[{tag:'span',cls:'minutes-down glyphicon glyphicon-chevron-down'}]}]},{tag:'td',cls:'separator'}]});},update:function(){this.time=(typeof(this.time)==='undefined')?new Date():this.time;this.fill();},fill:function(){var A=this.time.getHours();var B=this.time.getMinutes();var C='AM';if(A>11){C='PM';}if(A==0){A=12;}if(A>12){A=A-12;}if(A<10){A='0'+A;}if(B<10){B='0'+B;}
 this.pop.select('.timepicker-hour',true).first().dom.innerHTML=A;this.pop.select('.timepicker-minute',true).first().dom.innerHTML=B;this.pop.select('button',true).first().dom.innerHTML=C;},place:function(){this.picker().removeClass(['bottom','top']);if((Roo.lib.Dom.getViewHeight()+Roo.get(document.body).getScroll().top)-(this.inputEl().getBottom()+this.picker().getHeight())<0){this.picker().addClass('top');this.picker().setTop(0-this.picker().getHeight()).setLeft(this.inputEl().getLeft()-this.el.getLeft());return;}
 this.picker().addClass('bottom');this.picker().setTop(this.inputEl().getHeight()).setLeft(this.inputEl().getLeft()-this.el.getLeft());},onFocus:function(){Roo.bootstrap.TimeField.superclass.onFocus.call(this);this.show();},onBlur:function(){Roo.bootstrap.TimeField.superclass.onBlur.call(this);this.hide();},show:function(){this.picker().show();this.pop.show();this.update();this.place();},hide:function(){this.picker().hide();this.pop.hide();},setTime:function(){this.hide();this.setValue(this.time.format(this.format));},onMousedown:function(e){e.stopPropagation();e.preventDefault();},onIncrementHours:function(){Roo.log('onIncrementHours');this.time=this.time.add(Date.HOUR,1);this.update();},onDecrementHours:function(){Roo.log('onDecrementHours');this.time=this.time.add(Date.HOUR,-1);this.update();},onIncrementMinutes:function(){Roo.log('onIncrementMinutes');this.time=this.time.add(Date.MINUTE,1);this.update();},onDecrementMinutes:function(){Roo.log('onDecrementMinutes');this.time=this.time.add(Date.MINUTE,-1);this.update();},onTogglePeriod:function(){Roo.log('onTogglePeriod');this.time=this.time.add(Date.HOUR,12);this.update();}});Roo.apply(Roo.bootstrap.TimeField,{content:{tag:'tbody',cn:[{tag:'tr',cn:[{tag:'td',colspan:'7'}]}]},footer:{tag:'tfoot',cn:[{tag:'tr',cn:[{tag:'th',colspan:'7',cls:'',cn:[{tag:'button',cls:'btn btn-info ok',html:'OK'}]}]}]}});Roo.apply(Roo.bootstrap.TimeField,{template:{tag:'div',cls:'datepicker dropdown-menu',cn:[{tag:'div',cls:'datepicker-time',cn:[{tag:'table',cls:'table-condensed',cn:[Roo.bootstrap.TimeField.content,Roo.bootstrap.TimeField.footer]}]}]}});
 //Roo/bootstrap/CheckBox.js