updated tabbed dialog API
[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                 "       previously_selected_tab = which_tab;                                    "
28                 "}                                                                              "
29                 "</script>                                                                      \n"
30         );
31
32         wprintf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
33                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
34         );
35
36         for (i=0; i<num_tabs; ++i) {
37                 wprintf("<td id=\"tabtd%d\" class=\"%s\" "
38                         "onClick='tabsel(\"%d\");'"
39                         ">",
40                         i,
41                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
42                         i,
43                         i
44                 );
45                 wprintf("%s", tabnames[i]);
46                 wprintf("</td>");
47
48                 wprintf("<td>&nbsp;</td>\n");
49         }
50
51         wprintf("</tr></table>\n");
52         wprintf("<div class=\"tabcontent\">");
53 }
54
55 /**
56  * \brief print the tab-header
57  * \param tabnum number of the tab to print
58  * \param num_tabs total number oftabs to be printed
59  */
60 void begin_tab(int tabnum, int num_tabs) {
61         wprintf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
62         wprintf("<div id=\"tabdiv%d\" style=\"display:%s\">",
63                 tabnum,
64                 ( (tabnum == 0) ? "block" : "none" )
65         );
66 }
67
68 /**
69  * \brief print the tab-footer
70  * \param tabnum number of the tab to print
71  * \param num_tabs total number of tabs to be printed
72  */
73 void end_tab(int tabnum, int num_tabs) {
74         wprintf("</div>\n");
75         wprintf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
76
77         if (tabnum == num_tabs-1) {
78                 wprintf("</div>\n");
79                 wprintf("<script type=\"text/javascript\">"
80                         " Nifty(\"table#TheTabs td\", \"small transparent top\");"
81                         " Nifty(\"div.tabcontent\", \"big transparent bottom\");"
82                         " Nifty(\"div.tabcontent_submit\", \"big transparent bottom\");"
83                         "</script>"
84                 );
85         }
86 }
87
88
89 /*@}*/