Changed the tabbed dialog API to include an epilogue that
[citadel.git] / webcit / tabs.c
1 /*
2  * $Id$
3  *
4  */
5
6 #include "webcit.h"
7
8 /*
9  * print tabbed dialog
10  */
11 void tabbed_dialog(int num_tabs, char *tabnames[]) {
12         int i;
13
14         wprintf("<script type=\"text/javascript\">                                              "
15                 "var previously_selected_tab = '0';                                             "
16                 "function tabsel(which_tab) {                                                   "
17                 "       if (which_tab == previously_selected_tab) {                             "
18                 "               return;                                                         "
19                 "       }                                                                       "
20                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
21                 "       $('tabdiv'+which_tab).style.display = 'block';                          "
22                 "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
23                 "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
24                 "       previously_selected_tab = which_tab;                                    "
25                 "}                                                                              "
26                 "</script>                                                                      \n"
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>\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