]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/search_bar.js
Committing initial limit-to-available and sort options on record result page
[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
17 function searchBarInit() {
18
19         _ts = G.ui.searchbar.type_selector;
20         _fs = G.ui.searchbar.form_selector;
21
22         try{G.ui.searchbar.text.focus();}catch(e){}
23         G.ui.searchbar.text.onkeydown = 
24                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
25         _ts.onkeydown = 
26                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
27         _fs.onkeydown = 
28                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
29
30         G.ui.searchbar.submit.onclick = searchBarSubmit;
31
32         /* set up the selector objects, etc */
33         G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
34         setSelector(_ts,        getStype());
35         setSelector(_fs,        getForm());
36
37         depthSelInit();
38
39
40         if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
41                 attachEvt('common','depthChanged', searchBarSubmit);
42         }
43
44     if( (limit = $('opac.result.limit2avail')) ) {
45         if(getAvail()) limit.checked = true;
46         s = getSort()+'.'+getSortDir();
47         if(s.length > 1)
48             setSelector($('opac.result.filters'), s);
49     }
50 }
51
52 function searchBarSubmit() {
53
54         var text = G.ui.searchbar.text.value;
55
56         clearSearchParams();
57
58         if(!text || text == "") return;
59         var d   = (newSearchDepth != null) ?  newSearchDepth : depthSelGetDepth();
60         if(isNaN(d)) d = 0;
61
62         var args = {};
63
64         if(SHOW_MR_DEFAULT) {
65                 args.page                               = MRESULT;
66         } else {
67                 args.page                               = RRESULT;
68                 args[PARAM_RTYPE]               = _ts.options[_ts.selectedIndex].value;
69         }
70
71         args[PARAM_STYPE]               = _ts.options[_ts.selectedIndex].value;
72         args[PARAM_TERM]                = text;
73         args[PARAM_LOCATION] = depthSelGetNewLoc();
74         args[PARAM_DEPTH]               = d;
75         args[PARAM_FORM]                = _fs.options[_fs.selectedIndex].value;
76
77     if($('opac.result.limit2avail')) {
78         args[PARAM_AVAIL] = ($('opac.result.limit2avail').checked) ? 1 : '';
79         if( (val = getSelectorVal($('opac.result.filters'))) ) {
80             args[PARAM_SORT] = val.split('.')[0]
81             args[PARAM_SORT_DIR] = val.split('.')[1]
82         }
83     }
84
85         goTo(buildOPACLink(args));
86 }
87
88