1 var searchBarExpanded = false;
2 /* our search selector boxes */
6 G.evt.common.init.push(searchBarInit);
8 /* if set by the org selector, this will be the location used the
9 next time the search is submitted */
10 var newSearchLocation;
11 var newSearchDepth = null;
13 function searchBarInit() {
15 _ts = G.ui.searchbar.type_selector;
16 _ds = G.ui.searchbar.depth_selector;
17 _fs = G.ui.searchbar.form_selector;
19 G.ui.searchbar.text.focus();
20 G.ui.searchbar.text.onkeypress =
21 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
23 G.ui.searchbar.submit.onclick = searchBarSubmit;
25 _ds.onchange = depthSelectorChanged;
27 if( getLocation() == globalOrgTree.id() ) {
28 unHideMe( G.ui.searchbar.lib_sel_span );
29 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
31 unHideMe( G.ui.searchbar.depth_sel_span );
32 buildLocationSelector();
35 /* set up the selector objects, etc */
36 G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
37 setSelector(_ts, getStype());
38 setSelector(_ds, getDepth());
39 setSelector(_fs, getForm());
43 function _opacHandleLocationTagClick() {
44 orgTreeSelector.openTo(
45 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
46 swapCanvas(G.ui.common.org_container);
49 function depthSelectorChanged() {
50 var i = _ds.selectedIndex;
51 if( i == _ds.options.length - 1 ) {
52 setSelector( _ds, getDepth() );
53 _opacHandleLocationTagClick();
57 function buildLocationSelector() {
59 if( getLocation() == globalOrgTree.id() ) return;
61 var selector = G.ui.searchbar.depth_selector
62 var node = selector.removeChild(selector.getElementsByTagName("option")[0]);
64 var location = findOrgUnit(getLocation());
65 var type = findOrgType(location.ou_type());
67 while( type && location ) {
68 var n = node.cloneNode(true);
69 n.setAttribute("value", type.depth());
71 n.appendChild(text(type.opac_label()));
72 selector.appendChild(n);
73 location = findOrgUnit(location.parent_ou());
74 if(location) type = findOrgType(location.ou_type());
78 selector.appendChild(node);
81 function updateLoc(location, depth) {
82 if( location != null )
83 newSearchLocation = location;
85 setSelector(G.ui.searchbar.depth_selector, depth);
86 newSearchDepth = depth;
91 function searchBarSubmit() {
93 var text = G.ui.searchbar.text.value;
94 if(!text || text == "") return;
98 args[PARAM_OFFSET] = 0;
99 args[PARAM_TERM] = text;
100 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
101 args[PARAM_LOCATION] = newSearchLocation;
102 args[PARAM_DEPTH] = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
103 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
105 goTo(buildOPACLink(args));