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