]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/SearchBarFormChunk.js
82f9b27d76944a48fde53bbdf4c28328dc80801d
[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
13         debug("Initing searchBarFormchunk");
14         this.search_query                       = getById("mr_search_query");
15         this.search_type                        = getById("mr_search_type");
16         this.search_button              = getById("mr_search_button");
17         this.searchRange                        = getById("search_range_select");
18         this.setFormat();
19 }
20
21
22 SearchBarFormChunk.prototype.setFormat = function() {
23         var fsel                                                = getById("mr_search_format");
24         var format                                      = paramObj.__format;
25         for( var idx = 0; idx != fsel.options.length; idx++ ) {
26                 var obj = fsel.options[idx];
27                 if(obj && obj.value == format) {
28                         fsel.selectedIndex = idx;
29                         obj.selected = true;
30                 }
31         }
32
33 }
34
35 SearchBarFormChunk.prototype.resetPage = function() {
36
37         this.init();
38
39         this.search_button.onclick              = mrSearchSubmitForm;
40
41         this.search_query.onkeydown     = mrSearchSubmitOnEnter;
42         this.search_type.onkeydown              = mrSearchSubmitOnEnter;
43
44         var s = paramObj.__mr_search_query;
45         if(!s) s = lastSearchString;
46         var t = paramObj.__mr_search_type;
47         if(!t) t = lastSearchType;
48         if(s) this.search_query.value = s;
49         if(t) this.search_type.value = t;
50
51         try{ this.search_query.focus(); } catch(E) {}
52
53 //      this.resetRange();
54
55 }
56
57
58         
59 function mrSearchSubmitForm() {
60
61         var search_query                = getById("mr_search_query").value;
62         var search_type         = getById("mr_search_type").value;
63         var form                                        = getById("mr_search_format").value 
64
65         /*
66         var fsel                                        = getById("mr_search_format");
67         var form                                        = fsel.options[fsel.selectedIndex].value 
68         */
69
70
71         var depth = globalSearchDepth;
72         var location = globalSelectedLocation;
73         if(location == null) 
74                 location = globalLocation.id();
75         else
76                 location = location.id();
77
78         url_redirect( [ 
79                         "target",                                       "mr_result",
80                         "mr_search_type",                       search_type,
81                         "mr_search_query",              search_query,
82                         "mr_search_location",   location,
83                         "mr_search_depth",              depth,
84                         "format",                                       form,
85                         "page",                                         0
86                         ] );
87 }
88
89
90 /* forces the submission of the search */
91 function mrSearchSubmitOnEnter(evt) {
92         var win = getWindow();
93         evt = (evt) ? evt : ((win.event) ? globalAppFrame.event : null); /* for mozilla and IE */
94         var obj = globalSearchBarFormChunk;
95         var code = grabCharCode(evt); 
96         if(code==13 || code==3) { 
97                 mrSearchSubmitForm();
98                 return false;
99         }
100 }
101
102
103