* fix various tiny flags, room-config is working flawlessly now.
[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';                                             \n"
17                 "function tabsel(which_tab) {                                                   \n"
18                 "       if (which_tab == previously_selected_tab) {                             \n"
19                 "               return;                                                         \n"
20                 "       }                                                                       \n"
21                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             \n"
22                 "       $('tabdiv'+which_tab).style.display = 'block';                          \n"
23                 "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         \n"
24                 "       $('tabtd'+which_tab).className = 'tab_cell_label';                      \n"
25                 "       previously_selected_tab = which_tab;                                    \n"
26                 "}                                                                              \n"
27         );
28
29         wc_printf("<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                 wc_printf("<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                 wc_printf("%s", tabnames[i]);
42                 wc_printf("</td>");
43
44                 wc_printf("<td>&nbsp;</td>\n");
45         }
46
47         wc_printf("</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                 wc_printf("<!-- begin tab-common epilogue -->\n");
61                 wc_printf("<div class=\"tabcontent_submit\">");
62         }
63
64         else {
65                 wc_printf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
66                 wc_printf("<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                 wc_printf("</div> <!-- end of 'tabcontent_submit' div -->\n");
83                 wc_printf("<!-- end tab-common epilogue -->\n");
84         }
85
86         else {
87                 wc_printf("</div>\n");
88                 wc_printf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
89         
90                 if (tabnum == num_tabs-1) {
91                         wc_printf("<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, StrBuf **Names) {
162
163         if (tabnum == num_tabs) {
164                 StrBufAppendBufPlain(
165                         Target, 
166                         HKEY("<!-- begin tab-common epilogue ["), 0);
167                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
168                 StrBufAppendBufPlain(
169                         Target, 
170                         HKEY("] -->\n<div class=\"tabcontent_submit\">"), 0);
171         }
172
173         else {
174                 StrBufAppendBufPlain(
175                         Target, 
176                         HKEY("<!-- begin tab "), 0);
177                 StrBufAppendPrintf(
178                         Target,  "%d of %d [",
179                         tabnum, num_tabs);
180                 
181                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
182
183                 StrBufAppendPrintf(
184                         Target, 
185                         "] -->\n<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
186                         tabnum,
187                         ( (tabnum == 0) ? "block" : "none" )
188                         );
189         }
190 }
191
192 /*
193  * print the tab-footer
194  * tabnum:       number of the tab to print
195  * num_tabs:     total number of tabs to be printed
196  *
197  */
198 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs) {
199
200         if (tabnum == num_tabs) {
201                 StrBufAppendBufPlain(
202                         Target, 
203                         HKEY(
204                                 "</div>\n"
205                                 "<!-- end tab-common epilogue -->\n"), 0);
206         }
207
208         else {
209                 StrBufAppendPrintf(
210                         Target, 
211                         "</div>\n",
212                         "<!-- end tab %d of %d -->\n", tabnum, num_tabs);
213         
214                 if (tabnum == num_tabs-1) {
215                         StrBufAppendBufPlain(
216                                 Target, 
217                                 HKEY(
218                                         "<script type=\"text/javascript\">"
219                                         " Nifty(\"table#TheTabs td\", \"small transparent top\");"
220                                         "</script>"), 0);
221                 }
222         }
223         if (HAVEBSTR("last_tabsel"))
224         {
225                 StrBufAppendPrintf(Target, "<script type=\"text/javascript\">tabsel(%s);</script>", BSTR("last_tabsel"));
226         }
227 }
228
229