wip: canvas.commands - lists through new api
[fnpeditor.git] / src / smartxml / transformations.js
index a5a84df..f0b89f1 100644 (file)
@@ -19,27 +19,66 @@ toret.createGenericTransformation = function(desc, name) {
     desc = getTransDesc(desc);
     
     var GenericTransformation = function(document, args) {
     desc = getTransDesc(desc);
     
     var GenericTransformation = function(document, args) {
-        this.args = args || {};
+        this.args = args || [];
 
         var transformation = this;
 
         var transformation = this;
-        _.keys(this.args).forEach(function(key) {
-            if(transformation.args[key].nodeType) { //@@ change to instanceof check, fix circular dependency
-                var value = transformation.args[key],
-                    path = value.getPath();
-                Object.defineProperty(transformation.args, key, {
-                    get: function() {
-                        if(transformation.hasRun) {
-                            //console.log('returning via path');
-                            return transformation.document.getNodeByPath(path);
-                        } else {
-                            //console.log('returning original arg');
-                            return value;
-
+        // _.keys(this.args).forEach(function(key) {
+        //     if(transformation.args[key].nodeType) { //@@ change to instanceof check, fix circular dependency
+        //         var value = transformation.args[key],
+        //             path = value.getPath();
+        //         Object.defineProperty(transformation.args, key, {
+        //             get: function() {
+        //                 if(transformation.hasRun) {
+        //                     //console.log('returning via path');
+        //                     return transformation.document.getNodeByPath(path);
+        //                 } else {
+        //                     //console.log('returning original arg');
+        //                     return value;
+
+        //                 }
+        //             }
+        //         });
+        //     }
+        // });
+
+        // potem spr na dotychczasowych undo/redo tests;
+        
+
+        this.args.forEach(function(arg, idx, args) {
+            var path;
+            if(arg) {
+                if(arg.nodeType) { // ~
+                    path = arg.getPath();
+                    Object.defineProperty(args, idx, {
+                        get: function() {
+                            if(transformation.hasRun && path) {
+                                return transformation.document.getNodeByPath(path);
+                            } else {
+                                return arg;
+                            }
                         }
                         }
-                    }
-                });
+                    });
+                } else if(_.isObject(arg)) {
+                    _.keys(arg).forEach(function(key) {
+                        var value = arg[key],
+                            path;
+                        if(value && value.nodeType) {
+                            path = value.getPath();
+                            Object.defineProperty(arg, key, {
+                                get: function() {
+                                    if(transformation.hasRun && path) {
+                                        return transformation.document.getNodeByPath(path);
+                                    } else {
+                                        return value;
+                                    }
+                                }
+                            });   
+                        }
+                    });
+                }
             }
         });
             }
         });
+
         this.document = document;
         this.hasRun = false;
         if(desc.init) {
         this.document = document;
         this.hasRun = false;
         if(desc.init) {
@@ -55,7 +94,8 @@ toret.createGenericTransformation = function(desc, name) {
                 this.snapshot = changeRoot.clone();
                 this.changeRootPath = changeRoot.getPath();
             }
                 this.snapshot = changeRoot.clone();
                 this.changeRootPath = changeRoot.getPath();
             }
-            var toret = desc.impl.call(this.context, this.args); // a argumenty do metody?
+            //var toret = desc.impl.call(this.context, this.args); // a argumenty do metody?
+            var toret = desc.impl.apply(this.context, this.args);
             this.hasRun = true;
             return toret;
         },
             this.hasRun = true;
             return toret;
         },