1 var searchBarExpanded = false;
2 /* our search selector boxes */
5 attachEvt( "common", "locationChanged", updateLoc );
7 var isFrontPage = false;
10 G.evt.common.init.push(searchBarInit);
12 /* if set by the org selector, this will be the location used the
13 next time the search is submitted */
14 var newSearchLocation;
15 var newSearchDepth = null;
17 function searchBarInit() {
19 _ts = G.ui.searchbar.type_selector;
20 _ds = G.ui.searchbar.depth_selector;
21 _fs = G.ui.searchbar.form_selector;
23 G.ui.searchbar.text.focus();
24 //G.ui.searchbar.text.onkeypress =
25 G.ui.searchbar.text.onkeydown =
26 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
28 G.ui.searchbar.submit.onclick = searchBarSubmit;
30 _ds.onchange = depthSelectorChanged;
32 if( getLocation() == globalOrgTree.id() ) {
33 unHideMe( G.ui.searchbar.lib_sel_span );
34 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
36 unHideMe( G.ui.searchbar.depth_sel_span );
37 buildLocationSelector();
40 /* set up the selector objects, etc */
41 G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
42 setSelector(_ts, getStype());
43 setSelector(_ds, getDepth());
44 setSelector(_fs, getForm());
48 var orgTreeIsBuilt = false;
49 function _opacHandleLocationTagClick() {
51 orgTreeSelector.openTo(
52 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
54 swapCanvas(G.ui.common.org_container);
58 orgTreeIsBuilt = true;
63 function depthSelectorChanged() {
64 var i = _ds.selectedIndex;
65 if( i == _ds.options.length - 1 ) {
66 setSelector( _ds, getDepth() );
67 _opacHandleLocationTagClick();
70 if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
77 var chooseAnotherNode;
78 function buildLocationSelector(newLoc) {
81 if(newLoc != null) loc = newLoc;
82 else loc = getLocation();
84 if( loc == globalOrgTree.id() ) return;
86 var selector = G.ui.searchbar.depth_selector
87 if(!chooseAnotherNode)
88 chooseAnotherNode = selector.removeChild(
89 selector.getElementsByTagName("option")[0]);
90 var node = chooseAnotherNode;
91 removeChildren(selector);
93 var location = findOrgUnit(loc);
94 var type = findOrgType(location.ou_type());
96 while( type && location ) {
97 var n = node.cloneNode(true);
98 n.setAttribute("value", type.depth());
100 n.appendChild(text(type.opac_label()));
101 selector.appendChild(n);
102 location = findOrgUnit(location.parent_ou());
103 if(location) type = findOrgType(location.ou_type());
107 selector.appendChild(node);
110 function updateLoc(location, depth) {
111 if( location != null )
112 newSearchLocation = location;
114 if( depth != null ) {
116 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
117 if( location == globalOrgTree.id() ) {
118 hideMe( G.ui.searchbar.depth_sel_span );
119 unHideMe( G.ui.searchbar.lib_sel_span );
121 buildLocationSelector(location);
122 hideMe( G.ui.searchbar.lib_sel_span );
123 unHideMe( G.ui.searchbar.depth_sel_span );
127 setSelector(G.ui.searchbar.depth_selector, depth);
128 newSearchDepth = depth;
131 runEvt('common','locationUpdated');
134 if(!isFrontPage && (findCurrentPage() != MYOPAC)
135 && (newSearchLocation != getLocation()) ) {
142 function searchBarSubmit() {
144 var text = G.ui.searchbar.text.value;
145 if(!text || text == "") return;
146 var d = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
151 args[PARAM_OFFSET] = 0;
152 args[PARAM_TERM] = text;
153 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
154 args[PARAM_LOCATION] = newSearchLocation;
155 args[PARAM_DEPTH] = d;
156 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
158 goTo(buildOPACLink(args));