From 78f57106d86fd31156033dce3d4fa9d8df5361fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 28 Mar 2014 14:52:49 +0100 Subject: [PATCH] editor: canvas - initiate commands transactions via Document.transaction This makes those transactions support automatic rollback on error. --- src/editor/modules/documentCanvas/commands.js | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/editor/modules/documentCanvas/commands.js b/src/editor/modules/documentCanvas/commands.js index 6335e0a..5f3583e 100644 --- a/src/editor/modules/documentCanvas/commands.js +++ b/src/editor/modules/documentCanvas/commands.js @@ -120,21 +120,21 @@ commands.register('newNodeRequested', function(canvas, params, user) { }; if(params.wlxmlTag === 'aside' && params.wlxmlClass === 'comment') { - doc.startTransaction(); - node = insertion(); - if(user) { - creator = user.name; - if(user.email) { - creator += ' (' + user.email + ')'; + doc.transaction(function() { + node = insertion(); + if(user) { + creator = user.name; + if(user.email) { + creator += ' (' + user.email + ')'; + } + } else { + creator = 'anonymous'; } - } else { - creator = 'anonymous'; - } - metadata = node.getMetadata(); - metadata.add({key: 'creator', value: creator}); - metadata.add({key: 'date', value: datetime.currentStrfmt()}); - doc.endTransaction(); + metadata = node.getMetadata(); + metadata.add({key: 'creator', value: creator}); + metadata.add({key: 'date', value: datetime.currentStrfmt()}); + }); execCallback(node); } else if(params.wlxmlClass === 'link') { dialog = Dialog.create({ @@ -146,18 +146,18 @@ commands.register('newNodeRequested', function(canvas, params, user) { ] }); dialog.on('execute', function(event) { - doc.startTransaction(); - node = insertion(); - node.setAttr('href', event.formData.href); - doc.endTransaction(); - event.success(); + doc.transaction(function() { + node = insertion(); + node.setAttr('href', event.formData.href); + event.success(); + }); execCallback(node); }); dialog.show(); } else { - doc.startTransaction(); - node = insertion(); - doc.endTransaction(); + doc.transaction(function() { + node = insertion(); + }); execCallback(node); } }; @@ -228,9 +228,10 @@ commands.register('newNodeRequested', function(canvas, params, user) { ] }); dialog.on('execute', function(event) { - canvas.wlxmlDocument.startTransaction(); - node.setAttr('href', event.formData.href); - event.success(); + canvas.wlxmlDocument.transaction(function() { + node.setAttr('href', event.formData.href); + event.success(); + }); canvas.wlxmlDocument.endTransaction(); }); dialog.show(); -- 2.20.1