]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/search_bar.js
a8c7c7cf52bf2bffbdcb68c982c643ae1dba2354
[working/Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / search_bar.js
1 var searchBarExpanded = false;
2 /* our search selector boxes */
3 var _ts, _fs, _ds;
4
5
6 /* if set by the org selector, this will be the location used the
7         next time the search is submitted */
8 var newSearchLocation; 
9
10 function searchBarInit() {
11
12         _ts = G.ui.searchbar.type_selector;
13         _ds = G.ui.searchbar.depth_selector;
14         _fs = G.ui.searchbar.form_selector;
15
16         G.ui.searchbar.text.focus();
17         G.ui.searchbar.text.onkeydown = 
18                 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
19
20         G.ui.searchbar.submit.onclick = searchBarSubmit;
21         G.ui.searchbar.tag.onclick = function(){searchBarToggle();}
22
23         /* set up the selector objects, etc */
24         G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
25         setSelector(_ts,        getStype());
26         setSelector(_ds,        getDepth());
27         setSelector(_fs,        getForm());
28
29         G.ui.searchbar.location_tag.onclick = function() {
30                 orgTreeSelector.openTo(  
31                         (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
32                 swapCanvas(G.ui.common.org_container);
33         }
34 }
35
36 function updateLoc(location, depth) {
37         if( location != null )
38                 newSearchLocation = location;
39         if( depth != null ) 
40                 setSelector(G.ui.searchbar.depth_selector, depth);
41 }
42 function searchBarSubmit() {
43
44         var text = G.ui.searchbar.text.value;
45         if(!text || text == "") return;
46
47
48         var args = {};
49         args.page                               = MRESULT;
50         args[PARAM_OFFSET]      = 0;
51         args[PARAM_TERM]                = text;
52         args[PARAM_STYPE]               = _ts.options[_ts.selectedIndex].value;
53         args[PARAM_LOCATION] = newSearchLocation;
54         args[PARAM_DEPTH]               = parseInt(_ds.options[_ds.selectedIndex].value);
55         args[PARAM_FORM]                = _fs.options[_fs.selectedIndex].value;
56
57         goTo(buildOPACLink(args));
58 }
59
60
61 function searchBarToggle() {
62         if(searchBarExpanded) {
63                 hideMe(G.ui.searchbar.extra_row);
64                 hideMe(G.ui.searchbar.tag_on);
65                 unHideMe(G.ui.searchbar.tag_off);
66         } else {
67                 unHideMe(G.ui.searchbar.extra_row);
68                 hideMe(G.ui.searchbar.tag_off);
69                 unHideMe(G.ui.searchbar.tag_on);
70         }
71         searchBarExpanded = !searchBarExpanded;
72 }
73
74