]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkout.js
on_failure
[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(true);
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' : false, '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' : false, 'render' : 'my.circ.renewal_remaining()'
111                                         },
112                                         {
113                                                 'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
114                                                 'primary' : false, 'hidden' : false, '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                                                 }
134                                         ],
135                                         'cmd_broken' : [
136                                                 ['command'],
137                                                 function() { alert('Not Yet Implemented'); }
138                                         ],
139                                         'cmd_checkout_submit_barcode' : [
140                                                 ['command'],
141                                                 function() {
142                                                         try {
143                                                                 var barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
144                                                                 var permit = obj.network.request(
145                                                                         'open-ils.circ',
146                                                                         'open-ils.circ.permit_checkout',
147                                                                         [ obj.session, barcode, obj.patron_id, 0 ]
148                                                                 );
149
150                                                                 if (permit.status == 0) {
151                                                                         var checkout = obj.network.request(
152                                                                                 'open-ils.circ',
153                                                                                 'open-ils.circ.checkout.barcode',
154                                                                                 [ obj.session, barcode, obj.patron_id ]
155                                                                         );
156                                                                         obj.list.append(
157                                                                                 {
158                                                                                         'row' : {
159                                                                                                 'my' : {
160                                                                                                 'circ' : checkout.circ,
161                                                                                                 'mvr' : checkout.record,
162                                                                                                 'acp' : checkout.copy
163                                                                                                 }
164                                                                                         }
165                                                                                 //I could override map_row_to_column here
166                                                                                 }
167                                                                         );
168                                                                         if (typeof obj.on_checkout == 'function') {
169                                                                                 obj.on_checkout();
170                                                                         }
171
172                                                                 } else {
173                                                                         throw(permit.text);
174                                                                 }
175                                                         } catch(E) {
176                                                                 alert('FIXME: need special alert and error handling\n'
177                                                                         + js2JSON(E));
178                                                                 if (typeof obj.on_failure == 'function') {
179                                                                         obj.on_failure();
180                                                                 }
181                                                         }
182                                                 }
183                                         ],
184                                         'cmd_checkout_print' : [
185                                                 ['command'],
186                                                 function() {
187                                                 }
188                                         ],
189                                         'cmd_checkout_reprint' : [
190                                                 ['command'],
191                                                 function() {
192                                                 }
193                                         ],
194                                         'cmd_checkout_done' : [
195                                                 ['command'],
196                                                 function() {
197                                                 }
198                                         ],
199                                 }
200                         }
201                 );
202
203         },
204
205         'on_checkout' : function() {
206                 this.controller.view.checkout_barcode_entry_textbox.value = '';
207                 this.controller.view.checkout_barcode_entry_textbox.focus();
208         },
209
210         'on_failure' : function() {
211                 this.controller.view.checkout_barcode_entry.textbox.select();
212                 this.controller.view.checkout_barcode_entry_textbox.focus();
213         }
214 }
215
216 dump('exiting circ.checkout.js\n');