Author: reebalazs
Date: Mon Feb 19 11:20:49 2007
New Revision: 39194

Modified:
   kukit/kukit.js/trunk/kukit/kssparser.js
   kukit/kukit.js/trunk/kukit/oper.js
   kukit/kukit.js/trunk/kukit/resourcedata.js
   kukit/kukit.js/trunk/kukit/selectorreg.js
   kukit/kukit.js/trunk/tests/test_kssparser.js
Log:
Add kssSelector generic action parameter

Modified: kukit/kukit.js/trunk/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kssparser.js     (original)
+++ kukit/kukit.js/trunk/kukit/kssparser.js     Mon Feb 19 11:20:49 2007
@@ -129,6 +129,12 @@
     this.txt = '';
 };
 kukit.kssp.Block.prototype.addDeclaration = function(key, value) {
+
+    var ppRegistries = {
+        '': kukit.pprovidersGlobalRegistry,
+        'kssSelector': kukit.sr.pproviderSelRegistry
+    };
+
     // p.s. value is here a KssXxParm. In most cases we check and unwrap it.
     // the keys look like this:
     //
@@ -272,6 +278,24 @@
                     // 
                     // value may be either txt or method parms, and they get 
stored with the wrapper.
                     action.parms[akey] = value;
+                    // 
+                    // Check the syntax of the value at this point. This will 
also set
+                    // the paramproviders on the value (from check).
+                    // check the syntax of the declaration
+                    //
+                    // Figure out which registry to use.
+                    var registry = ppRegistries[akey];
+                    if (typeof(registry) == 'undefined') {
+                        // use default pproviders
+                        registry = ppRegistries[''];
+                    }
+                    //
+                    try {
+                        // Check also sets the parameter provider on the value.
+                        value.check(registry);
+                    } catch(e) {
+                        throw new kukit.err.tk.ParsingError('Error in value: ' 
+ e,  this.src.makeMarker(this.startpos));
+                    }
                 } break;
         }
     }
@@ -327,22 +351,6 @@
         }
     }
     this.result = [];
-    }
-    //
-    if (typeof this.value != 'undefined') {
-        // Check the syntax of the value, enables early error detection.
-        // use a different registry, if it's a kssXxx parameter
-        var registry = kukit.pprovidersGlobalRegistry;
-        // XXX This is lame. We should not do it this way.
-        // TODO change this, it should be decided from the name of the key.
-        if (! registry.exists(this.value.methodname)) {
-            registry = kukit.selectorTypesGlobalRegistry;
-        try {
-            this.value.check(kukit.pprovidersGlobalRegistry);
-        } catch(e) {
-            throw new kukit.err.tk.ParsingError('Error in value: ' + e,  
this.src.makeMarker(this.startpos));
-        }
-    }
 };
 kukit.kssp.PropValue.prototype.multiword_allowed = true;
 kukit.kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;

Modified: kukit/kukit.js/trunk/kukit/oper.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/oper.js  (original)
+++ kukit/kukit.js/trunk/kukit/oper.js  Mon Feb 19 11:20:49 2007
@@ -108,11 +108,46 @@
 };
 
 kukit.op.Oper.prototype.executeClientAction = function(name) {
-    var func = kukit.actionsGlobalRegistry.get(name);
-    func(this);
+    // Check kss action parameters
+    var nodes = null;
+    // XXX TODO this should be refactored with parms constraint checking
+    for (key in this.aparms) {
+        switch (key) {
+            case 'kssSelector': {
+                // The value already contains the results
+                nodes = this.aparms[key];
+            } break;
+            default: {
+                throw 'No kss parameter "' + key + '" allowed in 
action-client. (Normal parameters cannot start with kss.)';
+            } break;
+        }
+    }
+    //
+    // XXX TODO refactor this with commands execution (or the other way)
+    var executeActions = kukit.actionsGlobalRegistry.get(name);
+    if (nodes != null) { 
+        kukit.logDebug('action Selector type selected nodes:' + nodes.length);
+        if (!nodes || nodes.length == 0) {
+            kukit.logWarning('action Selector found no nodes');
+        }
+        for (var i=0; i < nodes.length; i++) {
+            this.node = nodes[i];
+            //XXX error handling for wrong command name
+            //kukit.logDebug('action Name: ' + this.name);
+            executeActions(this);
+        }
+    } else {
+        // single node
+        executeActions(this);
+    }
 };
 
 kukit.op.Oper.prototype.executeDefaultAction = function(name, optional) {
+    // Check kss action parameters
+    for (key in this.aparms) {
+        throw 'No kss parameter "' + key + '" allowed in action-default. 
(Normal parameters cannot start with kss.)';
+    }
+    //
     var namespace = this.binderinstance.__event_namespace__;
     var methodname = kukit.eventsGlobalRegistry.get(namespace, 
name).defaultactionmethodname;
     var success = false;
@@ -128,6 +163,9 @@
 };
 
 kukit.op.Oper.prototype.executeServerAction = function(name) {
+    for (key in this.aparms) {
+        throw 'No kss parameter "' + key + '" allowed in action-server. 
(Normal parameters cannot start with kss.)';
+    }
     // oper will be accessible to some commands that execute in return
     var sa = new kukit.sa.ServerAction(name, this.parms, this);
 };

Modified: kukit/kukit.js/trunk/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/resourcedata.js  (original)
+++ kukit/kukit.js/trunk/kukit/resourcedata.js  Mon Feb 19 11:20:49 2007
@@ -104,9 +104,6 @@
     // For normal string parameters, this would return the string itself.
     // In other execution contexts (like kssSelector, for example) this can
     // do something else.
-    if (! this.pprovider) {
-        this.check(kukit.pprovidersGlobalRegistry);
-    }
     parms[key] = this.pprovider.eval([this.txt], node, defaultparms);
 };
 
@@ -122,15 +119,13 @@
 kukit.rd.KssMethodValue.prototype.isMethod = true;
 kukit.rd.KssMethodValue.prototype.check = function(registry) {
     // Check syntax
-    this.pprovider = new (registry.get(this.methodname))();
+    var f = registry.get(this.methodname);
+    this.pprovider = new f();
     this.pprovider.check(this.args);
 };
 
 kukit.rd.KssMethodValue.prototype.evaluate = function(parms, key, node, 
defaultparms) {
     // Evaluate into parms.
-    if (! this.pprovider) {
-        this.check(kukit.pprovidersGlobalRegistry);
-    }
     parms[key] = this.pprovider.eval(this.args, node, defaultparms);
 };
 

Modified: kukit/kukit.js/trunk/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/selectorreg.js   (original)
+++ kukit/kukit.js/trunk/kukit/selectorreg.js   Mon Feb 19 11:20:49 2007
@@ -1,9 +1,6 @@
 /*
 * Copyright (c) 2005-2006
-* Authors:
-*   Godefroid Chapelle <[EMAIL PROTECTED]>
-*   Florian Schulze <[EMAIL PROTECTED]>
-*   Balázs Reé <[EMAIL PROTECTED]>
+# Authors: KSS Project Contributors (see docs/CREDITS.txt)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published
@@ -26,37 +23,29 @@
 
 kukit.sr.pproviderSelRegistry = new kukit.pr.ParamProviderRegistry();
 
-// This will provide the default case (string)
-kukit.sr.DefaultPP = function() {};
-kukit.sr.DefaultPP.prototype = {
-    check: function(args) {
-        // check does not need to be used here actually.
-        if (args.length != 1) {
-            throw 'internal error, DefaultPP needs 1 argument';
-        }
-    },
-    eval: function(args, node) {
-        return args[0];
-    }
-};
-kukit.sr.pproviderSelRegistry.register('', kukit.sr.DefaultPP);
-
 
 // this will provide an arbitrary selector, and is designed to
 // be used with the makeAnyPP factory function.
 kukit.sr.AnyPP = function() {};
 kukit.sr.AnyPP.prototype = {
-    check: kukit.sr.DefaultPP.prototype.check,
+    check: function(args) {
+        // check does not need to be used here actually.
+        if (args.length != 1) {
+            throw 'internal error, AnyPP needs 1 argument';
+        }
+    },
     eval: function(args, node) {
         var f = kukit.selectorTypesGlobalRegistry.get(this.selector_type);
         return f(args[0], node);
     }
 };
 
+kukit.sr.pproviderSelRegistry.register('', kukit.sr.AnyPP);
 
 kukit.sr.makeAnyPP = function(selector_type) {
     var pp = function () {};
-    pp.prototype = kukit.sr.AnyPP.prototype;
+    pp.prototype.eval = kukit.sr.AnyPP.prototype.eval;
+    pp.prototype.check = kukit.sr.AnyPP.prototype.check;
     pp.prototype.selector_type = selector_type;
     return pp;
 };

Modified: kukit/kukit.js/trunk/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/tests/test_kssparser.js        (original)
+++ kukit/kukit.js/trunk/tests/test_kssparser.js        Mon Feb 19 11:20:49 2007
@@ -639,6 +639,18 @@
             +"   evt-annoyClicker-annoy-preventdefault:   true;\n"
             +"   action-client:    namespaced-alert;\n"
             +'   namespaced-alert-message:       "You are an idiot! Ha ha ha. 
(But just keep on trying...)";\n'
+            +'}\n'
+            +'#button_1:click {\n'
+            +'action-client: setStyle;\n'
+            +'setStyle-kssSelector: htmlid(button_2);\n'
+            +'setStyle-name: backgroundColor;\n'
+            +'setStyle-value: #FFa0a0;\n'
+            +'}\n'
+            +'#button_3:click {\n'
+            +'action-client: setStyle;\n'
+            +'setStyle-kssSelector: "#button_4";\n'
+            +'setStyle-name: backgroundColor;\n'
+            +'setStyle-value: #FFa0a0;\n'
             +"}\n";
 
         var src = new kukit.tk.Cursor(txt);
@@ -647,7 +659,7 @@
         
         var parser = new kukit.kssp.Document(src, null, true);
         this.assertEquals(parser.finished, true);
-        this.assertEquals(parser.eventRules.length, 10);
+        this.assertEquals(parser.eventRules.length, 12);
         var rule;
         var action;
 
@@ -849,6 +861,59 @@
                 'message': new kukit.rd.KssTextValue( "You are an idiot! Ha ha 
ha. (But just keep on trying...)")
             });
 
+        // rule 10
+            //#button_1:click {
+            //    action-client: setStyle;
+            //    setStyle-kssSelector: htmlid(button_2);
+            //    setStyle-name: backgroundColor;
+            //    setStyle-value: #FFa0a0;
+            //}
+
+        rule = parser.eventRules[10];
+        this.assertDictEquals(rule.parms, {});
+        this.assertEquals(rule.kss_selector.isEventSelector, true);
+        this.assertEquals(rule.kss_selector.css,  '#button_1');
+        this.assertEquals(rule.kss_selector.name,  'click');
+        this.assertEquals(rule.kss_selector.namespace,  null);
+        this.assertEquals(rule.kss_selector.id,  null);
+        action = rule.actions.content['setStyle'];
+        this.assertEquals(action.type, 'C');
+        this.assertEquals(action.name, 'setStyle');
+        this.assertEquals(action.error, null);
+        // At this point the parms are before separation yet
+        this.assertKssParmEquals(action.parms, {
+                'name': new kukit.rd.KssTextValue('backgroundColor'),
+                'value': new kukit.rd.KssTextValue('#FFa0a0'),
+                'kssSelector': new kukit.rd.KssMethodValue('htmlid', 
['button_2'])
+            });
+
+        // rule 10
+            //#button_3:click {
+            //    action-client: setStyle;
+            //    setStyle-kssSelector: "#button_4";
+            //    setStyle-name: backgroundColor;
+            //    setStyle-value: #FFa0a0;
+            //}\n";
+
+        rule = parser.eventRules[11];
+        this.assertDictEquals(rule.parms, {});
+        this.assertEquals(rule.kss_selector.isEventSelector, true);
+        this.assertEquals(rule.kss_selector.css,  '#button_3');
+        this.assertEquals(rule.kss_selector.name,  'click');
+        this.assertEquals(rule.kss_selector.namespace,  null);
+        this.assertEquals(rule.kss_selector.id,  null);
+        action = rule.actions.content['setStyle'];
+        this.assertEquals(action.type, 'C');
+        this.assertEquals(action.name, 'setStyle');
+        this.assertEquals(action.error, null);
+        // At this point the parms are before separation yet
+        this.assertKssParmEquals(action.parms, {
+                'name': new kukit.rd.KssTextValue('backgroundColor'),
+                'value': new kukit.rd.KssTextValue('#FFa0a0'),
+                'kssSelector': new kukit.rd.KssTextValue('#button_4')
+            });
+
+
         
     };
 };
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to