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

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

add list code for lan/wan dns

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