Changeset 16013 for lang/actionscript

Show
Ignore:
Timestamp:
07/19/08 08:42:45 (4 months ago)
Author:
hoge1e3
Message:
 
Location:
lang/actionscript/todoshare
Files:
1 removed
5 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/todoshare/TodoShare.as

    r14845 r16013  
    11package { 
     2        import app.Todo; 
     3         
     4        import db.JSQL; 
     5         
    26        import flash.display.Bitmap; 
    37        import flash.display.BitmapData; 
     
    1014        import flash.net.URLRequestMethod; 
    1115        import flash.net.URLVariables; 
    12          
    13         import util.Debug; 
    1416        [SWF(width="800",height="600",frameRate="24",backgroundColor="#FFFFFF")] 
    1517     
     
    5052                                   "addTodo", addTodo 
    5153                        ); 
     54                        ExternalInterface.addCallback( 
     55                                   "modText", modText 
     56                        ); 
    5257                         
    5358                        ExternalInterface.addCallback( 
    54                                    "getDebug", function () { 
    55                                                 return Debug.getClear(); 
     59                                   "getEvents", function () { 
     60                                                var res:Array=evtBuf; 
     61                                                evtBuf=[]; 
     62                                                return res; 
    5663                                   } 
    57                         ); 
     64                        );  
     65                        load(); 
    5866                        //throw new Error(JSON.decode('{"a":"3", "b":"5"}')); 
    5967                } 
     68                public function modText(objId:String, content:String) { 
     69                        for (var i=0; i<numChildren ; i++) { 
     70                                var e=getChildAt(i); 
     71                                if (e instanceof Todo) { 
     72                                        var t:Todo=e; 
     73                                         
     74                                        /*if (t.id==objId) { 
     75                                        }*/ 
     76                                } 
     77                        } 
     78                } 
     79                public function load() { 
     80                        JSQL.select(["content","urgency","importance"],  
     81                        {},function (obj) { 
     82                                for (var i in obj) { 
     83                                        var todo:Todo=new Todo( 
     84                                           obj[i].content, 
     85                                           obj[i].urgency, 
     86                                           obj[i].importance 
     87                                        ); 
     88                                        addChild(todo); 
     89                                } 
     90                        }); 
     91                } 
    6092                public function addTodo(s:String) { 
    61                         addChild(new Todo(s,Math.random()*1-0.5,Math.random()*1-0.5)); 
     93                        var todo:Todo=new Todo(s,Math.random()*1-0.5,Math.random()*1-0.5); 
     94                        addChild(todo); 
     95                        todo.insert(); 
    6296                } 
    6397                public function fillRect(x:int,y:int,w:int,h:int,col:uint):void { 
     
    86120                throw new Error("received: " + e.target.data);//+" / "+params);//+"/"+ unescape(params.toString())); 
    87121        } 
     122        public static function sendEvent(o:Object):void { 
     123                evtBuf[evtBuf.length]=o; 
     124        } 
     125        public static var evtBuf:Array=[]; 
    88126 } 
    89127} 
  • lang/actionscript/todoshare/core/MObj.as

    r14846 r16013  
    66        { 
    77                public var id:String; 
     8                //public var relations:Object; 
    89                public function MObj() 
    910                { 
    10                         id=Date.length+""; 
     11                        var d:Date=new Date(); 
     12                        id=d+""; 
    1113                } 
    1214                 
  • lang/actionscript/todoshare/db/JSQL.as

    r14846 r16013  
    1 package 
     1package db 
    22{ 
    33        import com.adobe.serialization.json.JSON; 
     4         
     5        import flash.events.Event; 
     6        import flash.net.URLLoader; 
     7        import flash.net.URLRequest; 
     8        import flash.net.URLRequestMethod; 
     9        import flash.net.URLVariables; 
     10         
     11        import util.Debug; 
    412         
    513        public class JSQL 
     
    1119                        var variables:URLVariables = new URLVariables(); 
    1220                        variables.cmd=JSON.encode(q); 
    13                     var request:URLRequest = new URLRequest("http://192.168.28.128/workspace/TodoShare/index.cgi"); 
     21                        Debug.p(variables.cmd); 
     22                    var request:URLRequest = new URLRequest("http://192.168.28.128/workspace/TodoShare/db.cgi"); 
    1423                request.method = URLRequestMethod.POST; 
    1524                request.data = variables; 
    1625                var urlLoader:URLLoader = new URLLoader(); 
    1726                        urlLoader.load(request); 
    18                 urlLoader.addEventListener(Event.COMPLETE, onComplete); 
     27                urlLoader.addEventListener(Event.COMPLETE, function () { 
     28                        try { 
     29                           var data=JSON.decode(urlLoader.data); 
     30                           onComplete(data); 
     31                        } catch (e:Error ) { 
     32                                throw new Error("Invalid JSON: "+e+"\n"+urlLoader.data); 
     33                        }        
     34                }); 
     35                } 
     36                public static function insert(objectID:String, attrs:Object, onComplete:Function) { 
     37                        // set _class to table name 
     38                        doQuery(["INSERT2",objectID,attrs],onComplete); 
     39                } 
     40                // {from: table_name  where:{a: 3} } 
     41                public static function select(fields: Array, where:Object, onComplete:Function ) { 
     42                        doQuery(["GET2",fields],onComplete); 
     43                } 
     44                public static function del(objectID:String, onComplete:Function) { 
     45                        doQuery("DELETE2",onComplete); 
    1946                } 
    2047        } 
  • lang/actionscript/todoshare/index.cgi

    r14797 r16013  
    11#!/usr/bin/perl 
    22 
     3BEGIN { 
     4  push @INC,"perl"; 
     5} 
    36use strict; 
    4 use JSON; 
    57use CGI::Carp qw(fatalsToBrowser); 
    6 use DBI; 
     8use Html; 
     9use HtmlTag; 
     10header; 
     11 
     12&Html::p ([html, 
     13   [head, 
     14     [title,"MYS-monitor"]], 
     15   [body,  
     16      [h1,"メニュー"], 
     17       link("todo.cgi","Todo"), 
     18       link("swkText.cgi","SWK(Text Mode)"), 
     19       link("DBConsoleFlash.html","SWK(Flash Mode)"), 
     20       link("jsonDB.html","JSON DB Console"), 
     21       link("importObj.html","Import Objects(他のMYSからHTTPで取得します)"), 
     22      [h3,"File-related Menu"], 
     23       link("backupDB.html","Backup DB"), 
     24       link("restoreDB.html","Restore DB"), 
     25   ] 
     26]); 
    727 
    828 
    9 require 'cgi-lib.pl'; 
    10  
    11 print "Content-type: text/html\n\n"; 
    12  
    13 my $in=&ReadParse; 
    14 my $str_js=$in->{cmd}; 
    15  
    16 my $user = 'root'; 
    17 my $passwd = ''; 
    18 my $db = DBI->connect('DBI:mysql:todoshare:localhost', $user, $passwd); 
    19  
    20 #print $db; 
    21 my $cmd = decode_json( $str_js ); 
    22 if ($cmd->[0] eq 'GET') { 
    23         my $data=$cmd->[1]; 
    24         my $where=&where($data->{where}); 
    25         my $ord=&orderBy($data->{orderBy}); 
    26         my $query=qq( 
    27         select * from $data->{from} 
    28           $where $ord ; 
    29         ); 
    30         #die($query); 
    31         my $sth = $db->prepare($query); 
    32         my $eres=$sth->execute; 
    33         if (!$eres) { print encode_json(["Fail",$query,$sth->errstr]); exit; } 
    34         my $num_rows = $sth->rows; 
    35         my $res=[]; 
    36         for (my $i=0; $i<$num_rows; $i++) { 
    37             my $a = $sth->fetchrow_hashref; 
    38             $a->{_class}=$data->{from}; 
    39             push @{$res}, $a; 
    40         } 
    41         $sth->finish; 
    42         $db->disconnect; 
    43         print encode_json($res); 
    44 } elsif ($cmd->[0] eq 'POST' or $cmd->[0] eq 'PUT' ) { 
    45     my $data=$cmd->[1]; 
    46     my $values=&values($data); 
    47     my $query =qq( 
    48       insert into @{[&escapeSymbol($data->{_class})]} $values ; 
    49     ); 
    50     my $sth=$db->prepare($query); 
    51     my $res=$sth->execute; 
    52     if ($res) { print encode_json(["OK",$query]); } 
    53     else { print encode_json(["Fail",$query,$sth->errstr]); } 
     29sub link { 
     30  my ($href,$name)=@_; 
     31  sub {  
     32    my $p=shift; 
     33    $p->p([a,{href=>$href},$name])->brln; 
     34  }; 
    5435} 
    5536 
    56 sub values { 
    57    my $d=shift; 
    58    my @names; 
    59    my @values; 
    60    while (my ($k,$v)=each %{$d}) { 
    61       next if ($k eq "_class") ; 
    62       push @names, $k; 
    63       push @values, &escapeLiteral($v) ;  
    64    } 
    65    " (".join(", ",@names).") values (".join(", ",@values).")"; 
    66 } 
    67  
    68 sub where { 
    69   my $w=shift; 
    70   my @res; 
    71   while (my ($k,$v)=each %{$w}) { 
    72       push @res, "$k='$v'" ;  
    73   } 
    74   if (@res==0) {return ""} 
    75   "where ".join(" and ",@res); 
    76 } 
    77 sub orderBy { 
    78   my $ord=shift; 
    79   if ($ord) {" order by $ord ";} 
    80   else {"";} 
    81 } 
    82 sub escapeSymbol { 
    83   my $s=shift; 
    84   $s =~ s/\W//g; 
    85   $s; 
    86 #  $s =~ s/\\/\\\\/g; 
    87 #  $s =~ s/\"/\\"/g; 
    88 #  "\"$s\""; 
    89 } 
    90 sub escapeLiteral { 
    91   my $s=shift; 
    92   $s =~ s/\\/\\\\/g; 
    93   $s =~ s/\'/\\'/g; 
    94   "\'$s\'"; 
    95 } 
    96  
  • lang/actionscript/todoshare/util/Debug.as

    r14846 r16013  
    88                static var buf:String=""; 
    99                public static function p(s:String):void { 
    10                         buf+=s+"\n"; 
     10                        TodoShare.sendEvent(["debug",s]);  
     11                        //buf+=s+"\n"; 
    1112                } 
    12                 public static function getClear():String { 
     13                public static function o(s:Object):void { 
     14                        TodoShare.sendEvent(s); 
     15                } 
     16                /*              public static function getClear():String { 
    1317                        var res:String=buf; 
    1418                        buf=""; 
    1519                        return res; 
    16                 } 
     20                }*/ 
    1721        } 
    1822}