Author: jmorliaguet
Date: Mon Dec 19 22:34:08 2005
New Revision: 2060

Removed:
   cpsskins/branches/jmo-perspectives/ui/default/filters/style/jsonrpc.py
Modified:
   cpsskins/branches/jmo-perspectives/ui/default/filters/style/configure.zcml
   cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js
   cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.pt
   cpsskins/branches/jmo-perspectives/ui/default/filters/style/views.py
Log:

- first shot at a "JSON over HTTP" style editor



Modified: 
cpsskins/branches/jmo-perspectives/ui/default/filters/style/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/default/filters/style/configure.zcml  
(original)
+++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/configure.zcml  
Mon Dec 19 22:34:08 2005
@@ -31,19 +31,42 @@
       name="style_editor.js" file="style_editor.js"
       layer="cpsskins" />
 
-  <jsonrpc:view
-      class=".jsonrpc.Methods"
+  <browser:pages
       for="cpsskins.ui.default.formats.style.IStyle"
-      permission="zope.Public"
-      methods="getWidgetStyle getSelectorStyle getFieldRange renderPreview"
-  />
+      class=".views.JSONView"
+      permission="zope.ManageContent">
 
-  <jsonrpc:view
-      class=".jsonrpc.Methods"
-      for="cpsskins.ui.default.formats.style.IStyle"
-      permission="zope.ManageContent"
-      methods="setSelectorStyle delSelectorStyle"
-  />
+    <browser:page
+        name="getWidgetStyle"
+        attribute="getWidgetStyle"
+    />
+
+    <browser:page
+        name="getSelectorStyle"
+        attribute="getSelectorStyle"
+    />
+
+    <browser:page
+        name="setSelectorStyle"
+        attribute="setSelectorStyle"
+    />
+
+    <browser:page
+        name="delSelectorStyle"
+        attribute="delSelectorStyle"
+    />
+
+    <browser:page
+        name="getFieldRange"
+        attribute="getFieldRange"
+    />
+
+    <browser:page
+        name="renderPreview"
+        attribute="renderPreview"
+    />
+
+  </browser:pages>
 
   <!-- Stylesheets -->
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js 
(original)
+++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js 
Mon Dec 19 22:34:08 2005
@@ -71,8 +71,12 @@
 
 function download_style() {
   write_message("loading widget style ...");
-  clientWidgetStyle = serverWidgetStyle.getWidgetStyle();
-  clear_message();
+  new Ajax.Request('getWidgetStyle', {
+    onComplete: function(request) {
+      clientWidgetStyle = JSON.parse(request.responseText);
+      clear_message();
+    }
+  });
 }
 
 function update_selector_style(attrs) {
@@ -85,14 +89,25 @@
 function download_selector_style() {
   var sel = get_selector();
   write_message("loading style ...");
-  clientSelectorStyle = serverWidgetStyle.getSelectorStyle(sel);
-  clear_message();
+  new Ajax.Request('getSelectorStyle', {
+    parameters: $H({'k': sel}).toQueryString(),
+    onComplete: function(request) {
+      clientSelectorStyle = JSON.parse(request.responseText);
+      clear_message();
+    }
+  });
 }
 
 function upload_selector_style() {
   var sel = get_selector();
   write_message("saving style ...");
-  serverWidgetStyle.setSelectorStyle(sel, clientSelectorStyle, clear_message);
+  new Ajax.Request('setSelectorStyle', {
+    parameters: $H({'k': sel,
+                    'v': JSON.stringify(clientSelectorStyle)}).toQueryString(),
+    onComplete: function() {
+      clear_message();
+    }
+  });
 }
 
 /* VIEWS */
@@ -118,8 +133,9 @@
   var elems, selector_style;
 
   // Draw the preview area
-  style_preview = serverWidgetStyle.renderPreview(get_widget_type());
-  replaceHTML(widget_area, style_preview);
+  new Ajax.Updater(widget_area, 'renderPreview', {
+    parameters: $H({widget_type: get_widget_type()}).toQueryString(),
+  });
 
   // Set the widget area element
   set_widget_area();
@@ -147,7 +163,12 @@
   var widget = get_widget_type();
   var props = clientWidgetStyle[sel];
 
-  selector_schema = serverWidgetStyle.getFieldRange(widget, sel);
+  new Ajax.Request('getFieldRange', {
+    parameters: $H({'widget_type': widget, 'sel': sel}).toQueryString(),
+    onComplete: function(request) {
+      selector_schema = JSON.parse(request.responseText);
+    }
+  });
 
   // concept code for testing. to be rewritten
   var form = document.createElement('form');
@@ -273,16 +294,6 @@
 function setupEditor(widget_type) {
     set_widget_type(widget_type);
 
-    // Open a JSON-RPC connection for this style
-    serverWidgetStyle = jsonrpcConnect(addr=".",
-        methods=["getWidgetStyle",
-                 "getSelectorStyle",
-                 "setSelectorStyle",
-                 "delSelectorStyle",
-                 "getFieldRange",
-                 "renderPreview",
-                 "renderForm"]);
-
     // Set up the areas
     setupAreas();
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.pt 
(original)
+++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.pt 
Mon Dec 19 22:34:08 2005
@@ -10,6 +10,8 @@
       <script type="text/javascript"
               src="/++skin++cpsskins/@@/++resource++prototype.js"></script>
       <script type="text/javascript"
+              src="/++skin++cpsskins/@@/++resource++json.js"></script>
+      <script type="text/javascript"
               src="/++skin++cpsskins/@@/++resource++style_editor.js"></script>
     </tal:script>
     <tal:head metal:fill-slot="head">

Modified: cpsskins/branches/jmo-perspectives/ui/default/filters/style/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/default/filters/style/views.py        
(original)
+++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/views.py        
Mon Dec 19 22:34:08 2005
@@ -17,11 +17,73 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.component import getUtility
 from zope.app.form.browser.editview import EditView
+from zope.app.publisher.browser import BrowserView
 
+from cpsskins import configuration
+from cpsskins import minjson as json
 from cpsskins.ui.default.formats.style import IStyle
 
 class StyleEditor(EditView):
     """Style editor view"""
 
     schema = IStyle
+
+class JSONView(BrowserView):
+    """JSON methods
+
+    >>> s = Style()
+    >>> s[u'div.body'] = {'color': u'red'}
+    >>> s[u''] = {'color': u'blue'}
+
+    >>> methods = Methods(s, None)
+    >>> methods.getWidgetStyle()
+    {u'': {'color': 'blue'}, u'div.body': {'color': 'red'}}
+
+    >>> methods.getSelectorStyle('')
+    {'color': 'blue'}
+
+    >>> methods.getSelectorStyle('div.body')
+    {'color': 'red'}
+
+    >>> methods.setSelectorStyle('', {"border": "none", "font-style": 
"normal"})
+    >>> methods.getSelectorStyle('')
+    {'border': 'none', 'font-style': 'normal'}
+
+    >>> methods.delSelectorStyle('')
+    >>> methods.getWidgetStyle()
+    {u'div.body': {'color': 'red'}}
+    """
+
+    def getWidgetStyle(self):
+        return json.write(dict(self.context))
+
+    def getSelectorStyle(self, k):
+        return json.write(self.context.get(k))
+
+    def setSelectorStyle(self, k, v):
+        self.context[k] = json.read(v)
+
+    def delSelectorStyle(self, k):
+        if k in self.context:
+            del self.context[k]
+
+    def getFieldRange(self, widget_type, sel):
+        # TODO: this is for testing
+        return json.write({
+            'color': [],
+            'background-color': [],
+            'padding': [],
+            'margin': [],
+            'font-family': [u'arial, sans-serif', u'verdana', u'MS trebuchet'],
+            'font-size': [u'0.8em', u'12px', u'13px'],
+            'border': [u'1px solid #f0f0f0', u'none', u'1px inset gray'],
+            })
+
+    def renderPreview(self, widget_type):
+        """Render a style preview based on the specified widget.
+        """
+        widget = getUtility(configuration.IWidget, widget_type)
+        return widget.view(None, None).renderPreview()
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to