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 ]);
69 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
73 this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
77 'show_my_libs' : function() {
80 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
81 obj.show_libs( org, true );
83 var p_org = obj.data.hash.aou[ org.parent_ou() ];
85 JSAN.use('util.exec'); var exec = new util.exec();
87 for (var i = 0; i < p_org.children().length; i++) {
91 obj.show_libs( o, true );
93 }( p_org.children()[i] )
103 'show_all_libs' : function() {
108 obj.show_libs( obj.data.tree.aou );
110 JSAN.use('util.exec'); var exec = new util.exec();
112 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
118 }( obj.data.tree.aou.children()[i] )
127 'show_libs_with_copies' : function() {
130 JSAN.use('util.exec'); var exec = new util.exec();
131 JSAN.use('util.functional');
133 var orgs = util.functional.map_list(
135 function(id) { return obj.data.hash.aou[id]; }
138 if (a.shortname() < b.shortname()) return -1;
139 if (a.shortname() > b.shortname()) return 1;
144 for (var i = 0; i < orgs.length; i++) {
148 obj.show_libs(o,true);
159 'show_libs' : function(start_aou,show_open) {
162 if (!start_aou) throw('show_libs: Need a start_aou');
163 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
164 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
169 var temp_aou = start_aou;
170 while ( temp_aou.parent_ou() ) {
171 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
172 parents.push( temp_aou );
176 for (var i = 0; i < parents.length; i++) {
181 obj.append_org(o,p,{'container':'true','open':'true'});
183 obj.append_org(o,p,{'container':'true'});
186 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
192 return function() { obj.append_org(o,p); };
193 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
198 if (start_aou.children()) {
199 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
200 x.setAttribute('container','true');
201 if (show_open) x.setAttribute('open','true');
202 for (var i = 0; i < start_aou.children().length; i++) {
205 return function() { obj.append_org(o,p); };
206 }( start_aou.children()[i], start_aou )
220 'on_select' : function(list,twisty) {
222 for (var i = 0; i < list.length; i++) {
223 var node = obj.map_tree[ list[i] ];
224 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
225 var row_type = list[i].split('_')[0];
226 var id = list[i].split('_')[1];
228 case 'aou' : obj.on_select_org(id,twisty); break;
229 case 'acn' : obj.on_select_acn(id,twisty); break;
235 'on_select_acn' : function(acn_id,twisty) {
238 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
240 if (acn_tree.copies()) {
241 for (var i = 0; i < acn_tree.copies().length; i++) {
247 }( acn_tree.copies()[i], acn_tree )
251 JSAN.use('util.exec'); var exec = new util.exec();
258 'on_select_org' : function(org_id,twisty) {
260 var org = obj.data.hash.aou[ org_id ];
262 if (org.children()) {
263 for (var i = 0; i < org.children().length; i++) {
269 }(org.children()[i],org)
273 if (obj.map_acn[ 'aou_' + org_id ]) {
274 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
280 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
284 JSAN.use('util.exec'); var exec = new util.exec();
288 'append_org' : function (org,parent_org,params) {
291 if (obj.map_tree[ 'aou_' + org.id() ]) {
292 var x = obj.map_tree[ 'aou_' + org.id() ];
294 for (var i in params) {
295 x.setAttribute(i,params[i]);
307 'skip_all_columns_except' : [0,1,2],
308 'retrieve_id' : 'aou_' + org.id(),
312 if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
313 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
314 data.row.my.volume_count = '0';
315 data.row.my.copy_count = '<0>';
317 data.row.my.volume_count = '';
318 data.row.my.copy_count = '';
321 var v_count = 0; var c_count = 0;
322 acn_tree_list = obj.network.simple_request(
323 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
324 [ ses(), obj.docid, [ org.id() ] ]
326 for (var i = 0; i < acn_tree_list.length; i++) {
328 if (acn_tree_list[i].copies()) c_count += acn_tree_list[i].copies().length;
330 data.row.my.volume_count = v_count;
331 data.row.my.copy_count = '<' + c_count + '>';
334 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
337 var node = obj.list.append(data);
339 for (var i in params) {
340 node.setAttribute(i,params[i]);
343 obj.map_tree[ 'aou_' + org.id() ] = node;
345 if (org.children()) {
346 node.setAttribute('container','true');
350 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
351 data.node.setAttribute('open','true');
354 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
358 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
359 node.setAttribute('container','true');
368 'append_acn' : function( org, acn_tree, params ) {
371 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
372 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
374 for (var i in params) {
375 x.setAttribute(i,params[i]);
381 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
388 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
391 'skip_all_columns_except' : [0,1,2],
392 'retrieve_id' : 'acn_' + acn_tree.id(),
393 'node' : parent_node,
395 var node = obj.list.append(data);
396 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
398 for (var i in params) {
399 node.setAttribute(i,params[i]);
402 if (acn_tree.copies()) {
403 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
404 node.setAttribute('container','true');
413 'append_acp' : function( acp_item, acn_tree, params ) {
416 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
417 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
419 for (var i in params) {
420 x.setAttribute(i,params[i]);
426 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
430 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
437 'retrieve_id' : 'acp_' + acp_item.id(),
438 'node' : parent_node,
440 var node = obj.list.append(data);
441 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
443 for (var i in params) {
444 node.setAttribute(i,params[i]);
454 'list_init' : function( params ) {
457 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
460 JSAN.use('circ.util');
463 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
464 'primary' : true, 'hidden' : false,
465 'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
468 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
469 'primary' : false, 'hidden' : false,
470 'render' : 'my.volume_count'
473 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
474 'primary' : false, 'hidden' : false,
475 'render' : 'my.copy_count'
480 'location' : { 'hidden' : false },
481 'circ_lib' : { 'hidden' : false },
482 'owning_lib' : { 'hidden' : false },
483 'call_number' : { 'hidden' : false },
484 'status' : { 'hidden' : false },
512 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
516 'map_row_to_column' : circ.util.std_map_row_to_column(' '),
517 'retrieve_row' : function(params) {
519 var row = params.row;
523 if (!row.my.mvr) funcs.push(
526 row.my.mvr = obj.network.request(
527 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
528 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
529 [ row.my.circ.target_copy() ]
538 row.my.acp = obj.network.request(
539 api.FM_ACP_RETRIEVE.app,
540 api.FM_ACP_RETRIEVE.method,
541 [ row.my.circ.target_copy() ]
544 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
549 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
555 if (typeof params.on_retrieve == 'function') {
556 params.on_retrieve(row);
562 JSAN.use('util.exec'); var exec = new util.exec();
563 exec.on_error = function(E) {
564 var err = 'items chain: ' + js2JSON(E);
565 obj.error.sdump('D_ERROR',err);
566 return true; /* keep going */
572 'on_click' : function(ev) {
573 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
574 var row = {}; var col = {}; var nobj = {};
575 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
576 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
577 var node = obj.list.node.contentView.getItemAtIndex(row.value);
578 var list = [ node.getAttribute('retrieve_id') ];
579 if (typeof obj.on_select == 'function') {
580 obj.on_select(list,true);
582 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
583 window.xulG.on_select(list);
586 'on_select' : function(ev) {
587 JSAN.use('util.functional');
588 var sel = obj.list.retrieve_selection();
589 var list = util.functional.map_list(
591 function(o) { return o.getAttribute('retrieve_id'); }
593 if (typeof obj.on_select == 'function') {
596 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
597 window.xulG.on_select(list);
605 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
611 dump('exiting cat.copy_browser.js\n');