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