[KSS-checkins] r42253 - kukit/kukit.js/branch/ree-load-event-cleanup/kukit

reebalazs at codespeak.net reebalazs at codespeak.net
Mon Apr 23 11:21:50 CEST 2007


Author: reebalazs
Date: Mon Apr 23 11:21:50 2007
New Revision: 42253

Modified:
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/forms.js
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/kssparser.js
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/oper.js
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/providerreg.js
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js
   kukit/kukit.js/branch/ree-load-event-cleanup/kukit/utils.js
Log:
Merge the kssSubmitForm action parameter implementation from trunk,  -r42250:42251

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/forms.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/forms.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/forms.js	Mon Apr 23 11:21:50 2007
@@ -1,9 +1,6 @@
 /*
-* Copyright (c) 2005-2006
-* Authors:
-*   Godefroid Chapelle <gotcha at bubblenet.be>
-*   Florian Schulze <florian.schulze at gmx.net>
-*   Balázs Reé <ree at greenfinity.hu>
+* Copyright (c) 2005-2007
+* 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
@@ -89,7 +86,6 @@
 kukit.fo.findContainer = function(node, func) {
     // Starting with the given node, find the nearest containing element
     // for which the given function returns true.
-
     while (node != null) {
         if (func(node)) {
             return node;
@@ -99,9 +95,18 @@
     return null;
 };
 
-kukit.fo.getCurrentForm = function(target) {
+/*
+ * class CurrentFormLocator: gets the current form of a target
+ *
+ */
+
+kukit.fo.CurrentFormLocator = function(target) {
+    this.target = target;
+};
+
+kukit.fo.CurrentFormLocator.prototype.queryForm = function() {
     // Find the form that contains the target node.
-    return kukit.fo.findContainer(target, function(node) {
+    return kukit.fo.findContainer(this.target, function(node) {
         if (!node.nodeName) {
             return false;
         }
@@ -113,6 +118,33 @@
     });
 };
 
+kukit.fo.CurrentFormLocator.prototype.getForm = function() {
+    var form = this.queryForm();
+    if (!form) {
+        kukit.logWarning("No form found");
+        return null;
+    }
+    return form;
+};
+
+/*
+ * class NamedFormLocator: gets the form with a given name
+ *
+ */
+
+kukit.fo.NamedFormLocator = function(formname) {
+    this.formname = formname;
+};
+
+kukit.fo.NamedFormLocator.prototype.queryForm = function() {
+    // Find the form with the given name.
+    return document.forms[this.formname];
+};
+
+kukit.fo.NamedFormLocator.prototype.getForm = kukit.fo.CurrentFormLocator.prototype.getForm;
+
+/* methods to take the desired value(s) from the form */
+
 kukit.fo.getValueOfFormElement = function(element) {
     // Returns the value of the form element / or null
     // First: update the field in case an editor is lurking
@@ -154,8 +186,11 @@
     return value;
 };
 
-kukit.fo.getFormVar = function(form, name) {
-    // Extract the value of a formvar, from a given form
+kukit.fo.getFormVar = function(locator, name) {
+    var form = locator.getForm();
+    if (! form)
+        return null;
+    // Extract the value of a formvar
     var value = null;
     var element = form[name];
     if (element) {
@@ -171,9 +206,12 @@
     return value;
 };
 
-kukit.fo.getAllFormVars = function(form) {
+kukit.fo.getAllFormVars = function(locator, collector) {
+    var form = locator.getForm();
+    if (! form)
+        return collector.result;
     // extracts all elements of a given form
-    var data = {};
+    // the collect_hook will be called wih the name, value parameters to add it
     var elements = form.elements;
     for (var y=0; y<elements.length; y++) {
         var element = elements[y];
@@ -182,53 +220,12 @@
             kukit.logWarning('Form element not harvested: '+element.tagName);
         } else {
             kukit.logDebug("Form element ("+element.tagName+"): name="+element.name+", value="+value);
-            data[element.name] = value;
+            collector.add(element.name, value);
         }
     }
-    return data;
+    return collector.result;
 };
 
-/* Form data extraction, frontend */
-
-kukit.fo.getFormVarFromCurrentForm = function(target, name) {
-    // Just get one formvar, from the form that contains the target node
-    var form = kukit.fo.getCurrentForm(target);
-    if (!form) {
-        kukit.logWarning("No form found");
-        return null;
-    }
-    return kukit.fo.getFormVar(form, name);
-};
-
-kukit.fo.getFormVarFromNamedForm = function(formname, name) {
-    // Just get one formvar, from the named form 
-    var form = document.forms[formname];
-    if (!form) {
-        kukit.logWarning("No form found");
-        return null;
-    }
-    return kukit.fo.getFormVar(form, name);
-};
-
-kukit.fo.getAllFormVarsFromCurrentForm = function(target) {
-    // Just get one formvar, from the form that contains the target node
-    var form = kukit.fo.getCurrentForm(target);
-    if (!form) {
-        kukit.logWarning("No form found");
-        return {};
-    }
-    return kukit.fo.getAllFormVars(form);
-};
-
-kukit.fo.getAllFormVarsFromNamedForm = function(formname) {
-    // Just get one formvar, from the named form 
-    var form = document.forms[formname];
-    if (!form) {
-        kukit.logWarning("No form found");
-        return {};
-    }
-    return kukit.fo.getAllFormVars(form);
-};
 
 /* With editors, there are two main points of handling:
 
@@ -269,3 +266,42 @@
 
 kukit.fo.fieldUpdateRegistry = new kukit.fo.FieldUpdateRegistry();
 
+
+// Registry of the pprovider functions for kssSubmitForm
+
+kukit.fo.pproviderFormRegistry = new kukit.pr.ParamProviderRegistry();
+
+// form, currentForm will provide identical functions do those in normal parameters
+// except they return a tuple list, not a dictionary.
+// This is needed because duplications and order must be preserved.
+
+kukit.fo.FormPP = function() {};
+kukit.fo.FormPP.prototype = {
+    check: function(args) {
+        if (args.length != 1) {
+            throw 'form method needs 1 arguments (formname)';
+        }
+    },
+    eval: function(args, node) {
+        return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(args[0]), new kukit.ut.TupleCollector());
+    }
+};
+kukit.fo.pproviderFormRegistry.register('form', kukit.fo.FormPP);
+
+kukit.fo.CurrentFormPP = function() {};
+kukit.fo.CurrentFormPP.prototype = {
+    check: function(args) {
+        if (args.length != 0) {
+            throw 'currentForm method needs no argument';
+        }
+    },
+    eval: function(args, node) {
+        return kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator(node), new kukit.ut.TupleCollector());
+    }
+};
+kukit.fo.pproviderFormRegistry.register('currentForm', kukit.fo.CurrentFormPP);
+
+// If a string is given, that will look like a form lookup,
+// ie. identical to form
+kukit.fo.pproviderFormRegistry.register('', kukit.fo.FormPP);
+

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/kssparser.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/kssparser.js	Mon Apr 23 11:21:50 2007
@@ -1,8 +1,7 @@
 /*
-* Copyright (c) 2005-2006
-* Authors:
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt)
 *   Martin Heidegger <mastakaneda at gmail.com>
-*   Balázs Reé <ree at greenfinity.hu>
 *
 * 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
@@ -132,7 +131,8 @@
 
     var ppRegistries = {
         '': kukit.pprovidersGlobalRegistry,
-        'kssSelector': kukit.sr.pproviderSelRegistry
+        'kssSelector': kukit.sr.pproviderSelRegistry,
+        'kssSubmitForm': kukit.fo.pproviderFormRegistry
     };
 
     // p.s. value is here a KssXxParm. In most cases we check and unwrap it.

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/oper.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/oper.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/oper.js	Mon Apr 23 11:21:50 2007
@@ -1,9 +1,6 @@
 /*
-* Copyright (c) 2006
-* Authors:
-*   Godefroid Chapelle <gotcha at bubblenet.be>
-*   Florian Schulze <florian.schulze at gmx.net>
-*   Balázs Reé <ree at greenfinity.hu>
+* Copyright (c) 2006-2007
+* 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
@@ -177,6 +174,9 @@
             case 'kssUrl': {
                 // Value will be evaluated.
             } break;
+            case 'kssSubmitForm': {
+                // Value will be evaluated.
+            } break;
             default: {
                 throw 'No kss parameter "' + key + '" allowed in action-server. (Normal parameters cannot start with kss.)';
             } break;

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/providerreg.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/providerreg.js	Mon Apr 23 11:21:50 2007
@@ -107,7 +107,7 @@
         }
     },
     eval: function(args, node) {
-        return kukit.fo.getFormVarFromNamedForm(args[0], args[1]);
+        return kukit.fo.getFormVar(new kukit.fo.NamedFormLocator(args[0]), args[1]);
     }
 };
 kukit.pprovidersGlobalRegistry.register('formVar', kukit.pr.FormVarPP);
@@ -121,7 +121,7 @@
     },
     eval: function(args, node) {
         if (args.length == 1) {
-            return kukit.fo.getFormVarFromCurrentForm(node, args[0]);
+            return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(node), args[0]);
         } else {
             // no form var name, just get the value of the node.
             return kukit.fo.getValueOfFormElement(node);
@@ -145,7 +145,7 @@
             recurseParents = args[1];
         }
         var formvarname = kukit.dom.getRecursiveAttribute(node, argname, recurseParents, kukit.dom.getKssAttribute);
-        return kukit.fo.getFormVarFromCurrentForm(node, formvarname);
+        return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(node), formvarname);
     }
 };
 kukit.pprovidersGlobalRegistry.register('currentFormVarFromKssAttr', kukit.pr.CurrentFormVarFromKssAttrPP);
@@ -159,7 +159,7 @@
         }
     },
     eval: function(args, node) {
-        return kukit.fo.getAllFormVarsFromNamedForm(args[0]);
+        return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(args[0]), new kukit.ut.DictCollector());
     }
 };
 kukit.pprovidersGlobalRegistry.register('form', kukit.pr.FormPP);
@@ -172,7 +172,7 @@
         }
     },
     eval: function(args, node) {
-        return kukit.fo.getAllFormVarsFromCurrentForm(node);
+        return kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator(node), new kukit.ut.DictCollector());
     }
 };
 kukit.pprovidersGlobalRegistry.register('currentForm', kukit.pr.CurrentFormPP);

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js	Mon Apr 23 11:21:50 2007
@@ -77,6 +77,17 @@
     for (var key in this.oper.parms) {
         query.appendElem(key, this.oper.parms[key]);
     }
+    // also add the parameters that result from submitting an entire form.
+    // This is, unlike the normal parms, is a list. Keys and values are
+    // added at the end of the query, without mangling names.
+    var formsubmit = this.oper.aparms.kssSubmitForm;
+    if (formsubmit) {
+        for (var i=0; i<formsubmit.length; i++) {
+            var item = formsubmit[i];
+            query.appendElem(item[0], item[1]);
+        }
+    }
+    // encode the query
     var encoded = query.encode();
     // sending form
     var ts = new Date().getTime();

Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/utils.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/utils.js	(original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/utils.js	Mon Apr 23 11:21:50 2007
@@ -404,3 +404,22 @@
     return false;
 };
 
+
+/* collecting keys-values into a dict or into a tuple list */
+
+kukit.ut.DictCollector = function() {
+    this.result = {};
+};
+
+kukit.ut.DictCollector.prototype.add = function(key, value) {
+    this.result[key] = value;
+};
+
+kukit.ut.TupleCollector = function() {
+    this.result = [];
+};
+
+kukit.ut.TupleCollector.prototype.add = function(key, value) {
+    this.result.push([key, value]);
+};
+


More information about the Kukit-checkins mailing list