Author: jmorliaguet
Date: Wed Jun  7 12:27:48 2006
New Revision: 3344

Added:
   cpsskins/branches/paris-sprint-2006/standard/screens/
   cpsskins/branches/paris-sprint-2006/standard/screens/__init__.py   
(contents, props changed)
   cpsskins/branches/paris-sprint-2006/standard/screens/configure.zcml   
(contents, props changed)
   cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/
   cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/__init__.py 
  (contents, props changed)
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml 
  (contents, props changed)
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
   (contents, props changed)
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
   (contents, props changed)
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor_form.ctal
   (contents, props changed)
   cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py   
(contents, props changed)
Removed:
   cpsskins/branches/paris-sprint-2006/standard/filters/style/style_editor.js
   cpsskins/branches/paris-sprint-2006/standard/filters/style/style_editor.pt
   
cpsskins/branches/paris-sprint-2006/standard/filters/style/style_editor_form.ctal
   cpsskins/branches/paris-sprint-2006/standard/filters/style/views.py
Modified:
   cpsskins/branches/paris-sprint-2006/standard/configure.zcml
   cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml

Log:

- moved the style editor to standard/screens/styleeditor



Modified: cpsskins/branches/paris-sprint-2006/standard/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/configure.zcml (original)
+++ cpsskins/branches/paris-sprint-2006/standard/configure.zcml Wed Jun  7 
12:27:48 2006
@@ -26,6 +26,11 @@
   <include package=".filters" />
 
 
+  <!-- Standard screens -->
+
+  <include package=".screens" />
+
+
   <!-- Standard engine definition -->
 
   <include package=".engines" />

Modified: 
cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml   
Wed Jun  7 12:27:48 2006
@@ -13,54 +13,6 @@
       factory=".StyleFilter"
   />
 
-  <!-- Style editor -->
-
-  <browser:page
-      name="edit.html"
-      for="cpsskins.standard.formats.style.IStyle"
-      class=".views.StyleEditor"
-      template="style_editor.pt"
-      permission="zope.ManageContent"
-  />
-
-  <browser:resource
-      name="style_editor.js" file="style_editor.js"
-      layer="cpsskins.browser.skin.cpsskins" />
-
-  <browser:pages
-      for="*"
-      class=".views.StyleEditor"
-      permission="zope.ManageContent">
-
-    <browser:page
-        name="renderWidgetPreview"
-        attribute="renderWidgetPreview"
-    />
-
-    <browser:page
-        name="setFormData"
-        attribute="setFormData"
-    />
-
-    <browser:page
-        name="getStyleData"
-        attribute="getStyleData"
-    />
-
-    <browser:page
-        name="setStyleData"
-        attribute="setStyleData"
-    />
-
-  </browser:pages>
-
-  <browser:page
-    for="*"
-    name="style-editor-form.html"
-    permission="zope.ManageContent"
-    template="style_editor_form.ctal"
-  />
-
   <!-- Stylesheets -->
 
   <adapter

Added: cpsskins/branches/paris-sprint-2006/standard/screens/__init__.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/standard/screens/__init__.py    Wed Jun 
 7 12:27:48 2006
@@ -0,0 +1,18 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+

Added: cpsskins/branches/paris-sprint-2006/standard/screens/configure.zcml
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/standard/screens/configure.zcml Wed Jun 
 7 12:27:48 2006
@@ -0,0 +1,6 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";>
+
+    <include package=".styleeditor" />
+
+</configure>

Added: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/__init__.py
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/__init__.py    
    Wed Jun  7 12:27:48 2006
@@ -0,0 +1,18 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+

Added: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml 
    Wed Jun  7 12:27:48 2006
@@ -0,0 +1,55 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:browser="http://namespaces.zope.org/browser";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";
+    xmlns:jsonrpc="http://namespaces.zope.org/jsonrpc";>
+
+  <!-- Style editor -->
+
+  <browser:page
+      name="edit.html"
+      for="cpsskins.standard.formats.style.IStyle"
+      class=".views.StyleEditor"
+      template="style_editor.pt"
+      permission="zope.ManageContent"
+  />
+
+  <browser:resource
+      name="style_editor.js" file="style_editor.js"
+      layer="cpsskins.browser.skin.cpsskins" />
+
+  <browser:pages
+      for="*"
+      class=".views.StyleEditor"
+      permission="zope.ManageContent">
+
+    <browser:page
+        name="renderWidgetPreview"
+        attribute="renderWidgetPreview"
+    />
+
+    <browser:page
+        name="setFormData"
+        attribute="setFormData"
+    />
+
+    <browser:page
+        name="getStyleData"
+        attribute="getStyleData"
+    />
+
+    <browser:page
+        name="setStyleData"
+        attribute="setStyleData"
+    />
+
+  </browser:pages>
+
+  <browser:page
+    for="*"
+    name="style-editor-form.html"
+    permission="zope.ManageContent"
+    template="style_editor_form.ctal"
+  />
+
+</configure>

Added: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
    Wed Jun  7 12:27:48 2006
@@ -0,0 +1,63 @@
+
+CPSSkins.addActions({
+
+  'selectTag': function(info) {
+    var target = info.target;
+    var data = CPSSkins.getModelById('element-editor').getData();
+    var uri = data.form.uri;
+    var style_data = CPSSkins.getModelById('style-editor').getData();
+    var style_id = style_data.style_id;
+    var selector = getSelectorInContext(target, $('previewArea'), style_id);
+    CPSSkins.getModelById('style-editor').updateData(
+    {selector: selector, uri: uri});
+  },
+
+  'updateLabel': function(info) {
+    var x = Event.pointerX(info);
+    var y = Event.pointerY(info);
+    var box = $('labelInfo');
+    var label = info.target.getAttribute("label") || '';
+    var tagname = info.target.tagName.toLowerCase();
+    label += ' &lt;' + tagname + '&gt;';
+    box.innerHTML = label ;
+    box.setStyle({left: x+'px', top: y+15+'px'});
+    box.show();
+  },
+
+  'hideLabel': function(info) {
+    $('labelInfo').hide();
+  }
+
+});
+
+function getSelectorInContext(element, context, style_id) {
+  var i, node, tag, name, selector, classnames;
+  node = element;
+
+  // If no context is passed, use the document itself.
+  if (!context) context = document;
+
+  var selectors = new Array()
+  while (node) {
+    if (node == context) break;
+    tag = node.tagName;
+    if (!tag) break;
+    tag = tag.toLowerCase();
+    classnames = node.className;
+    name = '';
+    if (classnames) {
+      classnames = classnames.replace(' style' + style_id, '').split(' ');
+      name = classnames.join('.');
+    }
+    selector = name ? tag + '.' + name : tag;
+
+    // ignore tags that have the "ignore" attribute set
+    if (!node.getAttribute("ignore")) selectors.push(selector);
+    node = node.parentNode;
+  }
+  // reverse the array
+  selectors.reverse();
+  selectors.shift();
+  return selectors.join(" ");
+}
+

Added: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
    Wed Jun  7 12:27:48 2006
@@ -0,0 +1,48 @@
+<div i18n:domain="cpsskins"
+     tal:define="widget_types view/getWidgetTypes;
+                 style_id context/identifier">
+
+  <ins class="model" tal:content="view/getModelDef" />
+
+  <ins class="controller">
+  {"id": "style-editor-behaviour",
+   "type": "behaviour",
+   "rules": {
+     "#previewArea": {
+       "click": "selectTag",
+       "mousemove": "updateLabel",
+       "mouseout": "hideLabel"
+     }
+  }}
+  </ins>
+
+  <table style="width: 100%">
+    <tr>
+      <td style="width: 50%; vertical-align: top">
+        <fieldset id="previewArea" class="panel" style="cursor: pointer">
+          <legend class="panelTitle">Preview</legend>
+          <ins class="view" tal:content="view/getPreviewDef" />
+        </fieldset>
+        <div class="floatingHint" style="display: none"
+             id="labelInfo">&nbsp;</div>
+      </td>
+      <td style="width: 50%; vertical-align: top">
+        <fieldset class="panel">
+          <legend class="panelTitle">Edit settings</legend>
+          <ins class="view" tal:content="view/getFormDef" />
+        </fieldset>
+      </td>
+    </tr>
+  </table>
+
+  <fieldset class="panel">
+    <legend class="panelTitle">Widgets</legend>
+    <ul class="inlineButtons">
+      <li tal:repeat="type widget_types">
+        <a i18n:translate="" tal:content="string:widget.${type}"
+           tal:attributes="href 
string:javascript:CPSSkins.getModelById('style-editor').updateData({widget: 
'$type', selector: '', style_id: '$style_id'});" /></li>
+    </ul>
+    <div style="clear:both"></div>
+  </fieldset>
+
+</div>

Added: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor_form.ctal
==============================================================================
--- (empty file)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor_form.ctal
     Wed Jun  7 12:27:48 2006
@@ -0,0 +1,24 @@
+<form ctal:condition="selector"
+      action="@@setFormData" method="post" onsubmit="return false">
+
+  <p ctal:content="selector">SELECTOR</p>
+
+  <table>
+  <tr ctal:repeat="f fields">
+    <td>
+      <label ctal:content="f/label">LABEL</label>
+    </td>
+    <td>
+      <input type="text" ctal:attributes="value f/value; name f/name" />
+      <span class="status" ctal:condition="f/status"
+                           ctal:content="f/status">STATUS</span>
+    </td>
+  </tr>
+
+  </table>
+
+  <p>
+    <input type="submit" value="Save" />
+  </p>
+
+</form>

Added: cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py   
Wed Jun  7 12:27:48 2006
@@ -0,0 +1,189 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.app.cache.ram import RAMCache
+from zope.app.session.interfaces import ISession
+from zope.component import getUtility
+from zope.traversing.api import getPath
+
+from cpsskins import configuration
+from cpsskins import minjson as json
+from cpsskins import utils
+from cpsskins.elements.interfaces import IFormattable
+from cpsskins.setup.interfaces import IResourceManager
+from cpsskins.utils import getThemeManager
+
+cache = RAMCache()
+
+class StyleEditor:
+    """Style editor view"""
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+        self.session = ISession(request)['cpsskins']
+        self.tmutil = getThemeManager(context)
+
+    def getWidgetTypes(self):
+        readonly = self.request.form.get('readonly')
+        if readonly:
+            return []
+        else:
+            display_id = self.request.form.get('display')
+            display = self.tmutil.getElementById(display_id)
+            widget = IFormattable(display).getFormat(u'widget')
+            return widget.types
+
+    def renderWidgetPreview(self):
+        """Render a style preview based on the specified widget.
+        """
+        data = self.data
+        widget_type = data.get(u'widget', u'')
+        style_id = data.get(u'style_id')
+        if not widget_type:
+            return u''
+        widget = getUtility(configuration.IWidget, widget_type)
+        markup = widget.view(None, None).renderPreview()
+        markup = utils.insertCSSClass(markup, utils.camelize(widget_type))
+        markup = utils.insertCSSClass(markup, u'style' + unicode(style_id))
+        return markup
+
+    def getModelDef(self):
+        path = getPath(self.context)
+        return json.write({
+            'id': 'style-editor',
+            'storage': {
+                'type': 'remote',
+                'accessors': {
+                    'get': '/++skin++cpsskins/%s/@@getStyleData' % path,
+                    'set': '/++skin++cpsskins/%s/@@setStyleData' % path,
+                }
+            },
+            'data': {
+                'preview_url': '/++skin++cpsskins/%s/@@renderWidgetPreview' % \
+                               path,
+                'widget': '',
+                'selector': '',
+                'fields': [],
+                'style_id': '',
+                'uri': '',
+            },
+        })
+
+    def getPreviewDef(self):
+        return json.write({
+            'id': 'style-editor-preview',
+            'widget': {
+                'type': 'panel',
+                'url': 'preview_url',
+            },
+            'model': 'style-editor',
+            'controllers': ['style-editor-actions', 
'main-editor-perspectives'],
+            'perspectives': ['element-editor'],
+        })
+
+    def getFormDef(self):
+        path = getPath(self.context)
+        return json.write({
+            'id': 'style-editor-form',
+            'widget': {
+                'template': '/++skin++cpsskins/%s/@@style-editor-form.html' % \
+                            path,
+            },
+            'model': 'style-editor',
+            'controllers': ['style-editor-behaviour',
+                            'main-editor-perspectives'],
+            'perspectives': ['element-editor'],
+        })
+
+    def setFormData(self):
+        data = self.data
+        selector = data.get(u'selector')
+        if selector is None:
+            raise ValueError("The CSS selector is not set.")
+        uri = data.get(u'uri')
+        if not uri:
+            raise ValueError("The style URI is not set.")
+        resources = getUtility(IResourceManager)
+        style = resources.resolve(uri, context=self.context)
+
+        props = {}
+        for name in self.getFieldNames():
+            value = self.request.form.get(name)
+            if value is None:
+                continue
+            props[name] = value
+
+        style[selector] = props
+
+    def setStyleData(self, data):
+        self.data = json.read(data)
+        self.request.response.setHeader('content-type', 'text/x-json')
+        return self.getStyleData()
+
+    def getFieldNames(self):
+        return (u'font', u'color', u'background-color', 'background-image',
+                u'padding', u'margin', u'border', u'text-transform')
+
+    def getStyleData(self):
+        data = self.data
+        selector = data.get(u'selector', u'')
+        widget = data.get(u'widget', u'')
+        uri = data.get(u'uri')
+        style_id = data.get(u'style_id', u'')
+        resources = getUtility(IResourceManager)
+
+        data = {
+            'widget': widget,
+            'selector': selector,
+            'fields': [],
+            'uri': uri,
+            'style_id': style_id,
+        }
+
+        if uri and selector:
+            style = resources.resolve(uri, context=self.context)
+            fields = []
+            sel = style.get(selector)
+            if sel is None:
+                style[sel] = sel = {}
+            for f in self.getFieldNames():
+                fields.append({
+                    'name': f,
+                    'label': f,
+                    'value': sel.get(f, u''),
+                    'disabled': False,
+                    'status': u'',
+                })
+
+            data['fields'] = fields
+
+        self.request.response.setHeader('content-type', 'text/x-json')
+        return json.write(data)
+
+    ### Session  ######################################################
+
+    def getSessionData(self):
+        return cache.query('style-editor-data', {}, {})
+
+    def setSessionData(self, data):
+        cache.set(data, 'style-editor-data', {})
+
+    data = property(getSessionData, setSessionData)
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to