root/lang/actionscript/todoshare/todo.cgi @ 16061

Revision 16061, 2.6 kB (checked in by hoge1e3, 5 years ago)
Line 
1#!/usr/bin/perl
2
3BEGIN {
4  push @INC,"perl";
5}
6use Obj;
7
8use strict;
9use Html;
10use HtmlTag;
11use JSON;
12use CGI::Carp qw(fatalsToBrowser);
13
14require 'cgi-lib.pl';
15
16print "Content-type: text/html; charset=utf-8\n\n";
17
18my $in=&ReadParse;
19my $str_js=$in->{cmd};
20my $br=["br","\n"];
21my $script="todo.cgi";
22my $todoClass="class://Todo";
23my $eventClass="class://Event";
24my $notice= "※内容を記入すると「追加」,空欄にすると「参照」になります";
25if    ($in->{todoName}) {&add;}
26elsif ($in->{when} or $in->{whenText}) {&view; }
27else  {⊤}
28
29sub top {
30  &page(["span",\&inputForm,$notice]); 
31}
32
33sub page {
34  my $body=shift;
35  &Html::p(["html",["body",$body]]);
36}
37sub view {
38  &page(["span",
39     \&inputForm,
40     \&searchRes,
41     $notice,
42  ]);
43}
44sub add {
45   my $todo=&Obj::newID($todoClass);
46   &Obj::exe(["INSERT2",$todo,{
47      class=>$todoClass,
48      content=>$in->{todoName}
49   }]);
50   my $when;
51   if ($in->{whenText}) {
52     $when=&Obj::newID($eventClass);
53     &Obj::exe(["INSERT2",$when,{
54       class=>$eventClass,
55       content=>$in->{whenText}
56     }]);
57   } else {
58     $when=$in->{when};
59   }
60   die("when null") unless($when);
61   &Obj::exe(["MAKEREL",$when,"=>",$todo]);
62     
63   &page(sub {
64      my $c=shift;
65      $c->p("追加しました");
66      $c->p(\&inputForm);
67      $c->p($br);
68      $c->p(\&searchRes);
69   });
70}
71sub inputForm {
72    my $c=shift;
73        my $q;
74        $c->p(
75            [form(action=>$script,method=>"POST"),
76              "内容:",$br,
77              input(type=>"text" , name=>"todoName",value=>$in->{todoName}),$br,
78              "場所(条件):",$br,
79              [select(name=>"when"),
80                  sub {
81                     my $out=shift;
82                     my $res=&Obj::exe(["GET2",
83                        ["class", "content"],
84                        {
85                           class => $eventClass,
86                        },1
87                     ]);
88                     $q = "!". shift @{$res};
89                     for (@{$res}) {
90                        $out->p(["option",
91                             {value=>$_->{id}},
92                             $_->{content}                     
93                        ])->ln;
94                     }
95                  }
96              ],
97        #     ["pre",sub{@_[0]->p($q);}],
98              ["input",{type=>"text" , name=>"whenText"}],$br,
99              ["input",{type=>"submit", value=>"追加/参照※"}]
100             
101            ]
102        );
103}
104sub searchRes {
105    my $p=shift;
106    my $when = $in->{when};
107    my $res=&Obj::exe(["FINDREL", $when, "=>"]);
108#    my $res=&Obj::exe(["FINDREL", $when, "=>" , [{content:any}] ]);
109    for (@{$res}) {
110       my $id=$_->{val};
111       $p->p(["span",$_->{val},","]);       
112       my $res=&Obj::exe(["GET2",["content"], {id=>$id}]);
113       $p->p(["span",$res->[0]->{content},$br]);       
114       
115    }
116
117}
118
Note: See TracBrowser for help on using the browser.