mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-09-12 07:10:07 +02:00
Add support for revert changes ...
This commit is contained in:
parent
b321e205b1
commit
5cf9756ed3
@ -27,7 +27,7 @@ mindplot.LocalStorageManager = new Class({
|
||||
events.onSuccess();
|
||||
},
|
||||
|
||||
discard : function(mapId) {
|
||||
discardChanges : function(mapId) {
|
||||
localStorage.removeItem(mapId + "-xml");
|
||||
},
|
||||
|
||||
|
@ -21,7 +21,6 @@ mindplot.Messages = new Class({
|
||||
init:function (locale) {
|
||||
locale = $defined(locale) ? locale : 'en';
|
||||
mindplot.Messages.__bundle = mindplot.Messages.BUNDLES[locale];
|
||||
console.log(mindplot.Messages.__bundle);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -47,7 +47,7 @@ mindplot.PersistenceManager = new Class({
|
||||
return this.loadFromDom(mapId, domDocument);
|
||||
},
|
||||
|
||||
discard: function(mapId) {
|
||||
discardChanges: function(mapId) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
|
@ -18,39 +18,61 @@
|
||||
|
||||
mindplot.RESTPersistenceManager = new Class({
|
||||
Extends:mindplot.PersistenceManager,
|
||||
initialize: function(saveUrl) {
|
||||
initialize:function (saveUrl, revertUrl) {
|
||||
this.parent();
|
||||
$assert(saveUrl, "saveUrl can not be null");
|
||||
$assert(revertUrl, "revertUrl can not be null");
|
||||
this.saveUrl = saveUrl;
|
||||
this.revertUrl = revertUrl;
|
||||
},
|
||||
|
||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
|
||||
|
||||
var data = {
|
||||
id:mapId,
|
||||
xml: mapXml,
|
||||
properties: pref
|
||||
xml:mapXml,
|
||||
properties:pref
|
||||
};
|
||||
|
||||
var request = new Request({
|
||||
url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory,
|
||||
method: 'put',
|
||||
onSuccess:function(responseText, responseXML) {
|
||||
method:'put',
|
||||
onSuccess:function (responseText, responseXML) {
|
||||
events.onSuccess();
|
||||
|
||||
},
|
||||
onException:function(headerName, value) {
|
||||
onException:function (headerName, value) {
|
||||
events.onError();
|
||||
},
|
||||
onFailure:function(xhr) {
|
||||
onFailure:function (xhr) {
|
||||
events.onError();
|
||||
},
|
||||
headers: {"Content-Type":"application/json","Accept":"application/json"},
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
emulation:false,
|
||||
urlEncoded:false
|
||||
});
|
||||
request.put(JSON.encode(data));
|
||||
},
|
||||
|
||||
discardChanges:function (mapId) {
|
||||
var request = new Request({
|
||||
url:this.revertUrl.replace("{id}", mapId),
|
||||
async:false,
|
||||
method:'post',
|
||||
onSuccess:function () {
|
||||
console.log("Revert success ....");
|
||||
},
|
||||
onException:function () {
|
||||
},
|
||||
onFailure:function () {
|
||||
},
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
emulation:false,
|
||||
urlEncoded:false
|
||||
});
|
||||
request.post();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -34,10 +34,10 @@ mindplot.widget.IMenu = new Class({
|
||||
});
|
||||
},
|
||||
|
||||
discard:function () {
|
||||
discardChanges:function () {
|
||||
var persistenceManager = mindplot.PersistenceManager.getInstance();
|
||||
var mindmap = designer.getMindmap();
|
||||
persistenceManager.discard(mindmap.getId());
|
||||
persistenceManager.discardChanges(mindmap.getId());
|
||||
},
|
||||
|
||||
save:function (saveElem, designer, saveHistory) {
|
||||
|
@ -321,7 +321,13 @@ mindplot.widget.Menu = new Class({
|
||||
var discardElem = $('discard');
|
||||
if (discardElem) {
|
||||
this._addButton('discard', false, false, function () {
|
||||
this.discard();
|
||||
// Avoid autosave before leaving the page ....
|
||||
$(window).removeEvents(['beforeunload']);
|
||||
|
||||
// Discard changes ...
|
||||
this.discardChanges();
|
||||
|
||||
// Reload the page ...
|
||||
window.location.reload();
|
||||
}.bind(this));
|
||||
this._registerTooltip('discard', $msg('DISCARD_CHANGES'));
|
||||
|
@ -48,6 +48,7 @@ import java.util.*;
|
||||
|
||||
@Controller
|
||||
public class MindmapController extends BaseController {
|
||||
public static final String LATEST_HISTORY_REVISION = "latest";
|
||||
@Qualifier("mindmapService")
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
@ -116,9 +117,21 @@ public class MindmapController extends BaseController {
|
||||
|
||||
@RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST)
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateRevertMindmap(@PathVariable int id, @PathVariable int hid) throws WiseMappingException {
|
||||
public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException {
|
||||
final MindMap mindmap = mindmapService.findMindmapById(id);
|
||||
mindmapService.revertChange(mindmap, hid);
|
||||
final User user = Utils.getUser();
|
||||
|
||||
if (LATEST_HISTORY_REVISION.equals(hid)) {
|
||||
// Revert to the latest stored version ...
|
||||
List<MindMapHistory> mindmapHistory = mindmapService.findMindmapHistory(id);
|
||||
if (mindmapHistory.size() > 0) {
|
||||
final MindMapHistory mindMapHistory = mindmapHistory.get(0);
|
||||
mindmap.setXml(mindMapHistory.getXml());
|
||||
saveMindmap(true, mindmap, user);
|
||||
}
|
||||
} else {
|
||||
mindmapService.revertChange(mindmap, Integer.parseInt(hid));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
||||
|
@ -89,5 +89,5 @@ site.baseurl = http://localhost:8080
|
||||
##################################################################################
|
||||
# Google Analytics Settings
|
||||
##################################################################################
|
||||
google.analytics.enabled=true
|
||||
google.analytics.enabled=false
|
||||
google.analytics.account=UA-XXXX
|
@ -33,7 +33,7 @@
|
||||
|
||||
// Configure designer options ...
|
||||
var options = loadDesignerOptions();
|
||||
options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document");
|
||||
options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document","service/maps/{id}/history/latest");
|
||||
var userOptions = ${mindmap.properties};
|
||||
options.zoom = userOptions.zoom;
|
||||
options.readOnly = ${!!readOnlyMode};
|
||||
|
@ -83,7 +83,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="../js/editor.js"></script>
|
||||
<c:if test="${requestScope['google.analytics.enabled']}">
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', '${requestScope['google.analytics.account']}']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function () {
|
||||
var ga = document.createElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
</c:if>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user