Author: eallen
Date: 2008-10-07 18:20:19 -0400 (Tue, 07 Oct 2008)
New Revision: 2602
Modified:
mgmt/trunk/cumin/python/cumin/__init__.py
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/cumin/resources/wooly.js
Log:
Added AjaxField to update a page element.
Modified: mgmt/trunk/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/__init__.py 2008-10-07 21:48:09 UTC (rev 2601)
+++ mgmt/trunk/cumin/python/cumin/__init__.py 2008-10-07 22:20:19 UTC (rev 2602)
@@ -12,7 +12,7 @@
from threading import Thread, Event
from urllib import quote
-from model import CuminModel, ModelPage
+from model import CuminModel, ModelPage, DataPage
from demo import DemoData
from page import MainPage
from stat import StatChartPage
@@ -51,6 +51,7 @@
self.add_page(DevelPage(self, "devel.html"))
self.add_page(ModelPage(self, "model.xml"))
+ self.add_page(DataPage(self, "data.xml"))
self.add_page(ActionPage(self, "actions.html"))
self.add_page(StatChartPage(self, "stats.png"))
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-10-07 21:48:09 UTC (rev 2601)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-10-07 22:20:19 UTC (rev 2602)
@@ -2172,6 +2172,8 @@
action = self.Stop(self, "stop")
action.summary = True
+ action = self.GetLimitCount(self, "GetLimitCount")
+
def get_title(self, session):
return "Negotiator"
@@ -2214,6 +2216,32 @@
def do_invoke(self, negotiator, args, completion):
negotiator.Stop(self.cumin_model.data, completion)
+ class GetLimitCount(CuminAction):
+ def __init__(self, cls, name):
+ super(CuminNegotiator.GetLimitCount, self).__init__(cls, name)
+
+ self.navigable = False
+
+ def do_invoke(self, negotiator):
+ self.lim = dict()
+ self.got_data = False
+
+ def completion(status, data):
+ self.lim = data["Limits"]
+ self.got_data = True
+
+ def predicate():
+ return self.got_data
+
+ try:
+ negotiator.GetLimits(self.cumin_model.data, completion, self.lim)
+ except:
+ return self.lim
+
+ # wait for up to 5 seconds for completion to be called
+ wait(predicate, timeout=5)
+ return "<count value=\"%i\" />" % len(self.lim)
+
class ModelPage(Page):
def __init__(self, app, name):
super(ModelPage, self).__init__(app, name)
@@ -2244,3 +2272,43 @@
self.app.model.write_xml(writer, objects)
return writer.to_string()
+
+class DataPage(Page):
+ def __init__(self, app, name):
+ super(DataPage, self).__init__(app, name)
+
+ self.__class = CuminClassParameter(app, "class")
+ self.add_parameter(self.__class)
+
+ self.__id = IntegerParameter(app, "id")
+ self.add_parameter(self.__id)
+
+ self.__method = Parameter(app, "method")
+ self.add_parameter(self.__method)
+
+ def get_content_type(self, session):
+ return Page.xml_content_type
+
+ def do_render(self, session):
+ writer = Writer()
+ writer.write(Page.xml_1_0_declaration)
+
+ cls = self.__class.get(session)
+ id = self.__id.get(session)
+
+ if cls:
+ object = cls.mint_class.get(id)
+ method = self.__method.get(session)
+ #self.app.model.write_xml(writer, objects)
+ for action in cls.actions:
+ if action.name == method:
+ data = action.do_invoke(object)
+ self.write_xml(writer, data)
+
+ return writer.to_string()
+
+ def write_xml(self, writer, data):
+ writer.write("<data>")
+ writer.write(data)
+ writer.write("</data>")
+
\ No newline at end of file
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2008-10-07 21:48:09 UTC (rev 2601)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2008-10-07 22:20:19 UTC (rev 2602)
@@ -1094,3 +1094,20 @@
def render_title(self, session):
return "Preserve"
+
+class AjaxField(Widget):
+ def render_script(self, session):
+ script = """
+ <script language="javascript">
+ function get_%s() {
+ wooly.deferredUpdate('%s', got_%s, "%s");
+ }
+ addEvent(window, "load", get_%s);
+ </script>
+ """
+ url = self.get_url(session)
+ return script % (self.name, url, self.name, self.name, self.name)
+
+ def get_url(self, session):
+ pass
+
Modified: mgmt/trunk/cumin/resources/wooly.js
===================================================================
--- mgmt/trunk/cumin/resources/wooly.js 2008-10-07 21:48:09 UTC (rev 2601)
+++ mgmt/trunk/cumin/resources/wooly.js 2008-10-07 22:20:19 UTC (rev 2602)
@@ -221,6 +221,28 @@
this.console = window.console;
}
+
+ this.deferredUpdate = function(url, callback, passback) {
+ var req = this.request;
+
+ req.open("get", url, true);
+ req.onreadystatechange = update;
+ req.send(null);
+
+ function update() {
+ try {
+ if (req.readyState == 4 && req.status == 200) {
+ data = wooly.doc(req.responseXML);
+ var obj = data.objectify();
+ callback(obj, passback);
+ }
+ } catch (e) {
+ log(e);
+ throw e;
+ }
+ }
+ }
+
this.setIntervalUpdate = function(url, callback, interval) {
var req = this.request;