trying to move towards lassos
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / depth_selector.js
1
2 attachEvt( "common", "locationChanged", updateLoc );
3
4 var _ds;
5 var _libselspan;
6 var _libselslink;
7 var _dselspan;
8 var _newlocation = null;
9
10 function depthSelInit() {
11         _ds = $('depth_selector'); 
12         _ds.onchange = depthSelectorChanged;
13         _libselspan = $('lib_selector_span');
14         _libsellink = $('lib_selector_link');
15         _dselspan = $('depth_selector_span');
16
17         if( getLocation() == globalOrgTree.id() ) {
18                 unHideMe( _libselspan );
19                 _libsellink.onclick = _opacHandleLocationTagClick;
20         } else {
21                 unHideMe( _dselspan );
22                 buildLocationSelector();
23         }
24
25         setSelector(_ds,        getDepth());
26         _newlocation = getLocation();
27 }
28
29
30 var orgTreeIsBuilt = false;
31 function _opacHandleLocationTagClick() {
32
33         swapCanvas(G.ui.common.org_container);
34
35         if(!orgTreeIsBuilt) {
36                 drawOrgTree();
37                 orgTreeIsBuilt = true;
38         }
39
40 }
41
42 function depthSelGetDepth() {
43         var depth = parseInt(_ds.options[_ds.selectedIndex].value);
44         if(isNaN(depth)) depth = 0;
45         return depth;
46 }
47
48 function depthSelectorChanged() {
49         var i = _ds.selectedIndex;
50         if( i == _ds.options.length - 1 ) {
51                 setSelector( _ds, getDepth() );
52                 _opacHandleLocationTagClick();
53         } else { 
54                 /* this re-submits the search when they change the search range
55                         disabled for testing...
56                         */
57                 /*runEvt('common', 'depthChanged');*/ 
58         }
59 }
60
61 var chooseAnotherNode;
62 function buildLocationSelector(newLoc) {
63
64         var loc;
65         if(newLoc != null) loc = newLoc;
66         else loc = getLocation();
67
68         if( loc == globalOrgTree.id() ) return;
69
70         var selector = _ds;
71         if(!chooseAnotherNode) 
72                 chooseAnotherNode = selector.removeChild(
73                         selector.getElementsByTagName("option")[0]);
74         var node = chooseAnotherNode;
75         removeChildren(selector);
76         
77         var location = findOrgUnit(loc);
78         var type;
79         if (location) type = findOrgType(location.ou_type());
80
81         while( type && location ) {
82                 var n = node.cloneNode(true);   
83                 n.setAttribute("value", type.depth());
84                 removeChildren(n);
85                 n.appendChild(text(type.opac_label()));
86                 selector.appendChild(n);
87                 location = findOrgUnit(location.parent_ou());
88                 if(location) type = findOrgType(location.ou_type());
89                 else type = null;
90         }
91
92         selector.appendChild(node);
93 }
94
95 function getNewSearchDepth() { return newSearchDepth; }
96 function getNewSearchLocation() { return (isNull(_newlocation)) ? LOCATION : _newlocation; }
97 function depthSelGetNewLoc() { return getNewSearchLocation(); }
98
99 function updateLoc(location, depth) {
100         if( depth != null ) {
101                 if(depth != 0 ){
102                         _libsellink.onclick = _opacHandleLocationTagClick;
103                         if( location == globalOrgTree.id() ) {
104                                 hideMe( _dselspan );
105                                 unHideMe( _libselspan );
106                         } else {
107                                 buildLocationSelector(location);
108                                 hideMe( _libselspan );
109                                 unHideMe( _dselspan );
110                         }
111                 }
112
113                 setSelector(_ds, depth);
114                 newSearchDepth = depth;
115         }
116
117         _newlocation = location;
118         runEvt('common','locationUpdated', location);
119 }
120
121
122