From reebalazs at codespeak.net Mon Jul 3 18:29:02 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 3 Jul 2006 18:29:02 +0200 (CEST) Subject: [Kukit-checkins] r29612 - kukit/kukit.js/trunk/kukit Message-ID: <20060703162902.2B8371007D@code0.codespeak.net> Author: reebalazs Date: Mon Jul 3 18:28:59 2006 New Revision: 29612 Modified: kukit/kukit.js/trunk/kukit/kukit.js kukit/kukit.js/trunk/kukit/plugin.js kukit/kukit.js/trunk/kukit/resourcedata.js Log: Calling the bind of document: special selectors Modified: kukit/kukit.js/trunk/kukit/kukit.js ============================================================================== --- kukit/kukit.js/trunk/kukit/kukit.js (original) +++ kukit/kukit.js/trunk/kukit/kukit.js Mon Jul 3 18:28:59 2006 @@ -269,6 +269,10 @@ for (var y=0; y < rules.length; y++) { rules[y].mergeForSelectedNodes(ruletable, in_node); } + // bind special selectors first + if (typeof(in_node) == 'undefined') { + kukit.rd.methodTable.bindall(); + } // finally bind the merged events ruletable.bindall() }; Modified: kukit/kukit.js/trunk/kukit/plugin.js ============================================================================== --- kukit/kukit.js/trunk/kukit/plugin.js (original) +++ kukit/kukit.js/trunk/kukit/plugin.js Mon Jul 3 18:28:59 2006 @@ -80,6 +80,9 @@ kukit.pl.NativeEvent.prototype.__bind__ = function(name, parms, func_to_bind, node) { parms = kukit.pl.completeParms(parms, [], {}, 'native event binding'); + if (node == null) { + throw 'Native event must be bound to a node.'; + } var func = function(e) { target = kukit.pl.getTargetForBrowserEvent(e); if (target == node) { @@ -156,6 +159,9 @@ kukit.pl.CancelSubmitClickEvent.prototype.__bind__ = function(name, parms, func_to_bind, node) { parms = kukit.pl.completeParms(parms, [], {}, 'cancelSubmitClick event binding'); + if (node == null) { + throw 'cancelSubmitClick event must be bound to a node.'; + } var func = function(e) { target = kukit.pl.getTargetForBrowserEvent(e); if (target == node) { @@ -224,22 +230,33 @@ ); - kukit.ar.eventActionRegistry.register("logDebug", function (node, parms, eventrule) { parms = kukit.pl.completeParms(parms, [], {'message': 'Logging from Event'}, 'logDebug action'); - kukit.logDebug(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + node.nodeName); + var nodeName = ''; + if (node != null) { + nodeName = node.nodeName; + } + kukit.logDebug(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + nodeName); } ); kukit.ar.eventActionRegistry.register("log", function (node, parms, eventrule) { parms = kukit.pl.completeParms(parms, [], {'message': 'Logging from Event'}, 'log action'); - kukit.log(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + node.nodeName); + var nodeName = ''; + if (node != null) { + nodeName = node.nodeName; + } + kukit.log(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + nodeName); } ); kukit.ar.eventActionRegistry.register("alert", function (node, parms, eventrule) { parms = kukit.pl.completeParms(parms, [], {'message': 'Logging from Event'}, 'alert action'); - alert(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + node.nodeName); + var nodeName = ''; + if (node != null) { + nodeName = node.nodeName; + } + alert(parms.message + ', rule=#' + eventrule.getNr() + ', node=' + nodeName); } ); Modified: kukit/kukit.js/trunk/kukit/resourcedata.js ============================================================================== --- kukit/kukit.js/trunk/kukit/resourcedata.js (original) +++ kukit/kukit.js/trunk/kukit/resourcedata.js Mon Jul 3 18:28:59 2006 @@ -539,5 +539,17 @@ return mergedrule; }; +kukit.rd.MethodTable.prototype.bindall = function() { + // bind document events + var documentrules = this.content['document']; + var counter = 0; + for (var mergeid in documentrules) { + // bind to null as a node + documentrules[mergeid].bind(null); + counter += 1; + } + kukit.logDebug('Binding ' + counter + ' special rules in grand total'); +}; + kukit.rd.methodTable = new kukit.rd.MethodTable(); From reebalazs at codespeak.net Mon Jul 3 18:29:49 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 3 Jul 2006 18:29:49 +0200 (CEST) Subject: [Kukit-checkins] r29613 - kukit/azaxdemo/trunk/browser Message-ID: <20060703162949.253301007D@code0.codespeak.net> Author: reebalazs Date: Mon Jul 3 18:29:47 2006 New Revision: 29613 Modified: kukit/azaxdemo/trunk/browser/azax_demo.pt Log: Small (in template) doc fix Modified: kukit/azaxdemo/trunk/browser/azax_demo.pt ============================================================================== --- kukit/azaxdemo/trunk/browser/azax_demo.pt (original) +++ kukit/azaxdemo/trunk/browser/azax_demo.pt Mon Jul 3 18:29:47 2006 @@ -1,7 +1,5 @@ - @@ -64,7 +62,7 @@

This page defines a link in the header which rel attribute points to a .kukit server file : - + see the kukit file here.

This .kukit file declares CSS selectors associated with events and server URLs called when the event occur. From reebalazs at codespeak.net Mon Jul 3 18:41:20 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 3 Jul 2006 18:41:20 +0200 (CEST) Subject: [Kukit-checkins] r29615 - kukit/kukit.js/trunk/kukit Message-ID: <20060703164120.35ABD1007D@code0.codespeak.net> Author: reebalazs Date: Mon Jul 3 18:41:19 2006 New Revision: 29615 Modified: kukit/kukit.js/trunk/kukit/kukit.js Log: Remove PythonMethodSignature Modified: kukit/kukit.js/trunk/kukit/kukit.js ============================================================================== --- kukit/kukit.js/trunk/kukit/kukit.js (original) +++ kukit/kukit.js/trunk/kukit/kukit.js Mon Jul 3 18:41:19 2006 @@ -286,55 +286,6 @@ } }; -/* Python-style args and parameters setup */ - -kukit.PythonMethodSignature = function(f_proto, f_defaults) { - // proto = a list of argnames - // default = a dict of default values - // - // e.g. - // sig = kukit.PythonMethodSignature(['a', 'b'], {'c': 1, 'd': 2}); - // sig.f_keywords(['x'], {'b': 'y', 'c': 'z'}) ==> {'a': 'x', 'b': 'y', 'c': 'z', 'd': 2} - // sig.f_keywords(['x', 'y', 'z'], {'b': 'y', 'c': 'z'}) ==> ERROR - // sig.f_keywords(['x'], {'d': 3}) ==> ERROR - // sig.f_keywords(['x', 'y'], {'a': '1'}) ==> ERROR - // - this.f_proto = f_proto - this.f_defaults = f_defaults -}; - -kukit.PythonMethodSignature.prototype.f_keywords = function(args, kw) { - var result = {}; - // check - if (args.length < this.f_proto.length) { - for (var i = args.length; i < this.f_proto.length; i++) { - var key = this.f_proto[i]; - if (typeof(kw[key]) == 'undefined') { - throw 'Missing args in python-like method call"' + key + '"'; - } - } - } else if (args.length > this.f_proto.length) { - throw 'Excess args in python-like method call (' + args.length + ' > ' + this.f_proto.length + ')'; - } - // set args - for (var i = 0; i < args.length; i++) { - result[this.f_proto[i]] = args[i]; - } - // set keywords - for (key in kw) { - if (typeof(result[key]) != 'undefined') { - throw 'Multiple values for keyword argument "' + key + '"'; - } - result[key] = kw[key]; - } - // set default values - for (key in this.f_defaults) { - if (typeof(result[key]) == 'undefined') { - result[key] = this.f_defaults[key]; - } - } - return result; -}; /* Event handling */ From reebalazs at codespeak.net Thu Jul 6 19:59:07 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Thu, 6 Jul 2006 19:59:07 +0200 (CEST) Subject: [Kukit-checkins] r29706 - in kukit/kukit.js/trunk: kukit tests Message-ID: <20060706175907.8D81310090@code0.codespeak.net> Author: reebalazs Date: Thu Jul 6 19:59:04 2006 New Revision: 29706 Added: kukit/kukit.js/trunk/kukit/commandreg.js Modified: kukit/kukit.js/trunk/kukit/eventreg.js kukit/kukit.js/trunk/kukit/kukit.js kukit/kukit.js/trunk/kukit/plugin.js kukit/kukit.js/trunk/kukit/resourcedata.js kukit/kukit.js/trunk/tests/runner.html kukit/kukit.js/trunk/tests/runtests.sh Log: Refactoring - Moved command registry to its own js file - Get rid of 'eval' parameter method, add 'statevar' and a 'setStatevar' command. - Refactor CancelSubmitClick into the native click, preventdefault parm - XxxEvent -> XxxEventBinder, in plugins - Get rid of classname on event registration - Refactor: event class -> binder, __trigger_action__ -> __trigger_event__ Added: kukit/kukit.js/trunk/kukit/commandreg.js ============================================================================== --- (empty file) +++ kukit/kukit.js/trunk/kukit/commandreg.js Thu Jul 6 19:59:04 2006 @@ -0,0 +1,75 @@ + +/* Command registration */ + +kukit.cr = {}; + +kukit.cr.CommandRegistry = function () { + this.content = {}; +}; + +kukit.cr.CommandRegistry.prototype.register = function(name, klass) { + if (this.content[name]) { + // Do not allow redefinition + kukit.logError('Error : redefinition attempt of command ' + name); + return; + } + this.content[name] = klass; +}; + +kukit.cr.CommandRegistry.prototype.get = function(name) { + var klass = this.content[name]; + if (! klass) { + // not found + kukit.logError('Error : undefined command ' + name); + } + return klass; +}; + +kukit.cr.commandRegistry = new kukit.cr.CommandRegistry(); + +/* Command factories */ + +kukit.cr.makeCommand = function(selector, name, type, params, transport) { + var commandClass = kukit.cr.commandRegistry.get(name); + var command = new commandClass(); + command.selector = selector; + command.name = name; + command.selectorType = type; + command.params = params; + command.transport = transport; + return command; +} + +kukit.cr._Command_execute_selector = function() { + kukit.logDebug('Selector type: ' + this.selectorType); + kukit.logDebug('Selector : ' + this.selector); + var selfunc = kukit.selectors.get(this.selectorType); + var nodes = selfunc(this.selector); + if (!nodes || nodes.length == 0) { + kukit.logError('Command found no nodes'); + } + for (var i=0;i < nodes.length;i++) { + var node = nodes[i]; + //XXX error handling for wrong command name + kukit.logDebug('Command Name: ' + this.name); + this.executeOnSingleNode(node); + } +}; + +kukit.cr.makeSelectorCommand = function(name, executeOnSingleNode) { + var commandClass = function() {}; + commandClass.prototype = { + execute: kukit.cr._Command_execute_selector, + executeOnSingleNode: executeOnSingleNode + }; + kukit.cr.commandRegistry.register(name, commandClass); +}; + +kukit.cr.makeGlobalCommand = function(name, executeOnce) { + var commandClass = function() {}; + commandClass.prototype = { + execute: executeOnce + }; + kukit.cr.commandRegistry.register(name, commandClass); +}; + Modified: kukit/kukit.js/trunk/kukit/eventreg.js ============================================================================== --- kukit/kukit.js/trunk/kukit/eventreg.js (original) +++ kukit/kukit.js/trunk/kukit/eventreg.js Thu Jul 6 19:59:04 2006 @@ -3,41 +3,53 @@ kukit.er = {}; -/* Event class registry +/* Event registry * * available for plugin registration * -* class must be the *name* of the event class -* func must be a class (constructor) function. +* usage: +* +* kukit.er.eventRegistry.register(namespace, eventname, func, +* bindmethodname, defaultactionmethodname); +* +* namespace = null: means global namespace +* defaultactionmethodname = null: if there is no default action implemented +* func must be a class (constructor) function, this is the class that +* implements the binder. * */ -kukit.er.EventClassRegistry = function () { +kukit.er.eventClassCounter = 0; + +kukit.er.EventRegistry = function () { this.content = {}; + this.classes = {}; }; -kukit.er.EventClassRegistry.prototype.register = function(classname, func) { +/* binder registration */ + +kukit.er.EventRegistry.prototype.registerBinder = function(classname, func) { if (typeof(func) == 'undefined') { throw 'Func is mandatory.'; } - if (this.content[classname]) { + if (this.classes[classname]) { // Do not allow redefinition kukit.logError('Error : redefinition attempt of event class ' + classname); return; } // Decorate and store the class - kukit.er.decorateEventClass(func); - this.content[classname] = func; + kukit.er.decorateEventBinderClass(func); + this.classes[classname] = func; }; -kukit.er.EventClassRegistry.prototype.exists = function(classname) { - var func = this.content[classname]; +kukit.er.EventRegistry.prototype.existsBinder = function(classname) { + var func = this.classes[classname]; return (typeof(func) != 'undefined'); }; -kukit.er.EventClassRegistry.prototype.get = function(classname) { - var func = this.content[classname]; +kukit.er.EventRegistry.prototype.getBinder = function(classname) { + var func = this.classes[classname]; if (! func) { // not found throw 'Error : undefined event setup type ' + classname; @@ -45,33 +57,24 @@ return func; }; -kukit.er.eventClassRegistry = new kukit.er.EventClassRegistry(); - -/* Event registry -* -* available for plugin registration -* -* usage: -* -* kukit.er.eventRegistry.register(namespace, eventname, classname, -* bindmethodname, defaultactionmethodname); -* -* namespace = null: means global namespace -* defaultactionmethodname = null: if there is no default action implemented -* -*/ - -kukit.er.EventRegistry = function () { - this.content = {}; -}; +/* events (methods) registration */ -kukit.er.EventRegistry.prototype.register = function(namespace, eventname, classname, +kukit.er.EventRegistry.prototype.register = function(namespace, eventname, klass, bindmethodname, defaultactionmethodname) { if (typeof(defaultactionmethodname) == 'undefined') { throw 'EventRegistry.register misses some parameters'; } - if (!eventname || !classname) { - throw 'In EventRegistry.register eventname, classname must be non-empty'; + // Find out the class name. (Not specified now.) + classname = klass.prototype.__classname__; + if (typeof(classname) == 'undefined') { + // Create a classname, and register it too. + classname = '' + kukit.er.eventClassCounter; + kukit.er.eventClassCounter += 1; + this.registerBinder(classname, klass); + klass.prototype.__classname__ = classname; + } + if (!eventname) { + throw 'In EventRegistry.register eventname must be non-empty'; } var key = this._getKey(namespace, eventname); var entry = this.content[key]; @@ -133,7 +136,7 @@ * executed in the KSS. */ -kukit.er.Event__trigger_action__ = function(name, parms, node) { +kukit.er.Event__trigger_event__ = function(name, parms, node) { // Can be called from programs to execute an action programmatically. var eventrule = kukit.rd.methodTable.getMergedRule('kss', name, this); // getMergedRule gave a warning (once by page), so be silent if not found @@ -143,8 +146,8 @@ }; -kukit.er.decorateEventClass = function(cls) { - cls.prototype.__trigger_action__ = kukit.er.Event__trigger_action__; +kukit.er.decorateEventBinderClass = function(cls) { + cls.prototype.__trigger_event__ = kukit.er.Event__trigger_event__; }; /* Event instance registry @@ -162,7 +165,7 @@ var eventinstance = this.content[id]; if (typeof(eventinstance) == 'undefined') { // Create a new event. - eventinstance = this.content[id] = new (kukit.er.eventClassRegistry.get(classname))(); + eventinstance = this.content[id] = new (kukit.er.eventRegistry.getBinder(classname))(); // decorate it with id and class eventinstance.__event_id__ = id; eventinstance.__event_classname__ = classname; Modified: kukit/kukit.js/trunk/kukit/kukit.js ============================================================================== --- kukit/kukit.js/trunk/kukit/kukit.js (original) +++ kukit/kukit.js/trunk/kukit/kukit.js Thu Jul 6 19:59:04 2006 @@ -186,6 +186,10 @@ return this.elements[0]; }; +/* State vars srorage. This can be used from kss via a method. */ + +kukit.statevars = {}; + /* instantiate request manager */ kukit.requestManager = new kukit.RequestManager(); @@ -428,7 +432,7 @@ } kukit.log('Command params: '+ has_params); if (selector != "" && has_params && name != "") { - var command = new kukit.makeCommand(selector, name, type, params, transport); + var command = new kukit.cr.makeCommand(selector, name, type, params, transport); this.addCommand(command); } } @@ -547,180 +551,3 @@ return result; }; -/* Command registry */ - -kukit.CommandRegistry = function () { - this.content = {}; -}; - -kukit.CommandRegistry.prototype.register = function(name, klass) { - if (this.content[name]) { - // Do not allow redefinition - kukit.logError('Error : redefinition attempt of command ' + name); - return; - } - this.content[name] = klass; -}; - -kukit.CommandRegistry.prototype.get = function(name) { - var klass = this.content[name]; - if (! klass) { - // not found - kukit.logError('Error : undefined command ' + name); - } - return klass; -}; - -kukit.commandRegistry = new kukit.CommandRegistry(); - -/* Command factories */ - -kukit.makeCommand = function(selector, name, type, params, transport) { - var commandClass = kukit.commandRegistry.get(name); - var command = new commandClass(); - command.selector = selector; - command.name = name; - command.selectorType = type; - command.params = params; - command.transport = transport; - return command; -} - -kukit._Command_execute_selector = function() { - kukit.logDebug('Selector type: ' + this.selectorType); - kukit.logDebug('Selector : ' + this.selector); - var selfunc = kukit.selectors.get(this.selectorType); - var nodes = selfunc(this.selector); - if (!nodes || nodes.length == 0) { - kukit.logError('Command found no nodes'); - } - for (var i=0;i < nodes.length;i++) { - var node = nodes[i]; - //XXX error handling for wrong command name - kukit.logDebug('Command Name: ' + this.name); - this.executeOnSingleNode(node); - } -}; - -kukit.makeSelectorCommand = function(name, executeOnSingleNode) { - var commandClass = function() {}; - commandClass.prototype = { - execute: kukit._Command_execute_selector, - executeOnSingleNode: executeOnSingleNode - }; - kukit.commandRegistry.register(name, commandClass); -}; - -kukit.makeGlobalCommand = function(name, executeOnce) { - var commandClass = function() {}; - commandClass.prototype = { - execute: executeOnce - }; - kukit.commandRegistry.register(name, commandClass); -}; - -/* Core commands */ - -// innerHTML -kukit.makeSelectorCommand('setHtmlAsChild', function(node) { - var content = document.importNode(this.params['html'], true); - Sarissa.clearChildNodes(node); - kukit.dom.appendChildren(content.childNodes, node); - kukit.setupEvents(node); -}); - -// outerHTML ? -kukit.makeSelectorCommand('replaceNode', function(node) { - var childNodes = this.params['html'].childNodes; - var sourceSelector = this.params['selector'].firstChild.nodeValue || null; - var parentNode = node.parentNode; - var newNode = parentNode.cloneNode(false); - try { - kukit.dom.appendChildren(childNodes, newNode); - } catch(exc) { - newNode.innerHTML = Sarissa.serialize(this.params['html']); - } - if (sourceSelector) { - var element = cssQuery(sourceSelector, newNode)[0]; - if (element) - parentNode.replaceChild(element, node); - else - kukit.logDebug("Found no elements in response with selector '"+sourceSelector+"'."); - } else { - parentNode.replaceChild(newNode.firstChild, node); - } - kukit.setupEvents(parentNode); -}); - - -kukit.makeSelectorCommand('setAttribute', function(node) { - var name = this.params['name'].firstChild.nodeValue; - var value = this.params['value'].firstChild.nodeValue; - node.setAttribute(name, value); -}); - -kukit.makeSelectorCommand('addAfter', function(node) { - var content = document.importNode(this.params['html'], true); - var parentNode = node.parentNode; - var toNode = kukit.dom.getNextSiblingTag(node); - if (toNode == null) { - var inserted = kukit.dom.appendChildren(content.childNodes, parentNode); - } else { - var inserted = kukit.dom.insertBefore(content, parentNode, toNode); - } - // update the events for the new nodes - kukit.logDebug("Inserted nodes length: "+inserted.length); - kukit.setupEvents(node); -}); - -kukit.makeSelectorCommand('removeNextSibling', function(node) { - kukit.logDebug('removeNextSibling'); - var parentNode = node.parentNode; - var toNode = kukit.dom.getNextSiblingTag(node); - if (toNode != null) { - parentNode.removeChild(toNode); - } -}); - -kukit.makeSelectorCommand('removePreviousSibling', function(node) { - kukit.logDebug('removePreviousSibling'); - var parentNode = node.parentNode; - var toNode = kukit.dom.getPreviousSiblingTag(node); - parentNode.removeChild(toNode); -}); - -kukit.makeSelectorCommand('removeNode', function(node) { - var parentNode = node.parentNode; - parentNode.removeChild(node); -}); - -kukit.makeSelectorCommand('clearChildren', function(node) { - Sarissa.clearChildNodes(node); -}); - -kukit.makeSelectorCommand('moveNodeAfter', function(node) { - var parentNode = node.parentNode; - parentNode.removeChild(node); - - var id = this.params['html_id'].firstChild.nodeValue; - var toNode = document.getElementById(id); - - var nextNode = kukit.dom.getNextSiblingTag(toNode); - if (nextNode == null) { - toNode.parentNode.appendChild(node); - } else { - parentNode.insertBefore(node, nextNode); - } -}); - -kukit.makeSelectorCommand('copyChildrenFrom', function(node) { - var id = this.params['html_id'].firstChild.nodeValue; - var fromNode = document.getElementById(id); - Sarissa.copyChildNodes(fromNode, node); -}); - -kukit.makeSelectorCommand('copyChildrenTo', function(node) { - var id = this.params['html_id'].firstChild.nodeValue; - toNode = document.getElementById(id); - Sarissa.copyChildNodes(node, toNode); -}) Modified: kukit/kukit.js/trunk/kukit/plugin.js ============================================================================== --- kukit/kukit.js/trunk/kukit/plugin.js (original) +++ kukit/kukit.js/trunk/kukit/plugin.js Thu Jul 6 19:59:04 2006 @@ -34,25 +34,32 @@ return newparms; }; +kukit.pl.evalBool = function(parms, key, errname) { + value = parms[key]; + if (value == 'true' || value == 'True' || value == '1') { + value = true; + } else if (value == 'false' || value == 'False' || value == '0' || value == '') { + value = false; + } else { + throw 'Bad boolean value "' + value + '" for key "' + key + '" in ' + errname; + } + parms[key] = value; +}; + /* * Event plugins * -* __trigger_action__(name, parms, node) +* __trigger_event__(name, parms, node) * is a method bound to each class, so methods can call * it up to call an event action bound through kss. * * The event binder hooks * __bind__(name, parms, func_to_bind) -* __bind___(parms, func_to_bind) * should be defined to make binding of event to the given function. -* (Return true if binding was successful.) * * The event action hooks * __exec__(name, parms, node) -* __exec___(parms, node) -* can be defined to override the default event action. -* (Return true if execution was successful or false if -* chain should be continued.) +* can be defined to specify a default event action. * */ @@ -75,14 +82,18 @@ }; -kukit.pl.NativeEvent = function() { +kukit.pl.NativeEventBinder = function() { }; -kukit.pl.NativeEvent.prototype.__bind__ = function(name, parms, func_to_bind, node) { - parms = kukit.pl.completeParms(parms, [], {}, 'native event binding'); +kukit.pl.NativeEventBinder.prototype.__bind__ = function(name, parms, func_to_bind, node) { + parms = kukit.pl.completeParms(parms, [], {'preventdefault': ''}, 'native event binding'); + kukit.pl.evalBool(parms, 'preventdefault', 'native event binding'); if (node == null) { throw 'Native event must be bound to a node.'; } + if (parms.preventdefault && name != 'click') { + throw 'In native events only the click event can have preventdefault.'; + } var func = function(e) { target = kukit.pl.getTargetForBrowserEvent(e); if (target == node) { @@ -91,14 +102,25 @@ } else { kukit.log('Ignored event for "' + name + '", possibly wrong target'); } + }; + if (parms.preventdefault) { + var func_prevent = function(e) { + func(e); + // Cancel default event + // W3C style + if (e.preventDefault) + e.preventDefault(); + // MS style + try { e.returnValue = false; } catch (exc) {} + }; + kukit.registerEventListener(node, name, func_prevent); + } else { + kukit.registerEventListener(node, name, func); } - kukit.registerEventListener(node, name, func); - return true; }; -kukit.er.eventClassRegistry.register('native', kukit.pl.NativeEvent); -kukit.er.eventRegistry.register(null, 'click', 'native', '__bind__', null); -kukit.er.eventRegistry.register(null, 'change', 'native', '__bind__', null); +kukit.er.eventRegistry.register(null, 'click', kukit.pl.NativeEventBinder, '__bind__', null); +kukit.er.eventRegistry.register(null, 'change', kukit.pl.NativeEventBinder, '__bind__', null); // Timer events. The binding of this event will start one counter // per event rule. No matter how many nodes matched it. @@ -125,11 +147,11 @@ this.start(); }; -kukit.pl.TimeoutEvent = function() { +kukit.pl.TimeoutEventBinder = function() { this.counters = {}; }; -kukit.pl.TimeoutEvent.prototype.__bind__ = function(name, parms, func_to_bind, node, eventrule) { +kukit.pl.TimeoutEventBinder.prototype.__bind__ = function(name, parms, func_to_bind, node, eventrule) { parms = kukit.pl.completeParms(parms, ['delay'], {}, 'timeout event binding'); var key = eventrule.getNr(); if (this.counters[key]) { @@ -144,58 +166,20 @@ // Start the counter counter.start(); } - // Success in any case. - return true; -}; - -kukit.er.eventClassRegistry.register('timeout', kukit.pl.TimeoutEvent); -kukit.er.eventRegistry.register(null, 'timeout', 'timeout', '__bind__', null); - -// CancelSubmitClick. This is a mutated version of -// the browser click event. - -kukit.pl.CancelSubmitClickEvent = function() { -}; - -kukit.pl.CancelSubmitClickEvent.prototype.__bind__ = function(name, parms, func_to_bind, node) { - parms = kukit.pl.completeParms(parms, [], {}, 'cancelSubmitClick event binding'); - if (node == null) { - throw 'cancelSubmitClick event must be bound to a node.'; - } - var func = function(e) { - target = kukit.pl.getTargetForBrowserEvent(e); - if (target == node) { - // Execute the action - func_to_bind(); - } else { - kukit.log('Ignored event for "' + name + '", possibly wrong target') - } - // Cancel default event - // W3C style - if (e.preventDefault) - e.preventDefault(); - // MS style - try { e.returnValue = false; } catch (exc) {} - } - kukit.registerEventListener(node, 'click', func); - return true; }; -kukit.er.eventClassRegistry.register('cancelSubmitClick', kukit.pl.CancelSubmitClickEvent); -kukit.er.eventRegistry.register(null, 'cancelSubmitClick', 'cancelSubmitClick', '__bind__', null); +kukit.er.eventRegistry.register(null, 'timeout', kukit.pl.TimeoutEventBinder, '__bind__', null); -kukit.pl.LoadEvent = function() { +kukit.pl.LoadEventBinder = function() { }; -kukit.pl.LoadEvent.prototype.__bind__ = function(name, parms, func_to_bind, node) { +kukit.pl.LoadEventBinder.prototype.__bind__ = function(name, parms, func_to_bind, node) { parms = kukit.pl.completeParms(parms, [], {}, 'load event binding'); // Just execute the action right now. func_to_bind() - return true; }; -kukit.er.eventClassRegistry.register('load', kukit.pl.LoadEvent); -kukit.er.eventRegistry.register(null, 'load', 'load', '__bind__', null); +kukit.er.eventRegistry.register(null, 'load', kukit.pl.LoadEventBinder, '__bind__', null); /* Core actions @@ -260,4 +244,113 @@ } ); +/* Core commands */ + +// innerHTML +kukit.cr.makeSelectorCommand('setHtmlAsChild', function(node) { + var content = document.importNode(this.params['html'], true); + Sarissa.clearChildNodes(node); + kukit.dom.appendChildren(content.childNodes, node); + kukit.setupEvents(node); +}); + +// outerHTML ? +kukit.cr.makeSelectorCommand('replaceNode', function(node) { + var childNodes = this.params['html'].childNodes; + var sourceSelector = this.params['selector'].firstChild.nodeValue || null; + var parentNode = node.parentNode; + var newNode = parentNode.cloneNode(false); + try { + kukit.dom.appendChildren(childNodes, newNode); + } catch(exc) { + newNode.innerHTML = Sarissa.serialize(this.params['html']); + } + if (sourceSelector) { + var element = cssQuery(sourceSelector, newNode)[0]; + if (element) + parentNode.replaceChild(element, node); + else + kukit.logDebug("Found no elements in response with selector '"+sourceSelector+"'."); + } else { + parentNode.replaceChild(newNode.firstChild, node); + } + kukit.setupEvents(parentNode); +}); + +kukit.cr.makeSelectorCommand('setAttribute', function(node) { + var name = this.params['name'].firstChild.nodeValue; + var value = this.params['value'].firstChild.nodeValue; + node.setAttribute(name, value); +}); + +kukit.cr.makeSelectorCommand('addAfter', function(node) { + var content = document.importNode(this.params['html'], true); + var parentNode = node.parentNode; + var toNode = kukit.dom.getNextSiblingTag(node); + if (toNode == null) { + var inserted = kukit.dom.appendChildren(content.childNodes, parentNode); + } else { + var inserted = kukit.dom.insertBefore(content, parentNode, toNode); + } + // update the events for the new nodes + kukit.logDebug("Inserted nodes length: "+inserted.length); + kukit.setupEvents(node); +}); + +kukit.cr.makeSelectorCommand('removeNextSibling', function(node) { + kukit.logDebug('removeNextSibling'); + var parentNode = node.parentNode; + var toNode = kukit.dom.getNextSiblingTag(node); + if (toNode != null) { + parentNode.removeChild(toNode); + } +}); + +kukit.cr.makeSelectorCommand('removePreviousSibling', function(node) { + kukit.logDebug('removePreviousSibling'); + var parentNode = node.parentNode; + var toNode = kukit.dom.getPreviousSiblingTag(node); + parentNode.removeChild(toNode); +}); + +kukit.cr.makeSelectorCommand('removeNode', function(node) { + var parentNode = node.parentNode; + parentNode.removeChild(node); +}); + +kukit.cr.makeSelectorCommand('clearChildren', function(node) { + Sarissa.clearChildNodes(node); +}); + +kukit.cr.makeSelectorCommand('moveNodeAfter', function(node) { + var parentNode = node.parentNode; + parentNode.removeChild(node); + + var id = this.params['html_id'].firstChild.nodeValue; + var toNode = document.getElementById(id); + + var nextNode = kukit.dom.getNextSiblingTag(toNode); + if (nextNode == null) { + toNode.parentNode.appendChild(node); + } else { + parentNode.insertBefore(node, nextNode); + } +}); +kukit.cr.makeSelectorCommand('copyChildrenFrom', function(node) { + var id = this.params['html_id'].firstChild.nodeValue; + var fromNode = document.getElementById(id); + Sarissa.copyChildNodes(fromNode, node); +}); + +kukit.cr.makeSelectorCommand('copyChildrenTo', function(node) { + var id = this.params['html_id'].firstChild.nodeValue; + toNode = document.getElementById(id); + Sarissa.copyChildNodes(node, toNode); +}); + +kukit.cr.makeGlobalCommand('setStatevar', function(node) { + var varname = this.params['varname'].firstChild.nodeValue; + var value = this.params['value'].firstChild.nodeValue; + kukit.statevars[varname] = value; +}); Modified: kukit/kukit.js/trunk/kukit/resourcedata.js ============================================================================== --- kukit/kukit.js/trunk/kukit/resourcedata.js (original) +++ kukit/kukit.js/trunk/kukit/resourcedata.js Thu Jul 6 19:59:04 2006 @@ -100,9 +100,9 @@ throw 'nodeattr method needs 1 argument (attrname)'; } } break; - case 'eval': { + case 'statevar': { if (this.args.length != 1) { - throw 'eval method needs 1 argument (expression)'; + throw 'statevar method needs 1 argument (varname)'; } } break; default: { @@ -131,9 +131,14 @@ } parms[key] = value; } break; - case 'eval': { - // XXX do it with the variable registry - parms[key] = eval(this.args[0]); + case 'statevar': { + var key = this.args[0]; + var value = kukit.statevars[key]; + if (typeof(value) == 'undefined') { + // notfound arguments will get null + throw 'Nonexistent statevar "'+ key +'"'; + } + parms[key] = value; } break; default: { throw 'Ignored kss parameter method.'; @@ -527,7 +532,6 @@ } // look up the rule and merge if necessary var namespace = eventinstance.__event_namespace__; - var classname = eventinstance.__event_classname__; var id = eventinstance.__event_id__; var mergeid = kukit.rd.makeMergeId(id, namespace, name); var mergedrule = dict[mergeid]; Modified: kukit/kukit.js/trunk/tests/runner.html ============================================================================== --- kukit/kukit.js/trunk/tests/runner.html (original) +++ kukit/kukit.js/trunk/tests/runner.html Thu Jul 6 19:59:04 2006 @@ -21,6 +21,7 @@ + Modified: kukit/kukit.js/trunk/tests/runtests.sh ============================================================================== --- kukit/kukit.js/trunk/tests/runtests.sh (original) +++ kukit/kukit.js/trunk/tests/runtests.sh Thu Jul 6 19:59:04 2006 @@ -7,6 +7,7 @@ -f ../kukit/kssparser.js \ -f ../kukit/eventreg.js \ -f ../kukit/actionreg.js \ + -f ../kukit/commandreg.js \ -f ../kukit/forms.js \ -f ../kukit/plugin.js \ -f test_tokenizer.js \ From reebalazs at codespeak.net Thu Jul 6 19:59:21 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Thu, 6 Jul 2006 19:59:21 +0200 (CEST) Subject: [Kukit-checkins] r29707 - in kukit/azax/trunk: . plugins Message-ID: <20060706175921.0C76510090@code0.codespeak.net> Author: reebalazs Date: Thu Jul 6 19:59:19 2006 New Revision: 29707 Modified: kukit/azax/trunk/azaxview.py kukit/azax/trunk/configure.zcml kukit/azax/trunk/plugins/configure.zcml Log: Refactoring - Moved command registry to its own js file - Get rid of 'eval' parameter method, add 'statevar' and a 'setStatevar' command. - Refactor CancelSubmitClick into the native click, preventdefault parm - XxxEvent -> XxxEventBinder, in plugins - Get rid of classname on event registration - Refactor: event class -> binder, __trigger_action__ -> __trigger_event__ Modified: kukit/azax/trunk/azaxview.py ============================================================================== --- kukit/azax/trunk/azaxview.py (original) +++ kukit/azax/trunk/azaxview.py Thu Jul 6 19:59:19 2006 @@ -140,7 +140,7 @@ self.copyChildrenTo(selector, id) self.clearChildren(selector) - def executeCode(self, selector, code): - code = XmlParser(code)() - command = self.addCommand('executeCode', selector) - data = command.addParam('code', code) + def setStatevar(self, varname, value): + command = self.addCommand('setStatevar') + command.addParam('varname', varname) + command.addParam('value', value) Modified: kukit/azax/trunk/configure.zcml ============================================================================== --- kukit/azax/trunk/configure.zcml (original) +++ kukit/azax/trunk/configure.zcml Thu Jul 6 19:59:19 2006 @@ -17,6 +17,7 @@ kukit/kukit/kssparser.js kukit/kukit/eventreg.js kukit/kukit/actionreg.js + kukit/kukit/commandreg.js kukit/kukit/forms.js kukit/kukit/plugin.js" name="kukit.js" Modified: kukit/azax/trunk/plugins/configure.zcml ============================================================================== --- kukit/azax/trunk/plugins/configure.zcml (original) +++ kukit/azax/trunk/plugins/configure.zcml Thu Jul 6 19:59:19 2006 @@ -70,7 +70,10 @@ - + + @@ -83,7 +86,7 @@ /> From reebalazs at codespeak.net Thu Jul 6 19:59:56 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Thu, 6 Jul 2006 19:59:56 +0200 (CEST) Subject: [Kukit-checkins] r29708 - kukit/azaxdemo/trunk/browser Message-ID: <20060706175956.92A541008D@code0.codespeak.net> Author: reebalazs Date: Thu Jul 6 19:59:55 2006 New Revision: 29708 Modified: kukit/azaxdemo/trunk/browser/cancel_submit.kss kukit/azaxdemo/trunk/browser/more_selectors.js Log: Refactoring - Moved command registry to its own js file - Get rid of 'eval' parameter method, add 'statevar' and a 'setStatevar' command. - Refactor CancelSubmitClick into the native click, preventdefault parm - XxxEvent -> XxxEventBinder, in plugins - Get rid of classname on event registration - Refactor: event class -> binder, __trigger_action__ -> __trigger_event__ Modified: kukit/azaxdemo/trunk/browser/cancel_submit.kss ============================================================================== --- kukit/azaxdemo/trunk/browser/cancel_submit.kss (original) +++ kukit/azaxdemo/trunk/browser/cancel_submit.kss Thu Jul 6 19:59:55 2006 @@ -1,4 +1,5 @@ -input#submit:cancelSubmitClick { +input#submit:click { + evt-click-preventdefault: true; action-server: save; save-text_save: currentformvar(text_save); } Modified: kukit/azaxdemo/trunk/browser/more_selectors.js ============================================================================== --- kukit/azaxdemo/trunk/browser/more_selectors.js (original) +++ kukit/azaxdemo/trunk/browser/more_selectors.js Thu Jul 6 19:59:55 2006 @@ -20,7 +20,7 @@ this.countsomuch = count; this.count = this.countsomuch; // Just bind the event via the native event binder - kukit.pl.NativeEvent.prototype.__bind__('click', {}, func_to_bind, node); + kukit.pl.NativeEventBinder.prototype.__bind__('click', {}, func_to_bind, node); }; kukit.more_selectors.AnnoyClickerEvent.prototype.__default_click__ = function(name, parms, node) { @@ -28,15 +28,13 @@ if (this.count == 0) { // Continue with the real action. this.count = this.countsomuch; - this.__trigger_action__('doit', parms, node); + this.__trigger_event__('doit', parms, node); } else { - this.__trigger_action__('annoy', parms, node); + this.__trigger_event__('annoy', parms, node); } }; -kukit.er.eventClassRegistry.register('annoyClicker', kukit.more_selectors.AnnoyClickerEvent); -kukit.er.eventRegistry.register('annoyclicker', 'click', 'annoyClicker', '__bind_click__', '__default_click__'); -kukit.er.eventRegistry.register('annoyclicker', 'annoy', 'annoyClicker', null, null); -kukit.er.eventRegistry.register('annoyclicker', 'doit', 'annoyClicker', null, null); - +kukit.er.eventRegistry.register('annoyclicker', 'click', kukit.more_selectors.AnnoyClickerEvent, '__bind_click__', '__default_click__'); +kukit.er.eventRegistry.register('annoyclicker', 'annoy', kukit.more_selectors.AnnoyClickerEvent, null, null); +kukit.er.eventRegistry.register('annoyclicker', 'doit', kukit.more_selectors.AnnoyClickerEvent, null, null); From reebalazs at codespeak.net Thu Jul 6 20:00:08 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Thu, 6 Jul 2006 20:00:08 +0200 (CEST) Subject: [Kukit-checkins] r29709 - kukit/bluekit/trunk/browser Message-ID: <20060706180008.6B35310092@code0.codespeak.net> Author: reebalazs Date: Thu Jul 6 20:00:06 2006 New Revision: 29709 Modified: kukit/bluekit/trunk/browser/mockup.js Log: Refactoring - Moved command registry to its own js file - Get rid of 'eval' parameter method, add 'statevar' and a 'setStatevar' command. - Refactor CancelSubmitClick into the native click, preventdefault parm - XxxEvent -> XxxEventBinder, in plugins - Get rid of classname on event registration - Refactor: event class -> binder, __trigger_action__ -> __trigger_event__ Modified: kukit/bluekit/trunk/browser/mockup.js ============================================================================== --- kukit/bluekit/trunk/browser/mockup.js (original) +++ kukit/bluekit/trunk/browser/mockup.js Thu Jul 6 20:00:06 2006 @@ -10,8 +10,7 @@ //var foo = new Foo(); -kukit.er.eventClassRegistry.register('update', Foo); -kukit.er.eventRegistry.register('bluekit', 'update', 'update', '__bind__', '__exec__'); +kukit.er.eventRegistry.register('bluekit', 'update', Foo, '__bind__', '__exec__'); Foo.prototype.__bind__ = function(name, parms, func_to_bind, node) { kukit.registerEventListener(node, 'click', func_to_bind); From reebalazs at codespeak.net Sun Jul 9 11:20:17 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sun, 9 Jul 2006 11:20:17 +0200 (CEST) Subject: [Kukit-checkins] r29878 - kukit/kukit.js/trunk/kukit Message-ID: <20060709092017.CE1F510076@code0.codespeak.net> Author: reebalazs Date: Sun Jul 9 11:20:15 2006 New Revision: 29878 Modified: kukit/kukit.js/trunk/kukit/eventreg.js kukit/kukit.js/trunk/kukit/plugin.js kukit/kukit.js/trunk/kukit/resourcedata.js Log: Default action fixes - The default action needs to be executed if it is defined on the event, even if no parameters are bound to it from the kss eventrule. - If an event is triggered programatically via a __trigger_event__ call, then it has to be executed even if there is no corresponding rule for it (kss:eventname) in the kss. This means that if no parameters are needed, the empty rule can be omitted from kss. - The js caller should be able to specify parms at the __trigger_event__ call, and in this case the action (local or remote) gets these parameters - in addition they get overwritten by the parameters actually specified for the action, as usual. Modified: kukit/kukit.js/trunk/kukit/eventreg.js ============================================================================== --- kukit/kukit.js/trunk/kukit/eventreg.js (original) +++ kukit/kukit.js/trunk/kukit/eventreg.js Sun Jul 9 11:20:15 2006 @@ -131,23 +131,54 @@ * */ +kukit.er.EventBinder_calldefault = function(namespace, name, parms, node) { + // private method for calling just a default method. + // params should be alredy prepared. + var methodname = kukit.er.eventRegistry.get(namespace, name).defaultactionmethodname + if (methodname) { + var method = this[methodname]; + if (! method) { + throw 'Could not bind event name "' + name + '" on namespace "' + namespace + '", because the method "' + methodname + '" does not exist.'; + } + // call it + method.call(this, name, parms, node); + } +} + /* This can be called on the event and will execute the * desired event action. Parameters will be these + those * executed in the KSS. +* +* Call example: eventinstance.__trigger_event__('doit', {'extravalue': '5'}, node); */ -kukit.er.Event__trigger_event__ = function(name, parms, node) { - // Can be called from programs to execute an action programmatically. - var eventrule = kukit.rd.methodTable.getMergedRule('kss', name, this); - // getMergedRule gave a warning (once by page), so be silent if not found +kukit.er.EventBinder__trigger_event__ = function(name, parms, node) { + // Called programmatically: look up the event rule. This may fail + // but yet we want to execute a default action in this case. + eventrule = kukit.rd.methodTable.getMergedRule('kss', name, this); + this._EventBinder_triggerevent(name, parms, node, eventrule); +} + +kukit.er.EventBinder_triggerevent = function(name, parms, node, eventrule) { + // Private. Called from __trigger_event__ or from main event execution. + if (eventrule) { - eventrule.trigger_event(node, this); + // Call the actions, if we had an event rule. + // This includes calling the default action. + eventrule.actions.execute(node, eventrule, parms, this); + } else { + // In case there is no event rule, just call the default event action. + // Parms cannot be specified this way. This is implicit calling. + var namespace = this.__event__namespace__; + kukit.logWarning('Calling implicit event "' + name + '" on namespace "' + namespace + '"') + this._EventBinder_calldefault(namespace, name, parms, node); } }; - kukit.er.decorateEventBinderClass = function(cls) { - cls.prototype.__trigger_event__ = kukit.er.Event__trigger_event__; + cls.prototype.__trigger_event__ = kukit.er.EventBinder__trigger_event__; + cls.prototype._EventBinder_triggerevent = kukit.er.EventBinder_triggerevent; + cls.prototype._EventBinder_calldefault = kukit.er.EventBinder_calldefault; }; /* Event instance registry Modified: kukit/kukit.js/trunk/kukit/plugin.js ============================================================================== --- kukit/kukit.js/trunk/kukit/plugin.js (original) +++ kukit/kukit.js/trunk/kukit/plugin.js Sun Jul 9 11:20:15 2006 @@ -127,9 +127,13 @@ // The timer will tick for ever (i.e. won't stop // even if the binding nodes are all deleted) -kukit.pl.TimerCounter = function(delay, func) { +kukit.pl.TimerCounter = function(delay, func, restart) { this.delay = delay; this.func = func; + if (typeof(restart) == 'undefined') { + restart = false; + } + this.restart = restart; }; kukit.pl.TimerCounter.prototype.start = function() { @@ -144,7 +148,9 @@ // Call the event action this.func(); // Restart the timer - this.start(); + if (this.restart) { + this.start(); + } }; kukit.pl.TimeoutEventBinder = function() { @@ -161,7 +167,7 @@ } else { kukit.logDebug('timer event key entered for actionEvent #' + key + ' ' + eventrule.selector); - var counter = new kukit.pl.TimerCounter(parms.delay, func_to_bind) + var counter = new kukit.pl.TimerCounter(parms.delay, func_to_bind, true) this.counters[key] = counter; // Start the counter counter.start(); Modified: kukit/kukit.js/trunk/kukit/resourcedata.js ============================================================================== --- kukit/kukit.js/trunk/kukit/resourcedata.js (original) +++ kukit/kukit.js/trunk/kukit/resourcedata.js Sun Jul 9 11:20:15 2006 @@ -233,48 +233,12 @@ } var self = this; var func_to_bind = function() { - self.trigger_event(node, eventinstance); + eventinstance._EventBinder_triggerevent(name, {}, node, self); } // do the binding method.call(eventinstance, name, parms, func_to_bind, node, this); }; -/* -* trigger_event(node, eventinstance) : calls event trigger hook on event instance. -* These hooks are tried in order, if succeeds it must return true: -* -* __exec__(name, parms, node) -* __exec___(parms, node) -* <> -* -* One of them executes in each case. -* -*/ - -kukit.rd.EventRule.prototype.trigger_event = function(node, eventinstance) { - // Take care of the default action - if any. - var namespace = this.kss_selector.namespace; - var name = this.kss_selector.name; - var methodname = kukit.er.eventRegistry.get(namespace, name).defaultactionmethodname - if (methodname) { - var method = eventinstance[methodname]; - if (! method) { - throw 'Could not bind event name "' + name + '" on namespace "' + namespace + '", because the method "' + methodname + '" does not exist.'; - } - // get the default action parms - var defaultaction = this.actions.getDefaultAction(); - var parms; - if (defaultaction) { - parms = defaultaction.getParms(node); - } else { - parms = {}; - } - // call it - method.call(eventinstance, name, parms, node); - } - // Call the actions, in any case - this.actions.execute(node, this); -}; // // Merging event rules @@ -357,10 +321,18 @@ } }; -kukit.rd.ActionSet.prototype.execute = function(node, eventrule) { +kukit.rd.ActionSet.prototype.execute = function(node, eventrule, defaultparms, eventinstance) { for (var key in this.content) { var action = this.content[key]; - action.execute(node, eventrule); + action.execute(node, eventrule, defaultparms, eventinstance); + } + // Execute the default action in case of there is one but there were no + // parameters so it was actually not entered as an action object + // otherwise, it would have been executed from action.execute already + if (typeof(this.content['default']) == 'undefined') { + var namespace = eventrule.kss_selector.namespace; + var name = eventrule.kss_selector.name; + eventinstance._EventBinder_calldefault(namespace, name, defaultparms, node); } }; @@ -407,9 +379,15 @@ }; -kukit.rd.Action.prototype.getParms = function(node) { +kukit.rd.Action.prototype.getParms = function(node, defaultparms) { // Return the completed action parameters, based on the node + // if defaultparms is given, it is used as the base. var parms = {}; + if (typeof(defaultparms) != 'undefined') { + for (var key in defaultparms) { + parms[key] = defaultparms[key]; + } + } for (var key in this.parms) { var kssvalue = this.parms[key]; // evaluate the method parameters into parms @@ -419,9 +397,14 @@ }; -kukit.rd.Action.prototype.execute = function(node, eventrule) { - var parms = this.getParms(node); - if (this.isRemote) { +kukit.rd.Action.prototype.execute = function(node, eventrule, defaultparms, eventinstance) { + var parms = this.getParms(node, defaultparms); + if (this.name == 'default') { + // Default action. + var namespace = eventrule.kss_selector.namespace; + var name = eventrule.kss_selector.name; + eventinstance._EventBinder_calldefault(namespace, name, parms, node); + } else if (this.isRemote) { // Remote action. var action = kukit.calculateAbsoluteURL(this.name); kukit.notifyServer(action, parms); @@ -536,8 +519,7 @@ var mergeid = kukit.rd.makeMergeId(id, namespace, name); var mergedrule = dict[mergeid]; if (typeof(mergedrule) == 'undefined') { - throw 'No method rule found category="' + category + '", event name="' + name + '" id="' + id + - '" namespace="' + namespace + '"'; + // no error, just return null. mergedrule = null; } return mergedrule; From reebalazs at codespeak.net Sun Jul 9 11:21:38 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sun, 9 Jul 2006 11:21:38 +0200 (CEST) Subject: [Kukit-checkins] r29879 - kukit/azaxdemo/trunk/browser Message-ID: <20060709092138.8DB0010076@code0.codespeak.net> Author: reebalazs Date: Sun Jul 9 11:21:37 2006 New Revision: 29879 Modified: kukit/azaxdemo/trunk/browser/more_selectors.js Log: Make the more selectors demo to pass no parameters, just to make it clearer Modified: kukit/azaxdemo/trunk/browser/more_selectors.js ============================================================================== --- kukit/azaxdemo/trunk/browser/more_selectors.js (original) +++ kukit/azaxdemo/trunk/browser/more_selectors.js Sun Jul 9 11:21:37 2006 @@ -28,9 +28,9 @@ if (this.count == 0) { // Continue with the real action. this.count = this.countsomuch; - this.__trigger_event__('doit', parms, node); + this.__trigger_event__('doit', {}, node); } else { - this.__trigger_event__('annoy', parms, node); + this.__trigger_event__('annoy', {}, node); } }; From reebalazs at codespeak.net Wed Jul 12 17:57:10 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Wed, 12 Jul 2006 17:57:10 +0200 (CEST) Subject: [Kukit-checkins] r29990 - kukit/bluekit/trunk/browser Message-ID: <20060712155710.183031006E@code0.codespeak.net> Author: reebalazs Date: Wed Jul 12 17:57:09 2006 New Revision: 29990 Added: kukit/bluekit/trunk/browser/plugin.js Log: Oops, forgot to check in this Added: kukit/bluekit/trunk/browser/plugin.js ============================================================================== --- (empty file) +++ kukit/bluekit/trunk/browser/plugin.js Wed Jul 12 17:57:09 2006 @@ -0,0 +1,12 @@ + +/* kss plugins for prototype, bling support */ + +kukit.cr.makeGlobalCommand('prototypeResponse', function(node) { + parms = kukit.pl.completeParms(this.params, ['html'], {}, 'addAfter command'); + parms.html = kukit.dom.forceToDom(parms.html); + // supposed to have a single cdata node + this.transport.responseText = parms.html.firstChild.data; + this.transport.responseXML = null; +}); + + From reebalazs at codespeak.net Mon Jul 17 07:58:03 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 17 Jul 2006 07:58:03 +0200 (CEST) Subject: [Kukit-checkins] r30097 - in kukit/azax/trunk: . plugins plugins/json/browser Message-ID: <20060717055803.997CA10091@code0.codespeak.net> Author: reebalazs Date: Mon Jul 17 07:58:00 2006 New Revision: 30097 Modified: kukit/azax/trunk/azaxview.py kukit/azax/trunk/commands.py kukit/azax/trunk/configure.zcml kukit/azax/trunk/parsers.py kukit/azax/trunk/plugins/configure.zcml kukit/azax/trunk/plugins/json/browser/jsonkukit.js Log: Refactoring (command parameters separation, __trigger_event__ fixes etc.) action, event, command helpers - add a triggerEvent command (can call back the same instance or another one by id) Make commands remember about the event that triggered them in return (as supplement data) Add command parameter conversion helpers When adding the parser output to the command, it must encode - best: ascii with xmlrefs Remove dummy "none" command params, fix IE incompatibility - remove the "none" param that was added to the empty commands Restructure command parameters - commands now except parms - json transport caught up with changes Modified: kukit/azax/trunk/azaxview.py ============================================================================== --- kukit/azax/trunk/azaxview.py (original) +++ kukit/azax/trunk/azaxview.py Mon Jul 17 07:58:00 2006 @@ -79,7 +79,7 @@ def setHtmlAsChild(self, selector, new_value): """ see interfaces.py """ - new_value = HtmlParser(new_value)() + new_value = HtmlParser(new_value)().encode('ascii', 'xmlcharrefreplace') command = self.addCommand('setHtmlAsChild', selector) data = command.addParam('html', new_value) @@ -91,34 +91,25 @@ def addAfter(self, selector, new_value): """ see interfaces.py """ - new_value = HtmlParser(new_value)() + new_value = HtmlParser(new_value)().encode('ascii', 'xmlcharrefreplace') command = self.addCommand('addAfter', selector) data = command.addParam('html', new_value) def clearChildren(self, selector): """ see interfaces.py """ command = self.addCommand('clearChildren', selector) - data = command.addParam('none') def removeNode(self, selector): """ see interfaces.py """ command = self.addCommand('removeNode', selector) - data = command.addParam('none') - - def removeNode(self, selector): - """ see interfaces.py """ - command = self.addCommand('removeNode', selector) - data = command.addParam('none') def removeNextSibling(self, selector): """ see interfaces.py """ command = self.addCommand('removeNextSibling', selector) - data = command.addParam('none') def removePreviousSibling(self, selector): """ see interfaces.py """ command = self.addCommand('removePreviousSibling', selector) - data = command.addParam('none') def copyChildrenFrom(self, selector, id): """ see interfaces.py """ @@ -144,3 +135,9 @@ command = self.addCommand('setStatevar') command.addParam('varname', varname) command.addParam('value', value) + + def triggerEvent(self, name, **kw): + command = self.addCommand('triggerEvent') + command.addParam('name', name) + for key, value in kw.iteritems(): + command.addParam(key, value) Modified: kukit/azax/trunk/commands.py ============================================================================== --- kukit/azax/trunk/commands.py (original) +++ kukit/azax/trunk/commands.py Mon Jul 17 07:58:00 2006 @@ -69,11 +69,52 @@ self.name = name self.params = [] + # -- + # Different parameter conversions + # -- + + # REMARK: with the jsonserver product present, you can + # just send complex data types directly with AddParam + def addParam(self, name, content=''): + 'Add the param as is' param = AzaxParam(name, content) self.params.append(param) return param + # + # Some helpers + # + + def addUnicodeParam(self, name, content=''): + 'Add the param as unicode' + self.addParam(name, content=content) + + def addStringParam(self, name, content='', encoding='utf'): + 'Add the param as an encoded string, by default UTF-8' + content = unicode(content, 'utf') + self.addParam(name, content=content) + + def addHtmlParam(self, name, content=''): + 'Add the param as an HTML content.' + content = HtmlParser(content)().encode('ascii', 'xmlcharrefreplace') + self.addParam(name, content=content) + + def addXmlParam(self, name, content=''): + 'Add the param as XML content' + content = XmlParser(content)().encode('ascii', 'xmlcharrefreplace') + self.addParam(name, content=content) + + def addCdataParam(self, name, content=''): + 'Add the param as a CDATA node' + content = '' % (content, ) + self.addParam(name, content=content) + + + # -- + # Accessors, not sure if we need them + # -- + def getName(self): return self.name @@ -86,6 +127,7 @@ def getParams(self): return self.params + class CommandView(object): '''View of a command. Modified: kukit/azax/trunk/configure.zcml ============================================================================== --- kukit/azax/trunk/configure.zcml (original) +++ kukit/azax/trunk/configure.zcml Mon Jul 17 07:58:00 2006 @@ -17,6 +17,7 @@ kukit/kukit/kssparser.js kukit/kukit/eventreg.js kukit/kukit/actionreg.js + kukit/kukit/dom.js kukit/kukit/commandreg.js kukit/kukit/forms.js kukit/kukit/plugin.js" Modified: kukit/azax/trunk/parsers.py ============================================================================== --- kukit/azax/trunk/parsers.py (original) +++ kukit/azax/trunk/parsers.py Mon Jul 17 07:58:00 2006 @@ -89,4 +89,5 @@ # 1. Fixes an IE bug. # 2. Needed for the alternate transport mechanism to work. value = replace_html_named_entities(value) + return value Modified: kukit/azax/trunk/plugins/configure.zcml ============================================================================== --- kukit/azax/trunk/plugins/configure.zcml (original) +++ kukit/azax/trunk/plugins/configure.zcml Mon Jul 17 07:58:00 2006 @@ -71,9 +71,13 @@ name="copyChildrenTo" /> - + + Modified: kukit/azax/trunk/plugins/json/browser/jsonkukit.js ============================================================================== --- kukit/azax/trunk/plugins/json/browser/jsonkukit.js (original) +++ kukit/azax/trunk/plugins/json/browser/jsonkukit.js Mon Jul 17 07:58:00 2006 @@ -15,28 +15,38 @@ * proxy method. */ -kukit.makeJSONKukitMethod = function(url, methodName, timeout) { +kukit.makeJSONKukitMethod = function(url, methodName, timeout, supplement) { // url and methodName can be used, // or methodName can be set to null and url will be used as a full url. if (typeof(timeout) == 'undefined' || timeout == null) { // default timeout is 4 sec... a sane choice timeout = 4000; } + if (typeof(supplement) == 'undefined') { + // default timeout is 4 sec... a sane choice + supplement = null; + } return new JSONRPCMethod(url, methodName, kukit.jsonCallback, kukit.jsonError, - 4000, null, null, kukit.requestManager); + 4000, supplement, null, kukit.requestManager); } // OVERWRITE kukit.js -kukit.notifyServer = function(url, params) { +kukit.notifyServer = function(url, params, backparms) { // sending form, with standard form parameters. - var method = kukit.makeJSONKukitMethod(url, null); + var method = kukit.makeJSONKukitMethod(url, null, null, backparms); method(params); } -kukit.jsonCallback = function(result) { - var command_processor = new kukit.CommandProcessor(); - command_processor.parseCommands(result); - command_processor.executeCommands(); +kukit.jsonCallback = function(result, backparms) { + try { + var command_processor = new kukit.CommandProcessor(); + // Transport parm is same as result (although we don't use it) + command_processor.parseCommands(result, result); + command_processor.executeCommands(backparms); + } catch(e) { + kukit.logError('Error during command execution: ' + e); + throw e; + } } kukit.jsonError = function(result) { @@ -46,88 +56,9 @@ /* Command execution */ // OVERWRITE kukit.js -kukit.CommandProcessor.prototype.parseCommand = function(command) { +kukit.CommandProcessor.prototype.parseCommand = function(command, transport) { // Add the command. + var command = new kukit.cr.makeCommand(command.selector, command.name, command.selectorType, command.params, transport); this.addCommand(command); } -kukit.CommandRegistry.prototype.forceJsonRegistry = function() { - if (typeof(this.jsonContent) == 'undefined') { - this.jsonContent = {}; - this.jsonNr = 0; - } -} - -kukit.CommandRegistry.prototype.registerJson = function(name, func) { - this.forceJsonRegistry(); - // Register a new style (json) command. - if (this.jsonContent[name] || this.content[name]) { - // Do not allow redefinition - kukit.logError('Error : redefinition attempt of command ' + name); - return; - } - this.jsonContent[name] = func; - this.jsonNr = this.jsonNr + 1; -} - -// OVERWRITE kukit.js -kukit.CommandRegistry.prototype.getFunc = function(name) { - this.forceJsonRegistry(); - var func = this.content[name]; - var jsonFunc = this.jsonContent[name]; - var stub = null; - if (jsonFunc) { - // json commands receive the parameters "as are" - stub = jsonFunc; - } else if (func) { - // old style commands need all the parameters converted to DOM - stub = function(node, command_data) { - var new_params = {}; - for (var key in command_data) { - var param = command_data[key]; - - // - // now convert to dom - // - - //param = ""; - // ***BROKEN*** param = ""; - //param = ""; - - // This is a good solution since it does not do magic to - // our html - BUT html is parsed as xml - // so we currently preprocess it on the server - // and remove html named entities from it. - // - var root_txt = '

' + param + '
'; - var doc = (new DOMParser()).parseFromString(root_txt, "text/xml"); - var root = doc.getElementsByTagName('div')[0]; - - // This would be the perfect solution: insert our stuff - // into the main document that is, since it is html, - // will parse html in correctly. But the problem is - // that is also sensitive to context which we have not - // at this point yet. So: