From 8b8729655ccd50f94765fb38350856c1437bb3e3 Mon Sep 17 00:00:00 2001 From: erickson Date: Sun, 26 Sep 2010 23:20:10 +0000 Subject: [PATCH] push copy location order update into ML method. return updated orders from method to prevent replication issues. update UI JS to match git-svn-id: svn://svn.open-ils.org/ILS/trunk@18015 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/CopyLocations.pm | 34 +++++++++++- .../conify/global/asset/copy_location_order.js | 62 +++++++++------------- 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm index 5ace445bfa..d7f0773293 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm @@ -182,7 +182,39 @@ sub fetch_loc { return $cl; } +__PACKAGE__->register_method( + api_name => "open-ils.circ.copy_location_order.update", + method => 'update_clo', + argc => 2, +); + +sub update_clo { + my($self, $client, $auth, $orders) = @_; + return [] unless $orders and @$orders; + + my $e = new_editor(authtoken => $auth, xact =>1); + return $e->die_event unless $e->checkauth; + + my $org = $$orders[0]->org; + return $e->die_event unless $e->allowed('ADMIN_COPY_LOCATION_ORDER', $org); + # clear out the previous order entries + my $existing = $e->search_asset_copy_location_order({org => $org}); + $e->delete_asset_copy_location_order($_) or return $e->die_event for @$existing; + + # create the new order entries + my $progress = 0; + for my $order (@$orders) { + return $e->die_event(OpenILS::Event->new('BAD_PARAMS')) unless $order->org == $org; + $e->create_asset_copy_location_order($order) or return $e->die_event; + $client->respond({maximum => scalar(@$orders), progress => $progress}) unless ($progress++ % 10); + } + + # fetch the new entries + $orders = $e->search_asset_copy_location_order({org => $org}); + $e->commit; + return {orders => $orders}; +} -23; +1; 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 5f3c783354..5032b34f66 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 @@ -34,12 +34,14 @@ 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 : fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(org), true)}, - {order_by : {acpl : 'name'}} - ); + if(!orders) { + var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + orders = pcrud.search('acplo', {org : org}, {order_by : {acplo : 'position'}}); + locations = pcrud.search('acpl', + {owning_lib : fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(org), true)}, + {order_by : {acpl : 'name'}} + ); + } // init the DnD environment source.selectAll(); @@ -80,30 +82,10 @@ function filterGrid(org) { } 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.eliminate( - orders, - { - async : true, - oncomplete : function() { - if(onload) onload(); - } - } - ); -} - -function createOrders() { + 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( @@ -113,21 +95,27 @@ function createOrders() { 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')); + o.org(contextOrg); newOrders.push(o); } ); - // send the order entries off to the server - var pcrud = new openils.PermaCrud({authtoken : user.authtoken}); - pcrud.create( - newOrders, + fieldmapper.standardRequest( + ['open-ils.circ', 'open-ils.circ.copy_location_order.update'], { async : true, - oncomplete : function(r) { - progressDialog.hide(); - filterGrid(contextOrgSelector.attr('value')); - } + params : [openils.User.authtoken, newOrders], + onresponse : function(r) { + if(r = openils.Util.readResponse(r)) { + if(r.orders) { + orders = r.order; + progressDialog.hide(); + filterGrid(contextOrg); + return; + } + progressDialog.update(r); + } + }, } ); } -- 2.11.0