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