Changeset 16013 for lang/actionscript
- Timestamp:
- 07/19/08 08:42:45 (4 months ago)
- Location:
- lang/actionscript/todoshare
- Files:
-
- 1 removed
- 5 modified
-
Todo.as (deleted)
-
TodoShare.as (modified) (4 diffs)
-
core/MObj.as (modified) (1 diff)
-
db/JSQL.as (modified) (2 diffs)
-
index.cgi (modified) (1 diff)
-
util/Debug.as (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/todoshare/TodoShare.as
r14845 r16013 1 1 package { 2 import app.Todo; 3 4 import db.JSQL; 5 2 6 import flash.display.Bitmap; 3 7 import flash.display.BitmapData; … … 10 14 import flash.net.URLRequestMethod; 11 15 import flash.net.URLVariables; 12 13 import util.Debug;14 16 [SWF(width="800",height="600",frameRate="24",backgroundColor="#FFFFFF")] 15 17 … … 50 52 "addTodo", addTodo 51 53 ); 54 ExternalInterface.addCallback( 55 "modText", modText 56 ); 52 57 53 58 ExternalInterface.addCallback( 54 "getDebug", function () { 55 return Debug.getClear(); 59 "getEvents", function () { 60 var res:Array=evtBuf; 61 evtBuf=[]; 62 return res; 56 63 } 57 ); 64 ); 65 load(); 58 66 //throw new Error(JSON.decode('{"a":"3", "b":"5"}')); 59 67 } 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 } 60 92 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(); 62 96 } 63 97 public function fillRect(x:int,y:int,w:int,h:int,col:uint):void { … … 86 120 throw new Error("received: " + e.target.data);//+" / "+params);//+"/"+ unescape(params.toString())); 87 121 } 122 public static function sendEvent(o:Object):void { 123 evtBuf[evtBuf.length]=o; 124 } 125 public static var evtBuf:Array=[]; 88 126 } 89 127 } -
lang/actionscript/todoshare/core/MObj.as
r14846 r16013 6 6 { 7 7 public var id:String; 8 //public var relations:Object; 8 9 public function MObj() 9 10 { 10 id=Date.length+""; 11 var d:Date=new Date(); 12 id=d+""; 11 13 } 12 14 -
lang/actionscript/todoshare/db/JSQL.as
r14846 r16013 1 package 1 package db 2 2 { 3 3 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; 4 12 5 13 public class JSQL … … 11 19 var variables:URLVariables = new URLVariables(); 12 20 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"); 14 23 request.method = URLRequestMethod.POST; 15 24 request.data = variables; 16 25 var urlLoader:URLLoader = new URLLoader(); 17 26 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); 19 46 } 20 47 } -
lang/actionscript/todoshare/index.cgi
r14797 r16013 1 1 #!/usr/bin/perl 2 2 3 BEGIN { 4 push @INC,"perl"; 5 } 3 6 use strict; 4 use JSON;5 7 use CGI::Carp qw(fatalsToBrowser); 6 use DBI; 8 use Html; 9 use HtmlTag; 10 header; 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 ]); 7 27 8 28 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]); } 29 sub link { 30 my ($href,$name)=@_; 31 sub { 32 my $p=shift; 33 $p->p([a,{href=>$href},$name])->brln; 34 }; 54 35 } 55 36 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 8 8 static var buf:String=""; 9 9 public static function p(s:String):void { 10 buf+=s+"\n"; 10 TodoShare.sendEvent(["debug",s]); 11 //buf+=s+"\n"; 11 12 } 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 { 13 17 var res:String=buf; 14 18 buf=""; 15 19 return res; 16 } 20 }*/ 17 21 } 18 22 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)