]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
new way of handling entities for remote xul
[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                                                 )
84                                         ); hbox.appendChild(ml);
85                                         var btn = document.createElement('button');
86                                         btn.setAttribute('label','Apply');
87                                         btn.setAttribute('accesskey','A');
88                                         btn.setAttribute('image','/xul/server/skin/media/images/down_arrow.gif');
89                                         hbox.appendChild(btn);
90                                         btn.addEventListener(
91                                                 'command',
92                                                 function() {
93                                                         var nl = document.getElementsByTagName('textbox');
94                                                         for (var i = 0; i < nl.length; i++) {
95                                                                 if (nl[i].getAttribute('rel_vert_pos')==2 
96                                                                         && !nl[i].disabled) nl[i].value = ml.value;
97                                                         }
98                                                 }, 
99                                                 false
100                                         );
101                                 }
102
103                                 var rows = document.getElementById('rows');
104
105                                 var node_id = 0;
106                                 for (var i = 0; i < ou_ids.length; i++) {
107                                         try {
108                                                 var row = document.createElement('row'); rows.appendChild(row); row.setAttribute('ou_id',ou_ids[i]);
109                                                 g.render_library_label(row,ou_ids[i]);
110                                                 g.render_volume_count_entry(row,ou_ids[i]);
111                                         } catch(E) {
112                                                 g.error.sdump('D_ERROR',E);
113                                         }
114                                 }
115
116                         } catch(E) {
117                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
118                                         "system administrator or software developer the following:\ncat/volume_copy_creator.xul\n" +E+ '\n';
119                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
120                                 alert(err_msg);
121                         }
122                 }
123
124                 g.render_library_label = function(row,ou_id) {
125                         var label = document.createElement('label'); row.appendChild(label);
126                         label.setAttribute('ou_id',ou_id);
127                         label.setAttribute('value',g.data.hash.aou[ ou_id ].shortname());
128                 }
129
130                 g.render_volume_count_entry = function(row,ou_id) {
131                         var hb = document.createElement('vbox'); row.appendChild(hb);
132                         var tb = document.createElement('textbox'); hb.appendChild(tb);
133                         tb.setAttribute('ou_id',ou_id); tb.setAttribute('size','3'); tb.setAttribute('cols','3');
134                         tb.setAttribute('rel_vert_pos','1'); 
135                         function render_copy_count_entry(ev) {
136                                 if (ev.target.disabled) return;
137                                 if (! isNaN( parseInt( ev.target.value) ) ) {
138                                         ev.target.disabled = true;
139                                         g.render_callnumber_copy_count_entry(row,ou_id,ev.target.value);
140                                 }
141                         }
142                         util.widgets.apply_vertical_tab_on_enter_handler( tb, render_copy_count_entry);
143                         tb.addEventListener( 'change', render_copy_count_entry, false);
144                         setTimeout(
145                                 function() {
146                                         try {
147                                         if (g.copy_shortcut) {
148                                                 JSAN.use('util.functional');
149                                                 tb.value = util.functional.map_object_to_list(
150                                                         g.copy_shortcut[ou_id],
151                                                         function(o,i) {
152                                                                 return g.copy_shortcut[ou_id][i];
153                                                         }
154                                                 ).length
155                                                 render_copy_count_entry({'target':tb});
156                                         }
157                                         } catch(E) {
158                                                 alert(E);
159                                         }
160                                 }, 0
161                         );
162                 }
163
164                 g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
165                         var grid = util.widgets.make_grid( [ {}, {} ] ); row.appendChild(grid);
166                         grid.setAttribute('flex','1');
167                         grid.setAttribute('ou_id',ou_id);
168                         var rows = grid.lastChild;
169                         var r = document.createElement('row'); rows.appendChild( r );
170                         var x = document.createElement('label'); r.appendChild(x);
171                         x.setAttribute('value','Call Numbers'); x.setAttribute('style','font-weight: bold');
172                         x = document.createElement('label'); r.appendChild(x);
173                         x.setAttribute('value','# of Copies'); x.setAttribute('style','font-weight: bold');
174
175                         function handle_change(tb1,tb2,hb3) {
176                                 if (tb1.value == '') return;
177                                 if (isNaN( parseInt( tb2.value ) )) return;
178
179                                 if (tb1.disabled || tb2.disabled) return;
180
181                                 tb1.disabled = true;
182                                 tb2.disabled = true;
183
184                                 g.render_barcode_entry(hb3,tb1.value,parseInt(tb2.value),ou_id);
185                         }
186
187                         function handle_change_tb1(ev) {
188                                 var _tb1 = ev.target;   
189                                 var _hb1 = _tb1.parentNode;
190                                 var _hb2 = _hb1.nextSibling;
191                                 var _tb2 = _hb2.firstChild;
192                                 var _hb3 = _hb2.nextSibling;
193                                 handle_change(_tb1,_tb2,_hb3);
194                         }
195
196                         function handle_change_tb2(ev) {
197                                 var _tb2 = ev.target;   
198                                 var _hb2 = _tb2.parentNode;
199                                 var _hb1 = _hb2.previousSibling;
200                                 var _tb1 = _hb1.firstChild;
201                                 var _hb3 = _hb2.nextSibling;
202                                 handle_change(_tb1,_tb2,_hb3);
203                         }
204
205                         for (var i = 0; i < count; i++) {
206                                 var r = document.createElement('row'); rows.appendChild(r);
207                                 var hb1 = document.createElement('vbox'); r.appendChild(hb1);
208                                 var hb2 = document.createElement('vbox'); r.appendChild(hb2);
209                                 var hb3 = document.createElement('vbox'); r.appendChild(hb3);
210                                 var tb1 = document.createElement('textbox'); hb1.appendChild(tb1);
211                                 tb1.setAttribute('rel_vert_pos','2');
212                                 util.widgets.apply_vertical_tab_on_enter_handler( tb1, handle_change_tb1);
213                                 var tb2 = document.createElement('textbox'); hb2.appendChild(tb2);
214                                 tb2.setAttribute('size','3'); tb2.setAttribute('cols','3');
215                                 tb2.setAttribute('rel_vert_pos','3');
216                                 util.widgets.apply_vertical_tab_on_enter_handler( tb2, handle_change_tb2);
217
218                                 tb1.addEventListener( 'change', handle_change_tb1, false);
219                                 tb2.addEventListener( 'change', handle_change_tb2, false);
220
221                                 setTimeout(
222                                         function(idx,tb){
223                                                 return function() {
224                                                         try {
225                                                         JSAN.use('util.functional');
226                                                         if (g.copy_shortcut) {
227                                                                 var label = util.functional.map_object_to_list(
228                                                                         g.copy_shortcut[ou_id],
229                                                                         function(o,i) {
230                                                                                 return i;
231                                                                         }
232                                                                 )[idx];
233                                                                 tb.value = label; handle_change_tb1({'target':tb});
234                                                         }
235                                                         } catch(E) {
236                                                                 alert(E);
237                                                         }
238                                                 }
239                                         }(i,tb1),0
240                                 );
241                         }
242                 }
243
244                 g.render_barcode_entry = function(node,callnumber,count,ou_id) {
245                         try {
246                                 function ready_to_create(ev) {
247                                         document.getElementById("Create").disabled = false;
248                                 }
249
250                                 for (var i = 0; i < count; i++) {
251                                         var tb = document.createElement('textbox'); node.appendChild(tb);
252                                         tb.setAttribute('ou_id',ou_id);
253                                         tb.setAttribute('callnumber',callnumber);
254                                         tb.setAttribute('rel_vert_pos','4');
255                                         util.widgets.apply_vertical_tab_on_enter_handler( tb, ready_to_create);
256                                         tb.addEventListener('change',ready_to_create,false);
257                                 }
258                         } catch(E) {
259                                 g.error.sdump('D_ERROR','g.render_barcode_entry: ' + E);
260                         }
261                 }
262
263                 g.new_node_id = -1;
264
265                 g.stash_and_close = function() {
266
267                         try {
268
269                                 var nl = document.getElementsByTagName('textbox');
270
271                                 var volumes_hash = {};
272
273                                 var barcodes = [];
274                                 
275                                 for (var i = 0; i < nl.length; i++) {
276                                         if ( nl[i].getAttribute('rel_vert_pos') == 4 ) barcodes.push( nl[i] );
277                                 };
278                         
279                                 for (var i = 0; i < barcodes.length; i++) {
280                                         var ou_id = barcodes[i].getAttribute('ou_id');
281                                         var callnumber = barcodes[i].getAttribute('callnumber');
282                                         var barcode = barcodes[i].value;
283
284                                         if (typeof volumes_hash[ou_id] == 'undefined') { volumes_hash[ou_id] = {} }
285                                         if (typeof volumes_hash[ou_id][callnumber] == 'undefined') { volumes_hash[ou_id][callnumber] = [] }
286
287                                         volumes_hash[ou_id][callnumber].push( barcode );
288                                 }
289
290                                 var volumes = [];
291                                 var copies = [];
292                                 var volume_labels = {};
293
294                                 for (var ou_id in volumes_hash) {
295                                         for (var cn in volumes_hash[ou_id]) {
296                                                 var volume = new acn();
297                                                 var acn_id;
298                                                 if (!g.copy_shortcut) {
299                                                         acn_id = g.new_node_id--;
300                                                         volume.isnew('1');
301                                                 } else {
302                                                         acn_id = g.copy_shortcut[ou_id][cn];
303                                                 }
304                                                 volume.id( acn_id );
305                                                 volume.record(g.doc_id);
306                                                 volume.label(cn);
307                                                 volume.owning_lib(ou_id);
308                                                 volume.copies( [] );
309                                                 volumes.push( volume );
310
311                                                 volume_labels[ acn_id ] = cn;
312
313                                                 for (var i = 0; i < volumes_hash[ou_id][cn].length; i++) {
314                                                         var copy = new acp();
315                                                         copy.id( g.new_node_id-- );
316                                                         copy.isnew('1');
317                                                         copy.barcode( volumes_hash[ou_id][cn][i] );
318                                                         copy.call_number( acn_id );
319                                                         copy.circ_lib(ou_id);
320                                                         /* FIXME -- use constants */
321                                                         copy.deposit(0);
322                                                         copy.fine_level(2);
323                                                         copy.loan_duration(2);
324                                                         copy.location(1);
325                                                         copy.status(0);
326                                                         copies.push( copy );
327                                                 }
328                                         }
329                                 }
330
331                                 JSAN.use('util.window'); var win = new util.window();
332                                 var w = win.open(
333                                         urls.XUL_COPY_EDITOR
334                                                 +'?session='+window.escape(g.session)
335                                                 +'&copies='+window.escape(js2JSON(copies))
336                                                 +'&callnumbers='+window.escape(js2JSON(volume_labels))
337                                                 +'&edit=1',
338                                         title,
339                                         'chrome,modal,resizable'
340                                 );
341                                 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
342                                 g.data.stash_retrieve();
343                                 copies = JSON2js( g.data.temp );
344
345                                 for (var i = 0; i < copies.length; i++) {
346                                         var copy = copies[i];
347                                         var volume = util.functional.find_id_object_in_list( volumes, copy.call_number() );
348                                         var temp = volume.copies();
349                                         temp.push( copy );
350                                         volume.copies( temp );
351                                 }
352
353                                 try {
354                                         var r = g.network.request(
355                                                 api.FM_ACN_TREE_UPDATE.app,
356                                                 api.FM_ACN_TREE_UPDATE.method,
357                                                 [ g.session, volumes ]
358                                         );
359                                         /* FIXME -- revisit the return value here */
360                                 } catch(E) {
361                                         alert('volume update error: ' + js2JSON(E));
362                                 }
363
364                                 window.close();
365
366                         } catch(E) {
367                                 alert(E);
368                         }
369                 }
370
371         ]]>
372         </script>
373
374         <groupbox flex="1" style="overflow: auto">
375                 <caption id="caption" label="Volume/Copy Creator"/>
376                 <hbox style="border-bottom: solid black thin">
377                         <hbox id="marc_cn"/>
378                         <spacer flex="1" />
379                         <button id="Create" label="Create" disabled="true" oncommand="g.stash_and_close();"/>
380                 </hbox>
381                 <grid flex="1">
382                         <columns> <column flex="0"/> <column flex="0"/> <column flex="1"/> </columns>
383                         <rows id="rows">
384                                 <row>
385                                         <label value="Library" style="font-weight: bold"/>
386                                         <label value="# of volumes" style="font-weight: bold"/>
387                                 </row>
388                         </rows>
389                 </grid>
390         </groupbox>
391
392 </window>
393