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