From: Bill Erickson Date: Mon, 20 Feb 2012 16:11:02 +0000 (-0500) Subject: copy loc groups: admin UI X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e31ca9618840bf0927ce5f48c872aa4717cbf513;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 d28bb8fee5..e86f8c96cf 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 @@ -65,7 +65,12 @@
-
[% l('Location Groups') %]
+
+ + + +
[% l('Location Groups') %]
+
    @@ -113,10 +118,10 @@ +
    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 58d05b3cc1..e20d2e533d 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 @@ -5,10 +5,12 @@ dojo.require("dojo.dnd.Source"); dojo.require('fieldmapper.OrgUtils'); dojo.require('openils.User'); dojo.require('openils.Util'); +dojo.require('openils.Event'); dojo.require('openils.PermaCrud'); dojo.require('openils.widget.AutoGrid'); dojo.require('openils.widget.ProgressDialog'); dojo.require('openils.widget.OrgUnitFilteringSelect'); +dojo.require('openils.widget.EditDialog'); var user; var groups; @@ -24,18 +26,23 @@ var currentOrg; function init() { - user = new openils.User(); - source = new dojo.dnd.Source('acplg-list'); + user = new openils.User(); + + // init the DnD environment + source = new dojo.dnd.Source('acplg-list'); + dojo.connect(source, 'onDndDrop', updateGroupOrder); - user.buildPermOrgSelector( + // context org selector + user.buildPermOrgSelector( 'ADMIN_COPY_LOCATION_GROUP', contextOrgSelector, null, function() { - dojo.connect(contextOrgSelector, 'onChange', drawPage); + dojo.connect(contextOrgSelector, 'onChange', drawPage); } ); + // 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, @@ -50,34 +57,44 @@ function init() { function drawPage(org) { - drawLocations(org); + currentOrg = org; + currentGroupId = null; + currentGroupMaps = null; + //drawLocations(); + drawGroupList(); +} +function drawGroupList(selectedGrp) { var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); - groups = pcrud.search('acplg', {owner : org}, {order_by : {acplg : 'pos'}}); + 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(); source.clearItems(); - var drag = dojo.byId('dnd-drag-actions').cloneNode(true); - drag.id = ''; dojo.forEach(groups, function(group) { if(!group) return; - 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 - } - ]); + 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 + }]); } ); - editGroupEntries(groups[0].id()); + if (groups.length == 0) { + selectedGrp = null + } else if (selectedGrp == null) { + selectedGrp = groups[0].id(); + } + + drawGroupEntries(selectedGrp); } -function drawLocations(org) { - currentOrg = org; +function drawLocations() { if (!locTbody) { locTbody = dojo.byId('acplg-loc-tbody'); @@ -88,7 +105,7 @@ function drawLocations(org) { locTbody.removeChild(node); } - var allMyOrgs = fieldmapper.aou.fullPath(org, true); + var allMyOrgs = fieldmapper.aou.fullPath(currentOrg, true); dojo.forEach(locations, function(loc) { @@ -110,19 +127,97 @@ function drawLocations(org) { ); } +function updateGroupOrder() { + var pos = 0; + var toUpdate = []; + + // find any groups that have changed position and send them off for update + dojo.forEach( + source.getAllNodes(), + function(node) { + var item = source.getItem(node.id); + var grpId = item.type[0]; + var grp = groups.filter(function(g) { return g.id() == grpId })[0]; + if (grp.pos() != pos) { + grp.pos(pos); + toUpdate.push(grp); + } + pos++; + } + ); + + if (toUpdate.length == 0) return; + + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + pcrud.update(toUpdate); // run sync to prevent UI changes mid-update +} + +function newGroup() { + + var dialog = new openils.widget.EditDialog({ + fmClass : 'acplg', + mode : 'create', + parentNode : dojo.byId('acplg-edit-dialog'), + suppressFields : ['id'], + // note: when 'pos' is suppressed, the value is not propagated. + overrideWidgetArgs : { + pos : {widgetValue : groups.length, dijitArgs : {disabled : true}}, + owner : {widgetValue : currentOrg, dijitArgs : {disabled : true}} + }, + onPostSubmit : function(req, cudResults) { + if (cudResults && cudResults.length) { + // refresh the group display + drawGroupList(cudResults[0].id()); + } + } + }); + + dialog.startup(); + dialog.show(); +} + function editGroup(grpId) { - // show EditDialog + var grp = groups.filter(function(g) { return g.id() == grpId })[0]; + + var dialog = new openils.widget.EditDialog({ + fmObject : grp, + mode : 'update', + parentNode : dojo.byId('acplg-edit-dialog'), + suppressFields : ['id', 'pos', 'owner'], + onPostSubmit : function(req, cudResults) { + if (cudResults && cudResults.length) { + // refresh the group display + // pcrud.update returns ID only + drawGroupList(cudResults[0]); + } + } + }); + + dialog.startup(); + dialog.show(); } function deleteGroup(grpId) { // confirm and delete + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + var grp = groups.filter(function(g) { return g.id() == grpId })[0]; + pcrud.eliminate(grp, {oncomplete : function() { drawGroupList() }}); } -function editGroupEntries(grpId) { +function drawGroupEntries(grpId) { currentGroupId = grpId; - var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); - currentGroupMaps = pcrud.search('acplgm', {lgroup : grpId}); + // init/reset the table of mapped copy locations + if (!locMapTbody) { + locMapTbody = dojo.byId('acplg-loc-map-tbody'); + locMapRowTemplate = locMapTbody.removeChild(dojo.byId('acplg-loc-map-row')); + } else { + // clear out the previous table + while (node = locMapTbody.childNodes[0]) + locMapTbody.removeChild(node); + } + + // update the 'selected' status dojo.query('[group]').forEach( function(node) { if (node.getAttribute('group') == grpId) { @@ -133,15 +228,17 @@ function editGroupEntries(grpId) { } ); - if (!locMapTbody) { - locMapTbody = dojo.byId('acplg-loc-map-tbody'); - locMapRowTemplate = locMapTbody.removeChild(dojo.byId('acplg-loc-map-row')); - } else { - // clear out the previous table - while (node = locMapTbody.childNodes[0]) - locMapTbody.removeChild(node); - } + if (!grpId) return; + // fetch the group + 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(); + + // draw the mapped copy locations + // remove any mapped locations from the location selector dojo.forEach(currentGroupMaps, function(map) { var row = locMapRowTemplate.cloneNode(true); @@ -154,7 +251,7 @@ function editGroupEntries(grpId) { locMapTbody.appendChild(row); // if the location is in the group, remove it from the location selection list - removeLocationRow(loc.id()); + //removeLocationRow(loc.id()); } ); } @@ -184,10 +281,12 @@ function editLocations(action) { var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); pcrud[action](maps, { oncomplete : function() { - editGroupEntries(currentGroupId) + drawGroupEntries(currentGroupId) + /* if (action != 'create') { - drawLocations(currentOrg); + drawLocations(); } + */ } }); } @@ -200,100 +299,11 @@ function deSelectAll(node) { ); } +/* function removeLocationRow(locId) { var row = dojo.query('[location=' + locId + ']', locTbody)[0]; if (row) locTbody.removeChild(row); } - -/* -function drawPage(org) { - - // fetch the groups and groupMaps - if(!orders) { - dojo.forEach - for (var grp - groupMaps = pcrud.search('acplgm', - {lgroupowning_lib : fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(org), true)}, - {order_by : {acpl : 'name'}} - ); - } - - // init the DnD environment - source.selectAll(); - source.deleteSelectedNodes(); - source.clearItems(); - - var locs = []; - - // sort and append by existing order settings - dojo.forEach(orders, - function(order) { - locs.push( - locations.filter(function(l) {return l.id() == order.location()})[0] - ); - } - ); - - // append any non-sorted locations - dojo.forEach(locations, - function(l) { - if(!locs.filter(function(ll) { return ll.id() == l.id() })[0]) - locs.push(l); - } - ); - - // shove them into the DnD environment - dojo.forEach(locs, - function(loc) { - if(!loc) return; - var node = source.insertNodes(false, [ - { - data : loc.name() + ' (' + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname()+')', - type : [loc.id()+''] // use the type field to store the ID - } - ]); - } - ); -} - -function applyChanges() { - progressDialog.show(); - - var newOrders = []; - var contextOrg = contextOrgSelector.attr('value'); - - // pull the locations out of the DnD environment and create order entries for them - dojo.forEach( - source.getAllNodes(), - function(node) { - var item = source.getItem(node.id); - var o = new fieldmapper.acplo(); - o.position(newOrders.length + 1); - o.location(item.type[0]); // location.id() is stored in DnD item type - o.org(contextOrg); - newOrders.push(o); - } - ); - - fieldmapper.standardRequest( - ['open-ils.circ', 'open-ils.circ.copy_location_order.update'], - { - async : true, - params : [openils.User.authtoken, newOrders], - onresponse : function(r) { - if(r = openils.Util.readResponse(r)) { - if(r.orders) { - orders = r.order; - progressDialog.hide(); - drawPage(contextOrg); - return; - } - progressDialog.update(r); - } - }, - } - ); -} */ openils.Util.addOnLoad(init);