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 = {
20 'init' : function( params ) {
23 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
26 obj.docid = params.docid;
28 JSAN.use('util.network'); obj.network = new util.network();
29 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
30 JSAN.use('util.controller'); obj.controller = new util.controller();
36 function() { alert('Not Yet Implemented'); }
38 'cmd_show_my_libs' : [
44 'cmd_show_all_libs' : [
50 'cmd_show_libs_with_copies' : [
53 obj.show_libs_with_copies();
67 JSAN.use('util.widgets'); JSAN.use('util.functional');
68 var list = util.functional.map_list(
69 util.functional.filter_list(
72 return o.split(/_/)[0] == 'acn';
76 return o.split(/_/)[1];
79 if (list.length == 0) return;
81 var copy_shortcut = {};
82 list = util.functional.map_list(
85 var ou_id = obj.map_acn['acn_' + o].owning_lib();
87 var label = obj.map_acn['acn_' + o].label();
88 if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {};
89 copy_shortcut[ou_id][ label ] = volume_id;
94 /* quick fix */ /* what was this fixing? */
95 list = []; for (var i in copy_shortcut) { list.push( i ); }
99 edit = obj.network.request(
100 api.PERM_MULTI_ORG_CHECK.app,
101 api.PERM_MULTI_ORG_CHECK.method,
104 obj.data.list.au[0].id(),
108 ).length == 0 ? 1 : 0;
110 obj.error.sdump('batch permission check: ' + E);
113 if (edit==0) return; // no read-only view for this interface
115 var title = 'Add Copy';
117 JSAN.use('util.window'); var win = new util.window();
119 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
120 +'?doc_id=' + window.escape(obj.docid)
121 +'&ou_ids=' + window.escape( js2JSON(list) )
122 +'©_shortcut=' + window.escape( js2JSON(copy_shortcut) ),
124 'chrome,modal,resizable'
128 obj.error.standard_unexpected_error_alert('copy browser -> add copies',E);
132 'cmd_add_items_to_buckets' : [
142 'cmd_delete_items' : [
147 'cmd_print_spine_labels' : [
152 'cmd_add_volumes' : [
156 JSAN.use('util.widgets'); JSAN.use('util.functional');
157 var list = util.functional.filter_list(
160 return o.split(/_/)[0] == 'aou';
163 list = util.functional.map_list(
166 return o.split(/_/)[1];
171 edit = obj.network.request(
172 api.PERM_MULTI_ORG_CHECK.app,
173 api.PERM_MULTI_ORG_CHECK.method,
176 obj.data.list.au[0].id(),
178 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
180 ).length == 0 ? 1 : 0;
182 obj.error.sdump('batch permission check: ' + E);
185 if (edit==0) return; // no read-only view for this interface
187 var title = 'Add Volume/Copy';
189 JSAN.use('util.window'); var win = new util.window();
191 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
192 +'?doc_id=' + window.escape(obj.docid)
193 +'&ou_ids=' + window.escape( js2JSON(list) ),
195 'chrome,modal,resizable'
200 obj.error.standard_unexpected_error_alert('copy browser -> add volumes',E);
204 'cmd_edit_volumes' : [
209 'cmd_delete_volumes' : [
214 'cmd_mark_volume' : [
219 'cmd_refresh_list' : [
228 obj.list_init(params);
230 obj.org_ids = obj.network.simple_request('FM_AOU_IDS_RETRIEVE_VIA_RECORD_ID',[ obj.docid ]);
232 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
233 obj.show_libs( org );
236 this.error.sdump('D_ERROR','cat.copy_browser.init: ' + E + '\n');
240 'show_my_libs' : function() {
243 var org = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
244 obj.show_libs( org, true );
246 var p_org = obj.data.hash.aou[ org.parent_ou() ];
248 JSAN.use('util.exec'); var exec = new util.exec();
250 for (var i = 0; i < p_org.children().length; i++) {
254 obj.show_libs( o, true );
256 }( p_org.children()[i] )
266 'show_all_libs' : function() {
271 obj.show_libs( obj.data.tree.aou );
273 JSAN.use('util.exec'); var exec = new util.exec();
275 for (var i = 0; i < obj.data.tree.aou.children().length; i++) {
281 }( obj.data.tree.aou.children()[i] )
290 'show_libs_with_copies' : function() {
293 JSAN.use('util.exec'); var exec = new util.exec();
294 JSAN.use('util.functional');
296 var orgs = util.functional.map_list(
298 function(id) { return obj.data.hash.aou[id]; }
301 if (a.shortname() < b.shortname()) return -1;
302 if (a.shortname() > b.shortname()) return 1;
307 for (var i = 0; i < orgs.length; i++) {
311 obj.show_libs(o,true);
322 'show_libs' : function(start_aou,show_open) {
325 if (!start_aou) throw('show_libs: Need a start_aou');
326 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
327 JSAN.use('util.functional'); JSAN.use('util.exec'); var exec = new util.exec();
332 var temp_aou = start_aou;
333 while ( temp_aou.parent_ou() ) {
334 temp_aou = obj.data.hash.aou[ temp_aou.parent_ou() ];
335 parents.push( temp_aou );
339 for (var i = 0; i < parents.length; i++) {
344 obj.append_org(o,p,{'container':'true','open':'true'});
346 obj.append_org(o,p,{'container':'true'});
349 }(parents[i], obj.data.hash.aou[ parents[i].parent_ou() ])
355 return function() { obj.append_org(o,p); };
356 }(start_aou,obj.data.hash.aou[ start_aou.parent_ou() ])
361 if (start_aou.children()) {
362 var x = obj.map_tree[ 'aou_' + start_aou.id() ];
363 x.setAttribute('container','true');
364 if (show_open) x.setAttribute('open','true');
365 for (var i = 0; i < start_aou.children().length; i++) {
368 return function() { obj.append_org(o,p); };
369 }( start_aou.children()[i], start_aou )
383 'on_select' : function(list,twisty) {
385 for (var i = 0; i < list.length; i++) {
386 var node = obj.map_tree[ list[i] ];
387 //if (node.lastChild.nodeName == 'treechildren') { continue; } else { alert(node.lastChild.nodeName); }
388 var row_type = list[i].split('_')[0];
389 var id = list[i].split('_')[1];
391 case 'aou' : obj.on_select_org(id,twisty); break;
392 case 'acn' : obj.on_select_acn(id,twisty); break;
398 'on_select_acn' : function(acn_id,twisty) {
401 var acn_tree = obj.map_acp[ 'acn_' + acn_id ];
403 if (acn_tree.copies()) {
404 for (var i = 0; i < acn_tree.copies().length; i++) {
410 }( acn_tree.copies()[i], acn_tree )
414 JSAN.use('util.exec'); var exec = new util.exec();
421 'on_select_org' : function(org_id,twisty) {
423 var org = obj.data.hash.aou[ org_id ];
425 if (org.children()) {
426 for (var i = 0; i < org.children().length; i++) {
432 }(org.children()[i],org)
436 if (obj.map_acn[ 'aou_' + org_id ]) {
437 for (var i = 0; i < obj.map_acn[ 'aou_' + org_id ].length; i++) {
443 }( org, obj.map_acn[ 'aou_' + org_id ][i] )
447 JSAN.use('util.exec'); var exec = new util.exec();
451 'append_org' : function (org,parent_org,params) {
454 if (obj.map_tree[ 'aou_' + org.id() ]) {
455 var x = obj.map_tree[ 'aou_' + org.id() ];
457 for (var i in params) {
458 x.setAttribute(i,params[i]);
470 'skip_all_columns_except' : [0,1,2],
471 'retrieve_id' : 'aou_' + org.id(),
475 if ( obj.org_ids.indexOf( org.id() ) == -1 ) {
476 if ( obj.data.hash.aout[ org.ou_type() ].can_have_vols() ) {
477 data.row.my.volume_count = '0';
478 data.row.my.copy_count = '<0>';
480 data.row.my.volume_count = '';
481 data.row.my.copy_count = '';
484 var v_count = 0; var c_count = 0;
485 acn_tree_list = obj.network.simple_request(
486 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS',
487 [ ses(), obj.docid, [ org.id() ] ]
489 for (var i = 0; i < acn_tree_list.length; i++) {
491 obj.map_acn[ 'acn_' + acn_tree_list[i].id() ] = function(r){return r;}(acn_tree_list[i]);
492 var copies = acn_tree_list[i].copies(); if (copies) c_count += copies.length;
493 for (var j = 0; j < copies.length; j++) {
494 obj.map_acp[ 'acp_' + copies[j].id() ] = function(r){return r;}(copies[j]);
497 data.row.my.volume_count = v_count;
498 data.row.my.copy_count = '<' + c_count + '>';
501 data.node = obj.map_tree[ 'aou_' + parent_org.id() ];
504 var node = obj.list.append(data);
506 for (var i in params) {
507 node.setAttribute(i,params[i]);
510 obj.map_tree[ 'aou_' + org.id() ] = node;
512 if (org.children()) {
513 node.setAttribute('container','true');
517 if ( obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou() == parent_org.id() ) {
518 data.node.setAttribute('open','true');
521 obj.map_tree[ 'aou_' + org.id() ].setAttribute('open','true');
525 obj.map_acn[ 'aou_' + org.id() ] = acn_tree_list;
526 node.setAttribute('container','true');
535 'append_acn' : function( org, acn_tree, params ) {
538 if (obj.map_tree[ 'acn_' + acn_tree.id() ]) {
539 var x = obj.map_tree[ 'acn_' + acn_tree.id() ];
541 for (var i in params) {
542 x.setAttribute(i,params[i]);
548 var parent_node = obj.map_tree[ 'aou_' + org.id() ];
555 'copy_count' : acn_tree.copies() ? acn_tree.copies().length : '0',
558 'skip_all_columns_except' : [0,1,2],
559 'retrieve_id' : 'acn_' + acn_tree.id(),
560 'node' : parent_node,
562 var node = obj.list.append(data);
563 obj.map_tree[ 'acn_' + acn_tree.id() ] = node;
565 for (var i in params) {
566 node.setAttribute(i,params[i]);
569 if (acn_tree.copies()) {
570 obj.map_acp[ 'acn_' + acn_tree.id() ] = acn_tree;
571 node.setAttribute('container','true');
580 'append_acp' : function( acp_item, acn_tree, params ) {
583 if (obj.map_tree[ 'acp_' + acp_item.id() ]) {
584 var x = obj.map_tree[ 'acp_' + acp_item.id() ];
586 for (var i in params) {
587 x.setAttribute(i,params[i]);
593 var parent_node = obj.map_tree[ 'acn_' + acn_tree.id() ];
597 'aou' : obj.data.hash.aou[ acn_tree.owning_lib() ],
604 'retrieve_id' : 'acp_' + acp_item.id(),
605 'node' : parent_node,
607 var node = obj.list.append(data);
608 obj.map_tree[ 'acp_' + acp_item.id() ] = node;
610 for (var i in params) {
611 node.setAttribute(i,params[i]);
621 'list_init' : function( params ) {
624 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
627 JSAN.use('circ.util');
630 'id' : 'tree_location', 'label' : 'Location/Barcode', 'flex' : 1,
631 'primary' : true, 'hidden' : false,
632 'render' : 'my.acp ? my.acp.barcode() : my.acn ? my.acn.label() : my.aou ? my.aou.shortname() + " : " + my.aou.name() : "???"'
635 'id' : 'volume_count', 'label' : 'Volumes', 'flex' : 0,
636 'primary' : false, 'hidden' : false,
637 'render' : 'my.volume_count'
640 'id' : 'copy_count', 'label' : 'Copies', 'flex' : 0,
641 'primary' : false, 'hidden' : false,
642 'render' : 'my.copy_count'
647 'location' : { 'hidden' : false },
648 'circ_lib' : { 'hidden' : false },
649 'owning_lib' : { 'hidden' : false },
650 'call_number' : { 'hidden' : false },
651 'status' : { 'hidden' : false },
679 JSAN.use('util.list'); obj.list = new util.list('copy_tree');
683 'map_row_to_column' : circ.util.std_map_row_to_column(' '),
684 'retrieve_row' : function(params) {
686 var row = params.row;
690 if (!row.my.mvr) funcs.push(
693 row.my.mvr = obj.network.request(
694 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.app,
695 api.MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.method,
696 [ row.my.circ.target_copy() ]
705 row.my.acp = obj.network.request(
706 api.FM_ACP_RETRIEVE.app,
707 api.FM_ACP_RETRIEVE.method,
708 [ row.my.circ.target_copy() ]
711 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
716 params.row_node.setAttribute( 'retrieve_id',row.my.acp.barcode() );
722 if (typeof params.on_retrieve == 'function') {
723 params.on_retrieve(row);
729 JSAN.use('util.exec'); var exec = new util.exec();
730 exec.on_error = function(E) {
731 var err = 'items chain: ' + js2JSON(E);
732 obj.error.sdump('D_ERROR',err);
733 return true; /* keep going */
739 'on_click' : function(ev) {
740 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
741 var row = {}; var col = {}; var nobj = {};
742 obj.list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
743 if ((row.value == -1)||(nobj.value != 'twisty')) { return; }
744 var node = obj.list.node.contentView.getItemAtIndex(row.value);
745 var list = [ node.getAttribute('retrieve_id') ];
746 if (typeof obj.on_select == 'function') {
747 obj.on_select(list,true);
749 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
750 window.xulG.on_select(list);
753 'on_select' : function(ev) {
754 JSAN.use('util.functional');
755 var sel = obj.list.retrieve_selection();
756 obj.sel_list = util.functional.map_list(
758 function(o) { return o.getAttribute('retrieve_id'); }
760 if (typeof obj.on_select == 'function') {
761 obj.on_select(obj.sel_list);
763 if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
764 window.xulG.on_select(obj.sel_list);
772 this.error.sdump('D_ERROR','cat.copy_browser.list_init: ' + E + '\n');
777 'refresh_list' : function() { alert('FIXME: refresh the list now'); },
780 dump('exiting cat.copy_browser.js\n');