From e480fac11b88096e6e5947c9c2a94439595d42ea Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 28 Oct 2009 15:59:14 +0000 Subject: [PATCH] plugged in load time ordering and apply changes operation to delete old order entries and create new ones git-svn-id: svn://svn.open-ils.org/ILS/trunk@14650 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../global/asset/copy_location_order.js | 90 +++++++++++++++++-- .../global/asset/copy_location_order.tt2 | 8 +- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js b/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js index be177e3bbf..3bdd80203d 100644 --- a/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js +++ b/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js @@ -7,9 +7,9 @@ dojo.require('openils.User'); dojo.require('openils.Util'); dojo.require('openils.widget.AutoGrid'); dojo.require('openils.PermaCrud'); +dojo.require('openils.widget.ProgressDialog'); var user; -var pcrud; var orders; var locations; var source; @@ -17,7 +17,6 @@ var source; function init() { user = new openils.User(); - pcrud = new openils.PermaCrud({authtoken : user.authtoken}); source = new dojo.dnd.Source('acl-ol'); user.buildPermOrgSelector( @@ -33,20 +32,101 @@ function init() { } function filterGrid(org) { + + // fetch the locations and order entries + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); orders = pcrud.search('acplo', {org : org}, {order_by : {acplo : 'position'}}); - locations = pcrud.search('acpl', {owning_lib : org}); //TODO + locations = pcrud.search('acpl', {owning_lib : org}, {order_by : {acpl : 'name'}}); // TODO + + // 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) { - source.insertNodes(false, [ - loc.name() + ' (' + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname()+')' + 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(true); + if(orders.length) + deleteOrders(createOrders); + else + createOrders(); +} + +function deleteOrders(onload) { + // delete the existing order entries in preparation for new ones + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + pcrud.delete( + orders, + { + async : true, + oncomplete : function() { + if(onload) onload(); + } + } + ); +} + +function createOrders() { + + var newOrders = []; + + // 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(contextOrgSelector.attr('value')); + newOrders.push(o); + } + ); + + // send the order entries off to the server + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + pcrud.create( + newOrders, + { + async : true, + oncomplete : function(r) { + progressDialog.hide(); + filterGrid(contextOrgSelector.attr('value')); + } + } + ); +} + openils.Util.addOnLoad(init); diff --git a/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 b/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 index 6c2813a49d..fef90880d7 100644 --- a/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 +++ b/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 @@ -5,8 +5,7 @@
Copy Location Order
-
-
+
@@ -17,10 +16,15 @@ labelAttr='shortname'> + To move an item, drag it up or down with the mouse.
    +