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 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
27 G.ui.searchbar.submit.onclick = searchBarSubmit;
29 _ds.onchange = depthSelectorChanged;
31 if( getLocation() == globalOrgTree.id() ) {
32 unHideMe( G.ui.searchbar.lib_sel_span );
33 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
35 unHideMe( G.ui.searchbar.depth_sel_span );
36 buildLocationSelector();
39 /* set up the selector objects, etc */
40 G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
41 setSelector(_ts, getStype());
42 setSelector(_ds, getDepth());
43 setSelector(_fs, getForm());
47 function _opacHandleLocationTagClick() {
48 orgTreeSelector.openTo(
49 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
50 swapCanvas(G.ui.common.org_container);
53 function depthSelectorChanged() {
54 var i = _ds.selectedIndex;
55 if( i == _ds.options.length - 1 ) {
56 setSelector( _ds, getDepth() );
57 _opacHandleLocationTagClick();
66 function buildLocationSelector(newLoc) {
69 if(newLoc != null) loc = newLoc;
70 else loc = getLocation();
72 if( loc == globalOrgTree.id() ) return;
74 var selector = G.ui.searchbar.depth_selector
75 var node = selector.removeChild(selector.getElementsByTagName("option")[0]);
76 removeChildren(selector);
78 var location = findOrgUnit(loc);
79 var type = findOrgType(location.ou_type());
81 while( type && location ) {
82 var n = node.cloneNode(true);
83 n.setAttribute("value", type.depth());
85 n.appendChild(text(type.opac_label()));
86 selector.appendChild(n);
87 location = findOrgUnit(location.parent_ou());
88 if(location) type = findOrgType(location.ou_type());
92 selector.appendChild(node);
95 function updateLoc(location, depth) {
96 if( location != null )
97 newSearchLocation = location;
101 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
102 if( location == globalOrgTree.id() ) {
103 hideMe( G.ui.searchbar.depth_sel_span );
104 unHideMe( G.ui.searchbar.lib_sel_span );
106 buildLocationSelector(location);
107 hideMe( G.ui.searchbar.lib_sel_span );
108 unHideMe( G.ui.searchbar.depth_sel_span );
112 setSelector(G.ui.searchbar.depth_selector, depth);
113 newSearchDepth = depth;
116 if(!isFrontPage && (findCurrentPage() != MYOPAC))
119 alert(findCurrentPage());
122 alert(findCurrentPage() == MYOPAC);
128 function searchBarSubmit() {
130 var text = G.ui.searchbar.text.value;
131 if(!text || text == "") return;
135 args[PARAM_OFFSET] = 0;
136 args[PARAM_TERM] = text;
137 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
138 args[PARAM_LOCATION] = newSearchLocation;
139 args[PARAM_DEPTH] = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
140 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
142 goTo(buildOPACLink(args));