6ef4bfde6b2b36250f0aa21196304bcea4605b39
[citadel.git] / webcit / tabs.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup TabUtils Utility functions for creating tabbed dialogs
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10
11 /**
12  * \brief print tabbed dialog
13  * \param num_tabs how many tabs do we have?
14  * \param tabnames the headers of the tables
15  */
16 void tabbed_dialog(int num_tabs, char *tabnames[]) {
17         int i;
18
19         wprintf("<script type=\"text/javascript\">                                              "
20                 "var previously_selected_tab = '0';                                             "
21                 "function tabsel(which_tab) {                                                   "
22                 "       if (which_tab == previously_selected_tab) {                             "
23                 "               return;                                                         "
24                 "       }                                                                       "
25                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
26                 "       $('tabdiv'+which_tab).style.display = 'block';                          "
27                 "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
28                 "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
29                 "       previously_selected_tab = which_tab;                                    "
30                 "}                                                                              "
31                 "</script>                                                                      \n"
32         );
33
34         wprintf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
35                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
36         );
37
38         for (i=0; i<num_tabs; ++i) {
39                 wprintf("<td id=\"tabtd%d\" class=\"%s\" "
40                         "onClick='tabsel(\"%d\");'"
41                         ">",
42                         i,
43                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
44                         i,
45                         i
46                 );
47                 wprintf("%s", tabnames[i]);
48                 wprintf("</td>");
49
50                 wprintf("<td>&nbsp;</td>\n");
51         }
52
53         wprintf("</tr></table>\n");
54 }
55
56 /**
57  * \brief print the tab-header
58  * \param tabnum number of the tab to print
59  * \param num_tabs total number oftabs to be printed
60  */
61 void begin_tab(int tabnum, int num_tabs) {
62         wprintf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
63         wprintf("<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
64                 tabnum,
65                 ( (tabnum == 0) ? "block" : "none" )
66         );
67 }
68
69 /**
70  * \brief print the tab-footer
71  * \param tabnum number of the tab to print
72  * \param num_tabs total number of tabs to be printed
73  */
74 void end_tab(int tabnum, int num_tabs) {
75         wprintf("</div>\n");
76         wprintf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
77
78         if (tabnum == num_tabs-1) {
79
80                 wprintf("<script type=\"text/javascript\">"
81                         " Nifty(\"table#TheTabs td\", \"small transparent top\");"
82                         "</script>"
83                 );
84
85         }
86 }
87
88
89 /*@}*/