Mailing list header changes (fuck you Google)
[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, const 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 }
87
88
89 /*
90  * print tabbed dialog
91  */
92 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]) {
93         int i;
94
95         StrBufAppendBufPlain(
96                 Target, 
97                 HKEY(
98                         "<script type=\"text/javascript\">                                              "
99                         "var previously_selected_tab = '0';                                             "
100                         "function tabsel(which_tab) {                                                   "
101                         "       if (which_tab == previously_selected_tab) {                             "
102                         "               return;                                                         "
103                         "       }                                                                       "
104                         "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
105                         "       $('tabdiv'+which_tab).style.display = 'block';                          "
106                         "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
107                         "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
108                         "       previously_selected_tab = which_tab;                                    "
109                         "}                                                                              "
110                         "</script>                                                                      \n"
111                         ), 0);
112
113         StrBufAppendBufPlain(
114                 Target, 
115                 HKEY(
116                         "<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
117                         "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
118                         ), 0);
119
120         for (i=0; i<num_tabs; ++i) {
121                 StrBufAppendPrintf(
122                         Target, 
123                         "<td id=\"tabtd%d\" class=\"%s\" "
124                         "onClick='tabsel(\"%d\");'"
125                         ">",
126                         i,
127                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
128                         i
129                         );
130                 StrEscAppend(Target, tabnames[i], NULL, 0, 0);
131                 StrBufAppendBufPlain(
132                         Target, 
133                         HKEY(
134                                 "</td>"
135                                 "<td>&nbsp;</td>\n"), 0);
136         }
137
138         StrBufAppendBufPlain(
139                 Target, 
140                 HKEY("</tr></table>\n"), 0);
141 }
142
143 /*
144  * print the tab-header
145  *
146  * tabnum:       number of the tab to print
147  * num_tabs:     total number oftabs to be printed
148  *
149  */
150 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs, StrBuf **Names) {
151
152         if (tabnum == num_tabs) {
153                 StrBufAppendBufPlain(
154                         Target, 
155                         HKEY("<!-- begin tab-common epilogue ["), 0);
156                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
157                 StrBufAppendBufPlain(
158                         Target, 
159                         HKEY("] -->\n<div class=\"tabcontent_submit\">"), 0);
160         }
161
162         else {
163                 StrBufAppendBufPlain(
164                         Target, 
165                         HKEY("<!-- begin tab "), 0);
166                 StrBufAppendPrintf(
167                         Target,  "%d of %d [",
168                         tabnum, num_tabs);
169                 
170                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
171
172                 StrBufAppendPrintf(
173                         Target, 
174                         "] -->\n<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
175                         tabnum,
176                         ( (tabnum == 0) ? "block" : "none" )
177                         );
178         }
179 }
180
181 /*
182  * print the tab-footer
183  * tabnum:       number of the tab to print
184  * num_tabs:     total number of tabs to be printed
185  *
186  */
187 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs) {
188
189         if (tabnum == num_tabs) {
190                 StrBufAppendBufPlain(
191                         Target, 
192                         HKEY(
193                                 "</div>\n"
194                                 "<!-- end tab-common epilogue -->\n"), 0);
195         }
196
197         else {
198                 StrBufAppendPrintf(
199                         Target, 
200                         "</div>\n",
201                         "<!-- end tab %d of %d -->\n", tabnum, num_tabs
202                 );
203         }
204         if (havebstr("last_tabsel"))
205         {
206                 StrBufAppendPrintf(Target, "<script type=\"text/javascript\">tabsel(%s);</script>", BSTR("last_tabsel"));
207         }
208 }
209
210