]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkout.js
a little checkout polish
[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('main.network'); this.network = new main.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('main.list'); obj.list = new main.list('checkout_list');
23                 //FIXME//getString used to wrap StringBundles, but we need to do the entity/div thing
24                 function getString(s) { return obj.OpenILS.data.entities[s]; }
25                 obj.list.init(
26                         {
27                                 'columns' : [
28                                         {
29                                                 'id' : 'acp_id', 'label' : getString('staff.acp_label_id'), 'flex' : 1,
30                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.id()'
31                                         },
32                                         {
33                                                 'id' : 'circ_id', 'label' : getString('staff.circ_label_id'), 'flex' : 1,
34                                                 'primary' : false, 'hidden' : true, 'render' : 'my.circ.id()'
35                                         },
36                                         {
37                                                 'id' : 'mvr_doc_id', 'label' : getString('staff.mvr_label_doc_id'), 'flex' : 1,
38                                                 'primary' : false, 'hidden' : true, 'render' : 'my.mvr.doc_id()'
39                                         },
40                                         {
41                                                 'id' : 'barcode', 'label' : getString('staff.acp_label_barcode'), 'flex' : 1,
42                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.barcode()'
43                                         },
44                                         {
45                                                 'id' : 'call_number', 'label' : getString('staff.acp_label_call_number'), 'flex' : 1,
46                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.call_number()'
47                                         },
48                                         {
49                                                 'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1,
50                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.copy_number()'
51                                         },
52                                         {
53                                                 'id' : 'location', 'label' : getString('staff.acp_label_location'), 'flex' : 1,
54                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.location()'
55                                         },
56                                         {
57                                                 'id' : 'loan_duration', 'label' : getString('staff.acp_label_loan_duration'), 'flex' : 1,
58                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.loan_duration()'
59                                         },
60                                         {
61                                                 'id' : 'circ_lib', 'label' : getString('staff.acp_label_circ_lib'), 'flex' : 1,
62                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_lib()'
63                                         },
64                                         {
65                                                 'id' : 'fine_level', 'label' : getString('staff.acp_label_fine_level'), 'flex' : 1,
66                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.fine_level()'
67                                         },
68                                         {
69                                                 'id' : 'deposit', 'label' : getString('staff.acp_label_deposit'), 'flex' : 1,
70                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit()'
71                                         },
72                                         {
73                                                 'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
74                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
75                                         },
76                                         {
77                                                 'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
78                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
79                                         },
80                                         {
81                                                 'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
82                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_as_type()'
83                                         },
84                                         {
85                                                 'id' : 'circ_modifier', 'label' : getString('staff.acp_label_circ_modifier'), 'flex' : 1,
86                                                 'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_modifier()'
87                                         },
88                                         {
89                                                 'id' : 'xact_start', 'label' : getString('staff.circ_label_xact_start'), 'flex' : 1,
90                                                 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_start()'
91                                         },
92                                         {
93                                                 'id' : 'xact_finish', 'label' : getString('staff.circ_label_xact_finish'), 'flex' : 1,
94                                                 'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_finish()'
95                                         },
96                                         {
97                                                 'id' : 'due_date', 'label' : getString('staff.circ_label_due_date'), 'flex' : 1,
98                                                 'primary' : false, 'hidden' : false, 'render' : 'my.circ.due_date().substr(0,10)'
99                                         },
100                                         {
101                                                 'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 2,
102                                                 'primary' : false, 'hidden' : false, 'render' : 'my.mvr.title()'
103                                         },
104                                         {
105                                                 'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
106                                                 'primary' : false, 'hidden' : false, 'render' : 'my.mvr.author()'
107                                         },
108                                         {
109                                                 'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
110                                                 'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
111                                         },
112                                         {
113                                                 'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
114                                                 'primary' : false, 'hidden' : true, 'render' : 'obj.OpenILS.data.hash.ccs[ my.acp.status() ].name()'
115                                         }
116                                 ],
117                                 'map_row_to_column' : function(row,col) {
118                                         // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
119                                         // col contains one of the objects listed above in columns
120                                         var my = row.my;
121                                         return eval( col.render );
122                                 },
123                         }
124                 );
125                 
126                 JSAN.use('main.controller'); obj.controller = new main.controller();
127                 obj.controller.init(
128                         {
129                                 'control_map' : {
130                                         'checkout_barcode_entry_textbox' : [
131                                                 ['keypress'],
132                                                 function(ev) {
133                                                         if (ev.keyCode && ev.keyCode == 13) {
134                                                                 obj.checkout();
135                                                         }
136                                                 }
137                                         ],
138                                         'cmd_broken' : [
139                                                 ['command'],
140                                                 function() { alert('Not Yet Implemented'); }
141                                         ],
142                                         'cmd_checkout_submit_barcode' : [
143                                                 ['command'],
144                                                 function() {
145                                                         obj.checkout();
146                                                 }
147                                         ],
148                                         'cmd_checkout_print' : [
149                                                 ['command'],
150                                                 function() {
151                                                 }
152                                         ],
153                                         'cmd_checkout_reprint' : [
154                                                 ['command'],
155                                                 function() {
156                                                 }
157                                         ],
158                                         'cmd_checkout_done' : [
159                                                 ['command'],
160                                                 function() {
161                                                 }
162                                         ],
163                                 }
164                         }
165                 );
166                 this.controller.view.checkout_barcode_entry_textbox.focus();
167
168         },
169
170         'checkout' : function() {
171                 var obj = this;
172                 try {
173                         var barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
174                         var permit = obj.network.request(
175                                 'open-ils.circ',
176                                 'open-ils.circ.permit_checkout',
177                                 [ obj.session, barcode, obj.patron_id, 0 ]
178                         );
179
180                         if (permit.status == 0) {
181                                 var checkout = obj.network.request(
182                                         'open-ils.circ',
183                                         'open-ils.circ.checkout.barcode',
184                                         [ obj.session, barcode, obj.patron_id ]
185                                 );
186                                 obj.list.append(
187                                         {
188                                                 'row' : {
189                                                         'my' : {
190                                                         'circ' : checkout.circ,
191                                                         'mvr' : checkout.record,
192                                                         'acp' : checkout.copy
193                                                         }
194                                                 }
195                                         //I could override map_row_to_column here
196                                         }
197                                 );
198                                 if (typeof obj.on_checkout == 'function') {
199                                         obj.on_checkout();
200                                 }
201
202                         } else {
203                                 throw(permit.text);
204                         }
205                 } catch(E) {
206                         alert('FIXME: need special alert and error handling\n'
207                                 + js2JSON(E));
208                         if (typeof obj.on_failure == 'function') {
209                                 obj.on_failure();
210                         }
211                 }
212
213         },
214
215         'on_checkout' : function() {
216                 this.controller.view.checkout_barcode_entry_textbox.value = '';
217                 this.controller.view.checkout_barcode_entry_textbox.focus();
218         },
219
220         'on_failure' : function() {
221                 this.controller.view.checkout_barcode_entry_textbox.select();
222                 this.controller.view.checkout_barcode_entry_textbox.focus();
223         }
224 }
225
226 dump('exiting circ.checkout.js\n');