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'];
20 JSAN.use('circ.util');
21 var columns = circ.util.columns(
23 'barcode' : { 'hidden' : false },
24 'title' : { 'hidden' : false },
25 'due_date' : { 'hidden' : false },
29 JSAN.use('util.list'); obj.list = new util.list('checkout_list');
33 'map_row_to_column' : circ.util.std_map_row_to_column(),
37 JSAN.use('util.controller'); obj.controller = new util.controller();
41 'checkout_menu_placeholder' : [
45 JSAN.use('util.widgets'); JSAN.use('util.functional');
46 var items = [ [ 'Barcode:' , 'barcode' ] ].concat(
47 util.functional.map_list(
50 return [ o.name(), o.id() ];
54 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
55 util.widgets.remove_children( e );
56 var ml = util.widgets.make_menulist(
60 ml.setAttribute('id','checkout_menulist');
61 ml.setAttribute('accesskey','');
65 var tb = obj.controller.view.checkout_barcode_entry_textbox;
66 if (ev.target.value == 'barcode') {
72 tb.value = 'Non-Cataloged';
76 obj.controller.view.checkout_menu = ml;
80 'checkout_barcode_entry_textbox' : [
83 if (ev.keyCode && ev.keyCode == 13) {
84 obj.checkout( { barcode: ev.target.value } );
90 function() { alert('Not Yet Implemented'); }
92 'cmd_checkout_submit' : [
96 if (obj.controller.view.checkout_menu.value == 'barcode' ||
97 obj.controller.view.checkout_menu.value == '') {
98 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
101 params.noncat_type = obj.controller.view.checkout_menu.value;
103 obj.checkout( params );
106 'cmd_checkout_print' : [
111 'cmd_checkout_reprint' : [
116 'cmd_checkout_done' : [
124 this.controller.render();
125 this.controller.view.checkout_barcode_entry_textbox.focus();
129 'checkout' : function(params) {
130 if (!params) params = {};
133 /**********************************************************************************************************************/
134 /* This does the actual checkout/renewal, but is called after a permit test further below */
135 function check_out(params) {
137 var checkout = obj.network.request(
140 [ obj.session, params ]
143 if (checkout.ilsevent == 0) {
145 if (!checkout.payload) checkout.payload = {};
147 if (!checkout.payload.circ) {
148 checkout.payload.circ = new aoc();
149 /*********************************************************************************************/
151 if (checkout.payload.noncat_circ) {
152 checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
153 checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
154 checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
156 JSAN.use('util.date');
157 var c = checkout.payload.noncat_circ.circ_time();
158 var d = c == "now" ? new Date() : util.date.db_date2Date( c );
159 var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
160 var cd = t.circ_duration() || "14 days";
161 var i = util.date.interval_to_seconds( cd ) * 1000;
162 d.setTime( Date.parse(d) + i );
163 checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
168 if (!checkout.payload.record) {
169 checkout.payload.record = new mvr();
170 /*********************************************************************************************/
172 if (checkout.payload.noncat_circ) {
173 checkout.payload.record.title(
174 obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
179 if (!checkout.payload.copy) {
180 checkout.payload.copy = new acp();
181 checkout.payload.copy.barcode( '' );
184 /*********************************************************************************************/
185 /* Override mvr title/author with dummy title/author for Pre cat */
186 if (checkout.payload.copy.dummy_title()) checkout.payload.record.title( checkout.payload.copy.dummy_title() );
187 if (checkout.payload.copy.dummy_author()) checkout.payload.record.author( checkout.payload.copy.dummy_author() );
193 'circ' : checkout.payload.circ,
194 'mvr' : checkout.payload.record,
195 'acp' : checkout.payload.copy
198 //I could override map_row_to_column here
201 if (typeof obj.on_checkout == 'function') {
202 obj.on_checkout(checkout.payload);
204 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkout == 'function') {
205 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_checkout()\n');
206 window.xulG.on_checkout(checkout.payload);
208 obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
215 /**********************************************************************************************************************/
216 /* Permissibility test before checkout */
219 params.patron = obj.patron_id;
221 var permit = obj.network.request(
222 api.CHECKOUT_PERMIT.app,
223 api.CHECKOUT_PERMIT.method,
224 [ obj.session, params ]
227 /**********************************************************************************************************************/
228 /* Normal case, proceed with checkout */
229 if (permit.ilsevent == 0) {
231 params.permit_key = permit.payload;
234 /**********************************************************************************************************************/
235 /* Item not cataloged or barcode mis-scan. Prompt for pre-cat option */
236 } else if (permit.ilsevent == 1202) {
238 if ( 1 == obj.error.yns_alert(
239 'Mis-scan or non-cataloged item. Checkout as a pre-cataloged item?',
247 obj.data.dummy_title = ''; obj.data.dummy_author = ''; obj.data.stash('dummy_title','dummy_author');
248 JSAN.use('util.window'); var win = new util.window();
249 win.open(urls.XUL_PRE_CAT, 'dummy_fields', 'chrome,resizable,modal');
250 obj.data.stash_retrieve();
252 params.permit_key = permit.payload;
253 params.dummy_title = obj.data.dummy_title;
254 params.dummy_author = obj.data.dummy_author;
257 if (params.dummy_title != '') { check_out( params ); } else { throw('Checkout cancelled'); }
265 alert('FIXME: need special alert and error handling\n'
267 if (typeof obj.on_failure == 'function') {
270 if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
271 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
272 window.xulG.on_failure(E);
274 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
280 'on_checkout' : function() {
281 this.controller.view.checkout_menu.selectedIndex = 0;
282 this.controller.view.checkout_barcode_entry_textbox.disabled = false;
283 this.controller.view.checkout_barcode_entry_textbox.value = '';
284 this.controller.view.checkout_barcode_entry_textbox.focus();
287 'on_failure' : function() {
288 this.controller.view.checkout_barcode_entry_textbox.select();
289 this.controller.view.checkout_barcode_entry_textbox.focus();
293 dump('exiting circ.checkout.js\n');