]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
go back to Barcode after a non-cat checkout
[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', 'hold_columns', 'CHECKIN_VIA_BARCODE', 'std_map_row_to_column', 'hold_capture_via_copy_barcode'
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                         'id' : 'checkin_status', 'label' : getString('staff.checkin_label_status'), 'flex' : 1,
108                         'primary' : false, 'hidden' : true, 'render' : 'my.status.toString()'
109                 },
110                 {
111                         'id' : 'checkin_route_to', 'label' : getString('staff.checkin_label_route_to'), 'flex' : 1,
112                         'primary' : false, 'hidden' : true, 'render' : 'my.route_to.toString()'
113                 },
114                 {
115                         'id' : 'checkin_text', 'label' : getString('staff.checkin_label_text'), 'flex' : 1,
116                         'primary' : false, 'hidden' : true, 'render' : 'my.text.toString()'
117                 }
118
119         ];
120         for (var i = 0; i < c.length; i++) {
121                 if (modify[ c[i].id ]) {
122                         for (var j in modify[ c[i].id ]) {
123                                 c[i][j] = modify[ c[i].id ][j];
124                         }
125                 }
126         }
127         return c;
128 }
129
130 circ.util.hold_columns = function(modify) {
131         
132         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
133
134         function getString(s) { return data.entities[s]; }
135
136         var c = [
137                 {
138                         'id' : 'request_time', 'label' : getString('staff.ahr_request_time_label'), 'flex' : 0,
139                         'primary' : false, 'hidden' : true,  
140                         'render' : 'my.ahr.request_time().toString().substr(0,10)'
141                 },
142                 {
143                         'id' : 'capture_time', 'label' : getString('staff.ahr_capture_time_label'), 'flex' : 1,
144                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.capture_time()'
145                 },
146                 {
147                         'id' : 'status', 'label' : getString('staff.ahr_status_label'), 'flex' : 1,
148                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.status()'
149                 },
150                 {
151                         'id' : 'hold_type', 'label' : getString('staff.ahr_hold_type_label'), 'flex' : 0,
152                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.hold_type()'
153                 },
154                 {
155                         'id' : 'pickup_lib', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 1,
156                         'primary' : false, 'hidden' : true,  
157                         'render' : 'obj.OpenILS.data.hash.aou[ my.ahr.pickup_lib() ].name()'
158                 },
159                 {
160                         'id' : 'pickup_lib_shortname', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 0,
161                         'primary' : false, 'hidden' : true,  
162                         'render' : 'obj.OpenILS.data.hash.aou[ my.ahr.pickup_lib() ].shortname()'
163                 },
164                 {
165                         'id' : 'current_copy', 'label' : getString('staff.ahr_current_copy_label'), 'flex' : 1,
166                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.current_copy()'
167                 },
168                 {
169                         'id' : 'email_notify', 'label' : getString('staff.ahr_email_notify_label'), 'flex' : 1,
170                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.email_notify()'
171                 },
172                 {
173                         'id' : 'expire_time', 'label' : getString('staff.ahr_expire_time_label'), 'flex' : 1,
174                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.expire_time()'
175                 },
176                 {
177                         'id' : 'fulfillment_time', 'label' : getString('staff.ahr_fulfillment_time_label'), 'flex' : 1,
178                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.fulfillment_time()'
179                 },
180                 {
181                         'id' : 'holdable_formats', 'label' : getString('staff.ahr_holdable_formats_label'), 'flex' : 1,
182                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.holdable_formats()'
183                 },
184                 {
185                         'id' : 'id', 'label' : getString('staff.ahr_id_label'), 'flex' : 1,
186                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.id()'
187                 },
188                 {
189                         'id' : 'phone_notify', 'label' : getString('staff.ahr_phone_notify_label'), 'flex' : 1,
190                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.phone_notify()'
191                 },
192                 {
193                         'id' : 'prev_check_time', 'label' : getString('staff.ahr_prev_check_time_label'), 'flex' : 1,
194                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.prev_check_time()'
195                 },
196                 {
197                         'id' : 'requestor', 'label' : getString('staff.ahr_requestor_label'), 'flex' : 1,
198                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.requestor()'
199                 },
200                 {
201                         'id' : 'selection_depth', 'label' : getString('staff.ahr_selection_depth_label'), 'flex' : 1,
202                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.selection_depth()'
203                 },
204                 {
205                         'id' : 'target', 'label' : getString('staff.ahr_target_label'), 'flex' : 1,
206                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.target()'
207                 },
208                 {
209                         'id' : 'usr', 'label' : getString('staff.ahr_usr_label'), 'flex' : 1,
210                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.usr()'
211                 },
212                 {
213                         'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 1,
214                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.title()'
215                 },
216                 {
217                         'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
218                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.author()'
219                 },
220
221         ];
222         for (var i = 0; i < c.length; i++) {
223                 if (modify[ c[i].id ]) {
224                         for (var j in modify[ c[i].id ]) {
225                                 c[i][j] = modify[ c[i].id ][j];
226                         }
227                 }
228         }
229         return c;
230 }
231
232 circ.util.std_map_row_to_column = function() {
233         return function(row,col) {
234                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
235                 // col contains one of the objects listed above in columns
236                 
237                 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
238                 var obj = {}; obj.OpenILS = {};  // One of our circ columns uses OpenILS.data
239                 JSAN.use('util.error'); obj.error = new util.error();
240                 JSAN.use('OpenILS.data'); obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
241
242                 var my = row.my;
243                 var value;
244                 try { 
245                         value = eval( col.render );
246                 } catch(E) {
247                         obj.error.sdump('D_ERROR','map_row_to_column: ' + E);
248                         value = '???';
249                 }
250                 return value;
251         }
252 }
253
254 circ.util.checkin_via_barcode = function(session,barcode,backdate) {
255         try {
256                 JSAN.use('util.error'); var error = new util.error();
257                 JSAN.use('util.network'); var network = new util.network();
258                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
259                 JSAN.use('util.date');
260                 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
261
262                 var check = network.request(
263                         api.CHECKIN_VIA_BARCODE.app,
264                         api.CHECKIN_VIA_BARCODE.method,
265                         [ session, barcode, null, backdate ]
266                 );
267
268                 /*
269                 { // REMOVE_ME, forcing a condition for testing
270                         check.status = 1;
271                         check.text = 'This copy is the first that could fulfill a hold.  Do it?';
272                 }
273                 */
274
275                 if (check.status != 0) {
276                         switch(check.status) {
277                                 case '1': case 1: /* possible hold capture */
278                                         var rv = error.yns_alert(
279                                                 check.text,
280                                                 'Alert',
281                                                 "Capture",
282                                                 "Don't Capture",
283                                                 null,
284                                                 "Check here to confirm this message"
285                                         );
286                                         switch(rv) {
287                                                 case 0: /* capture */
288                                                 try {
289                                                         var check2 = this.hold_capture_via_copy_barcode( session, barcode );
290                                                         if (check2) {
291                                                                 check.copy = check2.copy;
292                                                                 check.text = check2.text;
293                                                                 check.route_to = check2.route_to;
294                                                                 JSAN.use('patron.util');
295                                                                 var au_obj = patron.util.retrieve_au_via_id( session, check.hold.usr() );
296                                                                 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
297                                                                         check.record.title() + '  Author: ' + check.record.author() + 
298                                                                         '\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
299                                                                         au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + 
300                                                                         au_obj.first_given_name() + '\r\n'); //FIXME
301
302                                                                 /*
303                                                                 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
304                                                                         check.record.title() + '  Author: ' + check.record.author() + 
305                                                                         '<br />\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
306                                                                         au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + 
307                                                                         au_obj.first_given_name() + '<br />\r\n'
308                                                                 );
309                                                                 */
310
311                                                         }
312
313                                                 } catch(E) { 
314                                                         error.sdump('D_ERROR',E + '\n'); 
315                                                         /* 
316                                                         // demo testing 
317                                                         check.text = 'Captured for Hold';
318                                                         check.route_to = 'ARL-ATH';
319                                                         */
320                                                 }
321                                                 break;
322                                                 case 1: /* don't capture */
323
324                                                         check.text = 'Not Captured for Hold';
325                                                 break;
326                                         }
327                                 break;
328                                 case '2': case 2: /* LOST??? */
329                                         JSAN.use('patron.util');
330                                         var au_obj = patron.util.retrieve_au_via_id( session, check.circ.usr() );
331                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
332                                                         check.record.title() + '  Author: ' + check.record.author() + '\r\n' +
333                                                         'Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' +
334                                                         au_obj.first_given_name();
335                                         var pcheck = error.yns_alert(
336                                                 msg,
337                                                 'Lost Item',
338                                                 'Edit Copy & Patron',
339                                                 "Just Continue",
340                                                 null,
341                                                 "Check here to confirm this message"
342                                         ); 
343                                         if (pcheck == 0) {
344                                                 //FIXME//Re-implement
345                                                 /*
346                                                 var w = mw.spawn_main();
347                                                 setTimeout(
348                                                         function() {
349                                                                 mw.spawn_patron_display(w.document,'new_tab','main_tabbox',{'patron':au_obj});
350                                                                 mw.spawn_batch_copy_editor(w.document,'new_tab','main_tabbox',
351                                                                         {'copy_ids':[ check.copy.id() ]});
352                                                         }, 0
353                                                 );
354                                                 */
355                                         }
356                                 break;
357                                 case '3': case 3: /* TRANSIT ELSEWHERE */
358                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
359                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
360                                                         check.record.title() + '  Author: ' + check.record.author() + 
361                                                         '\r\n' + 'Route To: ' + check.route_to + '\r\n';
362                                         var pcheck = error.yns_alert(
363                                                 msg,
364                                                 'Alert',
365                                                 'Print Receipt',
366                                                 "Don't Print",
367                                                 null,
368                                                 "Check here to confirm this message"
369                                         ); 
370                                         if (pcheck == 0) {
371                                                 alert('To Printer\n' + msg); //FIXME//
372                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
373                                         }
374
375                                 break;
376                                 case '4': case 4: /* transit for hold is complete */
377                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
378                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
379                                                         check.record.title() + '  Author: ' + check.record.author() + 
380                                                         '\r\n' + 'Route To: ' + check.route_to +
381                                                         '\r\n';
382                                         var pcheck = error.yns_alert(
383                                                 msg,
384                                                 'Alert',
385                                                 'Print Receipt',
386                                                 "Don't Print",
387                                                 null,
388                                                 "Check here to confirm this message"
389                                         ); 
390                                         if (pcheck == 0) {
391                                                 alert('To Printer\n' + msg); //FIXME//
392                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
393                                         }
394
395                                 break;
396
397                                 default: 
398                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
399                                         var msg = check.text + '\r\nBarcode: ' + barcode + '  Route To: ' + check.route_to;
400                                         var pcheck = error.yns_alert(
401                                                 msg,
402                                                 'Alert',
403                                                 'Print Receipt',
404                                                 "Don't Print",
405                                                 null,
406                                                 "Check here to confirm this message"
407                                         ); 
408                                         if (pcheck == 0) {
409                                                 alert('To Printer\n' + msg); //FIXME//
410                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
411                                         }
412                                 break;
413                         }
414                 } else {  // status == 0
415                 }
416                 if (parseInt(check.route_to)) {
417                         if (check.route_to != data.list.au[0].home_ou()) {
418                                 check.route_to = data.hash.aou[ check.route_to ].shortname();
419                         } else {
420                                 check.route_to = data.hash.acpl[ check.copy.location() ].name();
421                         }
422                 }
423                 return check;
424         } catch(E) {
425                 JSAN.use('util.error'); var error = new util.error();
426                 var msg = E + '\n---\n' + js2JSON(E);
427                 error.sdump('D_ERROR',msg);
428                 alert(msg);
429                 return null;
430         }
431 }
432
433 circ.util.hold_capture_via_copy_barcode = function ( session, barcode, retrieve_flag ) {
434         try {
435                 JSAN.use('util.network'); var network = new util.network();
436                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
437                 var robj = network.request(
438                         api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.app,
439                         api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.method,
440                         [ session, barcode, retrieve_flag ]
441                 );
442                 var check = robj.payload;
443                 if (!check) {
444                         check = {};
445                         check.status = robj.ilsevent;
446                         check.copy = new acp(); check.copy.barcode( barcode );
447                 }
448                 check.text = robj.textcode;
449                 check.route_to = robj.route_to;
450                 //check.text = 'Captured for Hold';
451                 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
452                 return check;
453         } catch(E) {
454                 JSAN.use('util.error'); var error = new util.error();
455                 var msg = E + '\n---\n' + js2JSON(E);
456                 error.sdump('D_ERROR',msg);
457                 alert(msg);
458                 return null;
459         }
460 }
461
462
463 dump('exiting circ/util.js\n');