From: Bill Erickson Date: Mon, 20 Feb 2012 17:01:21 +0000 (-0500) Subject: copy loc groups: admin UI X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eeb72538ba47a8ff046f742fe3ff9b92a42b001b;p=evergreen%2Fequinox.git copy loc groups: admin UI Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/conify/global/asset/copy_location_group.tt2 b/Open-ILS/src/templates/conify/global/asset/copy_location_group.tt2 index e86f8c96cf..9259b87ef2 100644 --- a/Open-ILS/src/templates/conify/global/asset/copy_location_group.tt2 +++ b/Open-ILS/src/templates/conify/global/asset/copy_location_group.tt2 @@ -37,7 +37,7 @@ padding-bottom: 10px; } #acplg-header span { - font-size:110%; + font-size:105%; font-weight: bold; padding-right: 20px; } @@ -120,6 +120,10 @@ GRPNAME [ + [% l('Visible') %] + + + [% l('Edit') %] [% l('Delete') %] ] diff --git a/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_group.js b/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_group.js index e20d2e533d..9a9770b083 100644 --- a/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_group.js +++ b/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_group.js @@ -42,24 +42,68 @@ function init() { } ); - // TODO: fetch highest perm org and only fetch related locations - var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); - pcrud.retrieveAll('acpl', // this can take some time... - { async : true, - order_by : {aou : 'shortname'}, - oncomplete : function(r) { - locations = openils.Util.readResponse(r); - drawPage(user.user.ws_ou()); - } - } + fetchCopyLocations(); +} + +function fetchCopyLocations() { + // the full set of copy locations can be very large. + // Only retrieve the set of locations owned by orgs this user + // can use for building location groups. + user.getPermOrgList( + ['ADMIN_COPY_LOCATION_GROUP'], + function(list) { + + var ownerOrgList = []; + dojo.forEach(list, + function(org) { + // include parent orgs + ownerOrgList = ownerOrgList.concat(org).concat( + fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(org), true)); + } + ); + + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + pcrud.search('acpl', // this can take some time... + {owning_lib : ownerOrgList}, + { + async : true, + join : 'aou', + oncomplete : function(r) { + locations = openils.Util.readResponse(r); + sortCopyLocations(); + drawPage(user.user.ws_ou()); + } + } + ); + }, + true, + true ); } +// sort the list of copy locations according the shape of +// the org unit tree. apply a secondary sort on name. +function sortCopyLocations() { + var newlist = []; + + function addNode(node) { + // find locs for this org + var locs = locations.filter(function(loc) { return loc.owning_lib() == node.id() }); + // sort on name and append to the new list + newlist = newlist.concat(locs.sort(function(a, b) { return a.name() < b.name() ? -1 : 1 })); + // repeat for org child nodes + dojo.forEach(node.children(), addNode); + } + + addNode(fieldmapper.aou.globalOrgTree); + locations = newlist; +} + function drawPage(org) { currentOrg = org; currentGroupId = null; - currentGroupMaps = null; + currentGroupMaps = []; //drawLocations(); drawGroupList(); } @@ -68,8 +112,6 @@ function drawGroupList(selectedGrp) { var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); groups = pcrud.search('acplg', {owner : currentOrg}, {order_by : {acplg : 'pos'}}); - var drag = dojo.byId('dnd-drag-actions').cloneNode(true); - drag.id = ''; source.selectAll(); source.deleteSelectedNodes(); @@ -78,6 +120,13 @@ function drawGroupList(selectedGrp) { dojo.forEach(groups, function(group) { if(!group) return; + + var drag = dojo.byId('dnd-drag-actions').cloneNode(true); + drag.id = ''; + var vis = openils.Util.isTrue(group.opac_visible()); + openils.Util.hide(dojo.query('[name=' + (vis ? 'invisible' : 'visible') + ']', drag)[0]); + + var node = source.insertNodes(false, [{ data : drag.innerHTML.replace(/GRPID/g, group.id()).replace(/GRPNAME/g, group.name()), type : [group.id()+''] // use the type field to store the ID @@ -112,7 +161,7 @@ function drawLocations() { if (allMyOrgs.indexOf(loc.owning_lib()) == -1) return; // don't show locations contained in the current group - if (currentGroupMaps) { + if (currentGroupMaps.length) { var existing = currentGroupMaps.filter( function(map) { return (map.location() == loc.id()) }); if (existing.length > 0) return; @@ -228,11 +277,13 @@ function drawGroupEntries(grpId) { } ); - if (!grpId) return; + currentGroupMaps = []; // fetch the group - var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); - currentGroupMaps = pcrud.search('acplgm', {lgroup : grpId}); + if (grpId) { + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + currentGroupMaps = pcrud.search('acplgm', {lgroup : grpId}); + } // update the location selector to remove the already-selected orgs drawLocations();