1 var searchBarExpanded = false;
2 /* our search selector boxes */
6 var isFrontPage = false;
9 G.evt.common.init.push(searchBarInit);
11 /* if set by the org selector, this will be the location used the
12 next time the search is submitted */
13 var newSearchLocation;
14 var newSearchDepth = null;
16 function autoSuggestInit() {
17 var org_unit_getter = null;
18 var global_flag = fieldmapper.standardRequest(
19 ["open-ils.fielder", "open-ils.fielder.cgf.atomic"], [{
20 "query": {"name": "opac.use_autosuggest"},
21 "fields": ["enabled", "value"]
23 ).shift(); /* XXX do we want to use caching here? a cookie? */
25 if (!global_flag || !isTrue(global_flag.enabled))
27 else if (global_flag.value && global_flag.value.match(/opac_visible/))
28 org_unit_getter = depthSelGetNewLoc;
30 dojo.require("openils.widget.AutoSuggest");
32 /* See comments in openils.AutoSuggestStore, esp. near the constructor,
33 * to find out what you can control with the store_args object. */
34 var widg = new openils.widget.AutoSuggest(
37 "org_unit_getter": org_unit_getter
39 "type_selector": G.ui.searchbar.type_selector,
40 "submitter": searchBarSubmit,
41 "style": {"width": dojo.style("search_box", "width")},
42 "value": ((getTerm() != null) ? getTerm() : "")
46 G.ui.searchbar.text = widg.textbox;
47 setTimeout(function() { widg.focus(); }, 1000);/* raise chance of success */
50 function searchBarInit() {
52 _ts = G.ui.searchbar.type_selector;
53 _fs = G.ui.searchbar.form_selector;
55 try{G.ui.searchbar.text.focus();}catch(e){}
56 G.ui.searchbar.text.onkeydown =
57 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
59 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
61 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
63 G.ui.searchbar.submit.onclick = searchBarSubmit;
65 /* set up the selector objects, etc */
66 G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
67 if (!isFrontPage) G.ui.searchbar.facets.value = (getFacet() != null) ? getFacet() : "";
68 setSelector(_ts, getStype());
69 setSelector(_fs, getItemType());
74 if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
75 attachEvt('common','depthChanged', searchBarSubmit);
78 if( (limit = $('opac.result.limit2avail')) ) {
79 if(getAvail()) limit.checked = true;
80 if(getSort() && getSortDir())
81 setSelector($('opac.result.sort'), getSort()+'.'+getSortDir());
87 function searchBarSubmit(isFilterSort) {
89 var text = G.ui.searchbar.text.value;
90 var facet_text = isFrontPage ? '' : G.ui.searchbar.facets.value;
96 if(!text || text == "") return;
98 var d = (newSearchDepth != null) ? newSearchDepth : depthSelGetDepth();
103 if(SHOW_MR_DEFAULT || findCurrentPage() == MRESULT) {
107 args[PARAM_RTYPE] = _ts.options[_ts.selectedIndex].value;
110 args[PARAM_STYPE] = _ts.options[_ts.selectedIndex].value;
111 args[PARAM_TERM] = text;
112 args[PARAM_FACET] = facet_text;
113 args[PARAM_LOCATION] = depthSelGetNewLoc();
114 args[PARAM_DEPTH] = d;
115 args[PARAM_FORM] = _fs.options[_fs.selectedIndex].value;
117 if($('opac.result.limit2avail')) {
118 args[PARAM_AVAIL] = ($('opac.result.limit2avail').checked) ? 1 : '';
119 if( (val = getSelectorVal($('opac.result.sort'))) ) {
120 args[PARAM_SORT] = val.split('.')[0]
121 args[PARAM_SORT_DIR] = val.split('.')[1]
125 goTo(buildOPACLink(args));