]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/depth_selector.js
2403de1d40de0b11b530f47aa283466e23f8e5ad
[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;
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         return parseInt(_ds.options[_ds.selectedIndex].value);
44 }
45
46 function depthSelectorChanged() {
47         var i = _ds.selectedIndex;
48         if( i == _ds.options.length - 1 ) {
49                 setSelector( _ds, getDepth() );
50                 _opacHandleLocationTagClick();
51         } else { runEvt('common', 'depthChanged'); }
52 }
53
54 var chooseAnotherNode;
55 function buildLocationSelector(newLoc) {
56
57         var loc;
58         if(newLoc != null) loc = newLoc;
59         else loc = getLocation();
60
61         if( loc == globalOrgTree.id() ) return;
62
63         var selector = _ds;
64         if(!chooseAnotherNode) 
65                 chooseAnotherNode = selector.removeChild(
66                         selector.getElementsByTagName("option")[0]);
67         var node = chooseAnotherNode;
68         removeChildren(selector);
69         
70         var location = findOrgUnit(loc);
71         var type = findOrgType(location.ou_type());
72
73         while( type && location ) {
74                 var n = node.cloneNode(true);   
75                 n.setAttribute("value", type.depth());
76                 removeChildren(n);
77                 n.appendChild(text(type.opac_label()));
78                 selector.appendChild(n);
79                 location = findOrgUnit(location.parent_ou());
80                 if(location) type = findOrgType(location.ou_type());
81                 else type = null;
82         }
83
84         selector.appendChild(node);
85 }
86
87 function getNewSearchDepth() { return newSearchDepth; }
88 function getNewSearchLocation() { return _newlocation; }
89 function depthSelGetNewLoc() { return _newlocation; }
90
91 function updateLoc(location, depth) {
92         if( depth != null ) {
93                 if(depth != 0 ){
94                         _libsellink.onclick = _opacHandleLocationTagClick;
95                         if( location == globalOrgTree.id() ) {
96                                 hideMe( _dselspan );
97                                 unHideMe( _libselspan );
98                         } else {
99                                 buildLocationSelector(location);
100                                 hideMe( _libselspan );
101                                 unHideMe( _dselspan );
102                         }
103                 }
104
105                 setSelector(_ds, depth);
106                 newSearchDepth = depth;
107         }
108
109         _newlocation = location;
110         runEvt('common','locationUpdated', location);
111 }
112
113
114