]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/hold_capture.js
Mostly finish off server/circ i18n work
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / hold_capture.js
1 dump('entering circ.hold_capture.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 if (typeof circ == 'undefined') circ = {};
5 circ.hold_capture = function (params) {
6
7         JSAN.use('util.error'); this.error = new util.error();
8         JSAN.use('util.network'); this.network = new util.network();
9         this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
10 }
11
12 circ.hold_capture.prototype = {
13
14         'init' : function( params ) {
15
16                 var obj = this;
17
18                 JSAN.use('circ.util');
19                 var columns = circ.util.columns( 
20                         { 
21                                 'barcode' : { 'hidden' : false },
22                                 'title' : { 'hidden' : false },
23                                 'status' : { 'hidden' : false },
24                                 //'checkin_status' : { 'hidden' : false },
25                                 'checkin_route_to' : { 'hidden' : false },
26                                 'checkin_text' : { 'hidden' : false, 'flex' : 3 },
27                         } 
28                 );
29                 dump('columns = ' + js2JSON(columns) + '\n');
30
31                 JSAN.use('util.list'); obj.list = new util.list('hold_capture_list');
32                 obj.list.init(
33                         {
34                                 'columns' : columns,
35                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
36                         }
37                 );
38                 
39                 JSAN.use('util.controller'); obj.controller = new util.controller();
40                 obj.controller.init(
41                         {
42                                 'control_map' : {
43                                         'hold_capture_barcode_entry_textbox' : [
44                                                 ['keypress'],
45                                                 function(ev) {
46                                                         if (ev.keyCode && ev.keyCode == 13) {
47                                                                 obj.hold_capture();
48                                                         }
49                                                 }
50                                         ],
51                                         'cmd_broken' : [
52                                                 ['command'],
53                                                 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
54                                         ],
55                                         'cmd_hold_capture_submit_barcode' : [
56                                                 ['command'],
57                                                 function() {
58                                                         obj.hold_capture();
59                                                 }
60                                         ],
61                                         'cmd_hold_capture_print' : [
62                                                 ['command'],
63                                                 function() {
64                                                         var p = { 
65                                                                 'template' : 'hold_capture'
66                                                         };
67                                                         obj.list.print(p);
68                                                 }
69                                         ],
70                                         'cmd_hold_capture_reprint' : [
71                                                 ['command'],
72                                                 function() {
73                                                 }
74                                         ],
75                                         'cmd_hold_capture_done' : [
76                                                 ['command'],
77                                                 function() {
78                                                 }
79                                         ],
80                                 }
81                         }
82                 );
83                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
84
85         },
86
87         'hold_capture' : function() {
88                 var obj = this;
89                 try {
90                         var barcode = obj.controller.view.hold_capture_barcode_entry_textbox.value;
91                         JSAN.use('circ.util');
92                         var hold_capture = circ.util.hold_capture_via_copy_barcode(
93                                 ses(), barcode, true
94                         );
95                         if (hold_capture) {
96                                 JSAN.use('patron.util');
97                                 var au_obj;
98                                 if (hold_capture.hold && hold_capture.hold.usr()) {
99
100                                         au_obj = patron.util.retrieve_au_via_id( ses(), hold_capture.hold.usr() );
101
102                                 } else {
103
104                                         au_obj = new au(); au_obj.family_name( '???' );
105
106                                 }
107                                 obj.list.append(
108                                         {
109                                                 'row' : {
110                                                         'my' : {
111                                                                 'au' : au_obj,
112                                                                 'hr' : hold_capture.hold,
113                                                                 'circ' : hold_capture.circ,
114                                                                 'mvr' : hold_capture.record,
115                                                                 'acp' : hold_capture.copy,
116                                                                 'route_to' : hold_capture.route_to,
117                                                                 'message' : hold_capture.message,
118                                                         }
119                                                 }
120                                         //I could override map_row_to_column here
121                                         }
122                                 );
123                 
124                                 try {
125                                 alert(document.getElementById('circStrings').getString('staff.circ.hold_capture.print.to_printer') + '\n' + hold_capture.text + '\r\n' + 
126                                         document.getElementById('circStrings').getString('staff.circ.hold_capture.print.barcode') + ' ' + barcode + 
127                                         document.getElementById('circStrings').getString('staff.circ.hold_capture.print.title') + ' ' + hold_capture.record.title() + 
128                                         document.getElementById('circStrings').getString('staff.circ.hold_capture.print.author') + ' ' + hold_capture.record.author() + '\r\n' +
129                                         document.getElementById('circStrings').getString('staff.circ.hold_capture.print.route_to') + ' ' + hold_capture.route_to + 
130                                         document.getElementById('circStrings').getString('staff.circ.hold_capture.print.patron') + ' ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
131                                         '\r\n'); //FIXME
132                                 } catch(E) { dump('errors\n'); }
133                                 /*
134                                 sPrint(hold_capture.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + hold_capture.record.title() + 
135                                         '  Author: ' + hold_capture.record.author() + '<br />\r\n' +
136                                         'Route To: ' + hold_capture.route_to + 
137                                         '  Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
138                                         '<br />\r\n'
139                                 );
140                                 */
141
142                                 if (typeof obj.on_hold_capture == 'function') {
143                                         obj.on_hold_capture(hold_capture);
144                                 }
145                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_hold_capture == 'function') {
146                                         obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.hold_capture.calling_external') + '\n');
147                                         window.xulG.on_hold_capture(hold_capture);
148                                 } else {
149                                         obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.hold_capture.no_external') + '\n');
150                                 }
151                         } else {
152                                 throw(document.getElementById('circStrings').getString('staff.circ.hold_capture.capture_failed'));
153                         }
154
155                 } catch(E) {
156                         alert(document.getElementById('circStrings').getString('staff.circ.hold_capture.error') + '\n'
157                                 + js2JSON(E));
158                         if (typeof obj.on_failure == 'function') {
159                                 obj.on_failure(E);
160                         }
161                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
162                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.hold_capture.calling_external') + '\n');
163                                 window.xulG.on_failure(E);
164                         } else {
165                                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.hold_capture.no_external') + '\n');
166                         }
167                 }
168
169         },
170
171         'on_hold_capture' : function() {
172                 this.controller.view.hold_capture_barcode_entry_textbox.value = '';
173                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
174         },
175
176         'on_failure' : function() {
177                 this.controller.view.hold_capture_barcode_entry_textbox.select();
178                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
179         }
180 }
181
182 dump('exiting circ.hold_capture.js\n');