1 var searchBarExpanded = false;
2 /* our search selector boxes */
5 attachEvt( "common", "locationChanged", updateLoc );
8 G.evt.common.init.push(searchBarInit);
10 /* if set by the org selector, this will be the location used the
11 next time the search is submitted */
12 var newSearchLocation;
13 var newSearchDepth = null;
15 function searchBarInit() {
17 _ts = G.ui.searchbar.type_selector;
18 _ds = G.ui.searchbar.depth_selector;
19 _fs = G.ui.searchbar.form_selector;
21 G.ui.searchbar.text.focus();
22 G.ui.searchbar.text.onkeypress =
23 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
25 G.ui.searchbar.submit.onclick = searchBarSubmit;
27 _ds.onchange = depthSelectorChanged;
29 if( getLocation() == globalOrgTree.id() ) {
30 unHideMe( G.ui.searchbar.lib_sel_span );
31 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
33 unHideMe( G.ui.searchbar.depth_sel_span );
34 buildLocationSelector();
37 /* set up the selector objects, etc */
38 G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
39 setSelector(_ts, getStype());
40 setSelector(_ds, getDepth());
41 setSelector(_fs, getForm());
45 function _opacHandleLocationTagClick() {
46 orgTreeSelector.openTo(
47 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
48 swapCanvas(G.ui.common.org_container);
51 function depthSelectorChanged() {
52 var i = _ds.selectedIndex;
53 if( i == _ds.options.length - 1 ) {
54 setSelector( _ds, getDepth() );
55 _opacHandleLocationTagClick();
57 } else searchBarSubmit();
61 function buildLocationSelector() {
63 if( getLocation() == globalOrgTree.id() ) return;
65 var selector = G.ui.searchbar.depth_selector
66 var node = selector.removeChild(selector.getElementsByTagName("option")[0]);
68 var location = findOrgUnit(getLocation());
69 var type = findOrgType(location.ou_type());
71 while( type && location ) {
72 var n = node.cloneNode(true);
73 n.setAttribute("value", type.depth());
75 n.appendChild(text(type.opac_label()));
76 selector.appendChild(n);
77 location = findOrgUnit(location.parent_ou());
78 if(location) type = findOrgType(location.ou_type());
82 selector.appendChild(node);
85 function updateLoc(location, depth) {
86 if( location != null )
87 newSearchLocation = location;
89 setSelector(G.ui.searchbar.depth_selector, depth);
90 newSearchDepth = depth;
96 function searchBarSubmit() {
98 var text = G.ui.searchbar.text.value;
99 if(!text || text == "") return;
103 args[PARAM_OFFSET] = 0;
104 args[PARAM_TERM] = text;
105 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
106 args[PARAM_LOCATION] = newSearchLocation;
107 args[PARAM_DEPTH] = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
108 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
110 goTo(buildOPACLink(args));