]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/depth_selector.js
break out the org depth selector to share
[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 depthSelGetNewLoc() { return _newlocation; }
88
89 function updateLoc(location, depth) {
90         if( depth != null ) {
91                 if(depth != 0 ){
92                         _libsellink.onclick = _opacHandleLocationTagClick;
93                         if( location == globalOrgTree.id() ) {
94                                 hideMe( _dselspan );
95                                 unHideMe( _libselspan );
96                         } else {
97                                 buildLocationSelector(location);
98                                 hideMe( _libselspan );
99                                 unHideMe( _dselspan );
100                         }
101                 }
102
103                 setSelector(_ds, depth);
104                 newSearchDepth = depth;
105         }
106
107         _newlocation = location;
108         runEvt('common','locationUpdated', location);
109 }
110
111
112