]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/in_house_use.js
a46ea048c857eafeb6fbc8d53328b5ebf370568a
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / in_house_use.js
1 dump('entering circ.in_house_use.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 if (typeof circ == 'undefined') circ = {};
5 circ.in_house_use = function (params) {
6
7         JSAN.use('util.error'); this.error = new util.error();
8         JSAN.use('util.network'); this.network = new util.network();
9         JSAN.use('util.barcode');
10         JSAN.use('util.date');
11         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
12 }
13
14 circ.in_house_use.prototype = {
15
16         'init' : function( params ) {
17
18                 var obj = this;
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'status' : { 'hidden' : false },
26                                 'location' : { 'hidden' : false },
27                                 'call_number' : { 'hidden' : false },
28                                 'uses' : { 'hidden' : false },
29                         } 
30                 );
31
32                 JSAN.use('util.list'); obj.list = new util.list('in_house_use_list');
33                 obj.list.init(
34                         {
35                                 'columns' : columns,
36                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
37                                 'on_select' : function() {
38                                         var sel = obj.list.retrieve_selection();
39                                         document.getElementById('clip_button').disabled = sel.length < 1;
40                                 }
41                         }
42                 );
43                 
44                 JSAN.use('util.controller'); obj.controller = new util.controller();
45                 obj.controller.init(
46                         {
47                                 'control_map' : {
48                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
49                                         'sel_clip' : [
50                                                 ['command'],
51                                                 function() { obj.list.clipboard(); }
52                                         ],
53                                         'in_house_use_menu_placeholder' : [
54                                                 ['render'],
55                                                 function(e) {
56                                                         return function() {
57                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
58                                                                 var items = [ [ document.getElementById('circStrings').getString('staff.circ.in_house_use.barcode') , 'barcode' ] ].concat(
59                                                                         util.functional.map_list(
60                                                                                 util.functional.filter_list(
61                                                                                         obj.data.list.cnct,
62                                                                                         function(o) {
63                                                                                                 return util.fm_utils.compare_aou_a_is_b_or_ancestor(o.owning_lib(), obj.data.list.au[0].ws_ou());
64                                                                                         }
65                                                                                 ).sort(
66
67                                                                                         function(a,b) {
68                                                                                                 try { 
69                                                                                                         return util.fm_utils.sort_func_aou_by_depth_and_then_string(
70                                                                                                                 [ a.owning_lib(), a.name() ],
71                                                                                                                 [ b.owning_lib(), b.name() ]
72                                                                                                         );
73                                                                                                 } catch(E) {
74                                                                                                         alert(document.getElementById('circStrings').getString('staff.circ.in_house_use.noncat_sort_error') + ' ' + E);
75                                                                                                         return 0;
76                                                                                                 }
77                                                                                         }
78
79                                                                                 ),
80                                                                                 function(o) {
81                                                                                         return [ obj.data.hash.aou[ o.owning_lib() ].shortname() + ' : ' + o.name(), o.id() ];
82                                                                                 }
83                                                                         )
84                                                                 );
85                                                                 g.error.sdump('D_TRACE', document.getElementById('circStrings').getString('staff.circ.in_house_use.items_dump') + js2JSON(items));
86                                                                 util.widgets.remove_children( e );
87                                                                 var ml = util.widgets.make_menulist(
88                                                                         items
89                                                                 );
90                                                                 e.appendChild( ml );
91                                                                 ml.setAttribute('id','in_house_use_menulist');
92                                                                 ml.setAttribute('accesskey','');
93                                                                 ml.addEventListener(
94                                                                         'command',
95                                                                         function(ev) {
96                                                                                 var tb = obj.controller.view.in_house_use_barcode_entry_textbox;
97                                                                                 if (ev.target.value == 'barcode') {
98                                                                                         tb.disabled = false;
99                                                                                         tb.value = '';
100                                                                                         tb.focus();
101                                                                                 } else {
102                                                                                         tb.disabled = true;
103                                                                                         tb.value = document.getElementById('circStrings').getString('staff.circ.in_house_use.noncataloged');
104                                                                                 }
105                                                                         }, false
106                                                                 );
107                                                                 obj.controller.view.in_house_use_menu = ml;
108                                                         };
109                                                 },
110                                         ],
111                                         'in_house_use_barcode_entry_textbox' : [
112                                                 ['keypress'],
113                                                 function(ev) {
114                                                         if (ev.keyCode && ev.keyCode == 13) {
115                                                                 obj.in_house_use();
116                                                         }
117                                                 }
118                                         ],
119                                         'in_house_use_multiplier_label' : [
120                                                 ['render'],
121                                                 function(e) {
122                                                         return function() {
123                                                                 obj.controller.view.in_house_use_multiplier_textbox.select();
124                                                                 obj.controller.view.in_house_use_multiplier_textbox.value = 1;
125                                                         };
126                                                 }
127                                         ],
128                                         'in_house_use_multiplier_textbox' : [
129                                                 ['change'],
130                                                 function(ev) {
131                                                         if (ev.target.nodeName == 'textbox') {
132                                                                 try {
133                                                                         var value = Number(ev.target.value);
134                                                                         if (value > 0) {
135                                                                                 if (value > 99) ev.target.value = 99;
136                                                                         } else {
137                                                                                 ev.target.value = 1;
138                                                                         }
139                                                                 } catch(E) {
140                                                                         dump('in_house_use:multiplier: ' + E + '\n');
141                                                                         ev.target.value = 1;
142                                                                 }
143                                                         }
144                                                 }
145                                         ],
146                                         'cmd_broken' : [
147                                                 ['command'],
148                                                 function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
149                                         ],
150                                         'cmd_in_house_use_submit_barcode' : [
151                                                 ['command'],
152                                                 function() {
153                                                         obj.in_house_use();
154                                                 }
155                                         ],
156                                         'cmd_in_house_use_print' : [
157                                                 ['command'],
158                                                 function() {
159                                                         var p = { 
160                                                                 'template' : 'in_house_use'
161                                                         };
162                                                         obj.list.print(p);
163                                                 }
164                                         ],
165                                         'cmd_in_house_use_export' : [
166                                                 ['command'],
167                                                 function() {
168                                                         obj.list.dump_csv_to_clipboard();
169                                                 }
170                                         ],
171
172                                         'cmd_in_house_use_reprint' : [
173                                                 ['command'],
174                                                 function() {
175                                                 }
176                                         ],
177                                         'cmd_in_house_use_done' : [
178                                                 ['command'],
179                                                 function() {
180                                                 }
181                                         ],
182                                 }
183                         }
184                 );
185                 this.controller.render();
186                 this.controller.view.in_house_use_barcode_entry_textbox.focus();
187
188         },
189
190         'test_barcode' : function(bc) {
191                 var obj = this;
192                 var good = util.barcode.check(bc);
193                 var x = document.getElementById('strict_barcode');
194                 if (x && x.checked != true) return true;
195                 if (good) {
196                         return true;
197                 } else {
198                         if ( 1 == obj.error.yns_alert(
199                                                 document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
200                                                 document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
201                                                 document.getElementById('circStrings').getString('staff.circ.cancel'),
202                                                 document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
203                                                 null,
204                                                 document.getElementById('circStrings').getString('staff.circ.confirm'),
205                                                 '/xul/server/skin/media/images/bad_barcode.png'
206                         ) ) {
207                                 return true;
208                         } else {
209                                 return false;
210                         }
211                 }
212         },
213
214         'in_house_use' : function() {
215                 var obj = this;
216                 try {
217                         var barcode;
218                         if (obj.controller.view.in_house_use_menu.value == '' || obj.controller.view.in_house_use_menu.value == 'barcode') {
219                                 barcode = obj.controller.view.in_house_use_barcode_entry_textbox.value;
220                                 if (barcode) {
221                                         if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
222                                 }
223                         } else {
224                                 barcode = ( obj.controller.view.in_house_use_menu.value );
225                                 //barcode = obj.data.hash.cnct[ obj.controller.view.in_house_use_menu.value ].name()
226                         }
227                         var multiplier = Number( obj.controller.view.in_house_use_multiplier_textbox.value );
228
229                         if (barcode == '') {
230                                 obj.controller.view.in_house_use_barcode_entry_textbox.focus();
231                                 return; 
232                         }
233
234                         if (multiplier == 0 || multiplier > 99) {
235                                 obj.controller.view.in_house_use_multiplier_textbox.focus();
236                                 obj.controller.view.in_house_use_multiplier_textbox.select();
237                                 return;
238                         }
239
240                         if (multiplier > 20) {
241                                 var r = obj.error.yns_alert(
242                                         document.getElementById('circStrings').getFormattedString('staff.circ.in_house_use.confirm_multiple', [barcode, multiplier]),
243                                         document.getElementById('circStrings').getString('staff.circ.in_house_use.confirm_multiple.title'),
244                                         document.getElementById('circStrings').getString('staff.circ.in_house_use.yes'),
245                                         document.getElementById('circStrings').getString('staff.circ.in_house_use.no'),
246                                         null,
247                                         document.getElementById('circStrings').getString('staff.circ.confirm.msg')
248                                 );
249                                 if (r != 0) {
250                                         obj.controller.view.in_house_use_multiplier_textbox.focus();
251                                         obj.controller.view.in_house_use_multiplier_textbox.select();
252                                         return;
253                                 }
254                         }
255
256                         JSAN.use('circ.util');
257
258                         if (obj.controller.view.in_house_use_menu.value == 'barcode') {
259
260                                 var copy = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]); 
261                                 if (copy.ilsevent) { 
262                                         switch(copy.ilsevent) {
263                                                 case -1 : 
264                                                         obj.error.standard_network_error_alert(document.getElementById('circStrings').getString('staff.circ.in_house_use.failed.verbose'));
265                                                         break;
266                                                 case 1502 /* ASSET_COPY_NOT_FOUND */ : 
267                                                         obj.error.yns_alert(
268                                                                 copy.textcode,
269                                                                 document.getElementById('circStrings').getString('staff.circ.in_house_use.failed'),
270                                                                 document.getElementById('circStrings').getString('staff.circ.in_house_use.ok'),
271                                                                 null,
272                                                                 null,
273                                                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
274                                                         );
275                                                         break;
276                                                 default:
277                                                         throw(copy);
278                                         }
279                                         return; 
280                                 }
281         
282                                 var mods = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',[ copy.id() ]);
283                                 var result = obj.network.simple_request('FM_AIHU_CREATE',
284                                         [ ses(), { 'copyid' : copy.id(), 'location' : obj.data.list.au[0].ws_ou(), 'count' : multiplier } ]
285                                 );
286
287                         } else {
288                                 var result = obj.network.simple_request('FM_ANCIHU_CREATE',
289                                         [ ses(), { 'non_cat_type' : obj.controller.view.in_house_use_menu.value, 'location' : obj.data.list.au[0].ws_ou(), 'count' : multiplier } ]
290                                 );
291                                 mods = new mvr(); mods.title( obj.data.hash.cnct[ obj.controller.view.in_house_use_menu.value ].name()); 
292                                 copy = new acp(); copy.barcode( '' );
293                         }
294
295                         if (document.getElementById('trim_list')) {
296                                 var x = document.getElementById('trim_list');
297                                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
298                         }
299                         obj.list.append(
300                                 {
301                                         'row' : {
302                                                 'my' : {
303                                                         'mvr' : mods,
304                                                         'acp' : copy,
305                                                         'uses' : result.length,
306                                                 }
307                                         },
308                                         'to_top' : true,
309                                 //I could override map_row_to_column here
310                                 }
311                         );
312
313                         if (typeof obj.on_in_house_use == 'function') {
314                                 obj.on_in_house_use(result);
315                         }
316                         if (typeof window.xulG == 'object' && typeof window.xulG.on_in_house_use == 'function') {
317                                 obj.error.sdump('D_CIRC', + document.getElementById('circStrings').getString('staff.circ.in_house_use.external') + '\n');
318                                 window.xulG.on_in_house_use(result);
319                         } else {
320                                 obj.error.sdump('D_CIRC', + document.getElementById('circStrings').getString('staff.circ.in_house_use.no_external') + '\n');
321                         }
322
323                 } catch(E) {
324                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.in_house_use.failed'), E);
325                         if (typeof obj.on_failure == 'function') {
326                                 obj.on_failure(E);
327                         }
328                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
329                                 obj.error.sdump('D_CIRC', + document.getElementById('circStrings').getString('staff.circ.in_house_use.on_failure.external') + '\n');
330                                 window.xulG.on_failure(E);
331                         } else {
332                                 obj.error.sdump('D_CIRC', + document.getElementById('circStrings').getString('staff.circ.in_house_use.on_failure.external') + '\n');
333                         }
334                 }
335
336         },
337
338         'on_in_house_use' : function() {
339                 this.controller.view.in_house_use_multiplier_textbox.select();
340                 this.controller.view.in_house_use_multiplier_textbox.value = '1';
341                 this.controller.view.in_house_use_barcode_entry_textbox.value = '';
342                 this.controller.view.in_house_use_barcode_entry_textbox.focus();
343         },
344
345         'on_failure' : function() {
346                 this.controller.view.in_house_use_barcode_entry_textbox.select();
347                 this.controller.view.in_house_use_barcode_entry_textbox.focus();
348         }
349 }
350
351 dump('exiting circ.in_house_use.js\n');