]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
missing library
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / util.js
1 dump('entering circ/util.js\n');
2
3 if (typeof circ == 'undefined') var circ = {};
4 circ.util = {};
5
6 circ.util.EXPORT_OK     = [ 
7         'columns'
8 ];
9 circ.util.EXPORT_TAGS   = { ':all' : circ.util.EXPORT_OK };
10
11 circ.util.columns = function(modify) {
12         
13         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
14
15         function getString(s) { return data.entities[s]; }
16
17         var c = [
18                 {
19                         'id' : 'acp_id', 'label' : getString('staff.acp_label_id'), 'flex' : 1,
20                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.id()'
21                 },
22                 {
23                         'id' : 'circ_id', 'label' : getString('staff.circ_label_id'), 'flex' : 1,
24                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.id()'
25                 },
26                 {
27                         'id' : 'mvr_doc_id', 'label' : getString('staff.mvr_label_doc_id'), 'flex' : 1,
28                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.doc_id()'
29                 },
30                 {
31                         'id' : 'barcode', 'label' : getString('staff.acp_label_barcode'), 'flex' : 1,
32                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.barcode()'
33                 },
34                 {
35                         'id' : 'call_number', 'label' : getString('staff.acp_label_call_number'), 'flex' : 1,
36                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.call_number()'
37                 },
38                 {
39                         'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1,
40                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.copy_number()'
41                 },
42                 {
43                         'id' : 'location', 'label' : getString('staff.acp_label_location'), 'flex' : 1,
44                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.location()'
45                 },
46                 {
47                         'id' : 'loan_duration', 'label' : getString('staff.acp_label_loan_duration'), 'flex' : 1,
48                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.loan_duration()'
49                 },
50                 {
51                         'id' : 'circ_lib', 'label' : getString('staff.acp_label_circ_lib'), 'flex' : 1,
52                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_lib()'
53                 },
54                 {
55                         'id' : 'fine_level', 'label' : getString('staff.acp_label_fine_level'), 'flex' : 1,
56                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.fine_level()'
57                 },
58                 {
59                         'id' : 'deposit', 'label' : getString('staff.acp_label_deposit'), 'flex' : 1,
60                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit()'
61                 },
62                 {
63                         'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
64                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
65                 },
66                 {
67                         'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
68                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
69                 },
70                 {
71                         'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
72                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_as_type()'
73                 },
74                 {
75                         'id' : 'circ_modifier', 'label' : getString('staff.acp_label_circ_modifier'), 'flex' : 1,
76                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_modifier()'
77                 },
78                 {
79                         'id' : 'xact_start', 'label' : getString('staff.circ_label_xact_start'), 'flex' : 1,
80                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_start()'
81                 },
82                 {
83                         'id' : 'xact_finish', 'label' : getString('staff.circ_label_xact_finish'), 'flex' : 1,
84                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_finish()'
85                 },
86                 {
87                         'id' : 'due_date', 'label' : getString('staff.circ_label_due_date'), 'flex' : 1,
88                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.due_date().substr(0,10)'
89                 },
90                 {
91                         'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 2,
92                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.title()'
93                 },
94                 {
95                         'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
96                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.author()'
97                 },
98                 {
99                         'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
100                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
101                 },
102                 {
103                         'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
104                         'primary' : false, 'hidden' : true, 'render' : 'obj.OpenILS.data.hash.ccs[ my.acp.status() ].name()'
105                 },
106         ];
107         for (var i = 0; i < c.length; i++) {
108                 if (modify[ c[i].id ]) {
109                         for (var j in modify[ c[i].id ]) {
110                                 c[i][j] = modify[ c[i].id ][j];
111                         }
112                 }
113         }
114         return c;
115 }
116
117 circ.util.std_map_row_to_column = function() {
118         return function(row,col) {
119                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
120                 // col contains one of the objects listed above in columns
121                 
122                 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
123                 var obj = {}; obj.OpenILS = {};  // One of our circ columns uses OpenILS.data
124                 JSAN.use('util.error'); obj.error = new util.error();
125                 JSAN.use('OpenILS.data'); obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
126
127                 var my = row.my;
128                 var value;
129                 try { 
130                         value = eval( col.render );
131                 } catch(E) {
132                         obj.error.sdump('D_ERROR','map_row_to_column: ' + E);
133                         value = '???';
134                 }
135                 return value;
136         }
137 }
138
139 circ.util.checkin_via_barcode = function(session,barcode,backdate) {
140         try {
141                 JSAN.use('util.error'); var error = new util.error();
142                 JSAN.use('util.network'); var network = new util.network();
143                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
144                 JSAN.use('util.date');
145                 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
146
147                 var check = network.request(
148                         api.checkin_via_barcode.app,
149                         api.checkin_via_barcode.method,
150                         [ session, barcode, null, backdate ]
151                 );
152
153                 /*
154                 { // REMOVE_ME, forcing a condition for testing
155                         check.status = 1;
156                         check.text = 'This copy is the first that could fulfill a hold.  Do it?';
157                 }
158                 */
159
160                 if (check.status != 0) {
161                         switch(check.status) {
162                                 case '1': case 1: /* possible hold capture */
163                                         var rv = error.yns_alert(
164                                                 check.text,
165                                                 'Alert',
166                                                 "Capture",
167                                                 "Don't Capture",
168                                                 null,
169                                                 "Check here to confirm this message"
170                                         );
171                                         switch(rv) {
172                                                 case 0: /* capture */
173                                                 try {
174                                                         var check2 = this.hold_capture_by_copy_barcode( session, barcode );
175                                                         if (check2) {
176                                                                 check.copy = check2.copy;
177                                                                 check.text = check2.text;
178                                                                 check.route_to = check2.route_to;
179                                                                 JSAN.use('patron.util');
180                                                                 var patron = patron.util.retrieve_au_by_id( check.hold.usr() );
181                                                                 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
182                                                                         check.record.title() + '  Author: ' + check.record.author() + 
183                                                                         '\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
184                                                                         patron.card().barcode() + ' ' + patron.family_name() + ', ' + 
185                                                                         patron.first_given_name() + '\r\n'); //FIXME
186
187                                                                 /*
188                                                                 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
189                                                                         check.record.title() + '  Author: ' + check.record.author() + 
190                                                                         '<br />\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
191                                                                         patron.card().barcode() + ' ' + patron.family_name() + ', ' + 
192                                                                         patron.first_given_name() + '<br />\r\n'
193                                                                 );
194                                                                 */
195
196                                                         }
197
198                                                 } catch(E) { 
199                                                         error.sdump('D_ERROR',E + '\n'); 
200                                                         /* 
201                                                         // demo testing 
202                                                         check.text = 'Captured for Hold';
203                                                         check.route_to = 'ARL-ATH';
204                                                         */
205                                                 }
206                                                 break;
207                                                 case 1: /* don't capture */
208
209                                                         check.text = 'Not Captured for Hold';
210                                                 break;
211                                         }
212                                 break;
213                                 case '2': case 2: /* LOST??? */
214                                         JSAN.use('patron.util');
215                                         var patron = patron.util.retrieve_au_by_id( check.circ.usr() );
216                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
217                                                         check.record.title() + '  Author: ' + check.record.author() + '\r\n' +
218                                                         'Patron: ' + patron.card().barcode() + ' ' + patron.family_name() + ', ' +
219                                                         patron.first_given_name();
220                                         var pcheck = error.yns_alert(
221                                                 msg,
222                                                 'Lost Item',
223                                                 'Edit Copy & Patron',
224                                                 "Just Continue",
225                                                 null,
226                                                 "Check here to confirm this message"
227                                         ); 
228                                         if (pcheck == 0) {
229                                                 //FIXME//Re-implement
230                                                 /*
231                                                 var w = mw.spawn_main();
232                                                 setTimeout(
233                                                         function() {
234                                                                 mw.spawn_patron_display(w.document,'new_tab','main_tabbox',{'patron':patron});
235                                                                 mw.spawn_batch_copy_editor(w.document,'new_tab','main_tabbox',
236                                                                         {'copy_ids':[ check.copy.id() ]});
237                                                         }, 0
238                                                 );
239                                                 */
240                                         }
241                                 break;
242                                 case '3': case 3: /* TRANSIT ELSEWHERE */
243                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
244                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
245                                                         check.record.title() + '  Author: ' + check.record.author() + 
246                                                         '\r\n' + 'Route To: ' + check.route_to + '\r\n';
247                                         var pcheck = error.yns_alert(
248                                                 msg,
249                                                 'Alert',
250                                                 'Print Receipt',
251                                                 "Don't Print",
252                                                 null,
253                                                 "Check here to confirm this message"
254                                         ); 
255                                         if (pcheck == 0) {
256                                                 alert('To Printer\n' + msg); //FIXME//
257                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
258                                         }
259
260                                 break;
261                                 case '4': case 4: /* transit for hold is complete */
262                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
263                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
264                                                         check.record.title() + '  Author: ' + check.record.author() + 
265                                                         '\r\n' + 'Route To: ' + check.route_to +
266                                                         '\r\n';
267                                         var pcheck = error.yns_alert(
268                                                 msg,
269                                                 'Alert',
270                                                 'Print Receipt',
271                                                 "Don't Print",
272                                                 null,
273                                                 "Check here to confirm this message"
274                                         ); 
275                                         if (pcheck == 0) {
276                                                 alert('To Printer\n' + msg); //FIXME//
277                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
278                                         }
279
280                                 break;
281
282                                 default: 
283                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
284                                         var msg = check.text + '\r\nBarcode: ' + barcode + '  Route To: ' + check.route_to;
285                                         var pcheck = error.yns_alert(
286                                                 msg,
287                                                 'Alert',
288                                                 'Print Receipt',
289                                                 "Don't Print",
290                                                 null,
291                                                 "Check here to confirm this message"
292                                         ); 
293                                         if (pcheck == 0) {
294                                                 alert('To Printer\n' + msg); //FIXME//
295                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
296                                         }
297                                 break;
298                         }
299                 } else {  // status == 0
300                 }
301                 if (parseInt(check.route_to)) {
302                         if (check.route_to != data.list.au[0].home_ou()) {
303                                 check.route_to = data.hash.aou[ check.route_to ].shortname();
304                         } else {
305                                 check.route_to = data.hash.acpl[ check.copy.location() ].name();
306                         }
307                 }
308                 return check;
309         } catch(E) {
310                 JSAN.use('util.error'); var error = new util.error();
311                 var msg = E + '\n---\n' + js2JSON(E);
312                 error.sdump('D_ERROR',msg);
313                 alert(msg);
314                 return null;
315         }
316 }
317
318 circ.util.hold_capture_by_copy_barcode = function ( session, barcode, retrieve_flag ) {
319         try {
320                 JSAN.use('util.network'); var network = new util.network();
321                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
322                 var check = network.request(
323                         api.capture_copy_for_hold_via_barcode.app,
324                         api.capture_copy_for_hold_via_barcode.method,
325                         [ session, barcode, retrieve_flag ]
326                 )[0];
327                 check.text = 'Captured for Hold';
328                 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
329                 return check;
330         } catch(E) {
331                 JSAN.use('util.error'); var error = new util.error();
332                 var msg = E + '\n---\n' + js2JSON(E);
333                 error.sdump('D_ERROR',msg);
334                 alert(msg);
335                 return null;
336         }
337 }
338
339
340 dump('exiting circ/util.js\n');