]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/search_bar.js
massive web updates,
[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 /* if set by the org selector, this will be the location used the
9         next time the search is submitted */
10 var newSearchLocation; 
11 var newSearchDepth = null;
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.onkeypress = 
21                 function(evt) {if(userPressedEnter(evt)) searchBarSubmit();};
22
23         G.ui.searchbar.submit.onclick = searchBarSubmit;
24
25         _ds.onchange = depthSelectorChanged;
26
27         if( getLocation() == globalOrgTree.id() ) {
28                 unHideMe( G.ui.searchbar.lib_sel_span );
29                 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
30         } else {
31                 unHideMe( G.ui.searchbar.depth_sel_span );
32                 buildLocationSelector();
33         }
34
35         /* set up the selector objects, etc */
36         G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
37         setSelector(_ts,        getStype());
38         setSelector(_ds,        getDepth());
39         setSelector(_fs,        getForm());
40
41 }
42
43 function _opacHandleLocationTagClick() {
44         orgTreeSelector.openTo(  
45                 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
46         swapCanvas(G.ui.common.org_container);
47 }
48
49 function depthSelectorChanged() {
50         var i = _ds.selectedIndex;
51         if( i == _ds.options.length - 1 ) {
52                 setSelector( _ds, getDepth() );
53                 _opacHandleLocationTagClick();
54         }
55 }
56
57 function buildLocationSelector() {
58
59         if( getLocation() == globalOrgTree.id() ) return;
60
61         var selector = G.ui.searchbar.depth_selector
62         var node = selector.removeChild(selector.getElementsByTagName("option")[0]);
63         
64         var location = findOrgUnit(getLocation());
65         var type = findOrgType(location.ou_type());
66
67         while( type && location ) {
68                 var n = node.cloneNode(true);   
69                 n.setAttribute("value", type.depth());
70                 removeChildren(n);
71                 n.appendChild(text(type.opac_label()));
72                 selector.appendChild(n);
73                 location = findOrgUnit(location.parent_ou());
74                 if(location) type = findOrgType(location.ou_type());
75                 else type = null;
76         }
77
78         selector.appendChild(node);
79 }
80
81 function updateLoc(location, depth) {
82         if( location != null )
83                 newSearchLocation = location;
84         if( depth != null ) {
85                 setSelector(G.ui.searchbar.depth_selector, depth);
86                 newSearchDepth = depth;
87         }
88 }
89
90
91 function searchBarSubmit() {
92
93         var text = G.ui.searchbar.text.value;
94         if(!text || text == "") return;
95
96         var args = {};
97         args.page                               = MRESULT;
98         args[PARAM_OFFSET]      = 0;
99         args[PARAM_TERM]                = text;
100         args[PARAM_STYPE]               = _ts.options[_ts.selectedIndex].value;
101         args[PARAM_LOCATION] = newSearchLocation;
102         args[PARAM_DEPTH]               = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
103         args[PARAM_FORM]                = _fs.options[_fs.selectedIndex].value;
104
105         goTo(buildOPACLink(args));
106 }
107
108