]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/opac/LocationTree.js
builds the org tree widget
[working/Evergreen.git] / Open-ILS / src / javascript / opac / LocationTree.js
1 /* */
2
3 function LocationTree( tree ) {
4         this.orgTree = tree;
5 }
6
7 LocationTree.prototype.buildOrgTreeWidget = function(org_node) {
8
9         var item;
10
11         if(org_node == null) {
12                 org_node = this.orgTree;
13                 item = new WebFXTree(org_node.name());
14                 this.widget = item;
15                 item.setBehavior('classic');
16         } else {
17                 item = new WebFXTreeItem(org_node.name());
18         }
19
20         item.action = "javascript:globalPage.updateSelectedLocation('" + org_node.id() + "');";
21
22         for( var index in org_node.children()) {
23                 var childorg = org_node.children()[index];
24                 if( childorg != null ) {
25                         var tree_node = buildOrgTreeWidget(childorg);
26                         if(tree_node != null)
27                                 item.add(tree_node);
28                 }
29         }
30 }
31
32
33 LocationTree.prototype.hide = function() {
34         /*
35         if(this.treeContainerBox &&  
36                         this.treeContainerBox.className.indexOf("nav_bar_visible") != -1 ) {
37                 swapClass( this.treeContainerBox, "nav_bar_hidden", "nav_bar_visible" );
38         }
39         */
40 }
41
42 LocationTree.prototype.toggle = function(button_div, offsetx, offsety) {
43
44         this.treeContainerBox = getById("ot_nav_widget");
45         this.treeBox = getById("ot_nav_widget_box");
46         swapClass( this.treeContainerBox, "nav_bar_hidden", "nav_bar_visible" );
47
48         if(this.treeBox && this.treeBox.firstChild.nodeType == 3) {
49                 setTimeout("renderTree()", 5 );
50         }
51
52         if( button_div && !offsetx && !offsety) {
53                 var x = findPosX(button_div);
54                 var y = findPosY(button_div);
55                 var height = getObjectHeight(button_div);
56                 var xpos = x - getObjectWidth(this.treeBox) + getObjectWidth(button_div);
57                 offsety = y + height;
58                 offsetx = xpos; 
59         }
60
61         this.treeContainerBox.style.position = "absolute"; 
62         this.treeContainerBox.style.top = offsety; 
63         this.treeContainerBox.style.left = offsetx;
64 }
65
66
67 function renderTree() {
68
69         globalPage.locationTree.treeContainerBox = getById("ot_nav_widget");
70         globalPage.locationTree.treeBox = getById("ot_nav_widget_box");
71
72         if(!globalPage.locationTree.widget)
73                 globalPage.locationTree.buildOrgTreeWidget(); 
74         debug(" +++++++++++++ Adding org tree widget");
75         globalPage.locationTree.treeBox.innerHTML = 
76                 globalPage.locationTree.widget.toString();
77
78 }