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();
9 dump('cat.copy_browser: ' + E + '\n');
13 cat.copy_browser.prototype = {
19 'init' : function( params ) {
22 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
25 obj.docid = params.docid;
27 JSAN.use('util.network'); obj.network = new util.network();
28 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
29 JSAN.use('util.controller'); obj.controller = new util.controller();
35 function() { alert('Not Yet Implemented'); }
37 'cmd_show_my_libs' : [
43 'cmd_show_all_libs' : [
49 'cmd_show_libs_with_copies' : [
52 obj.show_libs_with_copies();
66 obj.list_init(params);
68 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
70 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
74 this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
78 'show_my_libs' : function() {
81 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
82 obj.show_libs( org, true );
84 var p_org = obj.data.hash.aou[ org.parent_ou() ];
86 JSAN.use('util.exec'); var exec = new util.exec();
88 for (var i = 0; i < p_org.children().length; i++) {
92 obj.show_libs( o, true );
94 }( p_org.children()[i] )
104 'show_all_libs' : function() {
109 obj.show_libs( obj.data.tree.aou );
111 JSAN.use('util.exec'); var exec = new util.exec();
113 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
119 }( obj.data.tree.aou.children()[i] )
128 'show_libs_with_copies' : function() {
131 JSAN.use('util.exec'); var exec = new util.exec();
132 JSAN.use('util.functional');
134 var orgs = util.functional.map_list(
136 function(id) { return obj.data.hash.aou[id]; }
139 if (a.shortname() < b.shortname()) return -1;
140 if (a.shortname() > b.shortname()) return 1;
145 for (var i = 0; i < orgs.length; i++) {
149 obj.show_libs(o,true);
160 'show_libs' : function(start_aou,show_open) {
163 if (!start_aou) throw('show_libs: Need a start_aou');
164 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
165 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
170 var temp_aou = start_aou;
171 while ( temp_aou.parent_ou() ) {
172 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
173 parents.push( temp_aou );
177 for (var i = 0; i < parents.length; i++) {
182 obj.append_org(o,p,{'container':'true','open':'true'});
184 obj.append_org(o,p,{'container':'true'});
187 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
193 return function() { obj.append_org(o,p); };
194 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
199 if (start_aou.children()) {
200 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
201 x.setAttribute('container','true');
202 if (show_open) x.setAttribute('open','true');
203 for (var i = 0; i < start_aou.children().length; i++) {
206 return function() { obj.append_org(o,p); };
207 }( start_aou.children()[i], start_aou )
221 'on_select' : function(list,twisty) {
223 for (var i = 0; i < list.length; i++) {
224 var node = obj.map_tree[ list[i] ];
225 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
226 var row_type = list[i].split('_')[0];
227 var id = list[i].split('_')[1];
229 case 'aou' : obj.on_select_org(id,twisty); break;
230 case 'acn' : obj.on_select_acn(id,twisty); break;
236 'on_select_acn' : function(acn_id,twisty) {
239 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
241 if (acn_tree.copies()) {
242 for (var i = 0; i < acn_tree.copies().length; i++) {
248 }( acn_tree.copies()[i], acn_tree )
252 JSAN.use('util.exec'); var exec = new util.exec();
259 'on_select_org' : function(org_id,twisty) {
261 var org = obj.data.hash.aou[ org_id ];
263 if (org.children()) {
264 for (var i = 0; i < org.children().length; i++) {
270 }(org.children()[i],org)
274 if (obj.map_acn[ 'aou_' + org_id ]) {
275 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
281 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
285 JSAN.use('util.exec'); var exec = new util.exec();
289 'append_org' : function (org,parent_org,params) {
292 if (obj.map_tree[ 'aou_' + org.id() ]) {
293 var x = obj.map_tree[ 'aou_' + org.id() ];
295 for (var i in params) {
296 x.setAttribute(i,params[i]);
308 'skip_all_columns_except' : [0,1,2],
309 'retrieve_id' : 'aou_' + org.id(),
313 if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
314 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
315 data.row.my.volume_count = '0';
316 data.row.my.copy_count = '<0>';
318 data.row.my.volume_count = '';
319 data.row.my.copy_count = '';
322 var v_count = 0; var c_count = 0;
323 acn_tree_list = obj.network.simple_request(
324 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
325 [ ses(), obj.docid, [ org.id() ] ]
327 for (var i = 0; i < acn_tree_list.length; i++) {
329 if (acn_tree_list[i].copies()) c_count += acn_tree_list[i].copies().length;
331 data.row.my.volume_count = v_count;
332 data.row.my.copy_count = '<' + c_count + '>';
335 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
338 var node = obj.list.append(data);
340 for (var i in params) {
341 node.setAttribute(i,params[i]);
344 obj.map_tree[ 'aou_' + org.id() ] = node;
346 if (org.children()) {
347 node.setAttribute('container','true');
351 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
352 data.node.setAttribute('open','true');
355 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
359 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
360 node.setAttribute('container','true');
369 'append_acn' : function( org, acn_tree, params ) {
372 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
373 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
375 for (var i in params) {
376 x.setAttribute(i,params[i]);
382 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
389 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
392 'skip_all_columns_except' : [0,1,2],
393 'retrieve_id' : 'acn_' + acn_tree.id(),
394 'node' : parent_node,
396 var node = obj.list.append(data);
397 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
399 for (var i in params) {
400 node.setAttribute(i,params[i]);
403 if (acn_tree.copies()) {
404 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
405 node.setAttribute('container','true');
414 'append_acp' : function( acp_item, acn_tree, params ) {
417 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
418 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
420 for (var i in params) {
421 x.setAttribute(i,params[i]);
427 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
431 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
438 'retrieve_id' : 'acp_' + acp_item.id(),
439 'node' : parent_node,
441 var node = obj.list.append(data);
442 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
444 for (var i in params) {
445 node.setAttribute(i,params[i]);
455 'list_init' : function( params ) {
458 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
461 JSAN.use('circ.util');
464 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
465 'primary' : true, 'hidden' : false,
466 'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
469 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
470 'primary' : false, 'hidden' : false,
471 'render' : 'my.volume_count'
474 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
475 'primary' : false, 'hidden' : false,
476 'render' : 'my.copy_count'
481 'location' : { 'hidden' : false },
482 'circ_lib' : { 'hidden' : false },
483 'owning_lib' : { 'hidden' : false },
484 'call_number' : { 'hidden' : false },
485 'status' : { 'hidden' : false },
513 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
517 'map_row_to_column' : circ.util.std_map_row_to_column(' '),
518 'retrieve_row' : function(params) {
520 var row = params.row;
524 if (!row.my.mvr) funcs.push(
527 row.my.mvr = obj.network.request(
528 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
529 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
530 [ row.my.circ.target_copy() ]
539 row.my.acp = obj.network.request(
540 api.FM_ACP_RETRIEVE.app,
541 api.FM_ACP_RETRIEVE.method,
542 [ row.my.circ.target_copy() ]
545 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
550 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
556 if (typeof params.on_retrieve == 'function') {
557 params.on_retrieve(row);
563 JSAN.use('util.exec'); var exec = new util.exec();
564 exec.on_error = function(E) {
565 var err = 'items chain: ' + js2JSON(E);
566 obj.error.sdump('D_ERROR',err);
567 return true; /* keep going */
573 'on_click' : function(ev) {
574 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
575 var row = {}; var col = {}; var nobj = {};
576 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
577 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
578 var node = obj.list.node.contentView.getItemAtIndex(row.value);
579 var list = [ node.getAttribute('retrieve_id') ];
580 if (typeof obj.on_select == 'function') {
581 obj.on_select(list,true);
583 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
584 window.xulG.on_select(list);
587 'on_select' : function(ev) {
588 JSAN.use('util.functional');
589 var sel = obj.list.retrieve_selection();
590 var list = util.functional.map_list(
592 function(o) { return o.getAttribute('retrieve_id'); }
594 if (typeof obj.on_select == 'function') {
597 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
598 window.xulG.on_select(list);
606 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
612 dump('exiting cat.copy_browser.js\n');