[rhmessaging-commits] rhmessaging commits: r3135 - in mgmt/trunk: wooly/python/wooly and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Feb 25 13:02:19 EST 2009


Author: eallen
Date: 2009-02-25 13:02:19 -0500 (Wed, 25 Feb 2009)
New Revision: 3135

Modified:
   mgmt/trunk/cumin/python/cumin/broker.py
   mgmt/trunk/cumin/python/cumin/broker.strings
   mgmt/trunk/cumin/python/cumin/user.strings
   mgmt/trunk/wooly/python/wooly/__init__.py
   mgmt/trunk/wooly/python/wooly/forms.py
   mgmt/trunk/wooly/python/wooly/forms.strings
   mgmt/trunk/wooly/python/wooly/server.py
Log:
Change the way <button>s are handled to work-around IE problem.
Save and inspect the HTTP_USER_AGENT for determining correct content_type to send to IE 6.

Modified: mgmt/trunk/cumin/python/cumin/broker.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/broker.py	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/cumin/python/cumin/broker.py	2009-02-25 18:02:19 UTC (rev 3135)
@@ -600,20 +600,13 @@
         self.field_tmpl = Template(self, "field_html")
         self.group_tmpl = Template(self, "group_html")
 
-        self.more_button = self.MoreEntries(app, "more_button")
-        self.add_child(self.more_button)
+        self.more = self.MoreEntries(app, "more")
+        self.add_child(self.more)
 
-        self.more = self.More(app, "more")
-        self.add_parameter(self.more)
-
     class Errors(Attribute):
         def get_default(self, session):
             return dict()
 
-    class More(Parameter):
-        def get_default(self, session):
-            return ""
-
     def process_display(self, session):
         if self.more.get(session):
             self.fields.set(session, self.fields.get(session) + 3)
@@ -677,12 +670,6 @@
             if groups[index] and group.id == groups[index].id:
                 return "selected=\"selected\""
 
-    def render_more_id(self, session):
-        return self.more_button.path
-
-    def render_more_name(self, session):
-        return self.more.path
-
     class MoreEntries(FormButton):
         def render_content(self, session):
             return "More Entries"
@@ -691,7 +678,15 @@
             return "more"
 
         def render_type(self, session):
+            """ using type="button" so pressing
+            Enter on the form will not add more fields """
             return "button"
+        
+        def render_onclick(self, session):
+            """ since this isn't a type="submit" button,
+            we need javascript to submit the form when
+            the button is clicked """
+            return "click_more"
 
 class BrokerSetAdd(BrokerSetForm):
     def process_cancel(self, session):
@@ -761,7 +756,7 @@
 
                     if count:
                         errs = aerrs.setdefault(i, list())
-                        errs.append("The broker at %s " % (url) +
+                        errs.append("The broker at %s " % (addr) +
                                     "is already registered")
 
         return not len(nerrs) and not len(aerrs)

Modified: mgmt/trunk/cumin/python/cumin/broker.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/broker.strings	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/cumin/python/cumin/broker.strings	2009-02-25 18:02:19 UTC (rev 3135)
@@ -242,7 +242,7 @@
         {fields}
       </table>
 
-      {more_button}<input type="hidden" name="{more_name}" value="" />
+      {more}
     </fieldset>
 
     {hidden_inputs}
@@ -254,18 +254,16 @@
   </div>
 </form>
 <script type="text/javascript" defer="defer">
-function attach_more_id() {
-	var oMore = document.getElementById("{more_id}");
-	if (oMore) {
-		oMore.onclick = function() { document.forms[0].elements["{more_name}"].value = "t"; document.forms[0].submit(); return True;}
-	}
+function click_more(id, value) {
+    click_button(id, value);
+	document.forms[0].submit(); 
+	return true;
 }
 (function() {
     var elem = wooly.doc().elembyid("{id}").node.elements[1];
     elem.focus();
     elem.select();
 }())
-addEvent(window, "load", attach_more_id);
 </script>
 
 

Modified: mgmt/trunk/cumin/python/cumin/user.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/user.strings	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/cumin/python/cumin/user.strings	2009-02-25 18:02:19 UTC (rev 3135)
@@ -44,6 +44,10 @@
   width: 12em;
 }
 
+form.LoginForm input.submit {
+    width: auto;
+}
+
 form.LoginForm > div.buttons {
   margin: 1.5em 0 0 0;
 }

Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/wooly/python/wooly/__init__.py	2009-02-25 18:02:19 UTC (rev 3135)
@@ -299,6 +299,7 @@
 class Page(Frame):
     xml_content_type = "text/xml"
     html_content_type = "text/html"
+    xhtml_content_type = "application/xhtml+xml"
     xml_1_0_declaration = """<?xml version="1.0"?>"""
     xhtml_1_1_doctype = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">"""
     xhtml_namespace = "http://www.w3.org/1999/xhtml"
@@ -315,6 +316,9 @@
 
         self.__saved_params = dict()
 
+        self.agent = Attribute(app, "agent")
+        self.add_attribute(self.agent)
+        
     def init(self):
         assert not self.sealed
         assert self.parent is None
@@ -332,10 +336,11 @@
         return datetime.utcnow()
 
     def get_content_type(self, session):
-        if self.name.endswith(".html"):
-            return "application/xhtml+xml"
+        agent = self.agent.get(session)
+        if self.name.endswith(".html") and (agent.find("MSIE 6") == -1):
+            return self.xhtml_content_type
         else:
-            return "text/html"
+            return self.html_content_type
 
     def get_cache_control(self, session):
         return None
@@ -370,6 +375,9 @@
         #print "Popping current frame", frame
         self.set_current_frame(session, frame.frame)
 
+    def set_agent(self, session, agent):
+        self.agent.set(session, agent)
+        
     def set_default_frame(self, frame):
         self.current_frame.default = frame
 

Modified: mgmt/trunk/wooly/python/wooly/forms.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/forms.py	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/wooly/python/wooly/forms.py	2009-02-25 18:02:19 UTC (rev 3135)
@@ -255,6 +255,9 @@
     def render_type(self, session, *args):
         return "submit"
 
+    def render_onclick(self, session, *args):
+        return "click_button"
+    
 class CheckboxInputSet(FormInput, ItemSet):
     def render_item_value(self, session, *args):
         return None

Modified: mgmt/trunk/wooly/python/wooly/forms.strings
===================================================================
--- mgmt/trunk/wooly/python/wooly/forms.strings	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/wooly/python/wooly/forms.strings	2009-02-25 18:02:19 UTC (rev 3135)
@@ -10,8 +10,19 @@
 [FormErrorSet.item_html]
 <li>{item_content}</li>
 
+[FormButton.javascript]
+// needed because IE will send the content instead of the value for form buttons
+function click_button(id, value) {
+    var oHidden = document.getElementById(id);
+    if (oHidden) {
+        oHidden.value = value;
+    }
+    return true;
+}
+
 [FormButton.html]
-<button class="{class}" id="{id}" type="{type}" name="{name}" value="{value}" tabindex="{tab_index}" {disabled_attr}>{content}</button>
+<button class="{class}" type="{type}" tabindex="{tab_index}" {disabled_attr} onclick="return {onclick}('{id}', '{value}')">{content}</button>
+<input type="hidden" id="{id}" name="{name}" value="" />
 
 [ScalarInput.html]
 <input type="text" name="{name}" value="{value}" tabindex="{tab_index}" {disabled_attr} size="{size}"/>

Modified: mgmt/trunk/wooly/python/wooly/server.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/server.py	2009-02-25 14:31:59 UTC (rev 3134)
+++ mgmt/trunk/wooly/python/wooly/server.py	2009-02-25 18:02:19 UTC (rev 3135)
@@ -48,13 +48,16 @@
         session = Session(page, headers)
         session.unmarshal_url_vars(env["QUERY_STRING"])
 
+        if "HTTP_USER_AGENT" in env:
+            page.set_agent(session, env["HTTP_USER_AGENT"])
+            
         if env["REQUEST_METHOD"] == "POST":
             if env["CONTENT_TYPE"] == "application/x-www-form-urlencoded":
                 length = int(env["CONTENT_LENGTH"])
                 vars = env["wsgi.input"].read(length)
             else:
                 raise Exception("Content type '%s' is not supported" \
-                                % content_type)
+                                % env["CONTENT_TYPE"])
 
             if vars:
                 session.unmarshal_url_vars(vars, "&")




More information about the rhmessaging-commits mailing list