From e5d93806998294e3b38e5a89e6647b02cd1833a5 Mon Sep 17 00:00:00 2001 From: Ezequiel Bergamaschi Date: Sat, 1 Feb 2014 16:24:48 -0300 Subject: [PATCH] change linkToMindmaps logic --- .../com/wisemapping/rest/LabelController.java | 14 +++-- .../src/main/webapp/js/buttonActions.js | 60 +++++++++---------- .../src/main/webapp/js/labelActions.js | 15 +++++ .../src/main/webapp/jsp/mindmapList.jsp | 4 +- 4 files changed, 54 insertions(+), 39 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/LabelController.java b/wise-webapp/src/main/java/com/wisemapping/rest/LabelController.java index d782d154..96af9697 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/LabelController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/LabelController.java @@ -67,13 +67,17 @@ public class LabelController extends BaseController { return new RestLabelList(all); } - @RequestMapping(method = RequestMethod.PUT, value = "/labels/maps", consumes = {"application/json"}) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void linkToMindMaps(@RequestBody RestLabel restLabel, @RequestParam(required = true) String ids) throws WiseMappingException { + @RequestMapping(method = RequestMethod.POST, value = "/labels/maps", consumes = {"application/json"}) + @ResponseStatus(value = HttpStatus.ACCEPTED) + public void linkToMindMaps(@RequestBody RestLabel restLabel, @RequestParam(required = true) String ids, @NotNull HttpServletResponse response) throws WiseMappingException { int id = restLabel.getId(); - final Label label = labelService.getLabelById(id); + Label label = labelService.getLabelById(id); if (label == null) { - throw new LabelCouldNotFoundException("Label could not be found. Id: " + id); + // create label.. + validate(restLabel); + createLabel(restLabel); + label = restLabel.getDelegated(); + response.setHeader("ResourceId", Integer.toString(label.getId())); } for (String mindmapId : ids.split(",")) { final Mindmap mindmap = mindmapService.findMindmapById(Integer.parseInt(mindmapId)); diff --git a/wise-webapp/src/main/webapp/js/buttonActions.js b/wise-webapp/src/main/webapp/js/buttonActions.js index 03186a34..a58d0824 100644 --- a/wise-webapp/src/main/webapp/js/buttonActions.js +++ b/wise-webapp/src/main/webapp/js/buttonActions.js @@ -11,9 +11,13 @@ $(function () { $(document).on('click', '#createLabelBtn', function () { + var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); $("#new-folder-dialog-modal").dialogForm({ - url:"c/restful/labels", - postUpdate: createLabelItem + url:"c/restful/labels/maps?ids=" + jQuery.makeArray(mapIds).join(','), + postUpdate: function(data, id) { + createLabelItem(data, id); + tagMindmaps(data.title, data.color); + } }); } ); @@ -35,39 +39,38 @@ $(function () { //append items to dropdown $.each(labels, function(index, value) { labelList.append( - $('
  • ') + //aca jay codigo repetido + $('
  • ').attr('value', value.id).attr('color', value.color) .append('' + - '' + - ''+ value.title + - '' + - '')); + "
    " + + "
    " + value.title + "
    " + + + '')); }); //add the defaultValue - labelList.append('
  • ') + labelList.append('
  • ') labelList.append(defaultValue); var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); - $("#add-label-dialog-modal").dialogForm({ - type:'PUT', - url:"c/restful/labels/maps?ids=" + jQuery.makeArray(mapIds).join(','), - postUpdate: function() { - //tag selected mindmaps... - var rows = $('#mindmapListTable').dataTableExt.getSelectedRows(); - for (var i = 0; i < rows.length; i++) { - var labelName = $(':selected', labelList).text(); - if ($(rows[i]).find('\'.labelTag:contains("' + labelName + '")\'').length == 0) { - $(rows[i]).find('.mindmapName').append( - labelTagsAsHtml([{ - title: labelName, - color: $(':selected', labelList).attr('color') - }]) - ) - } + $(document).one('click', '.chooseLabel', + function () { + var labelId = $(this).attr('value'); + var labelName = $(this).text(); + var labelColor = $(this).attr('color'); + + jQuery.ajax("c/restful/labels/maps?ids=" + jQuery.makeArray(mapIds).join(','), { + type:'POST', + dataType: "json", + contentType:"application/json; charset=utf-8", + data: JSON.stringify({id: labelId}), + success: function() { + tagMindmaps(labelName, labelColor); } + }); } - }); + ); } }); @@ -246,10 +249,3 @@ $(function () { }); }) }); - -function reloadTable() { - // Reload the table data ... - var dataTable = $('#mindmapListTable').dataTable(); - dataTable.fnReloadAjax("c/restful/maps/?q=" + $(this).attr('data-filter'), callbackOnTableInit, true); - event.preventDefault(); -} diff --git a/wise-webapp/src/main/webapp/js/labelActions.js b/wise-webapp/src/main/webapp/js/labelActions.js index 2bc3c8f4..1188a024 100644 --- a/wise-webapp/src/main/webapp/js/labelActions.js +++ b/wise-webapp/src/main/webapp/js/labelActions.js @@ -36,3 +36,18 @@ function fetchLabels(options) { } }); } + +function tagMindmaps(labelName, labelColor) { + //tag selected mindmaps... + var rows = $('#mindmapListTable').dataTableExt.getSelectedRows(); + for (var i = 0; i < rows.length; i++) { + if ($(rows[i]).find('\'.labelTag:contains("' + labelName + '")\'').length == 0) { + $(rows[i]).find('.mindmapName').append( + labelTagsAsHtml([{ + title: labelName, + color: labelColor + }]) + ) + } + } +} diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index e1a79171..4ee146e9 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -195,8 +195,8 @@ -