Bug 36084: svc - checkout_notes
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
6a9ff124a5
commit
526ceeb4fa
3 changed files with 69 additions and 46 deletions
|
@ -179,44 +179,52 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function show_error(){
|
||||||
|
// FIXME Can be improved by displaying meaningful error.
|
||||||
|
$("#error").text(_("Unable to change status of note.")).show();
|
||||||
|
}
|
||||||
|
|
||||||
$("#notestable").on("click", "button.seen, button.notseen", function(event){
|
$("#notestable").on("click", "button.seen, button.notseen", function(event){
|
||||||
event.preventDefault(); // prevent form submission
|
event.preventDefault(); // prevent form submission
|
||||||
var $op = $(this).attr("name");
|
var op = $(this).attr("name");
|
||||||
var $issue_id = $(this).data('issue_id');
|
var issue_id = $(this).data('issue_id');
|
||||||
var ajaxData = {
|
|
||||||
'op': $op,
|
|
||||||
'issue_id': $issue_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax({
|
const client = APIClient.circulation;
|
||||||
url: '/cgi-bin/koha/svc/checkout_notes/',
|
if ( op == 'seen' ) {
|
||||||
type: 'POST',
|
client.checkouts.mark_as_seen(issue_id).then(
|
||||||
dataType: 'json',
|
success => {
|
||||||
data: ajaxData,
|
if (success.seen){
|
||||||
})
|
$("#status_" + issue_id).text(_("Seen"));
|
||||||
|
$(event.target).parent().siblings(".seen0").removeClass("seen0").addClass("seen1");
|
||||||
.done(function(data){
|
$(event.target).siblings(".notseen").prop("disabled", false);
|
||||||
if (data.status == 'success'){
|
$(event.target).prop("disabled", true);
|
||||||
if ( $op == 'notseen' ){
|
} else {
|
||||||
$("#status_" + $issue_id).text(_("Not seen"));
|
show_error();
|
||||||
$(event.target).parent().siblings(".seen1").removeClass("seen1").addClass("seen0");
|
}
|
||||||
$(event.target).siblings(".seen").prop("disabled", false);
|
},
|
||||||
$(event.target).prop("disabled", true);
|
error => {
|
||||||
} else {
|
console.warn("Something wrong happened: %s".format(error));
|
||||||
$("#status_" + $issue_id).text(_("Seen"));
|
show_error();
|
||||||
$(event.target).parent().siblings(".seen0").removeClass("seen0").addClass("seen1");
|
|
||||||
$(event.target).siblings(".notseen").prop("disabled", false);
|
|
||||||
$(event.target).prop("disabled", true);
|
|
||||||
}
|
}
|
||||||
} else {
|
);
|
||||||
$("#error").text(_("Unable to change status of note."));
|
} else {
|
||||||
$("#error").show();
|
client.checkouts.mark_as_not_seen(issue_id).then(
|
||||||
}
|
success => {
|
||||||
})
|
if (!success.seen){
|
||||||
.error(function(data){
|
$("#status_" + issue_id).text(_("Not seen"));
|
||||||
$("#error").text(_("Unable to change status of note."));
|
$(event.target).parent().siblings(".seen1").removeClass("seen1").addClass("seen0");
|
||||||
$("#error").show();
|
$(event.target).siblings(".seen").prop("disabled", false);
|
||||||
});
|
$(event.target).prop("disabled", true);
|
||||||
|
} else {
|
||||||
|
show_error();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.warn("Something wrong happened: %s".format(error));
|
||||||
|
show_error();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -26,6 +26,29 @@ export class CirculationAPIClient extends HttpClient {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get checkouts() {
|
||||||
|
return {
|
||||||
|
mark_as_seen: checkout_id =>
|
||||||
|
this.post({
|
||||||
|
endpoint: "checkout_notes",
|
||||||
|
body: "issue_id=%s&op=%s".format(checkout_id, "cud-seen"),
|
||||||
|
headers: {
|
||||||
|
"Content-Type":
|
||||||
|
"application/x-www-form-urlencoded;charset=utf-8",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
mark_as_not_seen: checkout_id =>
|
||||||
|
this.post({
|
||||||
|
endpoint: "checkout_notes",
|
||||||
|
body: "issue_id=%s&op=%s".format(checkout_id, "cud-notseen"),
|
||||||
|
headers: {
|
||||||
|
"Content-Type":
|
||||||
|
"application/x-www-form-urlencoded;charset=utf-8",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CirculationAPIClient;
|
export default CirculationAPIClient;
|
||||||
|
|
|
@ -21,7 +21,6 @@ use Modern::Perl;
|
||||||
|
|
||||||
use JSON qw( to_json );
|
use JSON qw( to_json );
|
||||||
use CGI;
|
use CGI;
|
||||||
use C4::Service;
|
|
||||||
use C4::Auth qw ( check_cookie_auth );
|
use C4::Auth qw ( check_cookie_auth );
|
||||||
use C4::Output qw( is_ajax output_with_http_headers );
|
use C4::Output qw( is_ajax output_with_http_headers );
|
||||||
use Koha::Checkouts;
|
use Koha::Checkouts;
|
||||||
|
@ -41,23 +40,16 @@ my ( $auth_status ) = check_cookie_auth( $query->cookie('CGISESSID'), { circulat
|
||||||
if ( $auth_status ne "ok" ) {
|
if ( $auth_status ne "ok" ) {
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
my $op = $query->param('op');
|
||||||
if ($is_ajax) {
|
if ($is_ajax) {
|
||||||
my $issue_id = $query->param('issue_id');
|
my $issue_id = $query->param('issue_id');
|
||||||
my $issue = Koha::Checkouts->find($issue_id);
|
my $issue = Koha::Checkouts->find($issue_id);
|
||||||
my $op = $query->param('op');
|
if ($op eq 'cud-seen'){
|
||||||
my $status = 'success';
|
|
||||||
if ($op eq 'seen'){
|
|
||||||
$issue->set({ noteseen => 1 })->store;
|
$issue->set({ noteseen => 1 })->store;
|
||||||
if ( $issue->noteseen != 1 ) {
|
} elsif ($op eq 'cud-notseen'){
|
||||||
$status = 'failure';
|
|
||||||
}
|
|
||||||
} elsif ($op eq 'notseen'){
|
|
||||||
$issue->set({ noteseen => 0 })->store;
|
$issue->set({ noteseen => 0 })->store;
|
||||||
if ( $issue->noteseen != 0 ) {
|
|
||||||
$status = 'failure';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
my $json = to_json ( { status => $status } );
|
my $json = to_json ( { seen => $issue->noteseen } );
|
||||||
output_with_http_headers $query, undef, $json, 'js';
|
output_with_http_headers $query, undef, $json, 'js';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue