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;
59 //hideMe($('org_loading_div'));
64 function depthSelectorChanged() {
65 var i = _ds.selectedIndex;
66 if( i == _ds.options.length - 1 ) {
67 setSelector( _ds, getDepth() );
68 _opacHandleLocationTagClick();
71 if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
78 var chooseAnotherNode;
79 function buildLocationSelector(newLoc) {
82 if(newLoc != null) loc = newLoc;
83 else loc = getLocation();
85 if( loc == globalOrgTree.id() ) return;
87 var selector = G.ui.searchbar.depth_selector
88 if(!chooseAnotherNode)
89 chooseAnotherNode = selector.removeChild(
90 selector.getElementsByTagName("option")[0]);
91 var node = chooseAnotherNode;
92 removeChildren(selector);
94 var location = findOrgUnit(loc);
95 var type = findOrgType(location.ou_type());
97 while( type && location ) {
98 var n = node.cloneNode(true);
99 n.setAttribute("value", type.depth());
101 n.appendChild(text(type.opac_label()));
102 selector.appendChild(n);
103 location = findOrgUnit(location.parent_ou());
104 if(location) type = findOrgType(location.ou_type());
108 selector.appendChild(node);
111 function updateLoc(location, depth) {
112 if( location != null )
113 newSearchLocation = location;
115 if( depth != null ) {
117 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
118 if( location == globalOrgTree.id() ) {
119 hideMe( G.ui.searchbar.depth_sel_span );
120 unHideMe( G.ui.searchbar.lib_sel_span );
122 buildLocationSelector(location);
123 hideMe( G.ui.searchbar.lib_sel_span );
124 unHideMe( G.ui.searchbar.depth_sel_span );
128 setSelector(G.ui.searchbar.depth_selector, depth);
129 newSearchDepth = depth;
132 if(!isFrontPage && (findCurrentPage() != MYOPAC)
133 && (newSearchLocation != getLocation()) ) {
139 function searchBarSubmit() {
141 var text = G.ui.searchbar.text.value;
142 if(!text || text == "") return;
146 args[PARAM_OFFSET] = 0;
147 args[PARAM_TERM] = text;
148 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
149 args[PARAM_LOCATION] = newSearchLocation;
150 args[PARAM_DEPTH] = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
151 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
153 goTo(buildOPACLink(args));