]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/renew.js
in dedicated renewal interface, add billing info for previous circ for items being...
[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                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
51                                 'on_select' : function(ev) {
52                                         try {
53                                                 JSAN.use('util.functional');
54                                                 var sel = obj.list.retrieve_selection();
55                                                 obj.selection_list = util.functional.map_list(
56                                                         sel,
57                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
58                                                 );
59                                                 obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
60                                                 if (obj.selection_list.length == 0) {
61                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
62                                                         obj.controller.view.sel_opac.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_patron.setAttribute('disabled','false');
75                                                         obj.controller.view.sel_last_patron.setAttribute('disabled','false');
76                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
77                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
78                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
79                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
80                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
81                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
82                                                 }
83                                         } catch(E) {
84                                                 alert('FIXME: ' + E);
85                                         }
86                                 }
87                         }
88                 );
89                 
90                 JSAN.use('util.controller'); obj.controller = new util.controller();
91                 obj.controller.init(
92                         {
93                                 'control_map' : {
94                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
95                                         'sel_clip' : [
96                                                 ['command'],
97                                                 function() { 
98                             obj.list.clipboard(); 
99                             obj.controller.view.renew_barcode_entry_textbox.focus();
100                         }
101                                         ],
102                                         'sel_edit' : [
103                                                 ['command'],
104                                                 function() {
105                                                         try {
106                                                                 obj.spawn_copy_editor();
107                                                         } catch(E) {
108                                                                 alert(E);
109                                                         }
110                                                 }
111                                         ],
112                                         'sel_spine' : [
113                                                 ['command'],
114                                                 function() {
115                                                         JSAN.use('cat.util');
116                                                         cat.util.spawn_spine_editor(obj.selection_list);
117                                                 }
118                                         ],
119                                         'sel_opac' : [
120                                                 ['command'],
121                                                 function() {
122                                                         JSAN.use('cat.util');
123                                                         cat.util.show_in_opac(obj.selection_list);
124                                                 }
125                                         ],
126                                         'sel_transit_abort' : [
127                                                 ['command'],
128                                                 function() {
129                                                         JSAN.use('circ.util');
130                                                         circ.util.abort_transits(obj.selection_list);
131                                                 }
132                                         ],
133                                         'sel_patron' : [
134                                                 ['command'],
135                                                 function() {
136                                                         JSAN.use('circ.util');
137                                                         circ.util.show_last_few_circs(obj.selection_list);
138                                                 }
139                                         ],
140                                         'sel_last_patron' : [
141                                                 ['command'],
142                                                 function() {
143                                                         var patrons = {};
144                                                         for (var i = 0; i < obj.selection_list.length; i++) {
145                                                                 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
146                                                                 if (circs.length > 0) {
147                                                                         patrons[circs[0].usr()] = 1;
148                                                                 } else {
149                                                                         alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
150                                                                 }
151                                                         }
152                                                         for (var i in patrons) {
153                                                                 xulG.new_patron_tab({},{'id' : i});
154                                                         }
155                                                 }
156                                         ],
157                                         'sel_copy_details' : [
158                                                 ['command'],
159                                                 function() {
160                                                         JSAN.use('circ.util');
161                                                         for (var i = 0; i < obj.selection_list.length; i++) {
162                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
163                                                         }
164                                                 }
165                                         ],
166                                         'sel_mark_items_damaged' : [
167                                                 ['command'],
168                                                 function() {
169                                                         var funcs = [];
170                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
171                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
172                                                 }
173                                         ],
174                                         'sel_bucket' : [
175                                                 ['command'],
176                                                 function() {
177                                                         JSAN.use('cat.util');
178                                                         cat.util.add_copies_to_bucket(obj.selection_list);
179                                                 }
180                                         ],
181                                         'renew_barcode_entry_textbox' : [
182                                                 ['keypress'],
183                                                 function(ev) {
184                                                         if (ev.keyCode && ev.keyCode == 13) {
185                                                                 obj.renew();
186                                                         }
187                                                 }
188                                         ],
189                                         'cmd_broken' : [
190                                                 ['command'],
191                                                 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
192                                         ],
193                                         'cmd_renew_submit_barcode' : [
194                                                 ['command'],
195                                                 function() {
196                                                         obj.renew();
197                                                 }
198                                         ],
199                                         'cmd_renew_print' : [
200                                                 ['command'],
201                                                 function() {
202                                                         var p = { 
203                                                                 'template' : 'renew'
204                                                         };
205                                                         obj.list.print(p);
206                                                 }
207                                         ],
208                                         'cmd_csv_to_clipboard' : [ ['command'], function() { 
209                         obj.list.dump_csv_to_clipboard(); 
210                         obj.controller.view.renew_barcode_entry_textbox.focus();
211                     } ],
212                                         'cmd_csv_to_printer' : [ ['command'], function() { 
213                         obj.list.dump_csv_to_printer(); 
214                         obj.controller.view.renew_barcode_entry_textbox.focus();
215                     } ],
216                                         'cmd_csv_to_file' : [ ['command'], function() { 
217                         obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } ); 
218                         obj.controller.view.renew_barcode_entry_textbox.focus();
219                     } ]
220                                 }
221                         }
222                 );
223                 this.controller.render();
224                 this.controller.view.renew_barcode_entry_textbox.focus();
225
226         },
227
228         'test_barcode' : function(bc) {
229                 var obj = this;
230                 var x = document.getElementById('strict_barcode');
231                 if (x && x.checked != true) return true;
232                 var good = util.barcode.check(bc);
233                 if (good) {
234                         return true;
235                 } else {
236                         if ( 1 == obj.error.yns_alert(
237                                                 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
238                                                 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
239                                                 document.getElementById('circStrings').getString('staff.circ.cancel'),
240                                                 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
241                                                 null,
242                                                 document.getElementById('circStrings').getString('staff.circ.confirm'),
243                                                 '/xul/server/skin/media/images/bad_barcode.png'
244                         ) ) {
245                                 return true;
246                         } else {
247                                 return false;
248                         }
249                 }
250         },
251
252         'renew' : function() {
253                 var obj = this;
254                 try {
255                         var barcode = obj.controller.view.renew_barcode_entry_textbox.value;
256                         if (!barcode) return;
257                         if (barcode) {
258                                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
259                         }
260                         var auto_print = document.getElementById('renew_auto');
261                         if (auto_print) auto_print = auto_print.checked;
262                         JSAN.use('circ.util');
263                         var renew = circ.util.renew_via_barcode(
264                 barcode,
265                 null,
266                 function( r ) {
267                     obj.renew_followup( r, barcode );
268                 }
269                         );
270                 } catch(E) {
271                         obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew():', E);
272                         if (typeof obj.on_failure == 'function') {
273                                 obj.on_failure(E);
274                         }
275                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
276                                 window.xulG.on_failure(E);
277                         }
278                 }
279         },
280
281         'renew_followup' : function(r,bc) {
282                 var obj = this;
283                 try {
284                         if (!r) return obj.on_failure(); /* circ.util.renew handles errors and returns null currently */
285             if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
286                 // SUCCESS
287                 var x = document.getElementById('no_change_label');
288                 if (x) {
289                     x.hidden = true;
290                     x.setAttribute('value','');
291                 }
292             } else {
293                 // FAILURE
294                 var msg = document.getElementById("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
295                 var x = document.getElementById('no_change_label');
296                 if (x) {
297                     x.hidden = false;
298                     x.setAttribute('value',msg);
299                 }
300                         obj.controller.view.renew_barcode_entry_textbox.focus();
301                         obj.controller.view.renew_barcode_entry_textbox.select();
302                 return;
303             }
304             var renew = r[0].payload;
305                         var retrieve_id = js2JSON( { 'copy_id' : renew.copy.id(), 'barcode' : renew.copy.barcode(), 'doc_id' : (renew.record == null ? null : renew.record.doc_id() ) } );
306                         if (document.getElementById('trim_list')) {
307                                 var x = document.getElementById('trim_list');
308                                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
309                         }
310
311             var params = {
312                 'retrieve_id' : retrieve_id,
313                 'row' : {
314                     'my' : {
315                         'circ' : renew.circ,
316                         'mbts' : renew.parent_circ ? renew.parent_circ.billable_transaction().summary() : null,
317                         'mvr' : renew.record,
318                         'acp' : renew.copy,
319                         'status' : renew.status,
320                         'route_to' : renew.route_to,
321                         'message' : renew.message
322                     }
323                 },
324                 'to_top' : true
325             };
326                         obj.list.append( params );
327
328             if (params.row.my.mbts && ( document.getElementById('no_change_label') || document.getElementById('fine_tally') ) ) {
329                 JSAN.use('util.money');
330                 var bill = params.row.my.mbts;
331                 if (Number(bill.balance_owed()) == 0) { return; }
332                 if (document.getElementById('no_change_label')) {
333                     var m = document.getElementById('no_change_label').getAttribute('value');
334                     document.getElementById('no_change_label').setAttribute(
335                         'value', 
336                         m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.row.my.acp.barcode(), util.money.sanitize(bill.balance_owed())]) + '  '
337                     );
338                     document.getElementById('no_change_label').setAttribute('hidden','false');
339                 }
340                 if (document.getElementById('fine_tally')) {
341                     var amount = Number( document.getElementById('fine_tally').getAttribute('amount') ) + Number( bill.balance_owed() );
342                     document.getElementById('fine_tally').setAttribute('amount',amount);
343                     document.getElementById('fine_tally').setAttribute(
344                         'value',
345                         document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
346                     );
347                     document.getElementById('fine_tally').setAttribute('hidden','false');
348                 }
349             }
350
351                         obj.list.node.view.selection.select(0);
352
353                         JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
354
355                         if (typeof obj.on_renew == 'function') {
356                                 obj.on_renew(renew);
357                         }
358                         if (typeof window.xulG == 'object' && typeof window.xulG.on_renew == 'function') {
359                                 window.xulG.on_renew(renew);
360                         }
361
362                         return true;
363
364                 } catch(E) {
365                         obj.error.standard_unexpected_error_alert('Error in circ/renew.js, renew_followup():', E);
366                         if (typeof obj.on_failure == 'function') {
367                                 obj.on_failure(E);
368                         }
369                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
370                                 window.xulG.on_failure(E);
371                         }
372                 }
373
374         },
375
376         'on_renew' : function() {
377                 this.controller.view.renew_barcode_entry_textbox.disabled = false;
378                 this.controller.view.renew_barcode_entry_textbox.select();
379                 this.controller.view.renew_barcode_entry_textbox.value = '';
380                 this.controller.view.renew_barcode_entry_textbox.focus();
381         },
382
383         'on_failure' : function() {
384                 this.controller.view.renew_barcode_entry_textbox.disabled = false;
385                 this.controller.view.renew_barcode_entry_textbox.select();
386                 this.controller.view.renew_barcode_entry_textbox.focus();
387         },
388         
389         'spawn_copy_editor' : function() {
390
391                 var obj = this;
392
393                 JSAN.use('util.functional');
394
395                 var list = obj.selection_list;
396
397                 list = util.functional.map_list(
398                         list,
399                         function (o) {
400                                 return o.copy_id;
401                         }
402                 );
403
404                 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
405
406         }
407
408 }
409
410 dump('exiting circ.renew.js\n');