Add support for revert changes ...

This commit is contained in:
Paulo Gustavo Veiga 2012-07-04 02:15:55 -03:00
parent b321e205b1
commit 5cf9756ed3
10 changed files with 76 additions and 20 deletions

View File

@ -27,7 +27,7 @@ mindplot.LocalStorageManager = new Class({
events.onSuccess(); events.onSuccess();
}, },
discard : function(mapId) { discardChanges : function(mapId) {
localStorage.removeItem(mapId + "-xml"); localStorage.removeItem(mapId + "-xml");
}, },

View File

@ -21,7 +21,6 @@ mindplot.Messages = new Class({
init:function (locale) { init:function (locale) {
locale = $defined(locale) ? locale : 'en'; locale = $defined(locale) ? locale : 'en';
mindplot.Messages.__bundle = mindplot.Messages.BUNDLES[locale]; mindplot.Messages.__bundle = mindplot.Messages.BUNDLES[locale];
console.log(mindplot.Messages.__bundle);
} }
} }
}); });

View File

@ -47,7 +47,7 @@ mindplot.PersistenceManager = new Class({
return this.loadFromDom(mapId, domDocument); return this.loadFromDom(mapId, domDocument);
}, },
discard: function(mapId) { discardChanges: function(mapId) {
throw "Method must be implemented"; throw "Method must be implemented";
}, },

View File

@ -18,39 +18,61 @@
mindplot.RESTPersistenceManager = new Class({ mindplot.RESTPersistenceManager = new Class({
Extends:mindplot.PersistenceManager, Extends:mindplot.PersistenceManager,
initialize: function(saveUrl) { initialize:function (saveUrl, revertUrl) {
this.parent(); this.parent();
$assert(saveUrl, "saveUrl can not be null"); $assert(saveUrl, "saveUrl can not be null");
$assert(revertUrl, "revertUrl can not be null");
this.saveUrl = saveUrl; this.saveUrl = saveUrl;
this.revertUrl = revertUrl;
}, },
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) { saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
var data = { var data = {
id:mapId, id:mapId,
xml: mapXml, xml:mapXml,
properties: pref properties:pref
}; };
var request = new Request({ var request = new Request({
url:this.saveUrl.replace("{id}", 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();
}, },
onException:function(headerName, value) { onException:function (headerName, value) {
events.onError(); events.onError();
}, },
onFailure:function(xhr) { onFailure:function (xhr) {
events.onError(); events.onError();
}, },
headers: {"Content-Type":"application/json","Accept":"application/json"}, headers:{"Content-Type":"application/json", "Accept":"application/json"},
emulation:false, emulation:false,
urlEncoded:false urlEncoded:false
}); });
request.put(JSON.encode(data)); 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();
} }
} }
); );

View File

@ -34,10 +34,10 @@ mindplot.widget.IMenu = new Class({
}); });
}, },
discard:function () { discardChanges:function () {
var persistenceManager = mindplot.PersistenceManager.getInstance(); var persistenceManager = mindplot.PersistenceManager.getInstance();
var mindmap = designer.getMindmap(); var mindmap = designer.getMindmap();
persistenceManager.discard(mindmap.getId()); persistenceManager.discardChanges(mindmap.getId());
}, },
save:function (saveElem, designer, saveHistory) { save:function (saveElem, designer, saveHistory) {

View File

@ -321,7 +321,13 @@ mindplot.widget.Menu = new Class({
var discardElem = $('discard'); var discardElem = $('discard');
if (discardElem) { if (discardElem) {
this._addButton('discard', false, false, function () { 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(); window.location.reload();
}.bind(this)); }.bind(this));
this._registerTooltip('discard', $msg('DISCARD_CHANGES')); this._registerTooltip('discard', $msg('DISCARD_CHANGES'));

View File

@ -48,6 +48,7 @@ import java.util.*;
@Controller @Controller
public class MindmapController extends BaseController { public class MindmapController extends BaseController {
public static final String LATEST_HISTORY_REVISION = "latest";
@Qualifier("mindmapService") @Qualifier("mindmapService")
@Autowired @Autowired
private MindmapService mindmapService; private MindmapService mindmapService;
@ -116,9 +117,21 @@ public class MindmapController extends BaseController {
@RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST) @RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.NO_CONTENT) @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); 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"}) @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})

View File

@ -89,5 +89,5 @@ site.baseurl = http://localhost:8080
################################################################################## ##################################################################################
# Google Analytics Settings # Google Analytics Settings
################################################################################## ##################################################################################
google.analytics.enabled=true google.analytics.enabled=false
google.analytics.account=UA-XXXX google.analytics.account=UA-XXXX

View File

@ -33,7 +33,7 @@
// Configure designer options ... // Configure designer options ...
var options = loadDesignerOptions(); 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}; var userOptions = ${mindmap.properties};
options.zoom = userOptions.zoom; options.zoom = userOptions.zoom;
options.readOnly = ${!!readOnlyMode}; options.readOnly = ${!!readOnlyMode};

View File

@ -83,7 +83,23 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript" src="../js/editor.js"></script> <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> </body>
</html> </html>