Abort editing an image if title is empty.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 15 Sep 2014 19:46:31 +0000 (21:46 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Sep 2014 15:02:34 +0000 (17:02 +0200)
src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java
src/main/resources/templates/imageBrowser.html

index 0c45225..79de200 100644 (file)
@@ -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();
index da8d032..fd0296d 100644 (file)
                                                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;
                                        });