Cleaned up some templated HTML:
[citadel.git] / webcit / tabs.c
1 /*
2  * $Id$
3  *
4  */
5 #include <stdarg.h>
6 #define SHOW_ME_VAPPEND_PRINTF
7 #include "webcit.h"
8
9 /*
10  * print tabbed dialog
11  */
12 void tabbed_dialog(int num_tabs, char *tabnames[]) {
13         int i;
14
15         StrBufAppendPrintf(WC->trailing_javascript,
16                 "var previously_selected_tab = '0';                                             "
17                 "function tabsel(which_tab) {                                                   "
18                 "       if (which_tab == previously_selected_tab) {                             "
19                 "               return;                                                         "
20                 "       }                                                                       "
21                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
22                 "       $('tabdiv'+which_tab).style.display = 'block';                          "
23                 "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
24                 "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
25                 "       previously_selected_tab = which_tab;                                    "
26                 "}                                                                              "
27         );
28
29         wprintf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
30                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
31         );
32
33         for (i=0; i<num_tabs; ++i) {
34                 wprintf("<td id=\"tabtd%d\" class=\"%s\" "
35                         "onClick='tabsel(\"%d\");'"
36                         ">",
37                         i,
38                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
39                         i
40                         );
41                 wprintf("%s", tabnames[i]);
42                 wprintf("</td>");
43
44                 wprintf("<td>&nbsp;</td>\n");
45         }
46
47         wprintf("</tr></table>\n");
48 }
49
50 /*
51  * print the tab-header
52  *
53  * tabnum:       number of the tab to print
54  * num_tabs:     total number oftabs to be printed
55  *
56  */
57 void begin_tab(int tabnum, int num_tabs) {
58
59         if (tabnum == num_tabs) {
60                 wprintf("<!-- begin tab-common epilogue -->\n");
61                 wprintf("<div class=\"tabcontent_submit\">");
62         }
63
64         else {
65                 wprintf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
66                 wprintf("<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
67                         tabnum,
68                         ( (tabnum == 0) ? "block" : "none" )
69                 );
70         }
71 }
72
73 /*
74  * print the tab-footer
75  * tabnum:       number of the tab to print
76  * num_tabs:     total number of tabs to be printed
77  *
78  */
79 void end_tab(int tabnum, int num_tabs) {
80
81         if (tabnum == num_tabs) {
82                 wprintf("</div> <!-- end of 'tabcontent_submit' div -->\n");
83                 wprintf("<!-- end tab-common epilogue -->\n");
84         }
85
86         else {
87                 wprintf("</div>\n");
88                 wprintf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
89         
90                 if (tabnum == num_tabs-1) {
91                         wprintf("<script type=\"text/javascript\">"
92                                 " Nifty(\"table#TheTabs td\", \"small transparent top\");"
93                                 "</script>"
94                         );
95                 }
96         }
97 }
98
99
100 /*
101  * print tabbed dialog
102  */
103 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]) {
104         int i;
105
106         StrBufAppendBufPlain(
107                 Target, 
108                 HKEY(
109                         "<script type=\"text/javascript\">                                              "
110                         "var previously_selected_tab = '0';                                             "
111                         "function tabsel(which_tab) {                                                   "
112                         "       if (which_tab == previously_selected_tab) {                             "
113                         "               return;                                                         "
114                         "       }                                                                       "
115                         "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
116                         "       $('tabdiv'+which_tab).style.display = 'block';                          "
117                         "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
118                         "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
119                         "       previously_selected_tab = which_tab;                                    "
120                         "}                                                                              "
121                         "</script>                                                                      \n"
122                         ), 0);
123
124         StrBufAppendBufPlain(
125                 Target, 
126                 HKEY(
127                         "<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
128                         "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
129                         ), 0);
130
131         for (i=0; i<num_tabs; ++i) {
132                 StrBufAppendPrintf(
133                         Target, 
134                         "<td id=\"tabtd%d\" class=\"%s\" "
135                         "onClick='tabsel(\"%d\");'"
136                         ">",
137                         i,
138                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
139                         i
140                         );
141                 StrBufAppendBuf(Target, tabnames[i], 0);
142                 StrBufAppendBufPlain(
143                         Target, 
144                         HKEY(
145                                 "</td>"
146                                 "<td>&nbsp;</td>\n"), 0);
147         }
148
149         StrBufAppendBufPlain(
150                 Target, 
151                 HKEY("</tr></table>\n"), 0);
152 }
153
154 /*
155  * print the tab-header
156  *
157  * tabnum:       number of the tab to print
158  * num_tabs:     total number oftabs to be printed
159  *
160  */
161 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs) {
162
163         if (tabnum == num_tabs) {
164                 StrBufAppendBufPlain(
165                         Target, 
166                         HKEY(
167                                 "<!-- begin tab-common epilogue -->\n"
168                                 "<div class=\"tabcontent_submit\">"), 0);
169         }
170
171         else {
172                 StrBufAppendPrintf(
173                         Target, 
174                         "<!-- begin tab %d of %d -->\n"
175                         "<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
176                         tabnum, num_tabs, 
177                         tabnum,
178                         ( (tabnum == 0) ? "block" : "none" )
179                         );
180         }
181 }
182
183 /*
184  * print the tab-footer
185  * tabnum:       number of the tab to print
186  * num_tabs:     total number of tabs to be printed
187  *
188  */
189 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs) {
190
191         if (tabnum == num_tabs) {
192                 StrBufAppendBufPlain(
193                         Target, 
194                         HKEY(
195                                 "</div>\n"
196                                 "<!-- end tab-common epilogue -->\n"), 0);
197         }
198
199         else {
200                 StrBufAppendPrintf(
201                         Target, 
202                         "</div>\n",
203                         "<!-- end tab %d of %d -->\n", tabnum, num_tabs);
204         
205                 if (tabnum == num_tabs-1) {
206                         StrBufAppendBufPlain(
207                                 Target, 
208                                 HKEY(
209                                         "<script type=\"text/javascript\">"
210                                         " Nifty(\"table#TheTabs td\", \"small transparent top\");"
211                                         "</script>"), 0);
212                 }
213         }
214 }
215
216