editor: actions returns via callback
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 22 Apr 2014 10:35:16 +0000 (12:35 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 23 Apr 2014 11:05:05 +0000 (13:05 +0200)
src/editor/modules/documentToolbar/actionView.js
src/editor/plugins/core/core.js
src/editor/plugins/core/lists.js
src/editor/plugins/core/switch.js
src/editor/plugins/core/templates.js

index 114eb32..74db332 100644 (file)
@@ -108,8 +108,9 @@ var ActionView = Backbone.View.extend({
         this.trigger('mousedown');
     },
     onExecute: function() {
-        var ret = this.action.execute();
-        this.trigger('actionExecuted', this.action, ret);
+        this.action.execute(function(ret) {
+            this.trigger('actionExecuted', this.action, ret);
+        }.bind(this));
     },
     onSelectionChange: function(e) {
         var select = $(e.target),
index 3465046..4c2f4c0 100644 (file)
@@ -54,8 +54,9 @@ var undoRedoAction = function(dir) {
             label: dir === 'undo' ? '<-' : '->',
             icon: 'share-alt',
             iconStyle: dir === 'undo' ? '-webkit-transform: scale(-1,1); transform: scale(-1, 1)' : '',
-            execute: function(params) {
+            execute: function(callback, params) {
                 params.document[dir]();
+                callback();
             },
         },
         getState: function(params) {
@@ -90,7 +91,7 @@ var commentAction = {
     },
     stateDefaults: {
         icon: 'comment',
-        execute: function(params, editor) {
+        execute: function(callback, params, editor) {
             /* globals Node */
             var node = params.fragment.node,
                 action = this;
@@ -124,7 +125,8 @@ var commentAction = {
             }, {
                 metadata: {
                     description: action.getState().description
-                }
+                },
+                success: callback
             });
         },
     },
@@ -168,7 +170,7 @@ var createWrapTextAction = function(createParams) {
             return _.extend(state, {
                 allowed: true,
                 description: createParams.description,
-                execute: function(params) {
+                execute: function(callback, params) {
                     params.fragment.document.transaction(function() {
                         var parent = params.fragment.startNode.parent();
                         return parent.wrapText({
@@ -180,7 +182,8 @@ var createWrapTextAction = function(createParams) {
                     }, {
                         metadata: {
                             description: createParams.description
-                        }
+                        },
+                        success: callback
                     });
                 }
             });
@@ -189,7 +192,7 @@ var createWrapTextAction = function(createParams) {
 };
 
 
-var createLinkFromSelection = function(params) {
+var createLinkFromSelection = function(callback, params) {
     var doc = params.fragment.document,
         dialog = Dialog.create({
             title: gettext('Create link'),
@@ -215,13 +218,14 @@ var createLinkFromSelection = function(params) {
         }, {
             metadata: {
                 description: action.getState().description
-            }
+            },
+            success: callback
         });
     });
     dialog.show();
 };
 
-var editLink = function(params) {
+var editLink = function(callback, params) {
     var doc = params.fragment.document,
         link = params.fragment.node.getParent('link'),
         dialog = Dialog.create({
@@ -241,7 +245,8 @@ var editLink = function(params) {
         }, {
             metadata: {
                 description: action.getState().description
-            }
+            },
+            success: callback
         });
     });
     dialog.show();
index a8dc802..911a1f2 100644 (file)
@@ -32,7 +32,7 @@ var countItems = function(boundries) {
 var toggleListAction = function(type) {
     
     var execute = {
-        add: function(params) {
+        add: function(callback, params) {
             var boundries = getBoundriesForAList(params.fragment),
                 listParams = {klass: type === 'Bullet' ? 'list' : 'list.enum'},
                 action = this;
@@ -45,13 +45,14 @@ var toggleListAction = function(type) {
                 }, {
                     metadata: {
                         description: action.getState().description
-                    }
+                    },
+                    success: callback
                 });
             } else {
                 throw new Error('Invalid boundries');
             }
         },
-        remove: function(params) {
+        remove: function(callback, params) {
             /* globals Node */
             var current = params.fragment.node,
                 action = this;
@@ -65,14 +66,15 @@ var toggleListAction = function(type) {
                     }, {
                         metadata: {
                             description: action.getState().description
-                        }
+                        },
+                        success: callback
                     });
                     
                     return true; // break
                 }
             }.bind(this));
         },
-        changeType: function(params) {
+        changeType: function(callback, params) {
             var node = params.fragment.node,
                 action = this;
             node.document.transaction(function() {
@@ -80,7 +82,8 @@ var toggleListAction = function(type) {
             }, {
                 metadata: {
                     description: action.getState().description
-                }
+                },
+                success: callback
             });
         }
     };
index 2730761..57b28b9 100644 (file)
@@ -43,7 +43,7 @@ var createSwitchAction = function(createParams) {
                 allowed: !!toSwitch,
                 toggled: alreadyInTarget,
                 description: description,
-                execute: alreadyInTarget ? function() {} : function() {
+                execute: alreadyInTarget ? function() {} : function(callback) {
                     f.document.transaction(function() {
                         if(createParams.to.tagName) {
                             toSwitch = toSwitch.setTag(createParams.to.tagName);
@@ -54,7 +54,8 @@ var createSwitchAction = function(createParams) {
                     }, {
                         metadata: {
                             description: description
-                        }
+                        },
+                        success: callback
                     });
                 }
             });
index 69e30f9..7d6d74f 100644 (file)
@@ -38,7 +38,7 @@ var insertTemplateAction = {
         return {
             allowed: true,
             description: description,
-            execute: function(params) {
+            execute: function(callback, params) {
                 var node = params.fragment.node.getNearestElementNode();
                 node.document.transaction(function() {
                     var toAdd = node.document.createDocumentNode(params.template.content);
@@ -46,7 +46,8 @@ var insertTemplateAction = {
                 }, {
                     metadata: {
                         description: description
-                    }
+                    },
+                    success: callback
                 });
             }
         };