search_form.xul can take and make URI query components
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / search_form.js
1 dump('entering patron/search_form.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.search_form = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('main.network'); this.network = new main.network();
8         this.w = window;
9 }
10
11 patron.search_form.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.session = params['session'];
18
19                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
20                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
21
22                 JSAN.use('main.controller'); obj.controller = new main.controller();
23                 obj.controller.init(
24                         {
25                                 control_map : {
26                                         'cmd_broken' : [
27                                                 ['command'],
28                                                 function() { alert('Not Yet Implemented'); }
29                                         ],
30                                         'cmd_patron_search_submit' : [
31                                                 ['command'],
32                                                 function() {
33                                                         var query = '';
34                                                         for (var i = 0; i < obj.controller.render_list.length; i++) {
35                                                                 var id = obj.controller.render_list[i][0];
36                                                                 var node = document.getElementById(id);
37                                                                 if (node && node.value != '') {
38                                                                         if (query == '') {
39                                                                                 query += '?';
40                                                                         } else {
41                                                                                 query += '&';
42                                                                         }
43                                                                         query += id + '=' + window.escape(node.value);
44                                                                         dump('id = ' + id + '  value = ' + node.value + '\n');
45                                                                 }
46                                                         }
47                                                         if (typeof obj.on_submit == 'function') {
48                                                                 obj.on_submit(query);
49                                                         }
50                                                         if (typeof window.xulG == 'object' 
51                                                                 && typeof window.xulG.on_submit == 'function') {
52                                                                 obj.error.sdump('D_PATRON','patron.search_form: Calling external .on_submit()\n');
53                                                                 window.xulG.on_submit(query);
54                                                         } else {
55                                                                 obj.error.sdump('D_PATRON','patron.search_form: No external .on_query()\n');
56                                                         }
57
58                                                 }
59                                         ],
60                                         'cmd_patron_search_clear' : [
61                                                 ['command'],
62                                                 function() { obj.controller.render(); }
63                                         ],
64                                         'family_name' : [
65                                                 ['render'],
66                                                 function(e) {
67                                                         return function() {
68                                                                 if (params.query&&params.query.family_name) {
69                                                                         e.setAttribute('value',params.query.family_name);
70                                                                         e.value = params.query.family_name;
71                                                                 } else {
72                                                                         e.value = '';
73                                                                 }
74                                                         };
75                                                 }
76                                         ],
77                                         'first_given_name' : [
78                                                 ['render'],
79                                                 function(e) {
80                                                         return function() {
81                                                                 if (params.query&&params.query.first_given_name) {
82                                                                         e.setAttribute('value',params.query.first_given_name);
83                                                                         e.value = params.query.first_given_name;
84                                                                 } else {
85                                                                         e.value = '';
86                                                                 }
87                                                         };
88                                                 }
89                                         ],
90                                         'second_given_name' : [
91                                                 ['render'],
92                                                 function(e) {
93                                                         return function() {
94                                                                 if (params.query&&params.query.second_given_name) {
95                                                                         e.setAttribute('value',params.query.second_given_name);
96                                                                         e.value = params.query.second_given_name;
97                                                                 } else {
98                                                                         e.value = '';
99                                                                 }
100                                                         };
101                                                 }
102                                         ],
103                                         'email' : [
104                                                 ['render'],
105                                                 function(e) {
106                                                         return function() {
107                                                                 if (params.query&&params.query.email) {
108                                                                         e.setAttribute('value',params.query.email);
109                                                                         e.value = params.query.email;
110                                                                 } else {
111                                                                         e.value = '';
112                                                                 }
113                                                         };
114                                                 }
115                                         ],
116                                         'phone' : [
117                                                 ['render'],
118                                                 function(e) {
119                                                         return function() {
120                                                                 if (params.query&&params.query.phone) {
121                                                                         e.setAttribute('value',params.query.phone);
122                                                                         e.value = params.query.phone;
123                                                                 } else {
124                                                                         e.value = '';
125                                                                 }
126                                                         };
127                                                 }
128                                         ],
129                                         'ident' : [
130                                                 ['render'],
131                                                 function(e) {
132                                                         return function() {
133                                                                 if (params.query&&params.query.ident) {
134                                                                         e.setAttribute('value',params.query.ident);
135                                                                         e.value = params.query.ident;
136                                                                 } else {
137                                                                         e.value = '';
138                                                                 }
139                                                         };
140                                                 }
141                                         ],
142                                         'street1' : [
143                                                 ['render'],
144                                                 function(e) {
145                                                         return function() {
146                                                                 if (params.query&&params.query.street1) {
147                                                                         e.setAttribute('value',params.query.street1);
148                                                                         e.value = params.query.street1;
149                                                                 } else {
150                                                                         e.value = '';
151                                                                 }
152                                                         };
153                                                 }
154                                         ],
155                                         'street2' : [
156                                                 ['render'],
157                                                 function(e) {
158                                                         return function() {
159                                                                 if (params.query&&params.query.street2) {
160                                                                         e.setAttribute('value',params.query.street2);
161                                                                         e.value = params.query.street2;
162                                                                 } else {
163                                                                         e.value = '';
164                                                                 }
165                                                         };
166                                                 }
167                                         ],
168                                         'city' : [
169                                                 ['render'],
170                                                 function(e) {
171                                                         return function() {
172                                                                 if (params.query&&params.query.city) {
173                                                                         e.setAttribute('value',params.query.city);
174                                                                         e.value = params.query.city;
175                                                                 } else {
176                                                                         e.value = '';
177                                                                 }
178                                                         };
179                                                 }
180                                         ],
181                                         'state' : [
182                                                 ['render'],
183                                                 function(e) {
184                                                         return function() {
185                                                                 if (params.query&&params.query.state) {
186                                                                         e.setAttribute('value',params.query.state);
187                                                                         e.value = params.query.state;
188                                                                 } else {
189                                                                         e.value = '';
190                                                                 }
191                                                         };
192                                                 }
193                                         ],
194                                         'post_code' : [
195                                                 ['render'],
196                                                 function(e) {
197                                                         return function() {
198                                                                 if (params.query&&params.query.post_code) {
199                                                                         e.setAttribute('value',params.query.post_code);
200                                                                         e.value = params.query.post_code;
201                                                                 } else {
202                                                                         e.value = '';
203                                                                 }
204                                                         };
205                                                 }
206                                         ],
207                                 }
208                         }
209                 );
210
211                 obj.controller.render();
212         },
213
214         'on_submit' : function(q) {
215                 var msg = 'Query = ' + q;
216                 this.error.sdump('D_PATRON', msg);
217         },
218
219 }
220
221 dump('exiting patron/search_form.js\n');