]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/depth_selector.js
LP#1312309: JSPAC: remove index.xml from apache example configs and examples in docum...
[working/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         var orgHiding = checkOrgHiding();
82         while( type && location ) {
83                 var n = node.cloneNode(true);   
84                 n.setAttribute("value", type.depth());
85                 removeChildren(n);
86                 n.appendChild(text(type.opac_label()));
87                 selector.appendChild(n);
88                 location = findOrgUnit(location.parent_ou());
89                 if(location) {
90                         type = findOrgType(location.ou_type());
91                         if (orgHiding && orgHiding.depth > type.depth()) {
92                                 type = null;
93                         }
94                 } else {
95                         type = null;
96                 }
97         }
98
99         selector.appendChild(node);
100 }
101
102 function getNewSearchDepth() { return newSearchDepth; }
103 function getNewSearchLocation() { return (isNull(_newlocation)) ? LOCATION : _newlocation; }
104 function depthSelGetNewLoc() { return getNewSearchLocation(); }
105
106 function updateLoc(location, depth) {
107         if( depth != null ) {
108                 if(depth != 0 ){
109                         _libsellink.onclick = _opacHandleLocationTagClick;
110                         if( location == globalOrgTree.id() ) {
111                                 hideMe( _dselspan );
112                                 unHideMe( _libselspan );
113                         } else {
114                                 buildLocationSelector(location);
115                                 hideMe( _libselspan );
116                                 unHideMe( _dselspan );
117                         }
118                 }
119
120                 setSelector(_ds, depth);
121                 newSearchDepth = depth;
122         }
123
124         _newlocation = location;
125         runEvt('common','locationUpdated', location);
126 }
127
128
129