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