]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/search_bar.js
more advanced search fun
[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
17 function searchBarInit() {
18
19         _ts = G.ui.searchbar.type_selector;
20         _fs = G.ui.searchbar.form_selector;
21
22         G.ui.searchbar.text.focus();
23         G.ui.searchbar.text.onkeydown = 
24                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
25
26         G.ui.searchbar.submit.onclick = searchBarSubmit;
27
28         /* set up the selector objects, etc */
29         G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
30         setSelector(_ts,        getStype());
31         setSelector(_fs,        getForm());
32
33         depthSelInit();
34
35
36         if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
37                 attachEvt('common','depthChanged', searchBarSubmit);
38         }
39
40 }
41
42 function searchBarSubmit() {
43
44         var text = G.ui.searchbar.text.value;
45
46         if(!text) { /* assume it's an advaned search? */
47                 if(getAdvTerm()){}
48         }
49
50         if(!text || text == "") return;
51         var d   = (newSearchDepth != null) ?  newSearchDepth : depthSelGetDepth();
52         if(isNaN(d)) d = 0;
53
54         var args = {};
55         args.page                               = MRESULT;
56         args[PARAM_OFFSET]      = 0;
57         args[PARAM_TERM]                = text;
58         args[PARAM_STYPE]               = _ts.options[_ts.selectedIndex].value;
59         args[PARAM_LOCATION] = depthSelGetNewLoc();
60         args[PARAM_DEPTH]               = d;
61         args[PARAM_FORM]                = _fs.options[_fs.selectedIndex].value;
62
63         goTo(buildOPACLink(args));
64 }
65
66