]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/renew.js
Add "Show Holds on Bib" menu items
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / renew.js
1 dump('entering circ.renew.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.renew = function (params) {
5
6     JSAN.use('util.error'); this.error = new util.error();
7     JSAN.use('util.network'); this.network = new util.network();
8     JSAN.use('util.barcode');
9     JSAN.use('util.date');
10     this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11     this.data = this.OpenILS.data;
12 }
13
14 circ.renew.prototype = {
15
16     'selection_list' : [],
17
18     'init' : function( params ) {
19
20         var obj = this;
21
22         JSAN.use('circ.util'); JSAN.use('patron.util');
23         var columns = circ.util.columns( 
24             { 
25                 'barcode' : { 'hidden' : false },
26                 'title' : { 'hidden' : false },
27                 'location' : { 'hidden' : false },
28                 'call_number' : { 'hidden' : false },
29                 'status' : { 'hidden' : false },
30                 'alert_message' : { 'hidden' : false },
31                 'due_date' : { 'hidden' : false },
32                 'due_time' : { 'hidden' : false },
33                 'renewal_remaining' : { 'hidden' : false }
34             },
35             {
36                 'except_these' : [ 'uses', 'checkin_time_full' ]
37             }
38         ).concat(
39             patron.util.columns( { 'family_name' : { 'hidden' : 'false' } } )
40
41         ).concat(
42             patron.util.mbts_columns( {}, { 'except_these' : [ 'total_paid', 'total_owed', 'xact_start', 'xact_finish', 'xact_type' ] } )
43
44         ).sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
45
46         JSAN.use('util.list'); obj.list = new util.list('renew_list');
47         obj.list.init(
48             {
49                 'columns' : columns,
50                 'on_select' : function(ev) {
51                     try {
52                         JSAN.use('util.functional');
53                         var sel = obj.list.retrieve_selection();
54                         obj.selection_list = util.functional.map_list(
55                             sel,
56                             function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
57                         );
58                         obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
59                         if (obj.selection_list.length == 0) {
60                             obj.controller.view.sel_edit.setAttribute('disabled','true');
61                             obj.controller.view.sel_opac.setAttribute('disabled','true');
62                             obj.controller.view.sel_opac_holds.setAttribute('disabled','true');
63                             obj.controller.view.sel_patron.setAttribute('disabled','true');
64                             obj.controller.view.sel_last_patron.setAttribute('disabled','true');
65                             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
66                             obj.controller.view.sel_bucket.setAttribute('disabled','true');
67                             obj.controller.view.sel_spine.setAttribute('disabled','true');
68                             obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
69                             obj.controller.view.sel_clip.setAttribute('disabled','true');
70                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
71                         } else {
72                             obj.controller.view.sel_edit.setAttribute('disabled','false');
73                             obj.controller.view.sel_opac.setAttribute('disabled','false');
74                             obj.controller.view.sel_opac_holds.setAttribute('disabled','false');
75                             obj.controller.view.sel_patron.setAttribute('disabled','false');
76                             obj.controller.view.sel_last_patron.setAttribute('disabled','false');
77                             obj.controller.view.sel_copy_details.setAttribute('disabled','false');
78                             obj.controller.view.sel_bucket.setAttribute('disabled','false');
79                             obj.controller.view.sel_spine.setAttribute('disabled','false');
80                             obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
81                             obj.controller.view.sel_clip.setAttribute('disabled','false');
82                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
83                         }
84                     } catch(E) {
85                         alert('FIXME: ' + E);
86                     }
87                 }
88             }
89         );
90         
91         JSAN.use('util.controller'); obj.controller = new util.controller();
92         obj.controller.init(
93             {
94                 'control_map' : {
95                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
96                     'sel_clip' : [
97                         ['command'],
98                         function() { 
99                             obj.list.clipboard(); 
100                             obj.controller.view.renew_barcode_entry_textbox.focus();
101                         }
102                     ],
103                     'sel_edit' : [
104                         ['command'],
105                         function() {
106                             try {
107                                 obj.spawn_copy_editor();
108                             } catch(E) {
109                                 alert(E);
110                             }
111                         }
112                     ],
113                     'sel_spine' : [
114                         ['command'],
115                         function() {
116                             JSAN.use('cat.util');
117                             cat.util.spawn_spine_editor(obj.selection_list);
118                         }
119                     ],
120                     'sel_opac' : [
121                         ['command'],
122                         function() {
123                             JSAN.use('cat.util');
124                             cat.util.show_in_opac(obj.selection_list);
125                         }
126                     ],
127                     'sel_opac_holds' : [
128                         ['command'],
129                         function() {
130                             JSAN.use('cat.util');
131                             cat.util.show_in_opac(obj.selection_list,{default_view:'hold_browser'});
132                         }
133                     ],
134                     'sel_transit_abort' : [
135                         ['command'],
136                         function() {
137                             JSAN.use('circ.util');
138                             circ.util.abort_transits(obj.selection_list);
139                         }
140                     ],
141                     'sel_patron' : [
142                         ['command'],
143                         function() {
144                             JSAN.use('circ.util');
145                             circ.util.show_last_few_circs(obj.selection_list);
146                         }
147                     ],
148                     'sel_last_patron' : [
149                         ['command'],
150                         function() {
151                             var patrons = {};
152                             for (var i = 0; i < obj.selection_list.length; i++) {
153                                 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
154                                 if (circs.length > 0) {
155                                     patrons[circs[0].usr()] = 1;
156                                 } else {
157                                     alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
158                                 }
159                             }
160                             for (var i in patrons) {
161                                 xulG.new_patron_tab({},{'id' : i});
162                             }
163                         }
164                     ],
165                     'sel_copy_details' : [
166                         ['command'],
167                         function() {
168                             JSAN.use('circ.util');
169                             circ.util.item_details_new(
170                                 util.functional.map_list(
171                                     obj.selection_list,
172                                     function(o) { return o.barcode; }
173                                 )
174                             );
175                         }
176                     ],
177                     'sel_mark_items_damaged' : [
178                         ['command'],
179                         function() {
180                             var funcs = [];
181                             JSAN.use('cat.util'); JSAN.use('util.functional');
182                             cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
183                         }
184                     ],
185                     'sel_bucket' : [
186                         ['command'],
187                         function() {
188                             JSAN.use('cat.util');
189                             cat.util.add_copies_to_bucket(obj.selection_list);
190                         }
191                     ],
192                     'renew_barcode_entry_textbox' : [
193                         ['keypress'],
194                         function(ev) {
195                             if (ev.keyCode && ev.keyCode == 13) {
196                                 obj.renew();
197                             }
198                         }
199                     ],
200                     'cmd_broken' : [
201                         ['command'],
202                         function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
203                     ],
204                     'cmd_renew_submit_barcode' : [
205                         ['command'],
206                         function() {
207                             obj.renew();
208                         }
209                     ],
210                     'cmd_renew_print' : [
211                         ['command'],
212                         function() {
213                             var p = { 
214                                 'printer_context' : 'receipt',
215                                 'template' : 'renew'
216                             };
217                             obj.list.print(p);
218                         }
219                     ],
220                     'cmd_csv_to_clipboard' : [ ['command'], function() { 
221                         obj.list.dump_csv_to_clipboard(); 
222                         obj.controller.view.renew_barcode_entry_textbox.focus();
223                     } ],
224                     'cmd_csv_to_printer' : [ ['command'], function() { 
225                         obj.list.dump_csv_to_printer(); 
226                         obj.controller.view.renew_barcode_entry_textbox.focus();
227                     } ],
228                     'cmd_csv_to_file' : [ ['command'], function() { 
229                         obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } ); 
230                         obj.controller.view.renew_barcode_entry_textbox.focus();
231                     } ],
232                     'renew_duedate_datepicker' : [
233                         ['change'],
234                         function(ev) { 
235                             try {
236                                 if (obj.check_date(ev.target)) {
237                                     ev.target.parentNode.setAttribute('style','');
238                                 } else {
239                                     ev.target.parentNode.setAttribute('style','background-color: red');
240                                 }
241                             } catch(E) {
242                                 alert('Error in renew.js, renew_duedate_datepicker @change: ' + E);
243                             }
244                         }
245                     ]
246
247                 }
248             }
249         );
250         this.controller.render();
251         this.controller.view.renew_barcode_entry_textbox.focus();
252
253     },
254
255     'test_barcode' : function(bc) {
256         var obj = this;
257         var x = document.getElementById('strict_barcode');
258         if (x && x.checked != true) return true;
259         var good = util.barcode.check(bc);
260         if (good) {
261             return true;
262         } else {
263             if ( 1 == obj.error.yns_alert(
264                         document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
265                         document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
266                         document.getElementById('circStrings').getString('staff.circ.cancel'),
267                         document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
268                         null,
269                         document.getElementById('circStrings').getString('staff.circ.confirm'),
270                         '/xul/server/skin/media/images/bad_barcode.png'
271             ) ) {
272                 return true;
273             } else {
274                 return false;
275             }
276         }
277     },
278
279     'renew' : function(params) {
280         var obj = this;
281         try {
282             if (!params) params = {};
283
284             var barcode = obj.controller.view.renew_barcode_entry_textbox.value;
285             if (!barcode) return;
286             if (barcode) {
287                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
288             }
289             params.barcode = barcode;
290             params.return_patron = true;
291
292             var auto_print = document.getElementById('renew_auto');
293             if (auto_print) auto_print = auto_print.checked;
294
295             if (document.getElementById('renew_duedate_checkbox').checked) {
296                 if (! obj.check_date(obj.controller.view.renew_duedate_datepicker)) return;
297                 var tp = document.getElementById('renew_duedate_timepicker');
298                 var dp = obj.controller.view.renew_duedate_datepicker;
299                 var tp_date = tp.dateValue;
300                 var dp_date = dp.dateValue;
301                 dp_date.setHours( tp_date.getHours() );
302                 dp_date.setMinutes( tp_date.getMinutes() );
303
304                 JSAN.use('util.date');
305                 params.due_date = util.date.formatted_date(dp_date,'%{iso8601}');
306             }
307
308
309             JSAN.use('circ.util');
310             var renew = circ.util.renew_via_barcode(
311                 params,
312                 function( r ) {
313                     obj.renew_followup( r, barcode );
314                 }
315             );
316         } catch(E) {
317             obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew():', E);
318             if (typeof obj.on_failure == 'function') {
319                 obj.on_failure(E);
320             }
321             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
322                 window.xulG.on_failure(E);
323             }
324         }
325     },
326
327     'renew_followup' : function(r,bc) {
328         var obj = this;
329         try {
330             if (!r) return obj.on_failure(); /* circ.util.renew handles errors and returns null currently */
331             if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
332                 // SUCCESS
333                 var x = document.getElementById('no_change_label');
334                 if (x) {
335                     x.hidden = true;
336                     x.setAttribute('value','');
337                 }
338             } else {
339                 // FAILURE
340                 var msg = document.getElementById("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
341                 var x = document.getElementById('no_change_label');
342                 if (x) {
343                     x.hidden = false;
344                     x.setAttribute('value',msg);
345                 }
346                 obj.controller.view.renew_barcode_entry_textbox.focus();
347                 obj.controller.view.renew_barcode_entry_textbox.select();
348                 return;
349             }
350             var renew = r[0].payload;
351             var retrieve_id = js2JSON( { 'copy_id' : renew.copy.id(), 'barcode' : renew.copy.barcode(), 'doc_id' : (renew.record == null ? null : renew.record.doc_id() ) } );
352             if (document.getElementById('trim_list')) {
353                 var x = document.getElementById('trim_list');
354                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
355             }
356
357             var params = {
358                 'retrieve_id' : retrieve_id,
359                 'row' : {
360                     'my' : {
361                         'circ' : renew.circ,
362                         'mbts' : renew.parent_circ ? renew.parent_circ.billable_transaction().summary() : null,
363                         'mvr' : renew.record,
364                         'acp' : renew.copy,
365                         'acn' : renew.volume,
366                         'au' : renew.patron,
367                         'status' : renew.status,
368                         'route_to' : renew.route_to,
369                         'message' : renew.message
370                     }
371                 },
372                 'to_top' : true
373             };
374             obj.list.append( params );
375
376             if (params.row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
377                 JSAN.use('util.money');
378                 var bill = params.row.my.mbts;
379                 if (Number(bill.balance_owed()) != 0) {
380                     if (document.getElementById('no_change_label')) {
381                         var m = document.getElementById('no_change_label').getAttribute('value');
382                         document.getElementById('no_change_label').setAttribute(
383                             'value', 
384                             m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + '  '
385                         );
386                         document.getElementById('no_change_label').setAttribute('hidden','false');
387                     }
388                     if (document.getElementById('fine_tally')) {
389                         var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
390                         document.getElementById('fine_tally').setAttribute('amount',amount);
391                         document.getElementById('fine_tally').setAttribute(
392                             'value',
393                             document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
394                         );
395                         document.getElementById('fine_tally').setAttribute('hidden','false');
396                     }
397                 }
398             }
399
400             obj.list.node.view.selection.select(0);
401
402             JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
403
404             if (typeof obj.on_renew == 'function') {
405                 obj.on_renew(renew);
406             }
407             if (typeof window.xulG == 'object' && typeof window.xulG.on_renew == 'function') {
408                 window.xulG.on_renew(renew);
409             }
410
411             return true;
412
413         } catch(E) {
414             obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew_followup():', E);
415             if (typeof obj.on_failure == 'function') {
416                 obj.on_failure(E);
417             }
418             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
419                 window.xulG.on_failure(E);
420             }
421         }
422
423     },
424
425     'on_renew' : function() {
426         try {
427             this.controller.view.renew_barcode_entry_textbox.disabled = false;
428             this.controller.view.renew_barcode_entry_textbox.select();
429             this.controller.view.renew_barcode_entry_textbox.value = '';
430             this.controller.view.renew_barcode_entry_textbox.focus();
431         } catch(E) {
432             alert('Error in renew.js, on_renew(): ' + E);
433         }
434     },
435
436     'on_failure' : function() {
437         try {
438             this.controller.view.renew_barcode_entry_textbox.disabled = false;
439             this.controller.view.renew_barcode_entry_textbox.select();
440             this.controller.view.renew_barcode_entry_textbox.focus();
441         } catch(E) {
442             alert('Error in renew.js, on_failure(): ' + E);
443         }
444     },
445     
446     'spawn_copy_editor' : function() {
447
448         var obj = this;
449
450         JSAN.use('util.functional');
451
452         var list = obj.selection_list;
453
454         list = util.functional.map_list(
455             list,
456             function (o) {
457                 return o.copy_id;
458             }
459         );
460
461         JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
462
463     },
464
465     'check_date' : function(node) {
466         var obj = this;
467         JSAN.use('util.date');
468         try {
469             obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','false');
470             obj.controller.view.renew_barcode_entry_textbox.disabled = false;
471             obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','false');
472             obj.controller.view.cmd_renew_submit_barcode.disabled = false;
473             if (util.date.check_past('YYYY-MM-DD',node.value) ) {
474                 obj.controller.view.renew_barcode_entry_textbox.setAttribute('disabled','true');
475                 obj.controller.view.cmd_renew_submit_barcode.setAttribute('disabled','true');
476                 return false;
477             }
478             return true;
479         } catch(E) {
480             throw(E);
481         }
482     }
483
484 }
485
486 dump('exiting circ.renew.js\n');