Bug 36084: svc - cover_images
Removing the ability to remove several cover images, it was not used. FIXME - Note that I am getting randomly a failure when uploading an image and seeing the following error in the log: [Wed Feb 21 10:43:59.168934 2024] [cgi:error] [pid 24037] [client 172.18.0.1:45074] AH01215: Use of uninitialized value $fileID in bitwise and (&) at /kohadevbox/koha/tools/upload-cover-image.pl line 101.: /kohadevbox/koha/tools/upload-cover-image.pl, referer: http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=1 Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
0fe82b601b
commit
374db28eee
|
|
@ -1596,26 +1596,25 @@
|
|||
var copy = thumbnail.html();
|
||||
thumbnail.find("img").css("opacity", ".2");
|
||||
thumbnail.find("a.remove").html("<img style='display:inline-block' src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' />");
|
||||
$.ajax({
|
||||
url: "/cgi-bin/koha/svc/cover_images?action=delete&imagenumber=" + imagenumber,
|
||||
success: function(data) {
|
||||
$(data).each( function(i) {
|
||||
if ( this.deleted == 1 ) {
|
||||
thumbnail.remove();
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
}
|
||||
if ( $('ul.thumbnails > li').length == 0 ) {
|
||||
showNoImageMessage();
|
||||
}
|
||||
});
|
||||
const client = APIClient.cover_image;
|
||||
client.cover_images.delete(imagenumber).then(
|
||||
success => {
|
||||
if ( success.deleted == 1 ) {
|
||||
thumbnail.remove();
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
}
|
||||
if ( $('ul.thumbnails > li').length == 0 ) {
|
||||
showNoImageMessage();
|
||||
}
|
||||
},
|
||||
error: function(data) {
|
||||
error => {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
function showNoImageMessage() {
|
||||
|
|
|
|||
|
|
@ -185,27 +185,26 @@
|
|||
thumbnail.find("img").css("opacity", ".2");
|
||||
thumbnail.find("a.remove").html("<img style='display:inline-block' src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' />");
|
||||
|
||||
$.ajax({
|
||||
url: "/cgi-bin/koha/svc/cover_images?action=delete&imagenumber=" + imagenumber,
|
||||
success: function(data) {
|
||||
$(data).each( function() {
|
||||
if ( this.deleted == 1 ) {
|
||||
if( itemnumber ) {
|
||||
location.href="/cgi-bin/koha/catalogue/imageviewer.pl?itemnumber=" + itemnumber;
|
||||
} else {
|
||||
location.href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=" + biblionumber;
|
||||
}
|
||||
const client = APIClient.cover_image;
|
||||
client.cover_images.delete(imagenumber).then(
|
||||
success => {
|
||||
if ( success.deleted == 1 ) {
|
||||
if( itemnumber ) {
|
||||
location.href="/cgi-bin/koha/catalogue/imageviewer.pl?itemnumber=" + itemnumber;
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
location.href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=" + biblionumber;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
}
|
||||
},
|
||||
error: function(data) {
|
||||
error => {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
function showCover(img) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import ArticleRequestAPIClient from "./article-request-api-client.js";
|
|||
import AVAPIClient from "./authorised-value-api-client.js";
|
||||
import CirculationAPIClient from "./circulation-api-client.js";
|
||||
import ClubAPIClient from "./club-api-client.js";
|
||||
import CoverImageAPIClient from "./cover-image-api-client.js";
|
||||
import SysprefAPIClient from "./system-preferences-api-client.js";
|
||||
|
||||
export const APIClient = {
|
||||
|
|
@ -9,5 +10,6 @@ export const APIClient = {
|
|||
authorised_value: new AVAPIClient(),
|
||||
circulation: new CirculationAPIClient(),
|
||||
club: new ClubAPIClient(),
|
||||
cover_image: new CoverImageAPIClient(),
|
||||
syspref: new SysprefAPIClient(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
import HttpClient from "./http-client.js";
|
||||
|
||||
export class CoverImageAPIClient extends HttpClient {
|
||||
constructor() {
|
||||
super({
|
||||
baseURL: "/cgi-bin/koha/svc/cover_images",
|
||||
});
|
||||
}
|
||||
|
||||
get cover_images() {
|
||||
return {
|
||||
delete: image_id =>
|
||||
this.post({
|
||||
endpoint: "",
|
||||
body: "imagenumber=%s&op=%s".format(image_id, "cud-delete"),
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default CoverImageAPIClient;
|
||||
|
|
@ -124,6 +124,7 @@ function AjaxUpload ( formData, progressbar, xtra, callback ) {
|
|||
progressbar.val( 0 );
|
||||
progressbar.next('.fileuploadpercent').text( '0' );
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader("csrf_token", $('meta[name="csrf-token"]').attr("content"));
|
||||
xhr.upload.onprogress = function (e) {
|
||||
var p = Math.round( (e.loaded/e.total) * 100 );
|
||||
progressbar.val( p );
|
||||
|
|
@ -203,23 +204,22 @@ function removeLocalImage(imagenumber) {
|
|||
thumbnail.find("img").css("opacity", ".2");
|
||||
thumbnail.find("a.remove").html("<img style='display:inline-block' src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' />");
|
||||
|
||||
$.ajax({
|
||||
url: "/cgi-bin/koha/svc/cover_images?action=delete&biblionumber=" + biblionumber + "&imagenumber=" + imagenumber,
|
||||
success: function(data) {
|
||||
$(data).each( function() {
|
||||
if ( this.deleted == 1 ) {
|
||||
location.href="/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=" + biblionumber;
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(__("An error occurred on deleting this image"));
|
||||
}
|
||||
});
|
||||
const client = APIClient.cover_image;
|
||||
client.cover_images.delete(imagenumber).then(
|
||||
success => {
|
||||
if ( success.deleted == 1 ) {
|
||||
location.href="/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=" + biblionumber;
|
||||
} else {
|
||||
thumbnail.html( copy );
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
error => {
|
||||
thumbnail.html( copy );
|
||||
alert(__("An error occurred on deleting this image"));
|
||||
alert(_("An error occurred on deleting this image"));
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
function resetForm(){
|
||||
|
|
|
|||
|
|
@ -36,33 +36,31 @@ if ( $auth_status ne "ok" ) {
|
|||
exit 0;
|
||||
}
|
||||
|
||||
my $action = $input->param('action');
|
||||
my @imagenumbers = $input->multi_param('imagenumber');
|
||||
my $op = $input->param('op') || q{};
|
||||
my $imagenumber = $input->param('imagenumber');
|
||||
|
||||
# Array to store the reponse JSON
|
||||
my $response = [];
|
||||
my $response = q{};
|
||||
|
||||
if ( $action eq "delete" ) {
|
||||
if ( $op eq "cud-delete" ) {
|
||||
|
||||
foreach my $imagenumber ( @imagenumbers ) {
|
||||
eval {
|
||||
Koha::CoverImages->find($imagenumber)->delete;
|
||||
eval {
|
||||
Koha::CoverImages->find($imagenumber)->delete;
|
||||
};
|
||||
if ( $@ ) {
|
||||
$response = {
|
||||
imagenumber => $imagenumber,
|
||||
deleted => 0,
|
||||
error => "MSG_INVALID_IMAGENUMBER"
|
||||
};
|
||||
} else {
|
||||
$response = {
|
||||
imagenumber => $imagenumber,
|
||||
deleted => 1
|
||||
};
|
||||
if ( $@ ) {
|
||||
push @$response, {
|
||||
imagenumber => $imagenumber,
|
||||
deleted => 0,
|
||||
error => "MSG_INVALID_IMAGENUMBER"
|
||||
};
|
||||
} else {
|
||||
push @$response, {
|
||||
imagenumber => $imagenumber,
|
||||
deleted => 1
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# invalid action
|
||||
# FIXME be nicer!
|
||||
# invalid op
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue