Bug 36084: svc - problem_reports
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
bf3e4ec999
commit
25ea67c2ca
|
|
@ -203,52 +203,61 @@
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
function show_error(){
|
||||
// FIXME Can be improved by displaying meaningful error.
|
||||
$("#error").text(_("Unable to change status of problem report.")).show();
|
||||
}
|
||||
|
||||
$("#problemreportstable").on("click", "button.viewed, button.closed, button.new", function(event){
|
||||
event.preventDefault(); // prevent form submission
|
||||
var $action = $(this).attr("name");
|
||||
var $report_id = $(this).data('report_id');
|
||||
var ajaxData = {
|
||||
'action': $action,
|
||||
'report_id': $report_id,
|
||||
};
|
||||
var op = $(this).attr("name");
|
||||
var report_id = $(this).data('report_id');
|
||||
|
||||
$.ajax({
|
||||
url: '/cgi-bin/koha/svc/problem_reports/',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: ajaxData,
|
||||
})
|
||||
|
||||
.done(function(data){
|
||||
if (data.status == 'success'){
|
||||
if ( $action == 'viewed' ){
|
||||
$("#status_" + $report_id).text(_("Viewed"));
|
||||
const client = APIClient.ticket;
|
||||
if ( op == 'viewed' ) {
|
||||
client.tickets.mark_as_viewed(report_id).then(
|
||||
success => {
|
||||
$("#status_" + report_id).text(_("Viewed"));
|
||||
$(event.target).parent().siblings("[name='status']").removeClass().addClass("statusViewed");
|
||||
$(event.target).siblings(".closed").prop("disabled", false);
|
||||
$(event.target).siblings(".new").prop("disabled", false);
|
||||
$(event.target).prop("disabled", true);
|
||||
} else if ( $action == 'new' ){
|
||||
$("#status_" + $report_id).text(_("New"));
|
||||
$(event.target).parent().siblings("[name='status']").removeClass().addClass("statusNew");
|
||||
$(event.target).siblings(".closed").prop("disabled", false);
|
||||
$(event.target).siblings(".viewed").prop("disabled", false);
|
||||
$(event.target).prop("disabled", true);
|
||||
} else {
|
||||
$("#status_" + $report_id).text(_("Closed"));
|
||||
},
|
||||
error => {
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
show_error();
|
||||
}
|
||||
);
|
||||
} else if ( op == "closed" ) {
|
||||
client.tickets.mark_as_closed(report_id).then(
|
||||
success => {
|
||||
$("#status_" + report_id).text(_("Closed"));
|
||||
$(event.target).parent().siblings("[name='status']").removeClass().addClass("statusClosed");
|
||||
$(event.target).siblings(".viewed").prop("disabled", false);
|
||||
$(event.target).siblings(".new").prop("disabled", false);
|
||||
$(event.target).prop("disabled", true);
|
||||
},
|
||||
error => {
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
show_error();
|
||||
}
|
||||
} else {
|
||||
$("#error").text(_("Unable to change status of problem report."));
|
||||
$("#error").show();
|
||||
}
|
||||
})
|
||||
.error(function(data){
|
||||
$("#error").text(_("Unable to change status of problem report."));
|
||||
$("#error").show();
|
||||
});
|
||||
);
|
||||
} else {
|
||||
client.tickets.mark_as_new(report_id).then(
|
||||
success => {
|
||||
$("#status_" + report_id).text(_("New"));
|
||||
$(event.target).parent().siblings("[name='status']").removeClass().addClass("statusNew");
|
||||
$(event.target).siblings(".closed").prop("disabled", false);
|
||||
$(event.target).siblings(".viewed").prop("disabled", false);
|
||||
$(event.target).prop("disabled", true);
|
||||
},
|
||||
error => {
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
show_error();
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import CoverImageAPIClient from "./cover-image-api-client.js";
|
|||
import LocalizationAPIClient from "./localization-api-client.js";
|
||||
import PatronAPIClient from "./patron-api-client.js";
|
||||
import SysprefAPIClient from "./system-preferences-api-client.js";
|
||||
import TicketAPIClient from "./ticket-api-client.js";
|
||||
|
||||
export const APIClient = {
|
||||
article_request: new ArticleRequestAPIClient(),
|
||||
|
|
@ -15,5 +16,6 @@ export const APIClient = {
|
|||
cover_image: new CoverImageAPIClient(),
|
||||
localization: new LocalizationAPIClient(),
|
||||
patron: new PatronAPIClient(),
|
||||
ticket: new TicketAPIClient(),
|
||||
syspref: new SysprefAPIClient(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
import HttpClient from "./http-client.js";
|
||||
|
||||
export class TicketAPIClient extends HttpClient {
|
||||
constructor() {
|
||||
super({
|
||||
baseURL: "/cgi-bin/koha/svc/",
|
||||
});
|
||||
}
|
||||
|
||||
get tickets () {
|
||||
return {
|
||||
mark_as_viewed: ticket_id =>
|
||||
this.post({
|
||||
endpoint: "problem_reports",
|
||||
body: "report_id=%s&op=%s".format(ticket_id, "cud-viewed"),
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
}),
|
||||
mark_as_closed: ticket_id =>
|
||||
this.post({
|
||||
endpoint: "problem_reports",
|
||||
body: "report_id=%s&op=%s".format(ticket_id, "cud-closed"),
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
}),
|
||||
mark_as_new: ticket_id =>
|
||||
this.post({
|
||||
endpoint: "problem_reports",
|
||||
body: "report_id=%s&op=%s".format(ticket_id, "cud-new"),
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TicketAPIClient;
|
||||
|
|
@ -21,7 +21,6 @@ use Modern::Perl;
|
|||
|
||||
use JSON qw( to_json );
|
||||
use CGI;
|
||||
use C4::Service;
|
||||
use C4::Auth qw( check_cookie_auth );
|
||||
use C4::Output qw( is_ajax output_with_http_headers );
|
||||
use Koha::ProblemReports;
|
||||
|
|
@ -41,28 +40,18 @@ my ( $auth_status ) = check_cookie_auth( $query->cookie('CGISESSID'), { problem_
|
|||
if ( $auth_status ne "ok" ) {
|
||||
exit 0;
|
||||
}
|
||||
my $op = $query->param('op') || q{};
|
||||
if ($is_ajax) {
|
||||
my $report_id = $query->param('report_id');
|
||||
my $report = Koha::ProblemReports->find($report_id);
|
||||
my $action = $query->param('action');
|
||||
my $status = 'success';
|
||||
if ( $action eq 'viewed' ) {
|
||||
if ( $op eq 'cud-viewed' ) {
|
||||
$report->set({ status => 'Viewed' })->store;
|
||||
if ( $report->status ne 'Viewed' ) {
|
||||
$status = 'failure';
|
||||
}
|
||||
} elsif ( $action eq 'closed' ) {
|
||||
} elsif ( $op eq 'cud-closed' ) {
|
||||
$report->set({ status => 'Closed' })->store;
|
||||
if ( $report->status ne 'Closed' ) {
|
||||
$status = 'failure';
|
||||
}
|
||||
} elsif ( $action eq 'new' ) {
|
||||
} elsif ( $op eq 'cud-new' ) {
|
||||
$report->set({ status => 'New' })->store;
|
||||
if ( $report->status ne 'New' ) {
|
||||
$status = 'failure';
|
||||
}
|
||||
}
|
||||
my $json = to_json ( { status => $status } );
|
||||
my $json = to_json ( { status => $report->status } );
|
||||
output_with_http_headers $query, undef, $json, 'js';
|
||||
exit;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue