From 4a77cd97e1659f82384c8478d1788a993400aebb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 15 Sep 2014 21:46:31 +0200 Subject: [PATCH] Abort editing an image if title is empty. --- .../sone/web/ajax/EditImageAjaxPage.java | 3 +++ src/main/resources/templates/imageBrowser.html | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java index 0c45225..79de200 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java @@ -77,6 +77,9 @@ public class EditImageAjaxPage extends JsonPage { return createSuccessJsonObject().put("sourceImageId", image.getId()).put("destinationImageId", swappedImage.getId()); } String title = request.getHttpRequest().getParam("title").trim(); + if (title.isEmpty()) { + return createErrorJsonObject("invalid-image-title"); + } String description = request.getHttpRequest().getParam("description").trim(); image.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update(); webInterface.getCore().touchConfiguration(); diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index da8d032..fd0296d 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -116,13 +116,20 @@ title = $(":input[name='title']:enabled", this.form).val(); description = $(":input[name='description']:enabled", this.form).val(); ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "title": title, "description": description }, function(data) { - if (data && data.success) { - getImage(data.imageId).find(".image-title").text(data.title); - getImage(data.imageId).find(".image-description").html(data.parsedDescription); - getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title); - getImage(data.imageId).find(":input[name='description']").attr("defaultValue", data.description); + var imageElement = getImage(data.imageId); + var imageTitleInput = imageElement.find(":input[name='title']"); + var imageDescriptionInput = imageElement.find(":input[name='description']"); + if (data && data.success) { + imageElement.find(".image-title").text(data.title); + imageElement.find(".image-description").html(data.parsedDescription); + imageTitleInput.attr("defaultValue", data.title); + imageDescriptionInput.attr("defaultValue", data.description); cancelImageEditing(); - } + } else if (data && !data.success) { + imageTitleInput.attr("value", imageTitleInput.attr("defaultValue")); + imageDescriptionInput.attr("value", imageDescriptionInput.attr("defaultValue")); + cancelImageEditing(); + } }); return false; }); -- 2.7.4