1 dump('entering circ.checkout.js\n');
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkout = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
8 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11 circ.checkout.prototype = {
13 'init' : function( params ) {
17 obj.session = params['session'];
18 obj.patron_id = params['patron_id'];
19 obj.patron = obj.network.simple_request('FM_AU_RETRIEVE_VIA_ID',[obj.session,obj.patron_id]);
21 JSAN.use('circ.util');
22 var columns = circ.util.columns(
24 'barcode' : { 'hidden' : false },
25 'title' : { 'hidden' : false },
26 'due_date' : { 'hidden' : false },
30 JSAN.use('util.list'); obj.list = new util.list('checkout_list');
34 'map_row_to_column' : circ.util.std_map_row_to_column(),
38 JSAN.use('util.controller'); obj.controller = new util.controller();
42 'checkout_menu_placeholder' : [
46 JSAN.use('util.widgets'); JSAN.use('util.functional');
47 var items = [ [ 'Barcode:' , 'barcode' ] ].concat(
48 util.functional.map_list(
51 return [ o.name(), o.id() ];
55 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
56 util.widgets.remove_children( e );
57 var ml = util.widgets.make_menulist(
61 ml.setAttribute('id','checkout_menulist');
62 ml.setAttribute('accesskey','');
66 var tb = obj.controller.view.checkout_barcode_entry_textbox;
67 if (ev.target.value == 'barcode') {
73 tb.value = 'Non-Cataloged';
77 obj.controller.view.checkout_menu = ml;
81 'checkout_barcode_entry_textbox' : [
84 if (ev.keyCode && ev.keyCode == 13) {
85 obj.checkout( { barcode: ev.target.value } );
91 function() { alert('Not Yet Implemented'); }
93 'cmd_checkout_submit' : [
96 var params = {}; var count = 1;
97 if (obj.controller.view.checkout_menu.value == 'barcode' ||
98 obj.controller.view.checkout_menu.value == '') {
99 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
102 params.noncat_type = obj.controller.view.checkout_menu.value;
103 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
104 var r = window.prompt('Enter the number of ' + obj.data.hash.cnct[ params.noncat_type].name() + ' circulating:','1','Non-cataloged Items');
109 r = obj.error.yns_alert('Are you sure you want to circulate ' + count + ' ' + obj.data.hash.cnct[ params.noncat_type].name() + '?','Non-cataloged Circulation','Yes','No',null,'Check here to confirm this message.');
119 for (var i = 0; i < count; i++) {
120 obj.checkout( params );
124 'cmd_checkout_print' : [
129 'patron' : obj.patron,
130 'lib' : obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ],
131 'staff' : obj.data.list.au[0],
132 'header' : obj.data.print_list_templates.checkout.header,
133 'line_item' : obj.data.print_list_templates.checkout.line_item,
134 'footer' : obj.data.print_list_templates.checkout.footer,
135 'type' : obj.data.print_list_templates.checkout.type,
136 'list' : obj.list.dump(),
138 JSAN.use('util.print'); var print = new util.print();
139 print.tree_list( params );
141 this.error.sdump('D_ERROR','preview: ' + E);
142 alert('preview: ' + E);
147 'cmd_checkout_reprint' : [
152 'cmd_checkout_done' : [
160 this.controller.render();
161 this.controller.view.checkout_barcode_entry_textbox.focus();
165 'checkout' : function(params) {
166 if (!params) params = {};
169 /**********************************************************************************************************************/
170 /* This does the actual checkout/renewal, but is called after a permit test further below */
171 function check_out(params) {
173 var checkout = obj.network.request(
176 [ obj.session, params ]
179 if (checkout.ilsevent == 0) {
181 if (!checkout.payload) checkout.payload = {};
183 if (!checkout.payload.circ) {
184 checkout.payload.circ = new aoc();
185 /*********************************************************************************************/
187 if (checkout.payload.noncat_circ) {
188 checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
189 checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
190 checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
192 JSAN.use('util.date');
193 var c = checkout.payload.noncat_circ.circ_time();
194 var d = c == "now" ? new Date() : util.date.db_date2Date( c );
195 var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
196 var cd = t.circ_duration() || "14 days";
197 var i = util.date.interval_to_seconds( cd ) * 1000;
198 d.setTime( Date.parse(d) + i );
199 checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
204 if (!checkout.payload.record) {
205 checkout.payload.record = new mvr();
206 /*********************************************************************************************/
208 if (checkout.payload.noncat_circ) {
209 checkout.payload.record.title(
210 obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
215 if (!checkout.payload.copy) {
216 checkout.payload.copy = new acp();
217 checkout.payload.copy.barcode( '' );
220 /*********************************************************************************************/
221 /* Override mvr title/author with dummy title/author for Pre cat */
222 if (checkout.payload.copy.dummy_title()) checkout.payload.record.title( checkout.payload.copy.dummy_title() );
223 if (checkout.payload.copy.dummy_author()) checkout.payload.record.author( checkout.payload.copy.dummy_author() );
229 'circ' : checkout.payload.circ,
230 'mvr' : checkout.payload.record,
231 'acp' : checkout.payload.copy
234 //I could override map_row_to_column here
237 if (typeof obj.on_checkout == 'function') {
238 obj.on_checkout(checkout.payload);
240 if (typeof window.xulG == 'object' && typeof window.xulG.on_list_change == 'function') {
241 window.xulG.on_list_change(checkout.payload);
243 obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
250 /**********************************************************************************************************************/
251 /* Permissibility test before checkout */
254 params.patron = obj.patron_id;
256 var permit = obj.network.request(
257 api.CHECKOUT_PERMIT.app,
258 api.CHECKOUT_PERMIT.method,
259 [ obj.session, params ],
262 'title' : 'Override Checkout Failure?',
263 'overridable_events' : [ 7004, 7006 ],
267 /**********************************************************************************************************************/
268 /* Normal case, proceed with checkout */
269 if (permit.ilsevent == 0) {
271 JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
272 params.permit_key = permit.payload;
275 /**********************************************************************************************************************/
276 /* Item not cataloged or barcode mis-scan. Prompt for pre-cat option */
277 } else if (permit.ilsevent == 1202) {
279 if ( 1 == obj.error.yns_alert(
280 'Mis-scan or non-cataloged item. Checkout as a pre-cataloged item?',
288 obj.data.dummy_title = ''; obj.data.dummy_author = ''; obj.data.stash('dummy_title','dummy_author');
289 JSAN.use('util.window'); var win = new util.window();
290 win.open(urls.XUL_PRE_CAT, 'dummy_fields', 'chrome,resizable,modal');
291 obj.data.stash_retrieve();
293 params.permit_key = permit.payload;
294 params.dummy_title = obj.data.dummy_title;
295 params.dummy_author = obj.data.dummy_author;
298 if (params.dummy_title != '') { check_out( params ); } else { throw('Checkout cancelled'); }
306 obj.error.yns_alert('FIXME: If you see this alert, please let your friendly Evergreen Developers know.\n' + js2JSON(E), 'Check Out Failed', 'Ok', null, null, 'Check here to confirm this message' );
307 if (typeof obj.on_failure == 'function') {
310 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
311 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
312 window.xulG.on_failure(E);
314 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
320 'on_checkout' : function() {
321 this.controller.view.checkout_menu.selectedIndex = 0;
322 this.controller.view.checkout_barcode_entry_textbox.disabled = false;
323 this.controller.view.checkout_barcode_entry_textbox.value = '';
324 this.controller.view.checkout_barcode_entry_textbox.focus();
327 'on_failure' : function() {
328 this.controller.view.checkout_barcode_entry_textbox.select();
329 this.controller.view.checkout_barcode_entry_textbox.focus();
333 dump('exiting circ.checkout.js\n');