From 3da0eec8429231a741cdb5a89209a3d6941ce9e6 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 7 Apr 2012 12:45:35 -0300 Subject: [PATCH] Add error report for fields on new map. Display error messages --- .../controller/NewMindmapController.java | 61 ---------------- .../com/wisemapping/rest/AdminController.java | 19 ++++- .../com/wisemapping/rest/BaseController.java | 34 ++++++++- .../wisemapping/rest/MindmapController.java | 23 +++--- .../rest/TransformerController.java | 18 +++++ .../wisemapping/rest/ValidationException.java | 37 ++++++++++ .../wisemapping/rest/model/RestErrors.java | 70 +++++++++++++++++++ .../rest/view/ImportTransformationView.java | 19 ++++- .../wisemapping/rest/view/TransformView.java | 19 ++++- .../validator/MapInfoValidator.java | 16 +++-- .../WEB-INF/classes/messages.properties | 2 +- .../main/webapp/WEB-INF/defs/definitions.xml | 12 ---- .../main/webapp/WEB-INF/wisemapping-rest.xml | 11 +++ .../webapp/WEB-INF/wisemapping-servlet.xml | 19 +---- wise-webapp/src/main/webapp/jsp/init.jsp | 1 - .../src/main/webapp/jsp/mindmapList.jsp | 44 ++++++++++-- wise-webapp/src/main/webapp/jsp/newMap.jsp | 49 ------------- .../src/main/webapp/jsp/newMapError.jsp | 11 --- wise-webapp/src/main/webapp/jsp/template.jsp | 4 -- .../test/rest/RestMindmapTCase.java | 28 ++++++++ 20 files changed, 311 insertions(+), 186 deletions(-) delete mode 100644 wise-webapp/src/main/java/com/wisemapping/controller/NewMindmapController.java create mode 100644 wise-webapp/src/main/java/com/wisemapping/rest/ValidationException.java create mode 100644 wise-webapp/src/main/java/com/wisemapping/rest/model/RestErrors.java delete mode 100644 wise-webapp/src/main/webapp/jsp/newMap.jsp delete mode 100644 wise-webapp/src/main/webapp/jsp/newMapError.jsp diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/NewMindmapController.java b/wise-webapp/src/main/java/com/wisemapping/controller/NewMindmapController.java deleted file mode 100644 index 49fb469b..00000000 --- a/wise-webapp/src/main/java/com/wisemapping/controller/NewMindmapController.java +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Copyright [2011] [wisemapping] -* -* Licensed under WiseMapping Public License, Version 1.0 (the "License"). -* It is basically the Apache License, Version 2.0 (the "License") plus the -* "powered by wisemapping" text requirement on every single page; -* you may not use this file except in compliance with the License. -* You may obtain a copy of the license at -* -* http://www.wisemapping.org/license -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package com.wisemapping.controller; - -import com.wisemapping.exceptions.WiseMappingException; -import com.wisemapping.model.MindMap; -import com.wisemapping.model.User; -import com.wisemapping.security.Utils; -import com.wisemapping.service.MindmapService; -import com.wisemapping.view.MindMapInfoBean; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class NewMindmapController - extends BaseSimpleFormController { - - public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) - throws ServletException, WiseMappingException, IOException { - final MindMapInfoBean bean = (MindMapInfoBean) command; - - final String title = bean.getTitle(); - final String description = bean.getDescription(); - - final User user = Utils.getUser(); - final MindmapService service = getMindmapService(); - - // The map has not been created. Create a new one ... - MindMap mindmap = new MindMap(); - mindmap.setDescription(description); - mindmap.setTitle(title); - mindmap.setOwner(user); - - final String xml = MindMap.getDefaultMindmapXml(title); - mindmap.setXmlStr(xml); - - service.addMindmap(mindmap, user); - - return new ModelAndView("redirect:editor.htm?mapId=" + mindmap.getId() + "&action=open"); - } -} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java index 8b9e47b3..c4c89c96 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java @@ -1,5 +1,22 @@ -package com.wisemapping.rest; +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.wisemapping.rest; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.model.User; diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java index ecdfa21d..0fe7672b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java @@ -1,7 +1,27 @@ +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + package com.wisemapping.rest; - +import com.wisemapping.rest.model.RestErrors; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -9,6 +29,9 @@ import org.springframework.web.bind.annotation.ResponseStatus; public class BaseController { + @Autowired + private ResourceBundleMessageSource messageSource; + @ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody @@ -22,7 +45,14 @@ public class BaseController { @ResponseBody public String handleServerErrors(@NotNull Exception ex) { ex.printStackTrace(); -// LOGGER.error(ex.getMessage(), ex); return ex.getMessage(); } + + @ExceptionHandler(ValidationException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public RestErrors handleValidationErrors(@NotNull ValidationException ex) { + return new RestErrors(ex.getErrors(),messageSource); + } + + } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index ca79fd7b..e202c41b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -10,10 +10,13 @@ import com.wisemapping.rest.model.RestMindmapInfo; import com.wisemapping.rest.model.RestMindmapList; import com.wisemapping.security.Utils; import com.wisemapping.service.MindmapService; +import com.wisemapping.validator.MapInfoValidator; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @@ -154,22 +157,15 @@ public class MindmapController extends BaseController { @ResponseStatus(value = HttpStatus.CREATED) public void createMap(@RequestBody RestMindmap restMindmap, @NotNull HttpServletResponse response) throws IOException, WiseMappingException { - final String title = restMindmap.getTitle(); - if (title == null || title.isEmpty()) { - throw new IllegalArgumentException("Map title can not be null"); - } - - final String description = restMindmap.getDescription(); - if (description == null || description.isEmpty()) { - throw new IllegalArgumentException("Map details can not be null"); + // Validate ... + final BindingResult result = new BeanPropertyBindingResult(restMindmap, ""); + new MapInfoValidator(mindmapService).validate(restMindmap.getDelegated(), result); + if (result.hasErrors()) { + throw new ValidationException(result); } // Some basic validations ... final User user = Utils.getUser(); - final MindMap mindMap = mindmapService.getMindmapByTitle(title, user); - if (mindMap != null) { - throw new IllegalArgumentException("Map already exists with title '" + title + "'"); - } // If the user has not specified the xml content, add one ... final MindMap delegated = restMindmap.getDelegated(); @@ -186,7 +182,6 @@ public class MindmapController extends BaseController { // Return the new created map ... response.setHeader("Location", "/service/maps/" + delegated.getId()); response.setHeader("ResourceId", Integer.toString(delegated.getId())); - } @RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"}) @@ -222,8 +217,8 @@ public class MindmapController extends BaseController { // Return the new created map ... response.setHeader("Location", "/service/maps/" + clonedMap.getId()); + response.setHeader("ResourceId", Integer.toString(clonedMap.getId())); } - } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/TransformerController.java b/wise-webapp/src/main/java/com/wisemapping/rest/TransformerController.java index 8221ab5e..a7b7d548 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/TransformerController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/TransformerController.java @@ -1,3 +1,21 @@ +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + package com.wisemapping.rest; diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/ValidationException.java b/wise-webapp/src/main/java/com/wisemapping/rest/ValidationException.java new file mode 100644 index 00000000..4016ccd7 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/rest/ValidationException.java @@ -0,0 +1,37 @@ +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.wisemapping.rest; + + +import com.wisemapping.exceptions.WiseMappingException; +import org.jetbrains.annotations.NotNull; +import org.springframework.validation.Errors; + +public class ValidationException extends WiseMappingException{ + private Errors errors; + + public ValidationException(@NotNull Errors errors) { + super("Validation Exceptions"); + this.errors = errors; + } + + public Errors getErrors() { + return errors; + } +} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestErrors.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestErrors.java new file mode 100644 index 00000000..b07ae67b --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestErrors.java @@ -0,0 +1,70 @@ +package com.wisemapping.rest.model; + + +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnore; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.jetbrains.annotations.NotNull; +import org.springframework.context.MessageSource; +import org.springframework.validation.Errors; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.*; + +@XmlRootElement(name = "errors") +@XmlAccessorType(XmlAccessType.PROPERTY) +@JsonAutoDetect( + fieldVisibility = JsonAutoDetect.Visibility.NONE, + setterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, + isGetterVisibility = JsonAutoDetect.Visibility.NONE, + getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY +) +@JsonIgnoreProperties(ignoreUnknown = true) +public class RestErrors { + @JsonIgnore + private Errors errors; + @JsonIgnore + MessageSource messageSource; + + public RestErrors() { + + } + + public RestErrors(@NotNull Errors errors, @NotNull MessageSource messageSource) { + + this.errors = errors; + this.messageSource = messageSource; + } + + public List getGlobalErrors() { + final List result = new ArrayList(); + final List globalErrors = errors.getGlobalErrors(); + for (ObjectError globalError : globalErrors) { + result.add(globalError.getObjectName()); + } + return result; + } + + public void setGlobalErrors(List list) { + // Implemented only for XML serialization contract ... + } + + public Map getFieldErrors() { + final Map result = new HashMap(); + final List fieldErrors = errors.getFieldErrors(); + for (FieldError fieldError : fieldErrors) { + result.put(fieldError.getField(), messageSource.getMessage(fieldError, Locale.ENGLISH)); + } + return result; + } + + public void setFieldErrors(Map fieldErrors) { + // Implemented only for XML serialization contract ... + } + + +} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/view/ImportTransformationView.java b/wise-webapp/src/main/java/com/wisemapping/rest/view/ImportTransformationView.java index 31e290c4..ce3eb955 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/view/ImportTransformationView.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/view/ImportTransformationView.java @@ -1,5 +1,22 @@ -package com.wisemapping.rest.view; +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.wisemapping.rest.view; import com.wisemapping.importer.ImportFormat; import com.wisemapping.importer.Importer; diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java b/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java index 2ec1c1b1..0d62fc2c 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java @@ -1,5 +1,22 @@ -package com.wisemapping.rest.view; +/* +* Copyright [2011] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.wisemapping.rest.view; import com.wisemapping.exporter.ExportFormat; import com.wisemapping.exporter.ExportProperties; diff --git a/wise-webapp/src/main/java/com/wisemapping/validator/MapInfoValidator.java b/wise-webapp/src/main/java/com/wisemapping/validator/MapInfoValidator.java index a517b056..f792450b 100755 --- a/wise-webapp/src/main/java/com/wisemapping/validator/MapInfoValidator.java +++ b/wise-webapp/src/main/java/com/wisemapping/validator/MapInfoValidator.java @@ -24,6 +24,7 @@ import com.wisemapping.model.User; import com.wisemapping.model.Constants; import com.wisemapping.service.MindmapService; import com.wisemapping.view.MindMapInfoBean; +import org.jetbrains.annotations.NotNull; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; @@ -37,8 +38,16 @@ public class MapInfoValidator implements Validator { return clazz.equals(MindMapInfoBean.class); } - public void validate(Object obj, Errors errors) { - final MindMapInfoBean map = (MindMapInfoBean) obj; + public MapInfoValidator() { + + } + + public MapInfoValidator(@NotNull MindmapService service) { + this.mindmapService = service; + } + + public void validate(Object obj, @NotNull Errors errors) { + final MindMap map = (MindMap) obj; if (map == null) { errors.rejectValue("map", "error.not-specified", null, "Value required."); } else { @@ -53,9 +62,8 @@ public class MapInfoValidator implements Validator { new Object[]{Constants.MAX_MAP_NAME_LENGTH}, "The title must have less than " + Constants.MAX_MAP_NAME_LENGTH + " characters."); } else { - // Map alredy exists ? + // Map already exists ? final MindmapService service = this.getMindmapService(); - final User user = com.wisemapping.security.Utils.getUser(); final MindMap mindMap = service.getMindmapByTitle(title, user); if (mindMap != null) { diff --git a/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties b/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties index 307fc8ac..51e57c9d 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties @@ -245,7 +245,7 @@ IMPORT_MINDMAP_INFO=You can import FreeMind 0.9 version maps to WiseMapping. Ple PRINT=Print FREE_MIND_FILE=FreeMind File IMPORT_MAP_ERROR=FreeMind file could not be imported. {0} -MAP_TITLE_ALREADY_EXISTS=Map name already exists. +MAP_TITLE_ALREADY_EXISTS=A map already exists with this name. EMBEDDED_VIEWER=Embed a map viewer in your own web site, blog or post! EMBEDDED_VIEWER_MESSAGE=Once you make your map public, you will be able to embed a mind map viewer in your own web site, blog or post just as we did it here!
Try it!!, you can drag nodes, pan the map, and zoom in and out. FREEMIND_EXPORT_IMPORT=Import and Export maps from/to FreeMind diff --git a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml index 40fb68f3..c6b3d7b1 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml @@ -109,18 +109,6 @@ - - - - - - - - - - - - diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml index 52e6ba3e..892b65da 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml @@ -22,6 +22,7 @@ com.wisemapping.rest.model.RestMindmapInfo com.wisemapping.rest.model.RestMindmapList com.wisemapping.rest.model.RestUser + com.wisemapping.rest.model.RestErrors @@ -88,4 +89,14 @@ + + + + + + messages + + + + \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml index 2369b033..ab801839 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml @@ -134,10 +134,6 @@ - - - - @@ -159,19 +155,7 @@ - - - - - - - - - - - - - + @@ -254,7 +238,6 @@ embeddedView renameMapController importMapController - newMapController historyController homeController diff --git a/wise-webapp/src/main/webapp/jsp/init.jsp b/wise-webapp/src/main/webapp/jsp/init.jsp index 5b2df322..fd3a9545 100644 --- a/wise-webapp/src/main/webapp/jsp/init.jsp +++ b/wise-webapp/src/main/webapp/jsp/init.jsp @@ -5,7 +5,6 @@ <%@ page session="false" contentType="text/html;charset=UTF-8" %> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> -<%--<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>--%> <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <% diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index 2d0e4a70..a1348040 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -161,10 +161,14 @@ $("#buttons .newMap").button({ icons: { primary: "ui-icon-circle-plus" } }).click(function() { + // Clean previous dialog content ... + $("#new-dialog-modal div[id='errorMessage']").text("").removeClass("ui-state-highlight"); + $("#new-dialog-modal").dialog({ modal: true, buttons: { "Create": function() { + var formData = {}; $('#new-dialog-modal input').each(function(index, elem) { formData[elem.name] = elem.value; @@ -180,12 +184,37 @@ var mapId = jqXHR.getResponseHeader("ResourceId"); window.location = "c/editor.htm?action=open&mapId=" + mapId; }, - error: function() { - alert("Unexpected error removing maps. Refresh before continue."); + error: function(jqXHR, textStatus, errorThrown) { + if (jqXHR.status == 400) { + var errors = JSON.parse(jqXHR.responseText); + // Clean previous marks .... + $('#new-dialog-modal input').each(function(index, elem) { + $(elem).removeClass("ui-state-error"); + }); + + // Mark fields with errors ... + var fieldErrors = errors.fieldErrors; + if (fieldErrors) { + for (var fieldName in fieldErrors) { + // Mark the field ... + var message = fieldErrors[fieldName]; + var inputField = $("#new-dialog-modal input[name='" + fieldName + "']"); + $(inputField).addClass("ui-state-error"); + + + $("#new-dialog-modal div[id='errorMessage']").text(message).addClass("ui-state-highlight"); + } + + } + + } else { + alert("Unexpected error removing maps. Refresh before continue."); + } + } }); }, - Cancel: function() { + Cancel:function() { $(this).dialog("close"); } } @@ -221,7 +250,8 @@ }); } }); - }); + }) + ; @@ -241,7 +271,9 @@ -