remove debugging code
[roojs1] / Roo / bootstrap / MonthField.js
index 2201ea9..9348c26 100644 (file)
@@ -39,7 +39,8 @@ Roo.bootstrap.MonthField = function(config){
          * @event select
          * Fires when select a date.
          * @param {Roo.bootstrap.MonthField} this
-         * @param {Mixed} date The date value
+         * @param {String} oldvalue The old value
+         * @param {String} newvalue The new value
          */
         select : true
     });
@@ -47,8 +48,6 @@ Roo.bootstrap.MonthField = function(config){
 
 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
     
-    format : "F",
-    
     onRender: function(ct, position)
     {
         
@@ -65,9 +64,6 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
         this.component = (this.component && this.component.length === 0) ? false : this.component;
         this.hasInput = this.component && this.inputEL().length;
         
-        this.minViewMode = 1;
-        this.viewMode = 1;
-                
         this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
         
         this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
@@ -77,27 +73,31 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
         
         this.picker().addClass('datepicker-dropdown');
         
-        this.startViewMode = this.viewMode;
-
         Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
             v.setStyle('width', '189px');
         });
         
         this.fillMonths();
+        
         this.update();
         
         if(this.isInline) {
             this.show();
         }
+        
     },
     
-    setValue: function(v)
+    setValue: function(v, suppressEvent)
     {   
+        var o = this.getValue();
+        
         Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
         
         this.update();
 
-        this.fireEvent('select', this, this.date);
+        if(suppressEvent !== true){
+            this.fireEvent('select', this, o, v);
+        }
         
     },
     
@@ -128,6 +128,7 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
         this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
         
         this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
+        
         this.hide();
                         
     },
@@ -139,7 +140,7 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
     
     fillMonths: function()
     {    
-        var i = 0
+        var i = 0;
         var months = this.picker().select('>.datepicker-months td', true).first();
         
         months.dom.innerHTML = '';
@@ -149,7 +150,7 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
                 tag: 'span',
                 cls: 'month',
                 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
-            }
+            };
             
             months.createChild(month);
         }
@@ -175,7 +176,9 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
     
     place: function()
     {
-        if(this.isInline) return;
+        if(this.isInline) {
+            return;
+        }
         
         this.picker().removeClass(['bottom', 'top']);
         
@@ -225,7 +228,9 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
     
     hide : function()
     {
-        if(this.isInline) return;
+        if(this.isInline) {
+            return;
+        }
         this.picker().hide();
         this.fireEvent('hide', this, this.date);
         
@@ -246,14 +251,13 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
     fireKey: function(e)
     {
         if (!this.picker().isVisible()){
-            if (e.keyCode == 27) // allow escape to hide and re-show picker
+            if (e.keyCode == 27)   {// allow escape to hide and re-show picker
                 this.show();
+            }
             return;
         }
         
-        var dateChanged = false,
-        dir, day, month, year,
-        newDate;
+        var dir;
         
         switch(e.keyCode){
             case 27: // escape
@@ -264,49 +268,58 @@ Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
             case 39: // right
                 dir = e.keyCode == 37 ? -1 : 1;
                 
-                newDate = new Date();
-                
+                this.vIndex = this.vIndex + dir;
                 
+                if(this.vIndex < 0){
+                    this.vIndex = 0;
+                }
                 
-                newDate.setUTCDate(this.date.getUTCDate() + dir);
-                newViewDate = new Date(this.viewDate);
-                newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
+                if(this.vIndex > 11){
+                    this.vIndex = 11;
+                }
                 
+                if(isNaN(this.vIndex)){
+                    this.vIndex = 0;
+                }
                 
+                this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
                 
                 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);
+                
+                this.vIndex = this.vIndex + dir * 4;
+                
+                if(this.vIndex < 0){
+                    this.vIndex = 0;
+                }
+                
+                if(this.vIndex > 11){
+                    this.vIndex = 11;
                 }
-                if (this.dateWithinRange(newDate)){
-                    this.date = newDate;
-                    this.viewDate = newViewDate;
-                    this.setValue(this.formatDate(this.date));
-//                    this.update();
-                    e.preventDefault();
-                    dateChanged = true;
+                
+                if(isNaN(this.vIndex)){
+                    this.vIndex = 0;
                 }
+                
+                this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
                 break;
+                
             case 13: // enter
-                this.setValue(this.formatDate(this.date));
+                
+                if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
+                    this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
+                }
+                
                 this.hide();
                 e.preventDefault();
                 break;
             case 9: // tab
-                this.setValue(this.formatDate(this.date));
+                if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
+                    this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
+                }
                 this.hide();
                 break;
             case 16: // shift