first go at moving staff client 2 trap hold logic to staff client 3
[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                                 //'hold_capture_status' : { 'hidden' : false },
26                                 'hold_capture_route_to' : { 'hidden' : false },
27                                 'hold_capture_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_barcode(
90                                 obj.session, barcode, true
91                         );
92                         if (hold_capture) {
93                                 JSAN.use('patron.util');
94                                 var au_obj = patron.util.retrieve_via_id( hold_capture.hold.usr() );
95                                 obj.list.append(
96                                         {
97                                                 'row' : {
98                                                         'my' : {
99                                                                 'patron' : au_obj,
100                                                                 'circ' : hold_capture.circ,
101                                                                 'mvr' : hold_capture.record,
102                                                                 'acp' : hold_capture.copy,
103                                                                 'status' : hold_capture.status,
104                                                                 'route_to' : hold_capture.route_to,
105                                                                 'text' : hold_capture.text,
106                                                         }
107                                                 }
108                                         //I could override map_row_to_column here
109                                         }
110                                 );
111                         
112                                 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + check.record.title() + 
113                                         '  Author: ' + check.record.author() + '\r\n' +
114                                         'Route To: ' + check.route_to + 
115                                         '  Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
116                                         '\r\n'); //FIXME
117                                 /*
118                                 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + check.record.title() + 
119                                         '  Author: ' + check.record.author() + '<br />\r\n' +
120                                         'Route To: ' + check.route_to + 
121                                         '  Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
122                                         '<br />\r\n'
123                                 );
124                                 */
125
126                                 if (typeof obj.on_hold_capture == 'function') {
127                                         obj.on_hold_capture(hold_capture);
128                                 }
129                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_hold_capture == 'function') {
130                                         obj.error.sdump('D_CIRC','circ.hold_capture: Calling external .on_hold_capture()\n');
131                                         window.xulG.on_hold_capture(hold_capture);
132                                 } else {
133                                         obj.error.sdump('D_CIRC','circ.hold_capture: No external .on_hold_capture()\n');
134                                 }
135                         } else {
136                                 throw("Could not capture hold.");
137                         }
138
139                 } catch(E) {
140                         alert('FIXME: need special alert and error handling\n'
141                                 + js2JSON(E));
142                         if (typeof obj.on_failure == 'function') {
143                                 obj.on_failure(E);
144                         }
145                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
146                                 obj.error.sdump('D_CIRC','circ.hold_capture: Calling external .on_failure()\n');
147                                 window.xulG.on_failure(E);
148                         } else {
149                                 obj.error.sdump('D_CIRC','circ.hold_capture: No external .on_failure()\n');
150                         }
151                 }
152
153         },
154
155         'on_hold_capture' : function() {
156                 this.controller.view.hold_capture_barcode_entry_textbox.value = '';
157                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
158         },
159
160         'on_failure' : function() {
161                 this.controller.view.hold_capture_barcode_entry_textbox.select();
162                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
163         }
164 }
165
166 dump('exiting circ.hold_capture.js\n');