Revision: 4836
          http://sourceforge.net/p/vexi/code/4836
Author:   mkpg2
Date:     2015-12-19 06:32:58 +0000 (Sat, 19 Dec 2015)
Log Message:
-----------
datetime improvements.
- fix datepicker. Was initialising as today, not date.
- improve datepicker. Should initialise with default date.
- scroll between date and time fields (left right)
- enter/delete sets both fields
- ability to set default value on datetime
- removed some obselete (pre vexi.js.Date/vexi.js.Instant) code

Modified Paths:
--------------
    
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datetime.t
    
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/timefield.t
    branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t

Added Paths:
-----------
    branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/currencyfield.t

Modified: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    2015-12-09 15:57:13 UTC (rev 4835)
+++ 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    2015-12-19 06:32:58 UTC (rev 4836)
@@ -106,17 +106,27 @@
         
         var min = function(a, b) { return a>b ? b : a; }
         
+               thisbox["default"] ++= function(){
+               var r = cascade;
+               if(r==null)
+                       r = vexi.js.Date.today.as("YMD");
+               return r;
+        };
+        
         // set the surface position of the popbox
         $popbox.surface_x ++= function() { return 
min(surface.frame.distanceto(thisbox).x, surface.frame.width - $popbox.width); }
         $popbox.surface_y ++= function() { return 
min(surface.frame.distanceto(thisbox).y, surface.frame.height - 
$popbox.height); }
         
         /** assign date and popup */
         $select.action ++= function(v) {
-            popup = true;
             var date = value;
+            if(date==null) date = thisbox["default"];
             $datepicker.day = date?.day;
             $datepicker.month = date?.month;
             $datepicker.year = date?.year;
+            // have to set day,month,year before popuping up as widget 
initialises based on values, but 
+            // they cannot be set later ...
+            popup = true; 
             return;
         }
         
@@ -129,6 +139,10 @@
             finally { $editview.display = false; }
         }
         
+        thisbox.setDefault = function(){
+               value = thisbox["default"];
+        };
+        
         thisbox.enabled ++= function(v) {
             cascade = v;
             var max = vexi.ui.maxdim;
@@ -177,6 +191,12 @@
             return;
         }
         
+        thisbox.enterRight = function(){
+               thisbox.focused = true;
+               thisbox.selected = $dateview[$dateview.numchildren-1];       
+        };
+        
+        
         thisbox.KeyPressed ++= function(v) {
             if (popped) {
                 // delegate to datepicker if it's open
@@ -190,6 +210,11 @@
             }
             if (v.length>1) {
                 // timeview still on display
+                if(selected==null){
+                       selected = $dateview[si-2];
+                       return;
+                }
+                
                 var si = dateview.indexof(selected);
                 switch(v) {
                 case "left":
@@ -200,6 +225,10 @@
                 case "right":
                     if (4>si) {
                         selected = $dateview[si+2];
+                    }else{
+                       if(exitRight){
+                               exitRight();
+                       }
                     }
                     break;
                 case "up":
@@ -213,7 +242,7 @@
                     break;
                 case "enter":
                     if (value==null) {
-                        value = vexi.js.Date.today.as("YMD");
+                        setDefault();
                     } else {
                         value = value;
                     }

Modified: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datetime.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datetime.t 
    2015-12-09 15:57:13 UTC (rev 4835)
+++ 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datetime.t 
    2015-12-19 06:32:58 UTC (rev 4836)
@@ -6,31 +6,79 @@
     <ui:box margin="3" shrink="true">
         <datefield id="date" margin="0" fieldid="datefield" />
         <timefield id="time" margin="0" fieldid="timefield" />
-        
         const Date = vexi.js.Date;
+        const Instant = vexi.js.Instant;
         
+        thisbox["default"] ++= function(){
+               return ""+(cascade?:new vexi.js.Instant());             
+        };
+        
+        // handle interaction between the two widgets
+        
+        $date["default"] ++= function(){
+               var dt = ""+(thisbox["default"]);
+               var arr = dt.split(' ');
+            return Date.tryParseString(arr[0]);
+        };
+        
+        // scroll left/right between them
+        $date.exitRight = function(){
+               $time.enterLeft();
+               return true;
+        }
+        $time.exitLeft = function(){
+               $date.enterRight();
+               return true;
+        };
+        
+        // pass over/underflow from timefield to date
+        $time.dayout ++= function(v){
+               $date.value = $date.value.addPeriod('day', v);
+        };
+        
+        
+        const castValue = function(v){
+               if((typeof v)=="string"){
+                       return Instant.tryParseTimestamp(v);
+               }
+               return v;               
+        };
+                
+        const keyWrite = function(v){
+               switch(v){
+               case "enter":
+                       if(value==null){
+                               if($date.value!=null){
+                                       $time.setDefault();
+                               }else if($time.value!=null){
+                                       $date.setDefault();
+                               }else{
+                                       thisbox.value = 
castValue(thisbox["default"]); 
+                               }
+                               return;
+                       }
+                       break;
+               case "back_space":
+               case "delete":
+                       $date.value = null;
+                       $time.value = null;
+                   return;        
+               }
+               
+               cascade = v;
+        };
+        
+        $date.KeyPressed ++= keyWrite;
+        $time.KeyPressed ++= keyWrite;
+        
         thisbox.v_datefield = $date;
         thisbox.v_timefield = $time;
         thisbox.v_fillbox = thisbox;
         thisbox.v_textbox = false;
         
         thisbox.valuetype;
+
         
-        thisbox.date ++= function(v) {
-            $date.value = v;
-            $time.value = v;
-            return;
-        }
-        
-        thisbox.date ++= function() {
-            var dstr = $date.value+' '+$time.value;
-            try {
-                return vexi.date(dstr);
-            } catch(e) {
-                throw "invalid date string: "+d;
-            }
-        }
-        
         thisbox.enabled ++= function(v) {
             cascade = v;
             $date.enabled = v;
@@ -75,9 +123,12 @@
                 }
                 // purposefully fall through...
             case "date":
+               $date.value = v;
+                $time.setDefault();
+               break;
             case "null":
-                $date.value = v;
-                $time.value = v;
+                $date.value = null;
+                $time.value = null;
                 break;
             default:
                 throw "unsupported datetime type '"+typeof(v)+"'";
@@ -94,17 +145,13 @@
             }
             
             var r = d+' '+t;
-            if(valuetype=="vexi.js.Instant"){
-                r = vexi.js.Instant.tryParseTimestamp(r);
-                if(r==null) throw d+' '+t;                
-            }
-            
+            r = vexi.js.Instant.tryParseTimestamp(r);            
             storeval = r;
             return storeval;
         }
         
-        var updateValue = function(v) {
-            cascade = v;
+        var updateValue = function(v1) {
+            cascade = v1;
             value = value;
         }
         

Modified: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/timefield.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/timefield.t
    2015-12-09 15:57:13 UTC (rev 4835)
+++ 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/timefield.t
    2015-12-19 06:32:58 UTC (rev 4836)
@@ -90,9 +90,11 @@
         thisbox.hours  ++= function(v){
             while (v>23) {
                v = v-24;
+               dayout = 1;
                }
                while (0>v) {
                    v = v+24;
+                   dayout = -1;
                }
                
                if(_hours!=v){
@@ -273,6 +275,10 @@
         thisbox.focused ++= .timefield..focusWrite;
         thisbox.selected ++= .timefield..selectWrite;
         
+        thisbox.enterLeft = function(){
+               thisbox.focused = true;
+               thisbox.selected = $hours;       
+        };
         
         const selectPart = function(v) {
             selected = trapee;
@@ -283,7 +289,7 @@
         $mins.Press1   ++= selectPart;
         $period.Press1 ++= selectPart;
         
-        const setDefault = function(){
+        thisbox.setDefault = function(){
             if(_hours==null and _mins==null){
                parseValue(thisbox["default"]?:"now");
                        internalTrigger();
@@ -424,7 +430,11 @@
                 // timeview still on display
                 switch(v) {
                 case "left":
-                    selected = (selected==$period?$mins:$hours);
+                       if(selected==$hours and exitLeft){
+                               exitLeft();
+                       }else{
+                       selected = (selected==$period?$mins:$hours);
+                    }
                     break;
                 case "right":
                     selected = (selected==$hours?$mins:$period);

Added: 
branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/currencyfield.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/currencyfield.t  
                        (rev 0)
+++ branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/currencyfield.t  
2015-12-19 06:32:58 UTC (rev 4836)
@@ -0,0 +1,19 @@
+<!-- public domain -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget">
+    <w:surface />
+    <ui:box orient="vertical">
+        <ui:Box text="currency"/>
+        <w:numfield id="field"  scale="0" width="80">
+               <ui:Box align="left" id="box">
+                       <ui:Box width="2"  fill="#99ffffff"/>
+                       <ui:Box text="$" hshrink="true" fill="#77ffffff"/>      
        
+               </ui:Box>
+               thisbox.th_view.add($box);
+        </w:numfield>            
+            
+           
+        vexi.ui.frame = thisbox;
+        
+    </ui:box>
+</vexi>

Modified: branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t       
2015-12-09 15:57:13 UTC (rev 4835)
+++ branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t       
2015-12-19 06:32:58 UTC (rev 4836)
@@ -5,10 +5,15 @@
     <ui:box orient="vertical">
         <ui:box>
             <ui:box id="set1" orient="vertical">
-                       <w:timefield fill="#ffff99" id="time"/>
-                       <w:datefield fill="#ffff99" id="date"/>
+                       <!--<w:timefield fill="#ffff99" id="time"/>
+                       <w:datefield fill="#ffff99" id="date"/>-->
                        <w:datetime fill="#ffff99" id="datetime"/>
-                       <w:weekfield fill="#ffff99" id="week"/>
+                       <w:datetime fill="#ffff99" id="datetime2">
+                               thisbox["default"] ++= function(){
+                                       return "1969-07-07 12:00:00";           
                        
+                               };
+                       </w:datetime>
+                <!--        <w:weekfield fill="#ffff99" id="week"/>
                 <w:monthfield fill="#ffff99" />
                 <w:quarterfield fill="#ffff99" />
                        <w:yearfield fill="#ffff99" />
@@ -20,7 +25,7 @@
                 <w:datetime />
                 <w:monthfield />
                 <w:quarterfield />
-                <w:yearfield />
+                <w:yearfield />-->
             </ui:box>
         </ui:box>
         <ui:box>
@@ -46,13 +51,14 @@
         
         var printValueTrap = function(v){
             cascade = v;
-            vexi.trace(v);
+            vexi.trace([typeof v, v]);
+            if(v!=null and (typeof v)!="instant"){
+               trace(new vexi.js.Exception());
+            }
         };
         
         for (var i,b in $set1)
             b.value ++= printValueTrap;
-        $date.valuetype = "vexi.util.date";
-        $datetime.valuetype = "vexi.js.Instant";
         
         vexi.ui.frame = thisbox;
         

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to