]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/SearchBarFormChunk.js
0fe30a5a01ab25b2d9e18ec6819d66c77f4dbb91
[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         if(this.searchRange) {
37                 for( var index in globalOrgTypes ) {
38                         var otype = globalOrgTypes[index]
39                         var select =  new Option(otype.name(), otype.depth());
40         
41                         debug("org depth " + otype.name() + " : " + otype.depth() );
42                         if( otype.depth() == globalSearchDepth ) {
43                                 debug("Building range selector with depth " 
44                                                 + globalSearchDepth  + " and name " + otype.name() );
45                                 select.selected = true;
46                                 //this.searchRange.selectedIndex
47                         }
48         
49                         this.searchRange.options[index] = select;
50                 }
51         }
52
53 }
54         
55         
56 function mrSearchSubmitForm() {
57         var search_query                = getById("mr_search_query").value;
58         var search_type         = getById("mr_search_type").value;
59
60         var depth = globalSearchDepth;
61         var location = globalSelectedLocation;
62         if(location == null) 
63                 location = globalLocation.id();
64         else
65                 location = location.id();
66
67         url_redirect( [ 
68                         "target",                                       "mr_result",
69                         "mr_search_type",                       search_type,
70                         "mr_search_query",              search_query,
71                         "mr_search_location",   location,
72                         "mr_search_depth",              depth,
73                         "page",                                         0
74                         ] );
75 }
76
77
78 /* forces the submission of the search */
79 function mrSearchSubmitOnEnter(evt) {
80         evt = (evt) ? evt : ((window.event) ? event : null); /* for mozilla and IE */
81         var obj = globalSearchBarFormChunk;
82         var code = grabCharCode(evt); 
83         if(code==13||code==3) { 
84                 mrSearchSubmitForm();
85         }
86 }
87
88
89