]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
call number sort and accesskey
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / volume_copy_creator.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Copy Viewer/Editor -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
10
11 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!-- LOCALIZATION -->
13 <!DOCTYPE window PUBLIC "" ""[
14         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
15 ]>
16
17 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
18 <!-- OVERLAYS -->
19 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
20
21 <window id="cat_volume_copy_creator_win" 
22         onload="try { my_init(); } catch(E) { alert(E); }"
23         width="800" height="600"
24         title="Volume/Copy Editor"
25         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
26
27         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
28         <!-- BEHAVIOR -->
29         <script type="text/javascript">
30                 var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
31         </script>
32         <scripts id="openils_util_scripts"/>
33
34         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
35         <script>
36         <![CDATA[
37
38                 function my_init() {
39                         try {
40                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
41                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
42                                 JSAN.errorLevel = "die"; // none, warn, or die
43                                 JSAN.addRepository('/xul/server/');
44                                 JSAN.use('util.error'); g.error = new util.error();
45                                 g.error.sdump('D_TRACE','my_init() for cat/volume_copy_creator.xul');
46
47                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
48                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
49
50                                 g.cgi = new CGI();
51
52                                 g.session = g.cgi.param('session') || g.cgi.param('ses');
53                                 g.doc_id = g.cgi.param('doc_id');
54                                 g.copy_shortcut = g.cgi.param('copy_shortcut');
55                                 g.error.sdump('D_ERROR','location.href = ' + location.href + '\n\ncopy_short cut = ' + g.copy_shortcut + '\n\nou_ids = ' + g.cgi.param('ou_ids'));
56                                 if (g.copy_shortcut) g.copy_shortcut = JSON2js( g.copy_shortcut );
57
58                                 var ou_ids = [];
59                                 if (g.cgi.param('ou_ids')) 
60                                         ou_ids = JSON2js( g.cgi.param('ou_ids') );
61                                 if (!ou_ids) ou_ids = [];
62                                 if (window.xulG && window.xulG.ou_ids) 
63                                         ou_ids = ou_ids.concat( window.xulG.ou_ids );
64
65                                 JSAN.use('util.network'); g.network = new util.network();
66
67                                 var cn_blob;
68                                 try {
69                                         cn_blob = g.network.simple_request('BLOB_MARC_CALLNUMBERS_RETRIEVE',[g.doc_id]);
70                                 } catch(E) {
71                                         cn_blob = [];
72                                 }
73                                 if (cn_blob.length > 0) {
74                                         var hbox = document.getElementById('marc_cn');
75                                         var ml = util.widgets.make_menulist(
76                                                 util.functional.map_list(
77                                                         cn_blob,
78                                                         function(o) {
79                                                                 for (var i in o) {
80                                                                         return [ i + ' -> ' + o[i], o[i] ];
81                                                                 }
82                                                         }
83                                                 ).sort(
84                                                         function(b,a) {
85                                                                 if (a == 88 && b == 92) return -1;
86                                                                 if (a == 92 && b == 88) return 1;
87                                                                 if (a == 88) return -1;
88                                                                 if (a == 92) return -1;
89                                                                 if (a < b) return -1;
90                                                                 if (a > b) return 1;
91                                                                 return 0;
92                                                         }
93                                                 )
94                                         ); hbox.appendChild(ml);
95                                         var btn = document.createElement('button');
96                                         btn.setAttribute('label','Apply');
97                                         btn.setAttribute('accesskey','A');
98                                         btn.setAttribute('image','/xul/server/skin/media/images/down_arrow.gif');
99                                         hbox.appendChild(btn);
100                                         btn.addEventListener(
101                                                 'command',
102                                                 function() {
103                                                         var nl = document.getElementsByTagName('textbox');
104                                                         for (var i = 0; i < nl.length; i++) {
105                                                                 if (nl[i].getAttribute('rel_vert_pos')==2 
106                                                                         && !nl[i].disabled) nl[i].value = ml.value;
107                                                         }
108                                                 }, 
109                                                 false
110                                         );
111                                 }
112
113                                 var rows = document.getElementById('rows');
114
115                                 var node_id = 0;
116                                 for (var i = 0; i < ou_ids.length; i++) {
117                                         try {
118                                                 var row = document.createElement('row'); rows.appendChild(row); row.setAttribute('ou_id',ou_ids[i]);
119                                                 g.render_library_label(row,ou_ids[i]);
120                                                 g.render_volume_count_entry(row,ou_ids[i]);
121                                         } catch(E) {
122                                                 g.error.sdump('D_ERROR',E);
123                                         }
124                                 }
125
126                         } catch(E) {
127                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
128                                         "system administrator or software developer the following:\ncat/volume_copy_creator.xul\n" +E+ '\n';
129                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
130                                 alert(err_msg);
131                         }
132                 }
133
134                 g.render_library_label = function(row,ou_id) {
135                         var label = document.createElement('label'); row.appendChild(label);
136                         label.setAttribute('ou_id',ou_id);
137                         label.setAttribute('value',g.data.hash.aou[ ou_id ].shortname());
138                 }
139
140                 g.render_volume_count_entry = function(row,ou_id) {
141                         var hb = document.createElement('vbox'); row.appendChild(hb);
142                         var tb = document.createElement('textbox'); hb.appendChild(tb);
143                         tb.setAttribute('ou_id',ou_id); tb.setAttribute('size','3'); tb.setAttribute('cols','3');
144                         tb.setAttribute('rel_vert_pos','1'); 
145                         function render_copy_count_entry(ev) {
146                                 if (ev.target.disabled) return;
147                                 if (! isNaN( parseInt( ev.target.value) ) ) {
148                                         ev.target.disabled = true;
149                                         g.render_callnumber_copy_count_entry(row,ou_id,ev.target.value);
150                                 }
151                         }
152                         util.widgets.apply_vertical_tab_on_enter_handler( tb, render_copy_count_entry);
153                         tb.addEventListener( 'change', render_copy_count_entry, false);
154                         setTimeout(
155                                 function() {
156                                         try {
157                                         if (g.copy_shortcut) {
158                                                 JSAN.use('util.functional');
159                                                 tb.value = util.functional.map_object_to_list(
160                                                         g.copy_shortcut[ou_id],
161                                                         function(o,i) {
162                                                                 return g.copy_shortcut[ou_id][i];
163                                                         }
164                                                 ).length
165                                                 render_copy_count_entry({'target':tb});
166                                         }
167                                         } catch(E) {
168                                                 alert(E);
169                                         }
170                                 }, 0
171                         );
172                 }
173
174                 g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
175                         var grid = util.widgets.make_grid( [ {}, {} ] ); row.appendChild(grid);
176                         grid.setAttribute('flex','1');
177                         grid.setAttribute('ou_id',ou_id);
178                         var rows = grid.lastChild;
179                         var r = document.createElement('row'); rows.appendChild( r );
180                         var x = document.createElement('label'); r.appendChild(x);
181                         x.setAttribute('value','Call Numbers'); x.setAttribute('style','font-weight: bold');
182                         x = document.createElement('label'); r.appendChild(x);
183                         x.setAttribute('value','# of Copies'); x.setAttribute('style','font-weight: bold');
184
185                         function handle_change(tb1,tb2,hb3) {
186                                 if (tb1.value == '') return;
187                                 if (isNaN( parseInt( tb2.value ) )) return;
188
189                                 if (tb1.disabled || tb2.disabled) return;
190
191                                 tb1.disabled = true;
192                                 tb2.disabled = true;
193
194                                 g.render_barcode_entry(hb3,tb1.value,parseInt(tb2.value),ou_id);
195                         }
196
197                         function handle_change_tb1(ev) {
198                                 var _tb1 = ev.target;   
199                                 var _hb1 = _tb1.parentNode;
200                                 var _hb2 = _hb1.nextSibling;
201                                 var _tb2 = _hb2.firstChild;
202                                 var _hb3 = _hb2.nextSibling;
203                                 handle_change(_tb1,_tb2,_hb3);
204                         }
205
206                         function handle_change_tb2(ev) {
207                                 var _tb2 = ev.target;   
208                                 var _hb2 = _tb2.parentNode;
209                                 var _hb1 = _hb2.previousSibling;
210                                 var _tb1 = _hb1.firstChild;
211                                 var _hb3 = _hb2.nextSibling;
212                                 handle_change(_tb1,_tb2,_hb3);
213                         }
214
215                         for (var i = 0; i < count; i++) {
216                                 var r = document.createElement('row'); rows.appendChild(r);
217                                 var hb1 = document.createElement('vbox'); r.appendChild(hb1);
218                                 var hb2 = document.createElement('vbox'); r.appendChild(hb2);
219                                 var hb3 = document.createElement('vbox'); r.appendChild(hb3);
220                                 var tb1 = document.createElement('textbox'); hb1.appendChild(tb1);
221                                 tb1.setAttribute('rel_vert_pos','2');
222                                 util.widgets.apply_vertical_tab_on_enter_handler( tb1, handle_change_tb1);
223                                 var tb2 = document.createElement('textbox'); hb2.appendChild(tb2);
224                                 tb2.setAttribute('size','3'); tb2.setAttribute('cols','3');
225                                 tb2.setAttribute('rel_vert_pos','3');
226                                 util.widgets.apply_vertical_tab_on_enter_handler( tb2, handle_change_tb2);
227
228                                 tb1.addEventListener( 'change', handle_change_tb1, false);
229                                 tb2.addEventListener( 'change', handle_change_tb2, false);
230
231                                 setTimeout(
232                                         function(idx,tb){
233                                                 return function() {
234                                                         try {
235                                                         JSAN.use('util.functional');
236                                                         if (g.copy_shortcut) {
237                                                                 var label = util.functional.map_object_to_list(
238                                                                         g.copy_shortcut[ou_id],
239                                                                         function(o,i) {
240                                                                                 return i;
241                                                                         }
242                                                                 )[idx];
243                                                                 tb.value = label; handle_change_tb1({'target':tb});
244                                                         }
245                                                         } catch(E) {
246                                                                 alert(E);
247                                                         }
248                                                 }
249                                         }(i,tb1),0
250                                 );
251                         }
252                 }
253
254                 g.render_barcode_entry = function(node,callnumber,count,ou_id) {
255                         try {
256                                 function ready_to_create(ev) {
257                                         document.getElementById("Create").disabled = false;
258                                 }
259
260                                 for (var i = 0; i < count; i++) {
261                                         var tb = document.createElement('textbox'); node.appendChild(tb);
262                                         tb.setAttribute('ou_id',ou_id);
263                                         tb.setAttribute('callnumber',callnumber);
264                                         tb.setAttribute('rel_vert_pos','4');
265                                         util.widgets.apply_vertical_tab_on_enter_handler( tb, ready_to_create);
266                                         tb.addEventListener('change',ready_to_create,false);
267                                 }
268                         } catch(E) {
269                                 g.error.sdump('D_ERROR','g.render_barcode_entry: ' + E);
270                         }
271                 }
272
273                 g.new_node_id = -1;
274
275                 g.stash_and_close = function() {
276
277                         try {
278
279                                 var nl = document.getElementsByTagName('textbox');
280
281                                 var volumes_hash = {};
282
283                                 var barcodes = [];
284                                 
285                                 for (var i = 0; i < nl.length; i++) {
286                                         if ( nl[i].getAttribute('rel_vert_pos') == 4 ) barcodes.push( nl[i] );
287                                 };
288                         
289                                 for (var i = 0; i < barcodes.length; i++) {
290                                         var ou_id = barcodes[i].getAttribute('ou_id');
291                                         var callnumber = barcodes[i].getAttribute('callnumber');
292                                         var barcode = barcodes[i].value;
293
294                                         if (typeof volumes_hash[ou_id] == 'undefined') { volumes_hash[ou_id] = {} }
295                                         if (typeof volumes_hash[ou_id][callnumber] == 'undefined') { volumes_hash[ou_id][callnumber] = [] }
296
297                                         volumes_hash[ou_id][callnumber].push( barcode );
298                                 }
299
300                                 var volumes = [];
301                                 var copies = [];
302                                 var volume_labels = {};
303
304                                 for (var ou_id in volumes_hash) {
305                                         for (var cn in volumes_hash[ou_id]) {
306                                                 var volume = new acn();
307                                                 var acn_id;
308                                                 if (!g.copy_shortcut) {
309                                                         acn_id = g.new_node_id--;
310                                                         volume.isnew('1');
311                                                 } else {
312                                                         acn_id = g.copy_shortcut[ou_id][cn];
313                                                 }
314                                                 volume.id( acn_id );
315                                                 volume.record(g.doc_id);
316                                                 volume.label(cn);
317                                                 volume.owning_lib(ou_id);
318                                                 volume.copies( [] );
319                                                 volumes.push( volume );
320
321                                                 volume_labels[ acn_id ] = cn;
322
323                                                 for (var i = 0; i < volumes_hash[ou_id][cn].length; i++) {
324                                                         var copy = new acp();
325                                                         copy.id( g.new_node_id-- );
326                                                         copy.isnew('1');
327                                                         copy.barcode( volumes_hash[ou_id][cn][i] );
328                                                         copy.call_number( acn_id );
329                                                         copy.circ_lib(ou_id);
330                                                         /* FIXME -- use constants */
331                                                         copy.deposit(0);
332                                                         copy.fine_level(2);
333                                                         copy.loan_duration(2);
334                                                         copy.location(1);
335                                                         copy.status(0);
336                                                         copies.push( copy );
337                                                 }
338                                         }
339                                 }
340
341                                 JSAN.use('util.window'); var win = new util.window();
342                                 var w = win.open(
343                                         urls.XUL_COPY_EDITOR
344                                                 +'?session='+window.escape(g.session)
345                                                 +'&copies='+window.escape(js2JSON(copies))
346                                                 +'&callnumbers='+window.escape(js2JSON(volume_labels))
347                                                 +'&edit=1',
348                                         title,
349                                         'chrome,modal,resizable'
350                                 );
351                                 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
352                                 g.data.stash_retrieve();
353                                 copies = JSON2js( g.data.temp );
354
355                                 for (var i = 0; i < copies.length; i++) {
356                                         var copy = copies[i];
357                                         var volume = util.functional.find_id_object_in_list( volumes, copy.call_number() );
358                                         var temp = volume.copies();
359                                         temp.push( copy );
360                                         volume.copies( temp );
361                                 }
362
363                                 try {
364                                         var r = g.network.request(
365                                                 api.FM_ACN_TREE_UPDATE.app,
366                                                 api.FM_ACN_TREE_UPDATE.method,
367                                                 [ g.session, volumes ]
368                                         );
369                                         /* FIXME -- revisit the return value here */
370                                 } catch(E) {
371                                         alert('volume update error: ' + js2JSON(E));
372                                 }
373
374                                 window.close();
375
376                         } catch(E) {
377                                 alert(E);
378                         }
379                 }
380
381         ]]>
382         </script>
383
384         <groupbox flex="1" style="overflow: auto">
385                 <caption id="caption" label="Volume/Copy Creator"/>
386                 <hbox style="border-bottom: solid black thin">
387                         <hbox id="marc_cn"/>
388                         <spacer flex="1" />
389                         <button id="Create" accesskey="C" label="Create" disabled="true" oncommand="g.stash_and_close();"/>
390                 </hbox>
391                 <grid flex="1">
392                         <columns> <column flex="0"/> <column flex="0"/> <column flex="1"/> </columns>
393                         <rows id="rows">
394                                 <row>
395                                         <label value="Library" style="font-weight: bold"/>
396                                         <label value="# of volumes" style="font-weight: bold"/>
397                                 </row>
398                         </rows>
399                 </grid>
400         </groupbox>
401
402 </window>
403