Author: jmorliaguet
Date: Sat Oct  1 20:55:42 2005
New Revision: 27824

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring.js
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring_macros.pt
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/configure.zcml
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_panel.pt
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/editing.css
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/cell_edit_layout.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/slot_edit.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/pageblock_edit_layout.pt
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/view_editor.pt
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/storages/metaconfigure.py
   z3lab/cpsskins/branches/jmo-perspectives/controllers/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/views.py
   z3lab/cpsskins/branches/jmo-perspectives/relations/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/relations/configure.zcml
   z3lab/cpsskins/branches/jmo-perspectives/relations/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py
Log:

- saving work in progress: almost functional view editor



Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/__init__.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/__init__.py      
Sat Oct  1 20:55:42 2005
@@ -30,6 +30,7 @@
 from zope.component.interfaces import IFactory
 from zope.event import notify
 from zope.interface import implements
+from zope.security.proxy import removeSecurityProxy
 
 from jsonserver.interfaces import IJSONRPCPublisher
 
@@ -43,10 +44,14 @@
 from cpsskins.thememanager import getThemeManager
 
 class Authoring(BrowserView):
-
     adapts(IElement)
     implements(IAuthoring)
 
+    def _redirect(self):
+        request = self.request
+        target = request.get('HTTP_REFERER', '.')
+        request.response.redirect(target)
+
     def draw(self, **kw):
         """Draws a the canvas element in edit mode
         """
@@ -73,46 +78,56 @@
     def setCanvasMode(self, mode=None):
         """Set the canvas view mode
         """
-        request = self.request
         pkg_id = 'cpsskins'
-        session = ISession(request)[pkg_id]
+        session = ISession(self.request)[pkg_id]
         if mode is not None:
             session['canvas_mode'] = mode
-        target = request.get('HTTP_REFERER', '.')
-        request.response.redirect(target)
+        self._redirect()
 
     def setPerspective(self, perspective=None):
         """Set the perspective
         """
-        request = self.request
         pkg_id = 'cpsskins'
-        session = ISession(request)[pkg_id]
+        session = ISession(self.request)[pkg_id]
         tmutil = getThemeManager()
-        theme = tmutil.getDefaultTheme()
+        theme = tmutil.getEffectiveTheme(self.context)
         perspective = theme.getPerspectiveById(perspective)
-        if not perspective:
-            perspective = None
+
+        # remove the security proxy before storing the object in the session
+        if perspective is not None:
+            perspective = removeSecurityProxy(perspective)
         session['perspective'] = perspective
-        target = request.get('HTTP_REFERER', '.')
-        request.response.redirect(target)
+        self._redirect()
+
+    def cloneView(self, perspective=None):
+        """Clone a view in a given perspective by:
+
+        - assigning a new display to it
+
+        - by associating the original display's formats to the new display
+
+        """
+        tmutil = getThemeManager()
+        theme = tmutil.getEffectiveTheme(self.context)
+        perspective = theme.getPerspectiveById(perspective)
+        display = IDisplayable(self.context).getDisplay(perspective)
+        if display is None:
+            IViewable(self.context).cloneView(perspective)
+        self._redirect()
 
     def addView(self, perspective=None):
-        request = self.request
         tmutil = getThemeManager()
         theme = tmutil.getEffectiveTheme(self.context)
         perspective = theme.getPerspectiveById(perspective)
         IViewable(self.context).addView(perspective)
-        target = request.get('HTTP_REFERER', '.')
-        request.response.redirect(target)
+        self._redirect()
 
     def removeView(self, perspective=None):
-        request = self.request
         tmutil = getThemeManager()
         theme = tmutil.getEffectiveTheme(self.context)
         perspective = theme.getPerspectiveById(perspective)
         IViewable(self.context).removeView(perspective)
-        target = request.get('HTTP_REFERER', '.')
-        request.response.redirect(target)
+        self._redirect()
 
 
 class Editing(BrowserView):
@@ -178,22 +193,6 @@
         element = self._getElementById(id)
         element.edit(name, value)
 
-    def customizeElement(self, id, format):
-        """Customize the element by assigning a display to it in the current
-        perspective..
-        """
-        element = self._getElementById(id)
-        perspective = getMultiAdapter(
-            objects=(element, self.request),
-            interface=INegociation,
-            ).getPerspective()
-        display = IDisplayable(element).getDisplay(perspective)
-        if display is None:
-            display = IViewable(element).cloneView(perspective)
-
-        IFormattable(display).cloneFormat(format)
-        return id
-
     def copyElement(self, id):
         """Copy an element to the clipboard.
         """

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring.js
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring.js     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring.js     
Sat Oct  1 20:55:42 2005
@@ -29,9 +29,9 @@
 function MenuActions() {
   this.edit = Menu_edit;
   this.duplicate = Menu_duplicate;
-  this.customize = Menu_customize;
   this.copy = Menu_copy;
   this.paste = Menu_paste;
+  this.format = Menu_format;
   this.remove = Menu_remove;
 }
 
@@ -60,13 +60,6 @@
     finish_paste);
 }
 
-function model_customize(id, format) {
-  themeEditor.customizeElement(
-    id=id,
-    format=format,
-    finish_customize);
-}
-
 function model_delete(id) {
   themeEditor.deleteElement(
     id=id,
@@ -214,10 +207,10 @@
   }
 }
 
-function Menu_customize(format) {
+function Menu_format(format) {
   var id = pd_selected_item.getAttribute("id");
-  current_elem = document.getElementById(id);
-  model_customize(id, format);
+  var new_url = '@@edit-panel.html?id=' + id + '&format=' + format;
+  newWindow(new_url);
 }
 
 function Menu_copy() {
@@ -364,19 +357,6 @@
   model_add(container_id, type_name, order);
 }
 
-function finish_customize(resp, err) {
-  if (!err) {
-    var id = resp;
-    var rendered = render_element(id);
-    if (current_elem) {
-      current_elem.parentNode.replaceChild(rendered, current_elem);
-    }
-    current_elem = null;
-    pd_setupPage();
-    highlight(rendered);
-  }
-}
-
 function finish_add(resp, err) {
   if (!err) {
     var new_id = resp;
@@ -538,7 +518,6 @@
     themeEditor = jsonrpcConnect(addr=".",
         methods=["addElement",
                  "editElement",
-                 "customizeElement",
                  "copyElement",
                  "pasteElement",
                  "moveElement",

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring_macros.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring_macros.pt  
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/authoring_macros.pt  
    Sat Oct  1 20:55:42 2005
@@ -83,13 +83,6 @@
        menu-duplicate
     </a>
 
-    <a class="customize context-menu-item"
-       visible="customizable">
-      <tal:block i18n:translate="">menu-customize</tal:block>
-      <div class="context-submenu"
-       action="customize" expand="1" choice="formats"></div>
-    </a>
-
     <div class="separator"></div>
 
     <a class="copy" href="#" i18n:translate=""
@@ -100,7 +93,17 @@
        action="paste">
        menu-paste
     </a>
+
+    <div class="separator"></div>
+
+    <a class="customize context-menu-item">
+      <tal:block i18n:translate="">menu-format</tal:block>
+      <div class="context-submenu"
+       action="customize" expand="1" choice="formats"></div>
+    </a>
+
     <div class="separator"></div>
+
     <a class="delete" href="#" i18n:translate=""
        confirm="Deleting, are you sure?"
        visible="editable"

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/configure.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/configure.zcml   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/configure.zcml   
Sat Oct  1 20:55:42 2005
@@ -141,6 +141,11 @@
       />
 
       <page
+          name="cloneView"
+          attribute="cloneView"
+      />
+
+      <page
           name="addView"
           attribute="addView"
       />
@@ -305,7 +310,7 @@
       class=".Methods"
       for="*"
       permission="zope.ManageContent"
-      methods="addElement editElement moveElement customizeElement
+      methods="addElement editElement moveElement
                reorderElement deleteElement duplicateElement"
   />
 

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt     
Sat Oct  1 20:55:42 2005
@@ -1,6 +1,5 @@
 <html metal:use-macro="context/@@popup_macros/page">
   <body metal:fill-slot="body"
-   onload="javascript:parent.main.location.href = '@@edit.html'"
    class="panel" i18n:domain="cpsskins"
    tal:define="perspective context/@@getPerspective;
                displayable context/displayable:this;
@@ -39,29 +38,12 @@
 
     <div style="clear:both"></div>
 
-    <form class="views" action="@@setPerspective" method="post"
-     onchange="submit()"
-     tal:define="displayable context/displayable:this;
-                 actual_display python: displayable.getDisplay(perspective);
-                 infos displayable/getDisplayInfo">
+    <div class="views">
       <a href="@@view-editor.html" title="View editor" target="main">
-        <img src="/++skin++cpsskins/@@/perspective-12.png" /></a>
-      <tal:block repeat="info infos">
-        <tal:block define="
-           this_perspective info/perspective;
-           id python: this_perspective or 'default';
-           selected python: this_perspective == perspective or
-                            (not actual_display and not this_perspective)">
-          <input type="radio" name="perspective" i18n:attributes="value"
-           tal:attributes="id id;
-                           value python: this_perspective or ''" />
-          <label tal:content="id"
-           tal:attributes="for id;
-                           title string:Set the perspective to 
$this_perspective;
-                           class python: selected and 'selected' or nothing" />
-        </tal:block>
-      </tal:block>
-    </form>
+        Switch views
+      </a>
+    </div>
+
 
   </body>
 </html>

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_panel.pt
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_panel.pt    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_panel.pt    
Sat Oct  1 20:55:42 2005
@@ -3,12 +3,18 @@
     <frameset rows="70px,*,50px" frameborder="0"
      tal:define="tmutil context/@@getThemeManager;
                  id request/form/id;
+                 format_name request/form/format|string:style;
                  element python: tmutil.getElementById(id);
-                 element_url element/@@absolute_url">
+                 element_url element/@@absolute_url;
+                 perspective context/@@getPerspective;
+                 displayable element/displayable:this;
+                 display python: displayable.getEffectiveDisplay(perspective);
+                 formattable display/formattable:this;
+                 format python: formattable.getFormat(format_name)">
       <frame name="menu" scrolling="no"
        tal:attributes="src string:${element_url}/@@edit-menu.html" />
       <frame name="main"
-       tal:attributes="src string:${element_url}/@@edit.html" />
+       tal:attributes="src string:${format/@@absolute_url}/@@edit.html" />
       <frame name="control" scrolling="no"
        tal:attributes="src string:${element_url}/@@edit-control.html" />
     </frameset>

Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/editing.css
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/editing.css      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/editing.css      
Sat Oct  1 20:55:42 2005
@@ -200,16 +200,25 @@
 }
 
 .views {
-  font: 12px "Trebuchet MS", Verdana, Arial, Sans-Serif;
+  font: 13px "Trebuchet MS", Verdana, Arial, Sans-Serif;
   position: absolute;
-  top: 54px;
-  right: 25px;
+  top: 15px;
+  right: 15px;
   color: #666;
+  background-color: #fff;
+  padding: 0.2em 0.5em 0.2em 0.5em;
+  border: 1px solid #999;
+  -moz-border-radius: 6px;
+}
+
+.views a {
+  text-decoration: none;
 }
 
 .views img {
   border: none;
   vertical-align: middle;
+  padding-right: 4px;
 }
 
 .views input {
@@ -410,14 +419,16 @@
   border-top: 1px solid #999;
   border-bottom: 1px solid #999;
   border-right: 1px solid #999;
-  padding: 0 4em 0.1em 1em;
+  padding: 0.2em 2.5em 0.2em 2.5em;
   text-transform: lowercase;
+  text-align: center;
 }
 
 table.inline td {
   border-right: 1px solid #999;
   padding: 0.2em 1em;
   vertical-align: top;
+  text-align: center;
 }
 
 table.inline tr {
@@ -428,9 +439,3 @@
   background-color: #f3f3f3;
 }
 
-p.tips {
-  background-image: url(/++skin++cpsskins/@@/tip-16.png);
-  background-repeat: no-repeat;
-  background-position: 0% 50%;
-  padding-left: 20px;
-}

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/cell_edit_layout.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/cell_edit_layout.pt
      (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/cell_edit_layout.pt
      Sat Oct  1 20:55:42 2005
@@ -6,7 +6,7 @@
     rendered options/rendered;
     display info/display;
     actual_display info/actual_display;
-    formats display/formattable:getCustomizableFormats;
+    formats display/formattable:getFormatNames;
     canvas_mode options/canvas_mode|nothing;
     mode_is_layout python:canvas_mode == 'layout';
     title context/title;
@@ -16,7 +16,7 @@
     width layout/width"
   tal:attributes="
     editable python:1;
-    customizable python: formats and 1 or 0;
+    formattable python: formats and 1 or 0;
     formats python: ' '.join(formats);
     id id;
     width width;">

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
  (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
  Sat Oct  1 20:55:42 2005
@@ -1,22 +1,21 @@
 <div
   tal:define="
-     parent view/getParent;
-     info options/info;
-     perspective info/perspective;
-     display info/display;
-     actual_display info/actual_display;
-     formattable display/formattable:this;
-     formats python: formattable.getCustomizableFormats(perspective);
-     parent_type parent/elementtype;
-     editable python: str(parent_type) == 'ISlot';
-     title context/title;
-     id view/getId;"
+    parent view/getParent;
+    info options/info;
+    perspective info/perspective;
+    display info/display;
+    actual_display info/actual_display;
+    formats display/formattable:getFormatNames;
+    parent_type parent/elementtype;
+    editable python: str(parent_type) == 'ISlot';
+    title context/title;
+    id view/getId;"
   tal:attributes="
-     editable editable;
-     customizable python: formats and 1 or 0;
-     formats python: ' '.join(formats);
-     class python: editable and 'editable draggable hover' or nothing;
-     id id">
+    editable editable;
+    formattable python: formats and 1 or 0;
+    formats python: ' '.join(formats);
+    class python: editable and 'editable draggable hover' or nothing;
+    id id">
 
   <div tal:content="structure options/rendered" />
 

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
     (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
     Sat Oct  1 20:55:42 2005
@@ -1,20 +1,19 @@
 <div class="editable draggable hover"
   tal:define="
-     info options/info;
-     display info/display;
-     perspective info/perspective;
-     actual_display info/actual_display;
-     canvas_mode options/canvas_mode|nothing;
-     mode_is_layout python:canvas_mode == 'layout';
-     formattable display/formattable:this;
-     formats python: formattable.getCustomizableFormats(perspective);
-     title context/title;
-     id view/getId"
+    info options/info;
+    display info/display;
+    perspective info/perspective;
+    actual_display info/actual_display;
+    canvas_mode options/canvas_mode|nothing;
+    mode_is_layout python:canvas_mode == 'layout';
+    formats display/formattable:getFormatNames;
+    title context/title;
+    id view/getId"
   tal:attributes="
-     editable python:1;
-     customizable python: formats and 1 or 0;
-     formats python: ' '.join(formats);
-     id id">
+    editable python:1;
+    formattable python: formats and 1 or 0;
+    formats python: ' '.join(formats);
+    id id">
 
     <div class="portletBoxLayoutMode" tal:condition="mode_is_layout">
       <strong tal:condition="title" tal:content="title" />

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/slot_edit.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/slot_edit.pt
        (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/slot_edit.pt
        Sat Oct  1 20:55:42 2005
@@ -5,8 +5,7 @@
     rendered options/rendered;
     actual_display info/actual_display;
     display info/display;
-    formattable display/formattable:this;
-    formats python: formattable.getCustomizableFormats(perspective);
+    formats display/formattable:getFormatNames;
     slot_title context/title;
     slot_name context;
     id view/getId;
@@ -15,7 +14,7 @@
   <div class="slotFrame editable draggable"
    tal:attributes="
      editable python:1;
-     customizable python: formats and 1 or 0;
+     formattable python: formats and 1 or 0;
      formats python: ' '.join(formats);
      id id">
     <div class="title" tal:content="slot_title|slot_name" />

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/pageblock_edit_layout.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/pageblock_edit_layout.pt
 (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/pageblock_edit_layout.pt
 Sat Oct  1 20:55:42 2005
@@ -5,8 +5,7 @@
     perspective info/perspective;
     actual_display info/actual_display;
     display info/display;
-    formattable display/formattable:this;
-    formats python: formattable.getCustomizableFormats(perspective);
+    formats display/formattable:getFormatNames;
     mode_is_layout python:canvas_mode == 'layout';
     title context/title;
     layout nocall:options/layout;
@@ -18,7 +17,7 @@
    class="pageBlockEdit editable shiftable" constraint="vertical"
    tal:attributes="
      editable python:1;
-     customizable python: formats and 1 or 0;
+     formattable python: formats and 1 or 0;
      formats python: ' '.join(formats);
      folder_editable python:1;
      width width;

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/interfaces.py    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/interfaces.py    
Sat Oct  1 20:55:42 2005
@@ -46,3 +46,12 @@
 
     def setPerspective(perspective):
         """ """
+
+    def cloneView(id, format):
+        """ """
+
+    def addView(perspective):
+        """ """
+
+    def removeView(perspective):
+        """ """

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/view_editor.pt
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/view_editor.pt   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/view_editor.pt   
Sat Oct  1 20:55:42 2005
@@ -1,35 +1,60 @@
 <html metal:use-macro="context/@@popup_macros/page">
   <body metal:fill-slot="body" i18n:domain="cpsskins">
     <div class="editArea"
-     tal:define="perspective context/@@getPerspective;
+     tal:define="format_names python: ('effect', 'style', 'format');
+               tmutil context/@@getThemeManager;
+               current_theme python:tmutil.getThemeInContext(context);
+                 perspective context/@@getPerspective;
                  displayable context/displayable:this;
                  actual_display python: displayable.getDisplay(perspective)">
       <h1>View editor</h1>
+    <metal:block use-macro="context/@@authoring_macros/perspective_selector" />
       <p>The views associated to this element are listed in the table 
below:</p>
       <form action="." tal:attributes="action request/URL" method="post"
             enctype="multipart/form-data">
         <table class="inline"
-         tal:define="displayable context/displayable:this;
-                     infos displayable/getDisplayInfo">
+         tal:define="info context/viewable:getViewInfo;
+                     views info/views;
+                     format_names info/format_names">
           <tr>
             <th>View</th>
-            <th>Perspective</th>
+            <th style="text-align: center"
+             tal:repeat="format_name format_names">
+              <tal:block content="format_name" />
+            </th>
             <th>Action</th>
           </tr>
-          <tal:block repeat="info infos">
-            <tr tal:define="even repeat/info/even;
+          <tal:block repeat="view python: views.keys()">
+            <tr tal:define="info views/?view;
+                            even repeat/view/even;
                             perspective info/perspective"
                 tal:attributes="class python: even and 'even' or nothing">
-              <td tal:content="python: perspective and perspective or 
'default'" /> 
-              <td tal:content="perspective" /> 
-              <td><a tal:condition="perspective"
-                     tal:attributes="href 
string:@@removeView?perspective=$perspective">remove</a></td>
+              <td tal:content="view" /> 
+              <td style="text-align: center"
+               tal:repeat="format_name format_names">
+                <input type="checkbox"
+                 tal:attributes="name format_name;
+                                 disabled python: perspective is None and 
'disabled' or nothing" />
+              </td>
+              <td>
+                <a title="Delete view"
+                 tal:condition="perspective"
+                 tal:attributes="href 
string:@@removeView?perspective=$perspective">
+                  <img style="border: none"
+                   src="/++skin++cpsskins/@@/delete-16.png" />
+                </a>
+              </td>
             </tr>
           </tal:block>
         </table>
-        <p tal:condition="not:actual_display"
-           tal:content="string:There is no custom view associated to the 
$perspective perspective.
-                               The default view will be applied for this 
element." />
+        <tal:block condition="not:actual_display">
+         <p tal:content="string:There is no view associated to the 
$perspective perspective." />
+         <p>
+         &gt; <a href=""
+               tal:attributes="href 
string:@@cloneView?perspective=$perspective">Add a "<tal:block 
content="perspective" />" view</a>
+         </p>
+        </tal:block>
+
       </form>
     </div>
   </body>

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/storages/metaconfigure.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/storages/metaconfigure.py
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/storages/metaconfigure.py
    Sat Oct  1 20:55:42 2005
@@ -54,7 +54,7 @@
     # zope:content
     c = ContentDirective(_context=_context, class_=factory)
     c.factory(_context=_context, title=title, description=description) 
-    c.allow(_context=_context, 
+    c.allow(_context=_context,
         interface=(IReadContainer, interface))
     c.require(_context=_context,
         permission="zope.ManageSite",

Modified: z3lab/cpsskins/branches/jmo-perspectives/controllers/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/controllers/__init__.py    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/controllers/__init__.py    Sat Oct 
 1 20:55:42 2005
@@ -46,11 +46,11 @@
     if tmutil is None:
         return
 
-    # unregister the element
-    tmutil.unregisterElement(element)
-
     # get the object's controller
     controller = IController(element, None)
     if controller is not None:
         controller.removed()
 
+    # unregister the element
+    tmutil.unregisterElement(element)
+

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py      
Sat Oct  1 20:55:42 2005
@@ -17,12 +17,18 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.app.copypastemove.interfaces import IObjectCopier
 from zope.app.interface import queryType
+from zope.app.location.pickling import locationCopy
 from zope.app.traversing.interfaces import IPathAdapter
 from zope.interface import implements
+from zope.security.proxy import removeSecurityProxy
+from zope.proxy import ProxyBase, isProxy
 
 from cpsskins.elements import Element
 from cpsskins.elements.interfaces import IDisplayable, IDisplay, IDisplayType
+from cpsskins.elements.interfaces import IFormattable
+from cpsskins.elements.interfaces import IPerspective
 from cpsskins.relations import DyadicRelation, TriadicRelation
 from cpsskins.relations.tool import RelationTool
 from cpsskins.ontology import hasDisplay, hasDisplayFromPerspective
@@ -126,30 +132,11 @@
         displays = theme.getStorage(IDisplayStorage)
         return displays.add(display)
 
-    def getDisplayInfo(self):
-        """Return the list of display elements associated to the element.
+    def cloneDisplay(self, display):
+        """Clone an existing display.
         """
-        object = self.context
-        reltool = RelationTool(object)
-
-        info = []
-        for r in reltool.search(predicate=hasDisplay, first=object):
-            rel = reltool.get(r)
-            info.append(
-                {'relation': rel,
-                 'display': rel.second,
-                 'perspective': None,
-                })
-
-        for r in reltool.search(predicate=hasDisplayFromPerspective,
-                                first=object):
-            rel = reltool.get(r)
-            info.append(
-                {'relation': rel,
-                 'display': rel.second,
-                 'perspective': rel.third,
-                })
-        return info
+        new_display = locationCopy(removeSecurityProxy(display))
+        return self.storeDisplay(new_display)
 
     def getEffectiveDisplay(self, perspective=None):
         """Return a display from a given perspective if it exists.
@@ -180,6 +167,9 @@
         """
         context = self.context
 
+        if not IDisplay.providedBy(display):
+            raise ValueError("%s is not a display element" % repr(display))
+
         if perspective is None:
             relation = DyadicRelation(
                 predicate=hasDisplay,
@@ -187,6 +177,8 @@
                 second=display,
                 )
         else:
+            if not IPerspective.providedBy(perspective):
+                raise ValueError("%s is not a perspective" % repr(perspective))
             relation = TriadicRelation(
                 predicate=hasDisplayFromPerspective,
                 first=context,
@@ -207,18 +199,19 @@
         theme = tmutil.getThemeInContext(context)
         displays = theme.getStorage(IDisplayStorage)
 
-        # remove the display
         display = IDisplayable(context).getDisplay(perspective)
-        displays.remove(display)
 
         # Remove the relation
         reltool = RelationTool(context)
         relations = reltool.search(
-            first=context, second=display,
-            third=perspective,
+            first=context,
+            second=display,
             predicate=hasDisplayFromPerspective)
         reltool.remove(relations)
 
+        # remove the display
+        displays.remove(display)
+
     def factory(self):
         """Display factory. Return a display element.
         """

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py       
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py       
Sat Oct  1 20:55:42 2005
@@ -120,11 +120,9 @@
             return res[0]
         return None
 
-    def getCustomizableFormats(self, perspective=None):
-        """Return the list of customizable formats called by their name.
+    def getFormatNames(self):
+        """Return the list of format names.
         """
-        if perspective is None:
-            return []
         return [f.formatname for f in self.getFormats()]
 
     def addFormat(self, name='', id=''):
@@ -146,9 +144,6 @@
         reltool = RelationTool(context)
 
         new_format = locationCopy(self.getFormat(name))
-        tmutil = getThemeManager()
-        tmutil.registerElement(new_format)
-
         self.storeFormat(new_format)
 
         predicate = format_registry.get(name)['predicate']

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py     Sat Oct 
 1 20:55:42 2005
@@ -53,7 +53,10 @@
         """ """
 
     def getIdentifier():
-        """The identifier uniquely identifies each element."""
+        """Get the element's identifier."""
+
+    def setIdentifier(id):
+        """Set the element's identifier."""
 
     def isIdenticalTo(other):
         """ """
@@ -112,13 +115,13 @@
     def storeDisplay(display):
         """Add a display to the store."""
 
+    def cloneDisplay(display):
+        """Clone an existing display."""
+
     def getEffectiveDisplay(perspective):
         """Return a display from a given perspective if it exists.
         Otherwise return the default display."""
 
-    def getDisplayInfo():
-        """Return some information about the displays of the element."""
-
     def addDisplay(perspective):
         """Add a display to a displayable element."""
 
@@ -128,12 +131,15 @@
     def removeDisplay(perspective):
         """Remove a display from a displayable element."""
 
+    def factory():
+        """Will be moved to zcml (declared for security proxy reasons)"""
+
 class IFormattable(Interface):
 
     def getFormats(name):
         """ """
 
-    def getCustomizableFormats(perspective):
+    def getFormatNames():
         """ """
 
     def getFormat(name):
@@ -151,6 +157,10 @@
 class IViewable(Interface):
     """Viewable elements can be displayed and formatted."""
 
+    def getViewInfo():
+        """Return a dictionary with information about display and formats 
+        associated to the element in various views / perspectives."""
+
     def addView(perspective):
         """ """
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py  (original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py  Sat Oct  1 
20:55:42 2005
@@ -17,8 +17,8 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.interface import implements
 from zope.app.container.interfaces import INameChooser
+from zope.interface import implements
 
 from cpsskins.elements import InnerNode
 from cpsskins.storage.interfaces import IPortletStorage, IPerspectiveStorage

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/views.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/views.py  (original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/views.py  Sat Oct  1 
20:55:42 2005
@@ -45,7 +45,12 @@
         return self
 
     def addView(self, perspective=None):
-        """Add a view to an element
+        """Add a view to an element, i.e.:
+
+        - a factory display
+
+        - the factory formats associated to the display
+
         """
         context = self.context
         displayable = IDisplayable(context)
@@ -58,7 +63,10 @@
 
     def cloneView(self, perspective=None):
         """Clone the default view of an element.
-        Return the new display.
+
+        This is similar to addView() except that the formats of the cloned
+        view are used in the new view.
+
         """
         if perspective is None:
             raise ValueError("Must specify a destination perspective")
@@ -67,21 +75,16 @@
         reltool = RelationTool(context)
 
         displayable = IDisplayable(context)
-        display = displayable.getDisplay()
-
-        new_display = displayable.storeDisplay(locationCopy(display))
+        default_display = displayable.getDisplay()
+        display = displayable.cloneDisplay(default_display)
+        displayable.setDisplay(display=display, perspective=perspective)
 
-        tmutil = getThemeManager()
-        tmutil.registerElement(new_display)
-        new_display = displayable.setDisplay(new_display, perspective)
-
-        formattable = IFormattable(new_display)
-        for r in reltool.search(first=display, predicate=hasFormat):
+        formattable = IFormattable(display)
+        for r in reltool.search(first=default_display, predicate=hasFormat):
             rel = reltool.get(r)
             format = rel.second
             predicate = rel()
             formattable.setFormat(format, predicate)
-        return new_display
 
     def removeView(self, perspective=None):
         """Remove a view associated to an element
@@ -90,3 +93,32 @@
         displayable = IDisplayable(context)
         display = displayable.removeDisplay(perspective)
 
+    def getViewInfo(self):
+        """Return a dictionary with information about display and formats 
+        associated to the element in various views / perspectives.
+        """
+        object = self.context
+        reltool = RelationTool(object)
+
+        views = {}
+        for r in reltool.search(predicate=hasDisplay, first=object) \
+               + reltool.search(predicate=hasDisplayFromPerspective,
+                                first=object):
+            rel = reltool.get(r)
+            display = rel.second
+            formattable = IFormattable(display)
+            perspective = len(rel) == 3 and rel.third or None
+            view_id = perspective and str(perspective) or 'default'
+
+            views[view_id] = {
+                'relation': rel,
+                'display': display,
+                'formats': formattable.getFormats(),
+                'perspective': perspective,
+                }
+
+        return {
+            'views': views,
+            'format_names': formattable.getFormatNames(),
+            }
+

Modified: z3lab/cpsskins/branches/jmo-perspectives/relations/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/relations/__init__.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/relations/__init__.py      Sat Oct 
 1 20:55:42 2005
@@ -18,8 +18,10 @@
 __docformat__ = "reStructuredText"
 
 import re
+
 from persistent import Persistent
 from zope.interface import implements
+from zope.security.proxy import removeSecurityProxy as trusted
 
 from interfaces import IRelatable, IPredicate, ICompoundPredicate
 from interfaces import IMonadicRelation, IDyadicRelation, ITriadicRelation
@@ -77,6 +79,7 @@
     def __iter__(self):
         return iter([self._predicate])
 
+
 class CompoundPredicate:
     """A compound predicate is an unordered collection of predicates.
     They are used for doing queries.
@@ -225,8 +228,8 @@
     implements(IMonadicRelation)
 
     def __init__(self, predicate=None, first=None):
-        self._predicate = predicate
-        self._tuple = (first,)
+        self._predicate = trusted(predicate)
+        self._tuple = trusted(first),
 
     def __getattr__(self, name):
         if name == 'first':
@@ -273,8 +276,8 @@
     implements(IDyadicRelation)
 
     def __init__(self, predicate='', first=None, second=None):
-        self._predicate = predicate
-        self._tuple = (first, second)
+        self._predicate = trusted(predicate)
+        self._tuple = trusted(first), trusted(second)
 
     def __getattr__(self, name):
         if name == 'first':
@@ -329,8 +332,8 @@
     implements(ITriadicRelation)
 
     def __init__(self, predicate=None, first=None, second=None, third=None):
-        self._predicate = predicate
-        self._tuple = (first, second, third)
+        self._predicate = trusted(predicate)
+        self._tuple = trusted(first), trusted(second), trusted(third)
 
     def __getattr__(self, name):
         if name == 'first':

Modified: z3lab/cpsskins/branches/jmo-perspectives/relations/configure.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/relations/configure.zcml   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/relations/configure.zcml   Sat Oct 
 1 20:55:42 2005
@@ -1,6 +1,21 @@
 <configure
     xmlns="http://namespaces.zope.org/zope";>
 
+  <content class=".Relation">
+
+    <require
+        permission="zope.View"
+        interface=".interfaces.IRelation"
+        />
+
+    <require
+        permission="zope.ManageContent"
+        set_schema=".interfaces.IRelation"
+        />
+
+  </content>
+
+
   <content class=".MonadicRelation">
 
     <require
@@ -8,6 +23,11 @@
         interface=".interfaces.IMonadicRelation"
         />
 
+    <require
+        permission="zope.ManageContent"
+        set_schema=".interfaces.IMonadicRelation"
+        />
+
   </content>
 
 
@@ -18,6 +38,11 @@
         interface=".interfaces.IDyadicRelation"
         />
 
+    <require
+        permission="zope.ManageContent"
+        set_schema=".interfaces.IDyadicRelation"
+        />
+
   </content>
 
 
@@ -28,6 +53,11 @@
         interface=".interfaces.ITriadicRelation"
         />
 
+    <require
+        permission="zope.ManageContent"
+        set_schema=".interfaces.ITriadicRelation"
+        />
+
   </content>
 
 </configure>

Modified: z3lab/cpsskins/branches/jmo-perspectives/relations/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/relations/interfaces.py    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/relations/interfaces.py    Sat Oct 
 1 20:55:42 2005
@@ -18,6 +18,7 @@
 __docformat__ = "reStructuredText"
 
 from zope.interface import Interface
+from zope.schema import Object, Tuple
 
 # Relations
 class IRelatable(Interface):
@@ -32,6 +33,13 @@
 class IRelation(Interface):
     """A relation connects relates."""
 
+    def __len__():
+        """Return the relation's arity"""
+
+    def __call__():
+        """Return the relation's predicate"""
+
+
 class IMonadicRelation(IRelation):
     """A monadic relation connects a relate with itself."""
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py        Sat Oct 
 1 20:55:42 2005
@@ -19,7 +19,9 @@
 
 from zope.app.container.btree import BTreeContainer
 from zope.app.container.contained import Contained
-from zope.app.container.interfaces import INameChooser
+from zope.app.container.contained import ObjectAddedEvent, ObjectRemovedEvent
+from zope.app.container.interfaces import INameChooser, IContainer, IContained
+from zope.event import notify
 from zope.interface import implements
 
 from interfaces import IStorage
@@ -33,6 +35,7 @@
         chooser = INameChooser(self)
         name = chooser.chooseName(name, object)
         self[name] = object
+        notify(ObjectAddedEvent(object))
         return self[name]
 
     def remove(self, object):

Modified: z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py      Sat Oct 
 1 20:55:42 2005
@@ -18,10 +18,11 @@
 __docformat__ = "reStructuredText"
 
 from zope.app.container.constraints import contains
+from zope.app.container.interfaces import INameChooser, IContainer, IContained
 from zope.interface import Interface
 
-from cpsskins.elements.interfaces import IFormat, IDisplay, IPortlet, \
-    IPerspective
+from cpsskins.elements.interfaces import IFormat, IDisplay, IPortlet
+from cpsskins.elements.interfaces import IPerspective
 from cpsskins.relations.interfaces import IRelation
 
 class IStorage(Interface):
@@ -32,6 +33,9 @@
     def remove(object):
         """ """
 
+    def __setitem__(item):
+        """ """
+
 class IFormatStorage(IStorage):
 
     contains(IFormat)
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to