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