1 dump('entering cat.copy_browser.js\n');
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_browser = function (params) {
6 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
7 JSAN.use('util.error'); this.error = new util.error();
10 dump('cat.copy_browser: ' + E + '\n');
14 cat.copy_browser.prototype = {
20 'init' : function( params ) {
23 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
26 JSAN.use('util.network'); obj.network = new util.network();
27 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
28 JSAN.use('util.controller'); obj.controller = new util.controller();
34 function() { alert('Not Yet Implemented'); }
36 'cmd_show_my_libs' : [
42 'cmd_show_all_libs' : [
48 'cmd_show_libs_with_copies' : [
51 obj.show_libs_with_copies();
65 obj.list_init(params);
67 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
72 this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
76 'show_my_libs' : function() {
79 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
82 var p_org = obj.data.hash.aou[ org.parent_ou() ];
84 JSAN.use('util.exec'); var exec = new util.exec();
86 for (var i = 0; i < p_org.children().length; i++) {
92 }( p_org.children()[i] )
102 'show_all_libs' : function() {
105 obj.show_libs( obj.data.tree.aou );
107 JSAN.use('util.exec'); var exec = new util.exec();
109 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
115 }( obj.data.tree.aou.children()[i] )
124 'show_libs_with_copies' : function() {
127 JSAN.use('util.exec'); var exec = new util.exec();
128 JSAN.use('util.functional');
130 var orgs = util.functional.map_list(
132 function(id) { return obj.data.hash.aou[id]; }
135 if (a.shortname() < b.shortname()) return -1;
136 if (a.shortname() > b.shortname()) return 1;
141 for (var i = 0; i < orgs.length; i++) {
156 'show_libs' : function(start_aou) {
159 if (!start_aou) throw('show_libs: Need a start_aou');
160 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
161 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
166 var temp_aou = start_aou;
167 while ( temp_aou.parent_ou() ) {
168 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
169 parents.push( temp_aou );
173 for (var i = 0; i < parents.length; i++) {
177 obj.append_org(o,p,{'container':'true'});
179 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
185 return function() { obj.append_org(o,p); };
186 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
191 if (start_aou.children()) {
192 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
193 x.setAttribute('container','true');
194 //x.setAttribute('open','true');
195 for (var i = 0; i < start_aou.children().length; i++) {
198 return function() { obj.append_org(o,p); };
199 }( start_aou.children()[i], start_aou )
213 'on_select' : function(list) {
215 for (var i = 0; i < list.length; i++) {
216 var node = obj.map_tree[ list[i] ];
217 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
218 var row_type = list[i].split('_')[0];
219 var id = list[i].split('_')[1];
221 case 'aou' : obj.on_select_org(id); break;
222 case 'acn' : obj.on_select_acn(id); break;
228 'on_select_acn' : function(acn_id) {
231 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
233 if (acn_tree.copies()) {
234 for (var i = 0; i < acn_tree.copies().length; i++) {
240 }( acn_tree.copies()[i], acn_tree )
244 JSAN.use('util.exec'); var exec = new util.exec();
251 'on_select_org' : function(org_id) {
253 var org = obj.data.hash.aou[ org_id ];
255 if (org.children()) {
256 for (var i = 0; i < org.children().length; i++) {
262 }(org.children()[i],org)
266 if (obj.map_acn[ 'aou_' + org_id ]) {
267 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
273 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
277 JSAN.use('util.exec'); var exec = new util.exec();
281 'append_org' : function (org,parent_org,params) {
284 if (obj.map_tree[ 'aou_' + org.id() ]) {
285 var x = obj.map_tree[ 'aou_' + org.id() ];
287 for (var i in params) {
288 x.setAttribute(i,params[i]);
300 'retrieve_id' : 'aou_' + org.id(),
304 if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
305 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
306 data.row.my.volume_count = '0';
307 data.row.my.copy_count = '<0>';
309 data.row.my.volume_count = '';
310 data.row.my.copy_count = '';
313 var v_count = 0; var c_count = 0;
314 acn_tree_list = obj.network.simple_request(
315 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
316 [ obj.data.session, obj.docid, [ org.id() ] ]
318 for (var i = 0; i < acn_tree_list.length; i++) {
320 if (acn_tree_list[i].copies()) c_count += acn_tree_list[i].copies().length;
322 data.row.my.volume_count = v_count;
323 data.row.my.copy_count = '<' + c_count + '>';
326 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
329 var node = obj.list.append(data);
331 for (var i in params) {
332 node.setAttribute(i,params[i]);
335 obj.map_tree[ 'aou_' + org.id() ] = node;
337 if (org.children()) {
338 node.setAttribute('container','true');
342 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
343 data.node.setAttribute('open','true');
346 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
350 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
351 node.setAttribute('container','true');
360 'append_acn' : function( org, acn_tree, params ) {
363 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
364 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
366 for (var i in params) {
367 x.setAttribute(i,params[i]);
373 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
380 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
383 'retrieve_id' : 'acn_' + acn_tree.id(),
384 'node' : parent_node,
386 var node = obj.list.append(data);
387 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
389 for (var i in params) {
390 node.setAttribute(i,params[i]);
393 if (acn_tree.copies()) {
394 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
395 node.setAttribute('container','true');
404 'append_acp' : function( acp_item, acn_tree, params ) {
407 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
408 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
410 for (var i in params) {
411 x.setAttribute(i,params[i]);
417 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
421 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
428 'retrieve_id' : 'acp_' + acp_item.id(),
429 'node' : parent_node,
431 var node = obj.list.append(data);
432 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
434 for (var i in params) {
435 node.setAttribute(i,params[i]);
445 'list_init' : function( params ) {
448 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
451 JSAN.use('circ.util');
454 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
455 'primary' : true, 'hidden' : false,
456 'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.name() : "???"'
459 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
460 'primary' : false, 'hidden' : false,
461 'render' : 'my.volume_count'
464 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
465 'primary' : false, 'hidden' : false,
466 'render' : 'my.copy_count'
471 'location' : { 'hidden' : false },
472 'circ_lib' : { 'hidden' : false },
473 'owning_lib' : { 'hidden' : false },
474 'call_number' : { 'hidden' : false },
475 'barcode' : { 'hidden' : false },
480 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
484 'map_row_to_column' : circ.util.std_map_row_to_column(' '),
485 'retrieve_row' : function(params) {
487 var row = params.row;
491 if (!row.my.mvr) funcs.push(
494 row.my.mvr = obj.network.request(
495 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
496 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
497 [ row.my.circ.target_copy() ]
506 row.my.acp = obj.network.request(
507 api.FM_ACP_RETRIEVE.app,
508 api.FM_ACP_RETRIEVE.method,
509 [ row.my.circ.target_copy() ]
512 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
517 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
523 if (typeof params.on_retrieve == 'function') {
524 params.on_retrieve(row);
530 JSAN.use('util.exec'); var exec = new util.exec();
531 exec.on_error = function(E) {
532 //var err = 'items chain: ' + js2JSON(E);
533 //obj.error.sdump('D_ERROR',err);
534 return true; /* keep going */
540 'on_click' : function(ev) {
541 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
542 var row = {}; var col = {}; var nobj = {};
543 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
544 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
545 var node = obj.list.node.contentView.getItemAtIndex(row.value);
546 var list = [ node.getAttribute('retrieve_id') ];
547 if (typeof obj.on_select == 'function') {
550 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
551 window.xulG.on_select(list);
554 'on_select' : function(ev) {
555 JSAN.use('util.functional');
556 var sel = obj.list.retrieve_selection();
557 var list = util.functional.map_list(
559 function(o) { return o.getAttribute('retrieve_id'); }
561 if (typeof obj.on_select == 'function') {
564 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
565 window.xulG.on_select(list);
573 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
578 dump('exiting cat.copy_browser.js\n');