From 748ecf7608b15912adf3dbc8d22c2977530cf28a Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 7 Apr 2012 20:05:50 -0300 Subject: [PATCH] Add duplicate action. --- .../ncontroller/MindmapController.java | 8 - .../wisemapping/rest/MindmapController.java | 18 +- .../webapp/js/jquery.dataTables.plugins.js | 79 ++++++- .../src/main/webapp/jsp/mindmapList.jsp | 218 ++++++++++++------ 4 files changed, 224 insertions(+), 99 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java index 18f32c1d..e8fb2ddd 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java @@ -98,14 +98,6 @@ public class MindmapController { return view; } - @RequestMapping(value = "delete") - public ModelAndView delete(@RequestParam(required = true) long mapId, @NotNull HttpServletRequest request) throws WiseMappingException { - final User user = Utils.getUser(); - final MindMap mindmap = findMindmap(mapId); - mindmapService.removeCollaboratorFromMindmap(mindmap, user.getId()); - return list(request); - } - @RequestMapping(value = "updateMindmap") public ModelAndView updateMindmap(@RequestParam(required = true) long mapId, @RequestParam(required = true) String title, @RequestParam(required = true) String description, @NotNull HttpServletRequest request) throws WiseMappingException { final MindMap mindmap = findMindmap(mapId); 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 e202c41b..c2aef054 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -187,23 +187,15 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"}) @ResponseStatus(value = HttpStatus.CREATED) public void copyMap(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @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 searchByMap = mindmapService.getMindmapByTitle(title, user); - if (searchByMap != null) { - throw new IllegalArgumentException("Map already exists with title '" + title + "'"); - } // Create a shallowCopy of the map ... final MindMap mindMap = mindmapService.getMindmapById(id); diff --git a/wise-webapp/src/main/webapp/js/jquery.dataTables.plugins.js b/wise-webapp/src/main/webapp/js/jquery.dataTables.plugins.js index 54800b7e..eaae9ee9 100644 --- a/wise-webapp/src/main/webapp/js/jquery.dataTables.plugins.js +++ b/wise-webapp/src/main/webapp/js/jquery.dataTables.plugins.js @@ -43,20 +43,95 @@ jQuery.fn.dataTableExt.getSelectedMapsIds = function() { return ids; }; +jQuery.fn.dataTableExt.getSelectedRows = function() { + return $('.select input:checked[id!="selectAll"]').parent().parent(); +}; + jQuery.fn.dataTableExt.removeSelectedRows = function() { var mapIds = this.getSelectedMapsIds(); + var trs = this.getSelectedRows(); jQuery.ajax({ async:false, url: "../service/maps/batch?ids=" + mapIds.join(","), type:"DELETE", success : function(data, textStatus, jqXHR) { - var trs = $('.select input:checked[id!="selectAll"]').parent().parent(); trs.each(function() { $('#mindmapListTable').dataTable().fnDeleteRow(this); }); }, - error: function(){ + error: function() { alert("Unexpected error removing maps. Refresh before continue."); } }); }; + + +jQuery.fn.dialogForm = function(options) { + + var containerId = this[0].id; + var url = options.url; + var acceptButtonLabel = options.acceptButtonLabel; + + // Clean previous dialog content ... + $("#" + containerId + " div[id='errorMessage']").text("").removeClass("ui-state-highlight"); + + options.buttons = {}; + options.buttons[acceptButtonLabel] = function() { + var formData = {}; + $('#' + containerId + ' input').each(function(index, elem) { + formData[elem.name] = elem.value; + }); + + jQuery.ajax(url, { + async:false, + dataType: 'json', + data: JSON.stringify(formData), + type: options.type ? options.type : 'POST', + contentType:"application/json; charset=utf-8", + success : function(data, textStatus, jqXHR) { + if (options.redirect) { + var mapId = jqXHR.getResponseHeader("ResourceId"); + window.location = options.redirect + "&mapId=" + mapId; + } else if (options.postUpdate) { + options.postUpdate(formData); + } + $(this).dialog("close"); + }, + error: function(jqXHR, textStatus, errorThrown) { + if (jqXHR.status == 400) { + var errors = JSON.parse(jqXHR.responseText); + // Clean previous marks .... + $("#" + containerId + ' 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 = $("#" + containerId + " input[name='" + fieldName + "']"); + $(inputField).addClass("ui-state-error"); + $("#" + containerId + " div[id='errorMessage']").text(message).addClass("ui-state-highlight"); + } + + } + + } else { + alert("Unexpected error removing maps. Refresh before continue."); + } + + } + }); + }; + + var cancelButtonLabel = options.cancelButtonLabel; + options.buttons[cancelButtonLabel] = function() { + $(this).dialog("close"); + }; + + // Open the modal dialog ... + this.dialog(options); + +}; diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index a1348040..d79a6a6c 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -41,7 +41,11 @@ sClass : "columName", sTitle : "Name", bUseRendered : false, - mDataProp: "title" + mDataProp: "title", + fnRender : function(obj) { + return '' + obj.aData.title + ''; + } + }, { sTitle : "Description", @@ -157,77 +161,82 @@ } }); - $("#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({ + $("#new-dialog-modal").dialogForm({ modal: true, - buttons: { - "Create": function() { - - var formData = {}; - $('#new-dialog-modal input').each(function(index, elem) { - formData[elem.name] = elem.value; - }); - - jQuery.ajax("../service/maps", { - async:false, - dataType: 'json', - data: JSON.stringify(formData), - type: 'POST', - contentType:"application/json; charset=utf-8", - success : function(data, textStatus, jqXHR) { - var mapId = jqXHR.getResponseHeader("ResourceId"); - window.location = "c/editor.htm?action=open&mapId=" + mapId; - }, - 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() { - $(this).dialog("close"); - } - } + acceptButtonLabel : "Create", + cancelButtonLabel : "Cancel", + redirect: "c/editor.htm?action=open", + url : "../service/maps" }); }); - $("#buttons .importMap").button({ - icons: { primary: "ui-icon-trash" } - }); - $("#buttons .moreActions").button({ - icons: { primary: "ui-icon-triangle-1-s" } - }); + $("#buttons .duplicateMap").button({ + icons: { primary: "ui-icon-copy" } + }).click(function() { + // Map to be cloned ... + var tableElem = $('#mindmapListTable'); + var rows = tableElem.dataTableExt.getSelectedRows(); + if (rows.length > 0) { + + // Obtain map name ... + var rowData = tableElem.dataTable().fnGetData(rows[0]); + $('#duplicateMessage').text("Duplicate '" + rowData.title + "'"); + + // Obtains map id ... + var mapId = rowData.id; + + // Initialize dialog ... + $("#duplicate-dialog-modal").dialogForm({ + modal: true, + acceptButtonLabel : "Duplicated", + cancelButtonLabel : "Cancel", + redirect: "c/editor.htm?action=open", + url : "../service/maps/" + mapId + }); + } + }); + + $("#buttons .renameMap").button({ + icons: { primary: "ui-icon-gear" } + }).click(function() { + // Map to be cloned ... + var tableElem = $('#mindmapListTable'); + var rows = tableElem.dataTableExt.getSelectedRows(); + if (rows.length > 0) { + + // Obtain map name ... + var dataTable = tableElem.dataTable(); + var rowData = dataTable.fnGetData(rows[0]); + + // Fill dialog with default values ... + var mapId = rowData.id; + $("#rename-dialog-modal input[name='title']").attr('value', rowData.title); + $("#rename-dialog-modal input[name='description']").attr('value', rowData.description); + + // Initialize dialog ... + $("#rename-dialog-modal").dialogForm({ + modal: true, + type: 'PUT', + acceptButtonLabel : "Rename", + cancelButtonLabel : "Cancel", + postUpdate: function(reqBodyData) { + // Remove old entry ... + dataTable.fnDeleteRow(rowData); + + // Add a new one... + rowData.title = reqBodyData.title; + rowData.description = reqBodyData.description; + dataTable.fnAddData(rowData); + }, + url : "../service/maps/" + mapId + }); + } + }); + $("#buttons .delete").button({ icons: { primary: "ui-icon-trash" } @@ -250,8 +259,16 @@ }); } }); - }) - ; + + $("#buttons .importMap").button({ + icons: { primary: "ui-icon-trash" } + }); + + $("#buttons .moreActions").button({ + icons: { primary: "ui-icon-triangle-1-s" } + }); + + }); @@ -271,9 +288,37 @@ + + + + + + + + + + +
-
-

Mes dossiers:

- -
-
- -
-