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