root/lang/actionscript/todoshare/nohada.cgi @ 16259

Revision 16259, 3.0 kB (checked in by hoge1e3, 5 years ago)
Line 
1#!/usr/bin/perl
2
3BEGIN {
4  push @INC,"perl";
5}
6use strict;
7use CGI::Carp qw(fatalsToBrowser);
8use Html;
9use HtmlTag;
10use Obj;
11header;
12
13my $scr=<<'EOF';
14
15function doFocus(target) {
16  var tName=target.id;
17  var val=function (name) {
18    return (name==tName?["*"]:["like",$(name).value+"%"]);
19  }
20  var list=[
21     "FINDREL" ,
22     val("obj"),
23     val("name"),
24     val("val")
25  ];
26 
27  $("test").innerHTML=Object.toJSON(list);
28  get(list,function(data) {
29     var cand=data.map(function (e) {
30         return e[tName];
31     }).sort().uniq();
32     $("test").innerHTML=cand.length;
33     if (cand.length==1) {$(tName).value=cand[0];}
34     else {sugs[tName].candidateList=cand;}
35  });
36}
37function get(cmd,onComplete) {
38   new Ajax.Request("db.cgi", {
39                method: "put",
40                parameters: 'cmd='+encodeURI(Object.toJSON(cmd)) ,
41                onSuccess:function(httpObj){
42                   //alert(httpObj);
43                   //alert(httpObj.responseText);
44                   try {
45                     onComplete( httpObj.responseText.evalJSON() );
46                   } catch(e) {$("test").innerHTML=e;}
47                   //$("test").innerHTML=httpObj.responseText;
48                   
49                },
50                onFailure:function(httpObj) {
51                   $("test").innerHTML=httpObj.responseText;
52                }
53   });
54}
55
56var sugs=[];
57function init(id) {
58   sugs[id]= new Suggest.Local(
59             id, id+"_suggest",[id,id+"!"],
60             {dispAllKey: true});   
61}
62var start = function(){
63   init("obj");
64   init("name");
65   init("val");
66};
67function () {   
68              var suggest = new Suggest.LocalMulti("obj", "suggest",
69               list[0/*document.getElementById('select').selectedIndex*/], {dispAllKey: true});
70              /*var select = document.getElementById('select')
71              var change = function(){
72                suggest.candidateList = list[select.selectedIndex];
73              };
74              select.addEventListener ?
75                select.addEventListener('change', change, false) :
76                select.attachEvent('onchange', change);*/
77};
78window.addEventListener ?
79  window.addEventListener('load', start, false) :
80  window.attachEvent('onload', start);
81
82EOF
83my $style=<<'EOF';
84div.suggest {
85    position: absolute;
86    background-color: #FFFFFF;
87    border: 1px solid #CCCCFF;
88    font-size: 90%;
89    width: 200px;
90}
91div.select{ /* キー上下で選択した場合のスタイル */
92    color: #FFFFFF;
93    background-color: #3366FF;
94}
95div.over{ /* マウスオーバ時のスタイル */
96    background-color: #99CCFF;
97}
98EOF
99
100
101&Html::p(
102  [html,
103    [head,
104      [title,"のはだ"],
105      script(src=>"prototype.js"),
106      script(src=>"suggest.js"),
107      [script,$scr],
108      [style,$style],
109    ],
110    [body,[center,
111      [table,"\n",
112        &area("obj","の"),"\n",
113        &area("name","は"),"\n",
114        &area("val","だ"),"\n",
115      ],"\n",
116      [button(onClick=>"test()"),"OK"],[div(id=>"test"),"test"]
117    ]]
118  ]
119);
120
121sub area {
122  my ($id,$tail)=@_;
123  [&tr,
124       [td,
125            input(id=>$id,type=>"text",name=>$id,size=>50
126                  ,onFocus=>"doFocus(this)", autocomplete=>"off" ),
127            $tail,
128            div(id=>"$id\_suggest",class=>"suggest")]
129  ];
130}
131
Note: See TracBrowser for help on using the browser.