Rename and delete actions working ...

This commit is contained in:
Paulo Gustavo Veiga 2012-05-23 20:05:16 -03:00
parent 391c523b43
commit 5498c681a4
8 changed files with 284 additions and 219 deletions

View File

@ -33,7 +33,7 @@ mindplot.RESTPersistenceManager = new Class({
}; };
var request = new Request({ var request = new Request({
url:this.saveUrl + mapId + "?minor=" + !saveHistory, url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory,
method: 'put', method: 'put',
onSuccess:function(responseText, responseXML) { onSuccess:function(responseText, responseXML) {
events.onSuccess(); events.onSuccess();

View File

@ -54,9 +54,9 @@ public class MindmapController extends BaseController {
return new ModelAndView("mapsView", "list", restMindmapList); 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) @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 MindMap mindMap = mindmapService.getMindmapById(id);
final User user = Utils.getUser(); final User user = Utils.getUser();
@ -79,6 +79,58 @@ public class MindmapController extends BaseController {
updateMindmap(minor, mindMap, user); 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"}) @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/title", consumes = {"text/plain"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT) @ResponseStatus(value = HttpStatus.NO_CONTENT)
public void changeMapTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException { 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 ? // Is there a map with the same name ?
if (mindmapService.getMindmapByTitle(title, user) != null) { 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 ... // Update map ...
@ -129,7 +182,7 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}") @RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT) @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 User user = Utils.getUser();
final MindMap mindmap = mindmapService.getMindmapById(id); final MindMap mindmap = mindmapService.getMindmapById(id);
mindmapService.removeMindmap(mindmap, user); mindmapService.removeMindmap(mindmap, user);

View File

@ -224,6 +224,7 @@ COLOR=Color
SHARE=Share SHARE=Share
UNEXPECTED_ERROR=Outch!!. An unexpected error has occurred. 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_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=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. 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 SHARING=Sharing

View File

@ -53,6 +53,7 @@ jQuery.fn.dataTableExt.removeSelectedRows = function() {
trs.each(function() { trs.each(function() {
$('#mindmapListTable').dataTable().fnDeleteRow(this); $('#mindmapListTable').dataTable().fnDeleteRow(this);
}); });
updateStatus();
}; };
@ -62,18 +63,24 @@ jQuery.fn.dialogForm = function(options) {
var url = options.url; var url = options.url;
// Clear previous state ... // Clear previous state ...
$("#" + containerId + " .errorMessage").text("").removeClass("alert alert-error"); $("#" + containerId).find('.errorMessage').text("").removeClass("alert alert-error");
$("#" + containerId + " .control-group").removeClass('error'); $("#" + containerId).find('.control-group').removeClass('error');
$("#" + containerId + " input").attr('value', '');
// Clear form values ...
if (options.clearForm == undefined || options.clearForm) {
$("#" + containerId).find('input').attr('value', '');
}
// Reset button state ...
var acceptBtn = $('#' + containerId + ' .btn-accept'); var acceptBtn = $('#' + containerId + ' .btn-accept');
acceptBtn.button('reset');
acceptBtn.click(function() { acceptBtn.click(function() {
var formData = {}; var formData = {};
$('#' + containerId + ' input').each(function(index, elem) { $('#' + containerId + ' input').each(function(index, elem) {
formData[elem.name] = elem.value; formData[elem.name] = elem.value;
}); });
$(acceptBtn).button('loading');
var dialogElem = this; var dialogElem = this;
jQuery.ajax(url, { jQuery.ajax(url, {
async:false, async:false,
@ -86,7 +93,6 @@ jQuery.fn.dialogForm = function(options) {
var resourceId = jqXHR.getResponseHeader("ResourceId"); var resourceId = jqXHR.getResponseHeader("ResourceId");
var redirectUrl = options.redirect; var redirectUrl = options.redirect;
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId); redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
$(acceptBtn).button('loading');
window.location = redirectUrl; window.location = redirectUrl;
} else if (options.postUpdate) { } else if (options.postUpdate) {
@ -105,14 +111,18 @@ jQuery.fn.dialogForm = function(options) {
var message = fieldErrors[fieldName]; var message = fieldErrors[fieldName];
var inputField = $("#" + containerId + " input[name='" + 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'); inputField.parent().addClass('error');
} }
} }
} else { } 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:checked").parent().parent().addClass('row-selected');
$("#mindmapListTable tbody input:not(:checked)").parent().parent().removeClass('row-selected'); $("#mindmapListTable tbody input:not(:checked)").parent().parent().removeClass('row-selected');
$("#buttonsToolbar .act-multiple").hide(); $('#buttonsToolbar').find('.act-single').hide().end().find('.act-multiple').hide();
$("#buttonsToolbar .act-single").hide();
var tableElem = $('#mindmapListTable'); var tableElem = $('#mindmapListTable');
var selectedRows = tableElem.dataTableExt.getSelectedRows(); var selectedRows = tableElem.dataTableExt.getSelectedRows();
if (selectedRows.length > 0) { if (selectedRows.length > 0) {
if (selectedRows.length == 1) { if (selectedRows.length == 1) {
$("#buttonsToolbar .act-single").show(); $('#buttonsToolbar').find('.act-single').show().end().find('.act-multiple').show();
$("#buttonsToolbar .act-multiple").show();
// Can be executed by the owner ? // Can be executed by the owner ?
var rowData = tableElem.dataTable().fnGetData(selectedRows[0]); var rowData = tableElem.dataTable().fnGetData(selectedRows[0]);
if (rowData.ownerEmail != principalEmail) { if (rowData.ownerEmail != principalEmail) {
$("#buttonsToolbar #publishBtn").hide(); $("#buttonsToolbar").find('#publishBtn').hide().end().find('#shareBtn').hide();
$("#buttonsToolbar #shareBtn").hide();
} }
} else { } else {
$("#buttonsToolbar .act-multiple").show(); $("#buttonsToolbar .act-multiple").show();

View File

@ -37,7 +37,7 @@
// Configure designer options ... // Configure designer options ...
var options = loadDesignerOptions(); var options = loadDesignerOptions();
options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/"); options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document");
var userOptions = ${mindmap.properties}; var userOptions = ${mindmap.properties};
options.zoom = userOptions.zoom; options.zoom = userOptions.zoom;

View File

@ -4,7 +4,6 @@
<table> <table>
<tr> <tr>
<td class="formLabel"> <td class="formLabel">
<span class="fieldRequired">*</span>
<spring:message code="NAME"/>: <spring:message code="NAME"/>:
</td> </td>
<td> <td>
@ -34,8 +33,8 @@
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td> <td>
<input type="submit" value="<spring:message code="IMPORT"/>" class="btn-primary"> <input type="submit" value="<spring:message code="IMPORT"/>" class="btn btn-primary">
<input type="button" value="<spring:message code="CANCEL"/>" class="btn-secondary" <input type="button" value="<spring:message code="CANCEL"/>" class="btn"
onclick="window.location='/c/mymaps.htm'"> onclick="window.location='/c/mymaps.htm'">
</td> </td>
</tr> </tr>

View File

@ -78,7 +78,7 @@
oLanguage : { oLanguage : {
"sSearch" : "", "sSearch" : "",
"sInfo" : "_START_-_END_ of _TOTAL_", "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 bStateSave:true
}); });
@ -167,16 +167,15 @@
// Initialize dialog ... // Initialize dialog ...
$("#rename-dialog-modal").dialogForm({ $("#rename-dialog-modal").dialogForm({
type: 'PUT', type: 'PUT',
clearForm: false,
postUpdate: function(reqBodyData) { postUpdate: function(reqBodyData) {
// Remove old entry ... tableElem.dataTableExt.removeSelectedRows();
dataTable.fnDeleteRow(rowData);
// Add a new one...
rowData.title = reqBodyData.title; rowData.title = reqBodyData.title;
rowData.description = reqBodyData.description; rowData.description = reqBodyData.description;
dataTable.fnAddData(rowData); dataTable.fnAddData(JSON.parse(JSON.stringify(rowData)));
}, },
url : "../service/maps/" + mapId + "/title" url : "../service/maps/" + mapId
}); });
} }
}); });
@ -251,29 +250,36 @@
</head> </head>
<body> <body>
<div style="min-height: 500px"> <div style="min-height: 500px">
<jsp:include page="header.jsp"> <jsp:include page="header.jsp">
<jsp:param name="removeSignin" value="false"/> <jsp:param name="removeSignin" value="false"/>
<jsp:param name="showLogout" value="true"/> <jsp:param name="showLogout" value="true"/>
</jsp:include> </jsp:include>
<div id="mindmapListContainer">
<div id="messagesPanel" class="alert alert-error alert-block fade in hide" style="margin-top: 10px">
<strong><spring:message code="UNEXPECTED_ERROR"/></strong>
<p><spring:message code="UNEXPECTED_ERROR_SERVER_ERROR"/></p>
<div></div>
</div>
<div id="mindmapListContainer">
<div id="buttonsToolbar" class="btn-toolbar"> <div id="buttonsToolbar" class="btn-toolbar">
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-info" id="newBtn"><i class="icon-file icon-white"></i> New</button> <button id="newBtn" class="btn btn-info"><i class="icon-file icon-white"></i> New</button>
<button class="btn btn-info" id="importBtn"><i class="icon-upload icon-white"></i> Import</button> <button id="importBtn" class="btn btn-info"><i class="icon-upload icon-white"></i> Import</button>
</div> </div>
<div class="btn-group act-multiple" id="deleteBtn" style="display:none"> <div class="btn-group act-multiple" id="deleteBtn" style="display:none">
<button class="btn btn-info"><i class="icon-trash icon-white"></i> Delete</button> <button class="btn btn-info"><i class="icon-trash icon-white"></i> Delete</button>
</div> </div>
<div class="btn-group act-single" id="infoBtn" style="display:none"> <div id="infoBtn" class="btn-group act-single" style="display:none">
<button class="btn btn-info"><i class="icon-exclamation-sign icon-white"></i> Info</button> <button class="btn btn-info"><i class="icon-exclamation-sign icon-white"></i> Info</button>
</div> </div>
<div class="btn-group act-single" id="actionsBtn" style="display:none"> <div id="actionsBtn" class="btn-group act-single" style="display:none">
<button class="btn btn-info dropdown-toggle" data-toggle="dropdown"> <button class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<i class="icon-asterisk icon-white"></i> More <i class="icon-asterisk icon-white"></i> More
<span class="caret"></span> <span class="caret"></span>
@ -323,7 +329,7 @@
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary btn-accept" data-loading-text="Creating ...">Create</button> <button class="btn btn-primary btn-accept" data-loading-text="Saving ...">Create</button>
<button class="btn btn-cancel" data-dismiss="modal">Cancel</button> <button class="btn btn-cancel" data-dismiss="modal">Cancel</button>
</div> </div>
</div> </div>
@ -354,7 +360,7 @@
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary btn-accept" data-loading-text="Duplicating ...">Duplicate</button> <button class="btn btn-primary btn-accept" data-loading-text="Saving ...">Duplicate</button>
<button class="btn btn-cancel" data-dismiss="modal">Cancel</button> <button class="btn btn-cancel" data-dismiss="modal">Cancel</button>
</div> </div>
</div> </div>
@ -383,7 +389,7 @@
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary btn-accept">Rename</button> <button class="btn btn-primary btn-accept" data-loading-text="Saving ...">Rename</button>
<button class="btn btn-cancel" data-dismiss="modal">Cancel</button> <button class="btn btn-cancel" data-dismiss="modal">Cancel</button>
</div> </div>
</div> </div>
@ -402,7 +408,7 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary btn-accept">Delete</button> <button class="btn btn-primary btn-accept" data-loading-text="Saving ...">Delete</button>
<button class="btn btn-cancel" data-dismiss="modal">Cancel</button> <button class="btn btn-cancel" data-dismiss="modal">Cancel</button>
</div> </div>
</div> </div>
@ -443,9 +449,8 @@
<div id="tableFooter" class="form-inline"></div> <div id="tableFooter" class="form-inline"></div>
</div> </div>
</div>
</div> </div>
</div>
<jsp:include page="footer.jsp"/> <jsp:include page="footer.jsp"/>
</body> </body>

View File

@ -219,7 +219,7 @@ public class RestMindmapTCase {
mapToUpdate.setProperties("{zoom:x}"); mapToUpdate.setProperties("{zoom:x}");
// Update map ... // Update map ...
final String resourceUrl = HOST_PORT + resourceUri.toString(); final String resourceUrl = HOST_PORT + resourceUri.toString() + "/document";
requestHeaders.setContentType(MediaType.APPLICATION_XML); requestHeaders.setContentType(MediaType.APPLICATION_XML);
final HttpEntity<RestMindmap> updateEntity = new HttpEntity<RestMindmap>(mapToUpdate, requestHeaders); final HttpEntity<RestMindmap> updateEntity = new HttpEntity<RestMindmap>(mapToUpdate, requestHeaders);
template.put(resourceUrl, updateEntity); template.put(resourceUrl, updateEntity);