r19282: make the recent qooxdoo work that Derrell has done available via the
[kai/samba.git] / swat / scripting / menus.js
1 /*
2         menu object for SWAT
3 */
4
5 /*
6   display a menu object. Currently only the "simple", "vertical" menu style
7   is supported
8 */
9 function menu_display() {
10         var i, m = this;
11         assert(m.style == "simple" && m.orientation == "vertical");
12         write('<div class="' + m.class + '">\n');
13         write("<i>" + m.name + "</i><br /><ul>\n");
14         for (i = 0; i < m.element.length; i++) {
15                 var e = m.element[i];
16                 write("<li><a href=\"" + e.link + "\">" + e.label + "</a></li>\n");
17         }
18         write("</ul></div>\n");
19 }
20
21
22 /*
23   create a menu object with the defaults filled in, ready for display_menu()
24  */
25 function MenuObj(name, num_elements)
26 {
27         var i, o = new Object();
28         o.name = name;
29         o.class = "menu";
30         o.style = "simple";
31         o.orientation = "vertical"
32         o.element = new Array(num_elements);
33         for (i in o.element) {
34                 o.element[i] = new Object();
35         }
36         o.display = menu_display;
37         return o;
38 }
39
40 /*
41   return a menu object created using a title, followed by
42   a set of label/link pairs
43 */
44 function simple_menu() {
45         var i, m = MenuObj(arguments[0], (arguments.length-1)/2);
46         for (i=0;i<m.element.length;i++) {
47                 var ndx = i*2;
48                 m.element[i].label = arguments[ndx+1];
49                 m.element[i].link = arguments[ndx+2];
50         }
51         return m;
52 }
53