]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/SearchBarFormChunk.js
Let the onslaught continue...
[Evergreen.git] / Open-ILS / src / javascript / opac / SearchBarFormChunk.js
1 /*  */
2
3 var globalSearchBarFormChunk = null;
4
5 function SearchBarFormChunk() {
6         this.init();
7         globalSearchBarFormChunk = this;
8 }
9
10
11 SearchBarFormChunk.prototype.init = function() {
12         debug("Initing searchBarFormchunk");
13         this.search_query                       = getById("mr_search_query");
14         this.search_type                        = getById("mr_search_type");
15         this.search_button              = getById("mr_search_button");
16         this.searchRange                        = getById("search_range_select");
17 }
18
19 SearchBarFormChunk.prototype.resetPage = function() {
20
21         this.init();
22
23         this.search_button.onclick              = mrSearchSubmitForm;
24         this.search_query.onkeydown     = mrSearchSubmitOnEnter;
25         this.search_type.onkeydown              = mrSearchSubmitOnEnter;
26
27
28         if(paramObj.__mr_search_query)
29                 this.search_query.value = paramObj.__mr_search_query;
30
31         if(paramObj.__mr_search_type)
32                 this.search_type.value = paramObj.__mr_search_type;
33
34         try{ this.search_query.focus(); } catch(E) {}
35
36 //      this.resetRange();
37
38 }
39
40
41 /*
42 SearchBarFormChunk.prototype.resetRange = function() {
43
44         this.searchRange                        = getById("search_range_select");
45         var orgunit = globalSelectedLocation;
46         if(!orgunit)
47                 orgunit = globalLocation;
48
49         if(this.searchRange) {
50                 for( var index in globalOrgTypes ) {
51                         var otype = globalOrgTypes[index];
52
53                         if( otype.depth() > orgunit.ou_type() )
54                                 continue;
55
56                         var select =  new Option(otype.name(), otype.depth());
57         
58                         debug("org depth " + otype.name() + " : " + otype.depth() );
59                         if( otype.depth() == globalSearchDepth ) {
60                                 debug("Building range selector with depth " 
61                                                 + globalSearchDepth  + " and name " + otype.name() );
62                                 select.selected = true;
63                         }
64         
65                         this.searchRange.options[index] = select;
66                 }
67         }
68 }
69 */
70
71         
72 function mrSearchSubmitForm() {
73         var search_query                = getById("mr_search_query").value;
74         var search_type         = getById("mr_search_type").value;
75
76
77         var depth = globalSearchDepth;
78         var location = globalSelectedLocation;
79         if(location == null) 
80                 location = globalLocation.id();
81         else
82                 location = location.id();
83
84         url_redirect( [ 
85                         "target",                                       "mr_result",
86                         "mr_search_type",                       search_type,
87                         "mr_search_query",              search_query,
88                         "mr_search_location",   location,
89                         "mr_search_depth",              depth,
90                         "page",                                         0
91                         ] );
92 }
93
94
95 /* forces the submission of the search */
96 function mrSearchSubmitOnEnter(evt) {
97         evt = (evt) ? evt : ((window.event) ? event : null); /* for mozilla and IE */
98         var obj = globalSearchBarFormChunk;
99         var code = grabCharCode(evt); 
100         if(code==13||code==3) { 
101                 mrSearchSubmitForm();
102         }
103 }
104
105
106