Bug 36084: svc - creator_batches
No desire to have a nice api client for this. This patch also: Improve failure handling Remove unecessary code in svc script Remove duplicated on click binding Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
374db28eee
commit
8ebb11b244
|
|
@ -375,8 +375,8 @@
|
|||
var ajaxData = {
|
||||
'newdescription': newdescription,
|
||||
'batch_id': batch_id,
|
||||
'card_element': "batch",
|
||||
'creator': "label",
|
||||
op: 'cud-set_permission',
|
||||
csrf_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
|
|
@ -385,7 +385,6 @@
|
|||
dataType: 'json',
|
||||
data: ajaxData,
|
||||
})
|
||||
|
||||
.done(function(data){
|
||||
if (data.status == 'success') {
|
||||
$("input[name='description']").text(data.newdesc);
|
||||
|
|
@ -393,6 +392,8 @@
|
|||
} else {
|
||||
$("#change-status").text(_("Unable to save description"));
|
||||
}
|
||||
}).fail(function(){
|
||||
$("#change-status").text(_("Unable to save description"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -353,40 +353,16 @@
|
|||
var batch_id = $(this).data("batch-id");
|
||||
GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id=' + batch_id + '&label_id=' + label_id, 400, 800);
|
||||
});
|
||||
$("#savedesc").click(function(event){
|
||||
var newdescription = $(this).siblings('input[name="description"]').val();
|
||||
var batch_id = $(this).data('batch_id');
|
||||
var ajaxData = {
|
||||
'newdescription': newdescription,
|
||||
'batch_id': batch_id,
|
||||
'card_element': "batch",
|
||||
'creator': "patroncard",
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: '/cgi-bin/koha/svc/creator_batches',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: ajaxData,
|
||||
})
|
||||
|
||||
.done(function(data){
|
||||
if (data.status == 'success') {
|
||||
$("input[name='description']").text(data.newdesc);
|
||||
$("#change-status").text(_("Saved"));
|
||||
} else {
|
||||
$("#change-status").text(_("Unable to save description"));
|
||||
}
|
||||
});
|
||||
});
|
||||
$("#savedesc").click(function(event){
|
||||
event.preventDefault(); // prevent form submission
|
||||
var newdescription = $('input[name="description"]').val();
|
||||
var batch_id = $(this).data('batch_id');
|
||||
var ajaxData = {
|
||||
'newdescription': newdescription,
|
||||
'batch_id': batch_id,
|
||||
'card_element': "batch",
|
||||
'creator': "patroncard",
|
||||
op: 'cud-set_permission',
|
||||
csrf_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
|
|
@ -403,6 +379,8 @@
|
|||
} else {
|
||||
$("#change-status").text(_("Unable to save description"));
|
||||
}
|
||||
}).fail(function(){
|
||||
$("#change-status").text(_("Unable to save description"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -44,30 +44,26 @@ if ( $auth_status ne "ok" ) {
|
|||
exit 0;
|
||||
}
|
||||
|
||||
if ($is_ajax) {
|
||||
my $op = $cgi->param('op') || q{};
|
||||
if ($is_ajax && $op eq 'cud-set_permission') {
|
||||
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
|
||||
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';
|
||||
}
|
||||
} elsif ( $creator eq 'label' ) {
|
||||
my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
|
||||
if ( $batch->{description} eq $description ) {
|
||||
$status = 'success';
|
||||
}
|
||||
my $status = 'success';
|
||||
eval {
|
||||
my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute($description, $batch_id);
|
||||
};
|
||||
if ($@) {
|
||||
warn $@;
|
||||
undef $status;
|
||||
}
|
||||
|
||||
my $json = encode_json ( { status => $status, newdesc => $description } );
|
||||
output_with_http_headers $cgi, undef, $json, 'js';
|
||||
exit;
|
||||
} else {
|
||||
# FIXME be nicer
|
||||
exit 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue