]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkout.js
aef784e43bc512de3e715f8f20cc8e24e4bdec50
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkout.js
1 dump('entering circ.checkout.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 circ.checkout = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8
9         JSAN.use('OpenILS.data'); this.OpenILS = {};
10         this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11 }
12
13 circ.checkout.prototype = {
14
15         'init' : function( params ) {
16
17                 var obj = this;
18
19                 obj.session = params['session'];
20                 obj.patron_id = params['patron_id'];
21
22                 JSAN.use('circ.util');
23                 var columns = circ.util.columns( 
24                         { 
25                                 'barcode' : { 'hidden' : false },
26                                 'title' : { 'hidden' : false },
27                                 'due_date' : { 'hidden' : false },
28                         } 
29                 );
30
31                 JSAN.use('util.list'); obj.list = new util.list('checkout_list');
32                 obj.list.init(
33                         {
34                                 'columns' : columns,
35                                 'map_row_to_column' : function(row,col) {
36                                         // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
37                                         // col contains one of the objects listed above in columns
38                                         var my = row.my;
39                                         return eval( col.render );
40                                 },
41                         }
42                 );
43                 
44                 JSAN.use('util.controller'); obj.controller = new util.controller();
45                 obj.controller.init(
46                         {
47                                 'control_map' : {
48                                         'checkout_barcode_entry_textbox' : [
49                                                 ['keypress'],
50                                                 function(ev) {
51                                                         if (ev.keyCode && ev.keyCode == 13) {
52                                                                 obj.checkout();
53                                                         }
54                                                 }
55                                         ],
56                                         'cmd_broken' : [
57                                                 ['command'],
58                                                 function() { alert('Not Yet Implemented'); }
59                                         ],
60                                         'cmd_checkout_submit_barcode' : [
61                                                 ['command'],
62                                                 function() {
63                                                         obj.checkout();
64                                                 }
65                                         ],
66                                         'cmd_checkout_print' : [
67                                                 ['command'],
68                                                 function() {
69                                                 }
70                                         ],
71                                         'cmd_checkout_reprint' : [
72                                                 ['command'],
73                                                 function() {
74                                                 }
75                                         ],
76                                         'cmd_checkout_done' : [
77                                                 ['command'],
78                                                 function() {
79                                                 }
80                                         ],
81                                 }
82                         }
83                 );
84                 this.controller.view.checkout_barcode_entry_textbox.focus();
85
86         },
87
88         'checkout' : function() {
89                 var obj = this;
90                 try {
91                         var barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
92                         var permit = obj.network.request(
93                                 api.checkout_permit_via_barcode.app,
94                                 api.checkout_permit_via_barcode.method,
95                                 [ obj.session, barcode, obj.patron_id, 0 ]
96                         );
97
98                         if (permit.status == 0) {
99                                 var checkout = obj.network.request(
100                                         api.checkout_via_barcode.app,
101                                         api.checkout_via_barcode.method,
102                                         [ obj.session, barcode, obj.patron_id ]
103                                 );
104                                 obj.list.append(
105                                         {
106                                                 'row' : {
107                                                         'my' : {
108                                                         'circ' : checkout.circ,
109                                                         'mvr' : checkout.record,
110                                                         'acp' : checkout.copy
111                                                         }
112                                                 }
113                                         //I could override map_row_to_column here
114                                         }
115                                 );
116                                 if (typeof obj.on_checkout == 'function') {
117                                         obj.on_checkout(checkout);
118                                 }
119                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_checkout == 'function') {
120                                         obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_checkout()\n');
121                                         window.xulG.on_checkout(checkout);
122                                 } else {
123                                         obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
124                                 }
125
126                         } else {
127                                 throw(permit.text);
128                         }
129                 } catch(E) {
130                         alert('FIXME: need special alert and error handling\n'
131                                 + js2JSON(E));
132                         if (typeof obj.on_failure == 'function') {
133                                 obj.on_failure(E);
134                         }
135                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
136                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
137                                 window.xulG.on_failure(E);
138                         } else {
139                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
140                         }
141                 }
142
143         },
144
145         'on_checkout' : function() {
146                 this.controller.view.checkout_barcode_entry_textbox.value = '';
147                 this.controller.view.checkout_barcode_entry_textbox.focus();
148         },
149
150         'on_failure' : function() {
151                 this.controller.view.checkout_barcode_entry_textbox.select();
152                 this.controller.view.checkout_barcode_entry_textbox.focus();
153         }
154 }
155
156 dump('exiting circ.checkout.js\n');