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