smartxml: Rollback support for transactions
[fnpeditor.git] / src / smartxml / smartxml.js
index 426dce0..31faef0 100644 (file)
@@ -560,6 +560,7 @@ $.extend(Document.prototype, Backbone.Events, {
         if(this._currentTransaction) {
             throw new Error('Nested transactions not supported!');
         }
+        this._rollbackBackup = this.root.clone();
         this._currentTransaction = new Transaction([], metadata);
     },
 
@@ -573,6 +574,15 @@ $.extend(Document.prototype, Backbone.Events, {
         this._currentTransaction = null;
     },
 
+    rollbackTransaction: function() {
+        if(!this._currentTransaction) {
+            throw new Error('Transaction rollback requested, but there is no transaction in progress!');
+        }
+        this.replaceRoot(this._rollbackBackup);
+        this._rollbackBackup = null;
+        this._currentTransaction = null;
+    },
+
     transaction: function(callback, context, metadata) {
         var toret;
         this.startTransaction(metadata);