Leser: 1
10 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
HTML-Formular
|
| bei Auswahl Ajax-Request an CGI-Skript
v
zweite Select-Box füllen
|
| bei Auswahl zweiter Select-Box Ajax-Request
v
...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $file = 'article.txt'; my %hash = read_articles( $file ); my $cgi = CGI->new; my $pjx = new CGI::Ajax( 'group_one' => \&group_one, 'group_two' => \&group_two, 'group_three' => \&group_three, ); print $pjx->build_html( $cgi, \&Show_HTML); sub group_one{ # gib Select-Box mit Hauptgruppe zurück } sub group_two{ # gib Select-Box mit Subgruppe in Abhängigkeit von Hauptgruppe zurück } sub group_three{ #... } sub read_articles{ my %hash; if( open my $fh, '<', shift ){ while( my $line = <$fh> ){ chomp $line; my ($art,$g1,$g2,$g3) = split / /, $line; push @{ $hash{$g1}->{$g2}->{$g3} }, $art; } } return %hash; }
mandawar+2008-02-05 08:39:51--[...] ich hab gerade noch mal mit el Cheffe geredet und er meinte einen WebServer aufsetzen hatte er eigentlich nicht vor. [...]
mandawar+2008-02-05 08:39:51--ich hab gerade noch mal mit el Cheffe geredet und er meinte einen WebServer aufsetzen hatte er eigentlich nicht vor.
mandawar+2008-02-05 15:33:17--[...]
Es reicht also wenn der Artikelkatalog angezeigt wird, und Daten müssen an sich nicht verändert werden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
use 5.008; use strict; use warnings; use IO::Handle; use Text::CSV; use JSON; # A nested hash of groups my %hierarchy; # Parse the CSV input data into %hierarchy { my $csv = new Text::CSV(); while (my $fields = $csv->getline(\*DATA)) { my ($article, @groups) = @$fields; my $anchor = \%hierarchy; foreach (@groups) { $anchor->{$_}->{__name__} = $_; $anchor = $anchor->{$_} } push @{$anchor->{__articles__}}, $article; } die sprintf("Error parsing CSV input: %s\n", $csv->error_diag()) unless ($csv->eof()); } # Convert the hierarchy data into JS format my $hierarchy_json = do { my $json = new JSON(); $json->utf8(1)->pretty(1); $json->encode(\%hierarchy); }; # Print the HTML page print <<EOD <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Article Catalog</title> <script type="text/javascript"><![CDATA[ /* Group hierarchy generated by Perl script */ var hierarchy = $hierarchy_json; /* Group listboxes */ var group0; var group1; var group2; /* Articles list */ var articles; /* Function to fill a group selection box */ function fillInGroups(group, data) { while (group.options.length > 0) group.options[group.options.length - 1] = null; for (var name in data) if (!name.match(/^__/)) group.options[group.options.length] = new Option(name, name, true, false); group.data = data; } /* Function to fill a groups selection box according to its * parent group selection */ function fillInSubgroups(group, parent) { fillInGroups(group, parent.data[parent.value]) } /* Function to fill in the article data according to the group * selection */ function fillInArticles(group) { while (articles.firstChild != null) articles.removeChild(articles.firstChild); for each (var article in group.data[group.value].__articles__) { var text = document.createTextNode(article); var item = document.createElement("li"); item.appendChild(text); articles.appendChild(item); } } /* Initialization when the page has been loaded */ function init() { group0 = document.getElementById("group0"); group1 = document.getElementById("group1"); group2 = document.getElementById("group2"); articles = document.getElementById("articles"); fillInGroups(group0, hierarchy); } ]]></script> </head> <body onload="init()"> <h1>Article Catalog</h1> <h2>Group Selection</h2> <form action="javascript:alert('This%20is%20just%20a%20widget%20container!')"> <select id="group0" size="1" onchange="fillInSubgroups(group1, group0)"/> <select id="group1" size="1" onchange="fillInSubgroups(group2, group1)"/> <select id="group2" size="1" onchange="fillInArticles(group2)"/> </form> <h2>Articles</h2> <ul id="articles"/> </body> </html> EOD __DATA__ 42,Rhabarber,Quark,Quatsch 55,Rhabarber,Blubb,Schmarrn 27,Rhabarber,Quark,Stuss 38,Bananenbrei,Unfug,Kaese 67,Bananenbrei,Unsinn,Irgendwas
for each (var article in group.data[group.value].__articles__) {
1
2
3
var array = group.data[group.value].__articles__;
for (var index in array) {
var article = array[index];
10 Einträge, 1 Seite |