]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/circ/circ_utils.js
during checkin, copy the copy from hold capture
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / circ / circ_utils.js
1 sdump('D_TRACE','Loading circ_tree.js\n');
2
3 function is_barcode_valid( barcode ) {
4
5         // consider checkdigit, length, etc.
6
7         return check_checkdigit( barcode );
8 }
9
10 function cancel_hold( hold ) {
11         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
12         try {
13                 var result = user_request(
14                         'open-ils.circ',
15                         'open-ils.circ.hold.cancel',
16                         [ mw.G.auth_ses[0], hold.id() ]
17                 )[0];
18                 sdump('D_CIRC_UTILS','result = ' + result + '\n');
19                 return result;
20         } catch(E) {
21                 handle_error(E);
22                 return null;
23         }
24 }
25
26 function checkout_permit(barcode, patron_id, num_of_open_async_checkout_requests, f) {
27         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true,1:true,2:true}));
28         try {
29                 var check = user_request(
30                         'open-ils.circ',
31                         'open-ils.circ.permit_checkout',
32                         [ mw.G.auth_ses[0], barcode, patron_id, num_of_open_async_checkout_requests ],
33                         f
34                 )[0];
35                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
36                 return check;   
37         } catch(E) {
38                 handle_error(E);
39                 return null;
40         }       
41 }
42
43 function checkout_by_copy_barcode(barcode, patron_id, f) {
44         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true,1:true}));
45         try {
46                 var check = user_request(
47                         'open-ils.circ',
48                         'open-ils.circ.checkout.barcode',
49                         [ mw.G.auth_ses[0], barcode, patron_id ],
50                         f
51                 )[0];
52                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
53                 return check;
54         } catch(E) {
55                 sdump('D_ERROR',E);
56                 return null;
57         }
58 }
59
60 function hold_capture_by_copy_barcode( barcode, retrieve_flag ) {
61         try {
62                 var check = user_request(
63                         'open-ils.circ',
64                         'open-ils.circ.hold.capture_copy.barcode',
65                         [ mw.G.auth_ses[0], barcode, retrieve_flag ]
66                 )[0];
67                 return check;
68         } catch(E) {
69                 handle_error(E, true);
70                 return null;
71         }
72 }
73
74 function checkin_by_copy_barcode(barcode, f) {
75         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
76         try {
77                 var check = user_request(
78                         'open-ils.circ',
79                         'open-ils.circ.checkin.barcode',
80                         [ mw.G.auth_ses[0], barcode ],
81                         f
82                 )[0];
83
84                 /*
85                 { // REMOVE_ME, forcing a condition for testing
86                         check.status = 1;
87                         check.text = 'This copy is the first that could fulfill a hold.  Do it?';
88                 }
89                 */
90
91                 if (!f) {
92                         sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
93                         if (check.status != 0) {
94                                 switch(check.status) {
95                                         case '1': case 1: /* possible hold capture */
96                                                 var rv = yns_alert(
97                                                         check.text,
98                                                         'Check Check In Interrupt',
99                                                         "Capture",
100                                                         "Don't Capture",
101                                                         null,
102                                                         "Check here to confirm this message"
103                                                 );
104                                                 switch(rv) {
105                                                         case 0: /* capture */
106                                                         try {
107                                                                 var check2 = hold_capture_by_copy_barcode( barcode );
108                                                                 if (check2) {
109                                                                         sdump('D_CIRC_UTILS','check2 = ' + js2JSON(check2) + '\n');
110                                                                         check.copy = check2.copy;
111                                                                         check.text = 'Captured for Hold';
112                                                                         check.route_to = mw.G.org_tree_hash[ check2.route_to ].shortname();
113                                                                 }
114
115                                                         } catch(E) { 
116                                                                 sdump('D_ERROR',E + '\n'); 
117                                                                 /* 
118                                                                 // demo testing 
119                                                                 check.text = 'Captured for Hold';
120                                                                 check.route_to = 'ARL-ATH';
121                                                                 */
122                                                         }
123                                                         break;
124                                                         case 1: /* don't capture */
125
126                                                                 check.text = 'Not Captured for Hold';
127                                                         break;
128                                                 }
129                                         break;
130
131                                         default: s_alert(check.text ); break;
132                                 }
133                         }
134                 }
135                 return check;
136         } catch(E) {
137                 handle_error(E, true);
138                 return null;
139         }
140 }
141
142 function renew_by_circ_id(id, f) {
143         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
144         try {
145                 var check = user_request(
146                         'open-ils.circ',
147                         'open-ils.circ.renew',
148                         [ mw.G.auth_ses[0], id ],
149                         f
150                 )[0];
151                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
152                 return check;
153         } catch(E) {
154                 sdump('D_ERROR',E);
155                 return null;
156         }
157 }
158
159 function hold_cols() {
160         var cols = [
161 {
162         'id' : 'request_time', 'label' : getString('ahr_request_time_label'), 'flex' : 0,
163         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
164         'fm_field_render' : '.request_time().toString().substr(0,10)'
165 },
166 {
167         'id' : 'status', 'label' : getString('ahr_status_label'), 'flex' : 1,
168         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.status()'
169 },
170 {
171         'id' : 'hold_type', 'label' : getString('ahr_hold_type_label'), 'flex' : 0,
172         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.hold_type()'
173 },
174 {
175         'id' : 'pickup_lib', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 1,
176         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 
177         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].name()'
178 },
179 {
180         'id' : 'pickup_lib_shortname', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 0,
181         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
182         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].shortname()'
183 },
184                 {
185                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 1,
186                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
187                 },
188                 {
189                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
190                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
191                 },
192 {
193         'id' : 'capture_time', 'label' : getString('ahr_capture_time_label'), 'flex' : 1,
194         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.capture_time()'
195 },
196 {
197         'id' : 'current_copy', 'label' : getString('ahr_current_copy_label'), 'flex' : 1,
198         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.current_copy()'
199 },
200 {
201         'id' : 'email_notify', 'label' : getString('ahr_email_notify_label'), 'flex' : 1,
202         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.email_notify()'
203 },
204 {
205         'id' : 'expire_time', 'label' : getString('ahr_expire_time_label'), 'flex' : 1,
206         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.expire_time()'
207 },
208 {
209         'id' : 'fulfillment_time', 'label' : getString('ahr_fulfillment_time_label'), 'flex' : 1,
210         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.fulfillment_time()'
211 },
212 {
213         'id' : 'holdable_formats', 'label' : getString('ahr_holdable_formats_label'), 'flex' : 1,
214         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.holdable_formats()'
215 },
216 {
217         'id' : 'id', 'label' : getString('ahr_id_label'), 'flex' : 1,
218         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.id()'
219 },
220 {
221         'id' : 'phone_notify', 'label' : getString('ahr_phone_notify_label'), 'flex' : 1,
222         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.phone_notify()'
223 },
224 {
225         'id' : 'prev_check_time', 'label' : getString('ahr_prev_check_time_label'), 'flex' : 1,
226         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.prev_check_time()'
227 },
228 {
229         'id' : 'requestor', 'label' : getString('ahr_requestor_label'), 'flex' : 1,
230         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.requestor()'
231 },
232 {
233         'id' : 'selection_depth', 'label' : getString('ahr_selection_depth_label'), 'flex' : 1,
234         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.selection_depth()'
235 },
236 {
237         'id' : 'target', 'label' : getString('ahr_target_label'), 'flex' : 1,
238         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.target()'
239 },
240 {
241         'id' : 'usr', 'label' : getString('ahr_usr_label'), 'flex' : 1,
242         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.usr()'
243 }
244         ];
245         return cols;
246 }
247
248 function checkin_cols() {
249         var cols = [
250                 {
251                         'id' : 'checkin_status', 'label' : getString('checkin_label_status'), 'flex' : 1,
252                         'primary' : false, 'hidden' : true, 'fm_class' : '', 'fm_field_render' : '.status.toString()'
253                 },
254                 {
255                         'id' : 'checkin_route_to', 'label' : getString('checkin_label_route_to'), 'flex' : 1,
256                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.route_to.toString()'
257                 },
258                 {
259                         'id' : 'checkin_text', 'label' : getString('checkin_label_text'), 'flex' : 1,
260                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.text.toString()'
261                 }
262         ];
263         var std_cols = map_list( 
264                 circ_cols(), 
265                 function(o){ if ((o.fm_class == 'acp')||(o.fm_class == 'circ')) o.hidden = true; return o; }
266         );
267         return cols.concat( std_cols );
268 }
269
270 function circ_cols() {
271         return  [
272                 {
273                         'id' : 'barcode', 'label' : getString('acp_label_barcode'), 'flex' : 1,
274                         'primary' : true, 'hidden' : false, 'fm_class' : 'acp', 'fm_field_render' : '.barcode()'
275                 },
276                 {
277                         'id' : 'call_number', 'label' : getString('acp_label_call_number'), 'flex' : 1,
278                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.call_number()'
279                 },
280                 {
281                         'id' : 'copy_number', 'label' : getString('acp_label_copy_number'), 'flex' : 1,
282                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.copy_number()'
283                 },
284                 {
285                         'id' : 'status', 'label' : getString('acp_label_status'), 'flex' : 1,
286                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.status()'
287                 },
288                 {
289                         'id' : 'location', 'label' : getString('acp_label_location'), 'flex' : 1,
290                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.location()'
291                 },
292                 {
293                         'id' : 'loan_duration', 'label' : getString('acp_label_loan_duration'), 'flex' : 1,
294                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.loan_duration()'
295                 },
296                 {
297                         'id' : 'circ_lib', 'label' : getString('acp_label_circ_lib'), 'flex' : 1,
298                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_lib()'
299                 },
300                 {
301                         'id' : 'fine_level', 'label' : getString('acp_label_fine_level'), 'flex' : 1,
302                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.fine_level()'
303                 },
304                 {
305                         'id' : 'deposit', 'label' : getString('acp_label_deposit'), 'flex' : 1,
306                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit()'
307                 },
308                 {
309                         'id' : 'deposit_amount', 'label' : getString('acp_label_deposit_amount'), 'flex' : 1,
310                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit_amount()'
311                 },
312                 {
313                         'id' : 'price', 'label' : getString('acp_label_price'), 'flex' : 1,
314                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.price()'
315                 },
316                 {
317                         'id' : 'circ_as_type', 'label' : getString('acp_label_circ_as_type'), 'flex' : 1,
318                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_as_type()'
319                 },
320                 {
321                         'id' : 'circ_modifier', 'label' : getString('acp_label_circ_modifier'), 'flex' : 1,
322                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_modifier()'
323                 },
324                 {
325                         'id' : 'xact_start', 'label' : getString('circ_label_xact_start'), 'flex' : 1,
326                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_start()'
327                 },
328                 {
329                         'id' : 'xact_finish', 'label' : getString('circ_label_xact_finish'), 'flex' : 1,
330                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_finish()'
331                 },
332                 {
333                         'id' : 'renewal_remaining', 'label' : getString('circ_label_renewal_remaining'), 'flex' : 1,
334                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.renewal_remaining()'
335                 },
336                 {
337                         'id' : 'due_date', 'label' : getString('circ_label_due_date'), 'flex' : 1,
338                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.due_date()'
339                 },
340                 {
341                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 1,
342                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
343                 },
344                 {
345                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
346                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
347                 }
348                 
349         ]
350 };
351
352