]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/hold_capture.js
spawn buckets interface from copy status interface
[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                                                                 'route_to' : hold_capture.route_to,
114                                                                 'message' : hold_capture.message,
115                                                         }
116                                                 }
117                                         //I could override map_row_to_column here
118                                         }
119                                 );
120                 
121                                 try {
122                                 alert('To Printer\n' + hold_capture.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + hold_capture.record.title() + 
123                                         '  Author: ' + hold_capture.record.author() + '\r\n' +
124                                         'Route To: ' + hold_capture.route_to + 
125                                         '  Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
126                                         '\r\n'); //FIXME
127                                 } catch(E) { dump('errors\n'); }
128                                 /*
129                                 sPrint(hold_capture.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + hold_capture.record.title() + 
130                                         '  Author: ' + hold_capture.record.author() + '<br />\r\n' +
131                                         'Route To: ' + hold_capture.route_to + 
132                                         '  Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + 
133                                         '<br />\r\n'
134                                 );
135                                 */
136
137                                 if (typeof obj.on_hold_capture == 'function') {
138                                         obj.on_hold_capture(hold_capture);
139                                 }
140                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_hold_capture == 'function') {
141                                         obj.error.sdump('D_CIRC','circ.hold_capture: Calling external .on_hold_capture()\n');
142                                         window.xulG.on_hold_capture(hold_capture);
143                                 } else {
144                                         obj.error.sdump('D_CIRC','circ.hold_capture: No external .on_hold_capture()\n');
145                                 }
146                         } else {
147                                 throw("Could not capture hold.");
148                         }
149
150                 } catch(E) {
151                         alert('FIXME: need special alert and error handling\n'
152                                 + js2JSON(E));
153                         if (typeof obj.on_failure == 'function') {
154                                 obj.on_failure(E);
155                         }
156                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
157                                 obj.error.sdump('D_CIRC','circ.hold_capture: Calling external .on_failure()\n');
158                                 window.xulG.on_failure(E);
159                         } else {
160                                 obj.error.sdump('D_CIRC','circ.hold_capture: No external .on_failure()\n');
161                         }
162                 }
163
164         },
165
166         'on_hold_capture' : function() {
167                 this.controller.view.hold_capture_barcode_entry_textbox.value = '';
168                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
169         },
170
171         'on_failure' : function() {
172                 this.controller.view.hold_capture_barcode_entry_textbox.select();
173                 this.controller.view.hold_capture_barcode_entry_textbox.focus();
174         }
175 }
176
177 dump('exiting circ.hold_capture.js\n');