source: branches/whiterussian/openwrt/package/webif/files/usr/lib/webif/form.awk @ 2090

Last change on this file since 2090 was 2090, checked in by nbd, 11 years ago

add some partially crazy, but effective optimizations to webif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1# $1 = type
2# $2 = form variable name
3# $3 = form variable value
4# $4 = (radio button) value of button
5# $5 = string to append
6# $6 = additional attributes
7
8BEGIN {
9        FS="|"
10}
11
12# trim leading whitespaces
13{
14        gsub(/^[ \t]+/,"",$1)
15}
16
17($1 != "") && ($1 !~ /^option/) && (select_open == 1) {
18        select_open = 0
19        print "</select>"
20}
21$1 ~ /^start_form/ {
22        if ($3 != "") field_opts=" id=\"" $3 "\""
23        else field_opts=""
24        if ($4 == "hidden") field_opts = field_opts " style=\"display: none\""
25        start_form($2, field_opts);
26        print "<table width=\"100%\" summary=\"Settings\">"
27        form_help = ""
28        form_help_link = ""
29}
30$1 ~ /^field/ {
31        if (field_open == 1) print "</td></tr>"
32        if ($3 != "") field_opts=" id=\"" $3 "\""
33        else field_opts=""
34        if ($4 == "hidden") field_opts = field_opts " style=\"display: none\""
35        print "<tr" field_opts "><td width=\"45%\">" $2 "</td><td width=\"55%\">"
36        field_open=1
37}
38$1 ~ /^checkbox/ {
39        if ($3==$4) checkbox_selected="checked=\"checked\" "
40        else checkbox_selected=""
41        print "<input id=\"" $2 "_" $4 "\" type=\"checkbox\" name=\"" $2 "\" value=\"" $4 "\" " checkbox_selected $6 " />"
42}
43$1 ~ /^radio/ {
44        if ($3==$4) radio_selected="checked=\"checked\" "
45        else radio_selected=""
46        print "<input id=\"" $2 "_" $4 "\" type=\"radio\" name=\"" $2 "\" value=\"" $4 "\" " radio_selected $6 " />"
47}
48$1 ~ /^select/ {
49        print "<select id=\"" $2 "\" name=\"" $2 "\">"
50        select_open = 1
51        select_default = $3
52}
53($1 ~ /^option/) && (select_open == 1) {
54        if ($2 == select_default) option_selected=" selected=\"selected\""
55        else option_selected=""
56        if ($3 != "") option_title = $3
57        else option_title = $2
58        print "<option" option_selected " value=\"" $2 "\">" option_title "</option>"
59}
60($1 ~ /^listedit/) {
61        n = split($4 " ", items, " ")
62        for (i = 1; i <= n; i++) {
63                if (items[i] != "") print "<tr><td width=\"50%\">" items[i] "</td><td>&nbsp;<a href=\"" $3 $2 "remove=" items[i] "\">Remove</a></td></tr>"
64        }
65        print "<tr><td width=\"100%\" colspan="2"><input type=\"text\" name=\"" $2 "add\" value=\"" $5 "\" /><input type=\"submit\" name=\"" $2 "submit\" value=\"Add\" /></td></tr>"
66}
67$1 ~ /^text/ { print "<input id=\"" $2 "\" type=\"text\" name=\"" $2 "\" value=\"" $3 "\" />" $4 }
68$1 ~ /^submit/ { print "<input type=\"submit\" name=\"" $2 "\" value=\"" $3 "\" />" }
69$1 ~ /^helpitem/ { form_help = form_help "<dt>" $2 ":</dt>" }
70$1 ~ /^helptext/ { form_help = form_help "<dd>" $2 "</dd>" }
71$1 ~ /^helplink/ { form_help_link = "<div class=\"more-help\"><a href=\"" $2 "\">more...</a></div>" }
72
73($1 ~ /^checkbox/) || ($1 ~ /^radio/) {
74        print $5
75}
76
77$1 ~ /^end_form/ {
78        if (field_open == 1) print "</td></tr>"
79        field_open = 0
80        print "</table>"
81        end_form(form_help, form_help_link);
82        form_help = ""
83        form_help_link = ""
84}
Note: See TracBrowser for help on using the repository browser.