Author: jmorliaguet
Date: Sun Feb 12 22:34:08 2006
New Revision: 2371

Added:
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/form.css
   (contents, props changed)
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/sampleform.pt
   (contents, props changed)
Modified:
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/configure.zcml
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
Log:

- the sample form is drawn using a template (-70 lines)



Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     Sun Feb 12 22:34:08 2006
@@ -68,14 +68,22 @@
         fields = []
         for name in form_layout:
             field_def = FieldProperty(self.schema[name])
-            fields.append({
+            field_info = {
                 'name': name,
                 'label': field_def.title,
                 'hint': field_def.description,
                 'value': field_def.default,
                 'disabled': field_def.readonly,
                 'status': u'',
-            })
+            }
+
+            choices = getattr(field_def, 'vocabulary', None)
+            #if choices:
+               #print list(choices)
+               #field_info['values'] = choices()
+
+            fields.append(field_info)
+
         return {'fields': fields}
 
     def getFormData(self):
@@ -97,7 +105,7 @@
             field['status'] = u''
             try:
                 value = schema_field.fromUnicode(value)
-            except ConstraintNotSatisfied:
+            except (ValueError, ConstraintNotSatisfied):
                 field['status'] = u"Incorrect value"
             except RequiredMissing:
                 field['status'] = u"this field is required"
@@ -105,6 +113,7 @@
             field['value'] = value
 
         form_data = {'fields': fields}
+        print form_data
 
         cache.set(form_data, 'formdata', {})
         return json.write(form_data)

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/configure.zcml
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/configure.zcml
 (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/configure.zcml
 Sun Feb 12 22:34:08 2006
@@ -1,6 +1,10 @@
 <configure
     xmlns:browser="http://namespaces.zope.org/browser";>
 
+  <browser:resource
+      name="form.css" file="form.css"
+      layer="cpsskins-test" />
+
   <browser:page
       for="*"
       layer="cpsskins-test"
@@ -9,6 +13,14 @@
       template="cpsskins_form_validation.pt"
   />
 
+  <browser:page
+      for="*"
+      layer="cpsskins-test"
+      name="sampleform.html"
+      permission="zope.Public"
+      template="sampleform.pt"
+  />
+
   <browser:pages
       layer="cpsskins-test"
       for="*"

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    Sun Feb 12 22:34:08 2006
@@ -9,141 +9,15 @@
           type="text/javascript"></script>
   <script src="/++skin++cpsskins/@@/++resource++json.js"
           type="text/javascript"></script>
+  <script src="/++skin++cpsskins/@@/++resource++ctal.js"
+          type="text/javascript"></script>
   <script src="/++skin++cpsskins/@@/++resource++cpsskins.js"
           type="text/javascript"></script>
   <link rel="stylesheet" type="text/css"
         href="/++skin++cpsskins/@@/++resource++cpsskins.css" />
 
-  <style type="text/css">
-  form {
-    border: 1px solid #ccc;
-    background-color: #f6f3f0;
-    padding: 1em;
-    font: 1.3em arial, sans-serif;
-  }
-
-  label {
-    padding: 1em;
-  }
-
-  .hint {
-    padding: 1em;
-  }
-
-  .status {
-    padding: 1em;
-    color: red;
-  }
-
-  input {
-    border: 1px solid #999;
-    background-color: #fff;
-  }
-
-  input.disabled {
-    border-style: none;
-    color: black;
-  }
-
-  input:focus {
-    background-color: #ffc;
-  }
-
-  button {
-    margin: 1em;
-    border: 1px solid #999;
-    background-color: #ddd;
-  }
-  </style>
-
-  <script type="text/javascript">
-
-    Object.extend(Widgets, {
-
-      sampleform: function(def) {
-        var widget = Canvas.createNode({
-          tag: "form",
-          attributes: {"method": "post"}
-        });
-        return new SampleForm(widget, def);
-      }
-
-    });
-
-    SampleForm = Class.create();
-    SampleForm.prototype = Object.extend(new CPSSkins.View(), {
-
-      render: function(data) {
-        var widget = this.widget;
-        widget.innerHTML = '';
-
-        var fields = data.fields;
-
-        var renderField = this._renderField;
-        $A(fields).each(function(f) {
-          widget.appendChild(renderField(f));
-        });
-
-        var button = Canvas.createNode({
-          tag: "button",
-          attributes: {
-            "type": "submit"
-          },
-          text: "SEND!"
-        });
-        widget.appendChild(button);
-
-      },
-
-      _renderField: function(field) {
-        var p = Canvas.createNode({"tag": "p"});
-
-        var label = Canvas.createNode({
-          tag: "label",
-          text: field.label
-        });
-        p.appendChild(label);
-
-
-        var input_options = {
-          "tag": "input",
-          "attributes": {
-            "name": field.name,
-            "type": "text",
-            "value": field.value,
-          }
-        }
-
-        if (field.disabled == true) {
-          input_options["attributes"]["disabled"] = "disabled";
-          input_options["classes"] = "disabled";
-        }
-
-        var input = Canvas.createNode(input_options);
-        p.appendChild(input);
-
-        if (field.hint) {
-          var hint = Canvas.createNode({
-            tag: "span",
-            classes: "hint",
-            text: '(' + field.hint + ')'
-          });
-          p.appendChild(hint);
-        }
-
-        var status = Canvas.createNode({
-          tag: "span",
-          classes: "status",
-          text: field.status
-        });
-        p.appendChild(status);
-
-        return p;
-      }
-
-    });
-
-  </script>
+  <link rel="stylesheet" type="text/css"
+        href="/++skin++cpsskins-test/@@/++resource++form.css" />
 
 </head>
 <body>
@@ -178,7 +52,7 @@
 
     <ins class="view">
     {"widget": {
-      "type": "sampleform"
+      "template": "sampleform.html"
      },
      "model": "form-data",
      "controller": "form-controller"

Added: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/form.css
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/form.css
       Sun Feb 12 22:34:08 2006
@@ -0,0 +1,41 @@
+
+form {
+  border: 1px solid #ccc;
+  background-color: #f6f3f0;
+  padding: 1em;
+  font: 1.3em arial, sans-serif;
+}
+
+label {
+  padding: 1em;
+}
+
+.hint {
+  padding: 1em;
+}
+
+.status {
+  padding: 1em;
+  color: red;
+}
+
+input {
+  border: 1px solid #999;
+  background-color: #fff;
+}
+
+input.disabled {
+  border: 1px solid #ddd;
+  background-color: #f9f9f9;
+  color: #ccc;
+}
+
+input:focus {
+  background-color: #ffc;
+}
+
+button {
+  margin: 1em;
+  border: 1px solid #999;
+  background-color: #ddd;
+}

Added: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/sampleform.pt
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/sampleform.pt
  Sun Feb 12 22:34:08 2006
@@ -0,0 +1,15 @@
+<form action="" onsubmit="return false" method="post">
+
+  <p ctal:repeat="f fields">
+    <label ctal:content="f/label">LABEL</label>
+    <input ctal:attributes="value f/value; name f/name" />
+    <span class="hint" ctal:condition="f/hint" 
ctal:content="f/hint">HINT</span>
+    <span class="status" ctal:condition="f/status"
+                         ctal:content="f/status">STATUS</span>
+  </p>
+
+  <p>
+    <button type="submit">Save</button>
+  </p>
+
+</form>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to