push copy location order update into ML method. return updated orders from method...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 26 Sep 2010 23:20:10 +0000 (23:20 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 26 Sep 2010 23:20:10 +0000 (23:20 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18015 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm
Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js

index 5ace445..d7f0773 100644 (file)
@@ -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;
index 5f3c783..5032b34 100644 (file)
@@ -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);
+                }
+            },
         }
     );
 }