]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/search_bar.js
no longer using dtree
[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 attachEvt( "common", "locationChanged", updateLoc );
6
7 var isFrontPage = false;
8
9
10 G.evt.common.init.push(searchBarInit);
11
12 /* if set by the org selector, this will be the location used the
13         next time the search is submitted */
14 var newSearchLocation; 
15 var newSearchDepth = null;
16
17 function searchBarInit() {
18
19         _ts = G.ui.searchbar.type_selector;
20         _ds = G.ui.searchbar.depth_selector;
21         _fs = G.ui.searchbar.form_selector;
22
23         G.ui.searchbar.text.focus();
24         //G.ui.searchbar.text.onkeypress = 
25         G.ui.searchbar.text.onkeydown = 
26                 function(evt) {if(userPressedEnter(evt)) { searchBarSubmit(); } };
27
28         G.ui.searchbar.submit.onclick = searchBarSubmit;
29
30         _ds.onchange = depthSelectorChanged;
31
32         if( getLocation() == globalOrgTree.id() ) {
33                 unHideMe( G.ui.searchbar.lib_sel_span );
34                 G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
35         } else {
36                 unHideMe( G.ui.searchbar.depth_sel_span );
37                 buildLocationSelector();
38         }
39
40         /* set up the selector objects, etc */
41         G.ui.searchbar.text.value = (getTerm() != null) ? getTerm() : "";
42         setSelector(_ts,        getStype());
43         setSelector(_ds,        getDepth());
44         setSelector(_fs,        getForm());
45
46 }
47
48 var orgTreeIsBuilt = false;
49 function _opacHandleLocationTagClick() {
50         /*
51         orgTreeSelector.openTo(  
52                 (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
53                 */
54         swapCanvas(G.ui.common.org_container);
55
56         if(!orgTreeIsBuilt) {
57                 drawOrgTree();
58                 orgTreeIsBuilt = true;
59                 //hideMe($('org_loading_div'));
60         }
61
62 }
63
64 function depthSelectorChanged() {
65         var i = _ds.selectedIndex;
66         if( i == _ds.options.length - 1 ) {
67                 setSelector( _ds, getDepth() );
68                 _opacHandleLocationTagClick();
69
70         } else {
71                 if(!isFrontPage && (findCurrentPage() != MYOPAC)) {
72                         searchBarSubmit();
73                 }
74         }
75
76 }
77
78 var chooseAnotherNode;
79 function buildLocationSelector(newLoc) {
80
81         var loc;
82         if(newLoc != null) loc = newLoc;
83         else loc = getLocation();
84
85         if( loc == globalOrgTree.id() ) return;
86
87         var selector = G.ui.searchbar.depth_selector
88         if(!chooseAnotherNode) 
89                 chooseAnotherNode = selector.removeChild(
90                         selector.getElementsByTagName("option")[0]);
91         var node = chooseAnotherNode;
92         removeChildren(selector);
93         
94         var location = findOrgUnit(loc);
95         var type = findOrgType(location.ou_type());
96
97         while( type && location ) {
98                 var n = node.cloneNode(true);   
99                 n.setAttribute("value", type.depth());
100                 removeChildren(n);
101                 n.appendChild(text(type.opac_label()));
102                 selector.appendChild(n);
103                 location = findOrgUnit(location.parent_ou());
104                 if(location) type = findOrgType(location.ou_type());
105                 else type = null;
106         }
107
108         selector.appendChild(node);
109 }
110
111 function updateLoc(location, depth) {
112         if( location != null )
113                 newSearchLocation = location;
114
115         if( depth != null ) {
116                 if(depth != 0 ){
117                         G.ui.searchbar.lib_sel_link.onclick = _opacHandleLocationTagClick;
118                         if( location == globalOrgTree.id() ) {
119                                 hideMe( G.ui.searchbar.depth_sel_span );
120                                 unHideMe( G.ui.searchbar.lib_sel_span );
121                         } else {
122                                 buildLocationSelector(location);
123                                 hideMe( G.ui.searchbar.lib_sel_span );
124                                 unHideMe( G.ui.searchbar.depth_sel_span );
125                         }
126                 }
127
128                 setSelector(G.ui.searchbar.depth_selector, depth);
129                 newSearchDepth = depth;
130         }
131
132         if(!isFrontPage && (findCurrentPage() != MYOPAC) 
133                                 && (newSearchLocation != getLocation()) ) {
134                 searchBarSubmit();
135         }
136 }
137
138
139 function searchBarSubmit() {
140
141         var text = G.ui.searchbar.text.value;
142         if(!text || text == "") return;
143
144         var args = {};
145         args.page                               = MRESULT;
146         args[PARAM_OFFSET]      = 0;
147         args[PARAM_TERM]                = text;
148         args[PARAM_STYPE]               = _ts.options[_ts.selectedIndex].value;
149         args[PARAM_LOCATION] = newSearchLocation;
150         args[PARAM_DEPTH]               = (newSearchDepth != null) ? newSearchDepth : parseInt(_ds.options[_ds.selectedIndex].value);
151         args[PARAM_FORM]                = _fs.options[_fs.selectedIndex].value;
152
153         goTo(buildOPACLink(args));
154 }
155
156