}
);
- // 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();
}
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();
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
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;
}
);
- 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();