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