From 51c88b469153090c2cff89a7948c7293f5f87106 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 8 Feb 2017 01:36:07 +0000 Subject: [PATCH] Bug 15766: Changing code to use svc/creator_batches so file can be used for both modules Sponsored-by: Catalyst IT --- .../prog/en/modules/labels/label-edit-batch.tt | 4 +-- .../prog/en/modules/patroncards/edit-batch.tt | 4 +-- svc/{patroncards => creator_batches} | 37 ++++++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) rename svc/{patroncards => creator_batches} (60%) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt index fdb8212..5505fd7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt @@ -174,11 +174,11 @@ var ajaxData = { 'newdescription': newdescription, 'batch_id': batch_id, - 'card_element': "batch", + 'creator': "label", }; $.ajax({ - url: '/cgi-bin/koha/svc/patroncards', + url: '/cgi-bin/koha/svc/creator_batches', type: 'POST', dataType: 'json', data: ajaxData, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt index ca763c0..7966c8b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt @@ -163,11 +163,11 @@ var ajaxData = { 'newdescription': newdescription, 'batch_id': batch_id, - 'card_element': "batch", + 'creator': "patroncard", }; $.ajax({ - url: '/cgi-bin/koha/svc/patroncards', + url: '/cgi-bin/koha/svc/creator_batches', type: 'POST', dataType: 'json', data: ajaxData, diff --git a/svc/patroncards b/svc/creator_batches similarity index 60% rename from svc/patroncards rename to svc/creator_batches index 3766cca..c82e23c 100644 --- a/svc/patroncards +++ b/svc/creator_batches @@ -26,11 +26,11 @@ use C4::Context; use C4::Auth qw /check_cookie_auth/; use C4::Output qw(:DEFAULT :ajax); use C4::Patroncards::Batch; -use Data::Dumper; +use C4::Labels::Batch; =head1 NAME -svc/patroncards - Web service for managing AJAX functionality for patroncards +svc/creator_batches - Web service for managing AJAX functionality for patroncard batches and label batches =head1 DESCRIPTION @@ -44,24 +44,29 @@ if ( $auth_status ne "ok" ) { exit 0; } if ($is_ajax) { - my $card_element = $cgi->param('card_element'); - if ( $card_element eq 'batch' ) { - my $batch_id = $cgi->param('batch_id'); - my $description = $cgi->param('newdescription'); - my $status = ''; - my $dbh = C4::Context->dbh; - my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?"; - my $sth = $dbh->prepare($query); - $sth->execute($description, $batch_id); + my $batch_id = $cgi->param('batch_id'); + my $description = $cgi->param('newdescription'); + my $status = ''; + my $dbh = C4::Context->dbh; + my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?"; + my $sth = $dbh->prepare($query); + $sth->execute($description, $batch_id); - # Check for success + # Check for success + my $creator = $cgi->param('creator'); + if ( $creator eq 'patroncard' ) { my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id); if ( $batch->{description} eq $description ) { $status = 'success'; } - - my $json = to_json ( { status => $status, newdesc => $description } ); - output_with_http_headers $cgi, undef, $json, 'js'; - exit; + } elsif ( $creator eq 'label' ) { + my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); + if ( $batch->{description} eq $description ) { + $status = 'success'; + } } + + my $json = to_json ( { status => $status, newdesc => $description } ); + output_with_http_headers $cgi, undef, $json, 'js'; + exit; } -- 2.1.4