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