]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/search_bar.js
Use getItemType() instead of getForm() in searchBarInit().
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / search_bar.js
1 var searchBarExpanded = false;
2 /* our search selector boxes */
3 var _ts, _fs;
4
5
6 var isFrontPage = false;
7
8
9 G.evt.common.init.push(searchBarInit);
10
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;
15
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"]
22         }]
23     ).shift();  /* XXX do we want to use caching here? a cookie? */
24
25     if (!global_flag || !isTrue(global_flag.enabled))
26         return;
27     else if (global_flag.value && global_flag.value.match(/opac_visible/))
28         org_unit_getter = depthSelGetNewLoc;
29
30     dojo.require("openils.widget.AutoSuggest");
31
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(
35         {
36             "store_args": {
37                 "org_unit_getter": org_unit_getter
38             },
39             "type_selector": G.ui.searchbar.type_selector,
40             "submitter": searchBarSubmit,
41             "style": {"width": dojo.style("search_box", "width")},
42             "value": ((getTerm() != null) ? getTerm() : "")
43         }, "search_box"
44     );
45
46     G.ui.searchbar.text = widg.textbox;
47     setTimeout(function() { widg.focus(); }, 1000);/* raise chance of success */
48 }
49
50 function searchBarInit() {
51
52         _ts = G.ui.searchbar.type_selector;
53         _fs = G.ui.searchbar.form_selector;
54
55         try{G.ui.searchbar.text.focus();}catch(e){}
56         G.ui.searchbar.text.onkeydown = 
57                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
58         _ts.onkeydown = 
59                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
60         _fs.onkeydown = 
61                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
62
63         G.ui.searchbar.submit.onclick = searchBarSubmit;
64
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());
70
71         depthSelInit();
72
73
74         if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
75                 attachEvt('common','depthChanged', searchBarSubmit);
76         }
77
78     if( (limit = $('opac.result.limit2avail')) ) {
79         if(getAvail()) limit.checked = true;
80         if(getSort() && getSortDir()) 
81             setSelector($('opac.result.sort'), getSort()+'.'+getSortDir());
82     }
83
84     autoSuggestInit();
85 }
86
87 function searchBarSubmit(isFilterSort) {
88
89         var text = G.ui.searchbar.text.value;
90         var facet_text = isFrontPage ? '' : G.ui.searchbar.facets.value;
91
92     if (!isFilterSort) {        
93         clearSearchParams();
94     }
95
96         if(!text || text == "") return;
97
98         var d   = (newSearchDepth != null) ?  newSearchDepth : depthSelGetDepth();
99         if(isNaN(d)) d = 0;
100
101         var args = {};
102
103         if(SHOW_MR_DEFAULT || findCurrentPage() == MRESULT) {
104                 args.page                               = MRESULT;
105         } else {
106                 args.page                               = RRESULT;
107                 args[PARAM_RTYPE]               = _ts.options[_ts.selectedIndex].value;
108         }
109
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;
116
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]
122         }
123     }
124
125         goTo(buildOPACLink(args));
126 }
127
128