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 function _opacHandleLocationTagClick() {
50 orgTreeSelector.openTo(
51 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
53 swapCanvas(G.ui.common.org_container);
56 function depthSelectorChanged() {
57 var i = _ds.selectedIndex;
58 if( i == _ds.options.length - 1 ) {
59 setSelector( _ds, getDepth() );
60 _opacHandleLocationTagClick();
63 if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
70 var chooseAnotherNode;
71 function buildLocationSelector(newLoc) {
74 if(newLoc != null) loc = newLoc;
75 else loc = getLocation();
77 if( loc == globalOrgTree.id() ) return;
79 var selector = G.ui.searchbar.depth_selector
80 if(!chooseAnotherNode)
81 chooseAnotherNode = selector.removeChild(selector.getElementsByTagName("option")[0]);
82 var node = chooseAnotherNode;
83 removeChildren(selector);
85 var location = findOrgUnit(loc);
86 var type = findOrgType(location.ou_type());
88 while( type && location ) {
89 var n = node.cloneNode(true);
90 n.setAttribute("value", type.depth());
92 n.appendChild(text(type.opac_label()));
93 selector.appendChild(n);
94 location = findOrgUnit(location.parent_ou());
95 if(location) type = findOrgType(location.ou_type());
99 selector.appendChild(node);
102 function updateLoc(location, depth) {
103 if( location != null )
104 newSearchLocation = location;
106 if( depth != null ) {
108 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
109 if( location == globalOrgTree.id() ) {
110 hideMe( G.ui.searchbar.depth_sel_span );
111 unHideMe( G.ui.searchbar.lib_sel_span );
113 buildLocationSelector(location);
114 hideMe( G.ui.searchbar.lib_sel_span );
115 unHideMe( G.ui.searchbar.depth_sel_span );
119 setSelector(G.ui.searchbar.depth_selector, depth);
120 newSearchDepth = depth;
123 if(!isFrontPage && (findCurrentPage() != MYOPAC)
124 && (newSearchLocation != getLocation()) ) {
130 function searchBarSubmit() {
132 var text = G.ui.searchbar.text.value;
133 if(!text || text == "") return;
137 args[PARAM_OFFSET] = 0;
138 args[PARAM_TERM] = text;
139 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
140 args[PARAM_LOCATION] = newSearchLocation;
141 args[PARAM_DEPTH] = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
142 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
144 goTo(buildOPACLink(args));