diff --git a/mindplot/src/main/javascript/RestPersistenceManager.js b/mindplot/src/main/javascript/RestPersistenceManager.js index a270cb05..34ded5e4 100644 --- a/mindplot/src/main/javascript/RestPersistenceManager.js +++ b/mindplot/src/main/javascript/RestPersistenceManager.js @@ -33,7 +33,7 @@ mindplot.RESTPersistenceManager = new Class({ }; var request = new Request({ - url:this.saveUrl + mapId + "?minor=" + !saveHistory, + url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory, method: 'put', onSuccess:function(responseText, responseXML) { events.onSuccess(); 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 076ed514..d1d5ea94 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -54,9 +54,9 @@ public class MindmapController extends BaseController { return new ModelAndView("mapsView", "list", restMindmapList); } - @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) + @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void updateMap(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException { + public void updateDocument(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException { final MindMap mindMap = mindmapService.getMindmapById(id); final User user = Utils.getUser(); @@ -79,6 +79,58 @@ public class MindmapController extends BaseController { updateMindmap(minor, mindMap, user); } + + /** + * The intention of this method is the update of several properties at once ... + */ + @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void updateMap(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException { + + final MindMap mindMap = mindmapService.getMindmapById(id); + final User user = Utils.getUser(); + + // Update document properties ... + final String properties = restMindmap.getProperties(); + if (properties != null) { + mindMap.setProperties(properties); + } + final String xml = restMindmap.getXml(); + if (xml != null) { + mindMap.setXmlStr(xml); + } + + // Update title ... + final String title = restMindmap.getTitle(); + if (title != null && !title.equals(mindMap.getTitle())) { + if (mindmapService.getMindmapByTitle(title, user) != null) { + throw buildValidationException("title", "You already have a map with this title"); + } + mindMap.setTitle(title); + } + + // Update description ... + final String description = restMindmap.getDescription(); + if (description != null) { + mindMap.setDescription(description); + } + + final String tags = restMindmap.getTags(); + if (tags != null) { + mindMap.setTags(tags); + } + + // Update map ... + updateMindmap(minor, mindMap, user); + } + + private ValidationException buildValidationException(@NotNull String fieldName, @NotNull String message) throws ValidationException { + final BindingResult result = new BeanPropertyBindingResult(new RestMindmap(), ""); + result.rejectValue(fieldName, "error.not-specified", null, message); + return new ValidationException(result); + } + + @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/title", consumes = {"text/plain"}, produces = {"application/json", "text/html", "application/xml"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void changeMapTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException { @@ -88,7 +140,8 @@ public class MindmapController extends BaseController { // Is there a map with the same name ? if (mindmapService.getMindmapByTitle(title, user) != null) { - throw new IllegalArgumentException("Map already exists with this title"); + + throw buildValidationException("title", "You already have a mindmap with this title"); } // Update map ... @@ -129,7 +182,7 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}") @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void updateMap( @PathVariable int id) throws IOException, WiseMappingException { + public void updateMap(@PathVariable int id) throws IOException, WiseMappingException { final User user = Utils.getUser(); final MindMap mindmap = mindmapService.getMindmapById(id); mindmapService.removeMindmap(mindmap, user); 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 ae6a9f4f..70a6b064 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/classes/messages.properties @@ -224,6 +224,7 @@ COLOR=Color SHARE=Share UNEXPECTED_ERROR=Outch!!. An unexpected error has occurred. UNEXPECTED_ERROR_DETAILS=We're sorry, an error has occurred and we can't process your request. Please try again, or go to the home page. +UNEXPECTED_ERROR_SERVER_ERROR=We're sorry, an error has occurred and we can't process your request. Refresh the page and try again. If the problem persist, contact the administrator. NO_ENOUGH_PERMISSIONS=Outch!!. This map is not available anymore. NO_ENOUGH_PERMISSIONS_DETAILS=You do not have enough right access to see this map. This map has been changed to private or deleted. SHARING=Sharing diff --git a/wise-webapp/src/main/webapp/js/mymaps.js b/wise-webapp/src/main/webapp/js/mymaps.js index 33460bfe..c6dfbbd0 100644 --- a/wise-webapp/src/main/webapp/js/mymaps.js +++ b/wise-webapp/src/main/webapp/js/mymaps.js @@ -53,6 +53,7 @@ jQuery.fn.dataTableExt.removeSelectedRows = function() { trs.each(function() { $('#mindmapListTable').dataTable().fnDeleteRow(this); }); + updateStatus(); }; @@ -62,18 +63,24 @@ jQuery.fn.dialogForm = function(options) { var url = options.url; // Clear previous state ... - $("#" + containerId + " .errorMessage").text("").removeClass("alert alert-error"); - $("#" + containerId + " .control-group").removeClass('error'); - $("#" + containerId + " input").attr('value', ''); + $("#" + containerId).find('.errorMessage').text("").removeClass("alert alert-error"); + $("#" + containerId).find('.control-group').removeClass('error'); + // Clear form values ... + if (options.clearForm == undefined || options.clearForm) { + $("#" + containerId).find('input').attr('value', ''); + } + // Reset button state ... var acceptBtn = $('#' + containerId + ' .btn-accept'); + acceptBtn.button('reset'); + acceptBtn.click(function() { var formData = {}; $('#' + containerId + ' input').each(function(index, elem) { formData[elem.name] = elem.value; }); - + $(acceptBtn).button('loading'); var dialogElem = this; jQuery.ajax(url, { async:false, @@ -86,7 +93,6 @@ jQuery.fn.dialogForm = function(options) { var resourceId = jqXHR.getResponseHeader("ResourceId"); var redirectUrl = options.redirect; redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId); - $(acceptBtn).button('loading'); window.location = redirectUrl; } else if (options.postUpdate) { @@ -105,14 +111,18 @@ jQuery.fn.dialogForm = function(options) { var message = fieldErrors[fieldName]; var inputField = $("#" + containerId + " input[name='" + fieldName + "']"); - $("#" + containerId + " .errorMessage").text(message).addClass("alert alert-error"); + $("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error"); inputField.parent().addClass('error'); } } } else { - alert("Unexpected error removing maps. Refresh before continue."); + console.log(errorThrown); + console.log(jqXHR); + + dialogElem.modal('hide'); + $('#messagesPanel div').text(errorThrown).parent().show(); } } @@ -136,22 +146,19 @@ function updateStatus() { $("#mindmapListTable tbody input:checked").parent().parent().addClass('row-selected'); $("#mindmapListTable tbody input:not(:checked)").parent().parent().removeClass('row-selected'); - $("#buttonsToolbar .act-multiple").hide(); - $("#buttonsToolbar .act-single").hide(); + $('#buttonsToolbar').find('.act-single').hide().end().find('.act-multiple').hide(); var tableElem = $('#mindmapListTable'); var selectedRows = tableElem.dataTableExt.getSelectedRows(); if (selectedRows.length > 0) { if (selectedRows.length == 1) { - $("#buttonsToolbar .act-single").show(); - $("#buttonsToolbar .act-multiple").show(); + $('#buttonsToolbar').find('.act-single').show().end().find('.act-multiple').show(); // Can be executed by the owner ? var rowData = tableElem.dataTable().fnGetData(selectedRows[0]); if (rowData.ownerEmail != principalEmail) { - $("#buttonsToolbar #publishBtn").hide(); - $("#buttonsToolbar #shareBtn").hide(); + $("#buttonsToolbar").find('#publishBtn').hide().end().find('#shareBtn').hide(); } } else { $("#buttonsToolbar .act-multiple").show(); diff --git a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp index e7f1609a..63e8599c 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp @@ -37,7 +37,7 @@ // Configure designer options ... var options = loadDesignerOptions(); - options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/"); + options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document"); var userOptions = ${mindmap.properties}; options.zoom = userOptions.zoom; diff --git a/wise-webapp/src/main/webapp/jsp/mindmapImport.jsp b/wise-webapp/src/main/webapp/jsp/mindmapImport.jsp index dc2a41b0..bd985446 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapImport.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapImport.jsp @@ -4,7 +4,6 @@ diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index d6a64389..9f642aca 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -78,7 +78,7 @@ oLanguage : { "sSearch" : "", "sInfo" : "_START_-_END_ of _TOTAL_", - "sEmptyTable": "Hey, you don't have any mindmap. Go head and create one clicking the 'New' button !!!" + "sEmptyTable": "Hey, you don't have any mindmap. Go ahead and create one clicking on the 'New' button !!!" }, bStateSave:true }); @@ -167,16 +167,15 @@ // Initialize dialog ... $("#rename-dialog-modal").dialogForm({ type: 'PUT', + clearForm: false, postUpdate: function(reqBodyData) { - // Remove old entry ... - dataTable.fnDeleteRow(rowData); + tableElem.dataTableExt.removeSelectedRows(); - // Add a new one... rowData.title = reqBodyData.title; rowData.description = reqBodyData.description; - dataTable.fnAddData(rowData); + dataTable.fnAddData(JSON.parse(JSON.stringify(rowData))); }, - url : "../service/maps/" + mapId + "/title" + url : "../service/maps/" + mapId }); } }); @@ -251,201 +250,207 @@
- - - - + + + + +
+
+ -
-
- -
- - -
- - - - - - -
-
- - -
-
-
-
- -
- - - - - - - - -
- - - - - - - - - - -
-
- * : @@ -34,8 +33,8 @@
  - " class="btn-primary"> - " class="btn-secondary" + " class="btn btn-primary"> + " class="btn" onclick="window.location='/c/mymaps.htm'">
- -
-
- +

+
- +
+ +
+ + +
+ + + + + + +
+
+ + +
+
+
+
+ +
+ + + + + + + + +
+ + + + + + + + + + +
+ + +
+
+
+ + + diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java index 73bfc063..6a6adad5 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java @@ -219,7 +219,7 @@ public class RestMindmapTCase { mapToUpdate.setProperties("{zoom:x}"); // Update map ... - final String resourceUrl = HOST_PORT + resourceUri.toString(); + final String resourceUrl = HOST_PORT + resourceUri.toString() + "/document"; requestHeaders.setContentType(MediaType.APPLICATION_XML); final HttpEntity updateEntity = new HttpEntity(mapToUpdate, requestHeaders); template.put(resourceUrl, updateEntity);