Author: jmorliaguet
Date: Sun Dec  4 20:25:07 2005
New Revision: 1955

Added:
   cpsskins/branches/jmo-perspectives/browser/editing/create_setting.pt   
(contents, props changed)
   cpsskins/branches/jmo-perspectives/browser/editing/manage_settings.pt   
(contents, props changed)
Removed:
   cpsskins/branches/jmo-perspectives/browser/editing/edit_settings.pt
Modified:
   cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml
   cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt
   cpsskins/branches/jmo-perspectives/browser/editing/views.py
Log:

- split edit_settings.pt into create_setting.pt and manage_settings.pt

  - createSetting is called on the object that is to be converted into a setting

  - useSettingasFormat is called on the display



Modified: cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml   
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml   Sun Dec 
 4 20:25:07 2005
@@ -16,29 +16,36 @@
   <page
       for="*"
       name="edit-panel.html"
-      permission="zope.Public"
+      permission="zope.ManageContent"
       template="edit_panel.pt"
   />
 
   <page
       for="*"
       name="edit-menu.html"
-      permission="zope.Public"
+      permission="zope.ManageContent"
       template="edit_menu.pt"
   />
 
   <page
       for="*"
       name="edit-control.html"
-      permission="zope.Public"
+      permission="zope.ManageContent"
       template="edit_control.pt"
   />
 
   <page
       for="*"
-      name="edit-settings.html"
-      permission="zope.Public"
-      template="edit_settings.pt"
+      name="create-setting.html"
+      permission="zope.ManageContent"
+      template="create_setting.pt"
+  />
+
+  <page
+      for="*"
+      name="manage-settings.html"
+      permission="zope.ManageContent"
+      template="manage_settings.pt"
   />
 
   <view

Added: cpsskins/branches/jmo-perspectives/browser/editing/create_setting.pt
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/browser/editing/create_setting.pt        
Sun Dec  4 20:25:07 2005
@@ -0,0 +1,26 @@
+<html metal:use-macro="context/@@popup_macros/page">
+  <body metal:fill-slot="body" i18n:domain="cpsskins">
+    <div class="editArea">
+      <h1>Create setting</h1>
+
+      <div class="main">
+        <form enctype="multipart/form-data" method="post"
+              action="./@@createSetting">
+
+          <div class="row">
+            <div class="label">
+              <label for="title">Title</label>
+            </div>
+            <input id="title" type="text" name="title" />
+          </div>
+
+          <p>
+            <button type="submit" class="submitButton" name="UPDATE_SUBMIT"
+                    i18n:translate="create-button">Create</button>
+          </p>
+        </form>
+      </div>
+
+    </div>
+  </body>
+</html>

Modified: cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt     
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt     Sun Dec 
 4 20:25:07 2005
@@ -46,14 +46,14 @@
     <div class="editActions"
      tal:define="actions context/@@view_get_menu/cpsskins_editing_actions"
      tal:condition="actions">
+      <a tal:condition="format_name"
+         tal:attributes="href 
string:@@edit-menu.html?action=create-setting.html&format=$format_name">Create 
setting</a>
       <a href="#"
          tal:repeat="info actions"
          tal:attributes="href info/action;
                          class info/selected"
          tal:content="info/title"
          i18n:translate="" />
-      <a tal:condition="format_name"
-         tal:attributes="href 
string:@@edit-menu.html?action=@@edit-settings.html&format=$format_name">Settings</a>
     </div>
 
   </body>

Added: cpsskins/branches/jmo-perspectives/browser/editing/manage_settings.pt
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/browser/editing/manage_settings.pt       
Sun Dec  4 20:25:07 2005
@@ -0,0 +1,21 @@
+<html metal:use-macro="context/@@popup_macros/page">
+  <body metal:fill-slot="body" i18n:domain="cpsskins">
+    <div class="editArea">
+      <h1>Manage settings</h1>
+
+      <span tal:content="context/@@absolute_url" />
+      <!-- For testing -->
+      <ul tal:define="setting_info context/@@getSettingInfo">
+        <li tal:condition="python: 'IStyle' in setting_info"
+            tal:repeat="info setting_info/IStyle">
+          <tal:block define="name info/name">
+            <a href=""
+               tal:attributes="href 
string:./@@useSettingAsFormat?setting_name=$name&format_type=IStyle"
+               tal:content="info/name" />
+          </tal:block>
+        </li>
+      </ul>
+
+    </div>
+  </body>
+</html>

Modified: cpsskins/branches/jmo-perspectives/browser/editing/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/views.py (original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/views.py Sun Dec  4 
20:25:07 2005
@@ -28,7 +28,7 @@
 
 from cpsskins import configuration
 from cpsskins.elements.interfaces import IElement, IDisplayable, IFormattable
-from cpsskins.elements.interfaces import IType
+from cpsskins.elements.interfaces import IType, IDisplay
 from cpsskins.browser.negociation.interfaces import INegociation
 from cpsskins.ontology import hasFormat
 from cpsskins.relations.interfaces import IRelationTool
@@ -98,7 +98,7 @@
         form = request.form
         format_name = form.get('format')
         main_url = form.get('main_url')
-        action = form.get('action', '@@edit.html')
+        action = form.get('action', 'edit.html')
 
         negociation = getMultiAdapter((context, request),
                                       INegociation, 'negociation')
@@ -111,20 +111,25 @@
         main = context
         formats_info = []
         for f in formattable.getFormats(resolve=False):
-            format = f
-            if ISetting.providedBy(f):
+            is_setting = ISetting.providedBy(f)
+            if is_setting:
                 f = IResource(f).getResource()
             name = f.formatname
             selected = name == format_name
             if selected:
-                main = format
+                if is_setting:
+                    main = display
+                    action = 'manage-settings.html'
+                else:
+                    main = f
+
             formats_info.append({
                 'title': IType(f).getContentType().__name__,
                 'url': './@@edit-menu.html?format=%s' % name,
                 'selected': selected,
                 })
 
-        main_url = main_url or self.getAbsoluteURL(main) + '/' + action
+        main_url = main_url or self.getAbsoluteURL(main) + '/@@' + action
 
         element_info = {
             'selected': not format_name,
@@ -149,7 +154,7 @@
     def createSetting(title):
         """Create a setting from an object considered as a resource."""
 
-    def useSettingAsFormat(name):
+    def useSettingAsFormat(setting_name, format_type):
         """Replace an existing format with a setting."""
 
 class SettingsView(BrowserView):
@@ -157,37 +162,42 @@
     implements(ISettingsView)
 
     def createSetting(self, title=u''):
+        """Create a setting from the context.
+        """
         resource = locationCopy(removeSecurityProxy(self.context))
         resources = IResourceManager(resource)
         resources.register(title=title, resource=resource, 
context=self.context)
         target = self.request.get('HTTP_REFERER', '.')
         self.request.response.redirect(target)
 
-    def useSettingAsFormat(self, name=u''):
-        if not name:
-            raise KeyError("Must specify a setting's name.")
+    def useSettingAsFormat(self, setting_name=u'', format_type=u''):
+        """Use a setting specified by its name ('setting_name') as a format
+        of type 'format_type' (e.g. 'style', 'widget').
 
+        The context is the display
+
+        """
         context = self.context
-        setting = queryUtility(ISetting, name)
-        if setting is None:
-            raise KeyError("No such setting.")
+        if not setting_name:
+            raise KeyError("Must specify a setting's name.")
 
-        reltool = IRelationTool(context)
-        displays = reltool.getFirsts(second=context, predicate=hasFormat)
-        if len(displays) > 1:
-            raise KeyError("The format is used by several displays.")
-        display = displays[0]
+        if IDisplay.providedBy(context):
+            raise ValueError("The context must be a display.")
+
+        setting = queryUtility(ISetting, setting_name)
+        if setting is None:
+            raise KeyError("No such setting: '%s'." % setting_name)
 
         # create a display -- setting relation
-        predicate = getUtility(configuration.IFormat,
-                               context.formatname).predicate
-        relation = DyadicRelation(first=display, second=setting,
+        predicate = getUtility(configuration.IFormat, format_type).predicate
+        relation = DyadicRelation(first=context, second=setting,
                                   predicate=predicate)
+
+        reltool = IRelationTool(context)
         reltool.add(relation)
 
         # remove existing display -- format relation
-        old_rel = reltool.search(first=display, second=context,
-                                 predicate=hasFormat)
+        old_rel = reltool.search(first=context, predicate=predicate)
         reltool.remove(old_rel)
 
         target = self.request.get('HTTP_REFERER', '.')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to