[Zope-CVS] CVS: Products/PageDesign - PageDesign.py:1.2.2.7 Slot.py:1.1.2.7

Shane Hathaway shane@cvs.zope.org
Fri, 9 Aug 2002 23:33:41 -0400


Update of /cvs-repository/Products/PageDesign
In directory cvs.zope.org:/tmp/cvs-serv3516

Modified Files:
      Tag: page-redesign-branch
	PageDesign.py Slot.py 
Log Message:
Added the remove, move up, and move down controls for each slot element.
Made the element wrapper look consistent.


=== Products/PageDesign/PageDesign.py 1.2.2.6 => 1.2.2.7 ===
--- Products/PageDesign/PageDesign.py:1.2.2.6	Thu Aug  8 22:58:46 2002
+++ Products/PageDesign/PageDesign.py	Fri Aug  9 23:33:40 2002
@@ -94,13 +94,6 @@
     security.declareProtected(change_page_designs, 'object_list_rows')
     object_list_rows = PageTemplateFile('object_list_rows.pt', _www)
 
-    security.declareProtected(change_page_designs, 'sorted_down')
-    sorted_down = ImageFile('sorted_down.gif', _www)
-    sorted_down.__name__ = 'sorted_down'
-
-    security.declareProtected(change_page_designs, 'sorted_up')
-    sorted_up = ImageFile('sorted_up.gif', _www)
-    sorted_up.__name__ = 'sorted_up'
 
     head_html = '''
     <!-- Page design scripts and styles -->
@@ -206,6 +199,19 @@
             return self.dialog_done_html
 
 
+    security.declareProtected(change_page_designs, 'removeElement')
+    def removeElement(self, source_path, RESPONSE=None):
+        """Removes an element.
+        """
+        source = self.getPhysicalRoot().restrictedTraverse(source_path)
+        if not IClipboardSource.isImplementedBy(source):
+            raise DesignError, 'removeElement: bad or missing source_path'
+        getSecurityManager().validate(source, source, 'cut', source.cut)
+        source.cut()
+        if RESPONSE is not None:
+            RESPONSE.redirect(self.absolute_url() + '/editForm')
+
+
     security.declareProtected(change_page_designs, 'getSlotNames')
     def getSlotNames(self):
         """Returns the names of all slots filled and declared by the template.
@@ -338,6 +344,19 @@
 
 Globals.InitializeClass(PageDesignBase)
 
+# Set up the common images.
+for img_name in (
+    'sorted_up',
+    'sorted_down',
+    'moveup',
+    'movedown',
+    'remove',
+    ):
+    im = ImageFile('%s.gif' % img_name, _www)
+    im.__roles__ = None
+    setattr(PageDesignBase, img_name + '_icon', im)
+
+
 
 class PageDesign(PageDesignBase, SimpleItem, PropertyManager):
     meta_type = 'Page Design'
@@ -362,7 +381,6 @@
             REQUEST['RESPONSE'].redirect(
                 self.absolute_url() + '/manage_main?manage_tabs_message=' +
                 manage_tabs_message)
-
 
 Globals.InitializeClass(PageDesign)
 


=== Products/PageDesign/Slot.py 1.1.2.6 => 1.1.2.7 ===
--- Products/PageDesign/Slot.py:1.1.2.6	Fri Aug  9 13:55:15 2002
+++ Products/PageDesign/Slot.py	Fri Aug  9 23:33:40 2002
@@ -78,7 +78,11 @@
     title="Add element to slot: %(slot_name)s" /></a></div>'''
 
     element_html = '''<div class="design-element" id="%(clipboard_path)s">
-    <div class="design-element-titlebar">%(title)s</div>%(text)s</div>'''
+    <table class="design-element-titlebar" width="100%%"><tr>
+    <td align="left">&nbsp;%(title)s</td>
+    <td align="right">%(controls)s</td>
+    </tr></table>
+    <div class="design-element-body">%(text)s</div></div>'''
 
     _trackers = ()
 
@@ -97,6 +101,14 @@
 
 
     def renderSourceHTML(self, **kw):
+        c = []
+        for name in ('moveup', 'movedown', 'remove'):
+            url = kw.get(name + '_url')
+            if url:
+                # TODO: use server-wide icons
+                c.append('<a href="%s"><img src="%s_icon" border="0" /></a>'
+                         % (url, name))
+        kw['controls'] = '\n'.join(c)
         return self.element_html % kw
 
 
@@ -157,14 +169,32 @@
                     escape(('%s: %s' % (sys.exc_info()[:2]))[:80]))
 
             if editable:
+                design_url = design.absolute_url()
                 path = '%s/elementSources/%d' % (phys_path, index)
+                move_up_url = move_down_url = ''
+                if index > 0:
+                    # Can move up.
+                    move_up_url = (
+                        '%s/moveElement?source_path=%s'
+                        '&target_path=%s/elementTargets/%d' % (
+                        design_url, path, phys_path, index - 1))
+                if index < (clen - 1):
+                    # Can move down.
+                    move_down_url = (
+                        '%s/moveElement?source_path=%s'
+                        '&target_path=%s/elementTargets/%d' % (
+                        design_url, path, phys_path, index + 2))
+                remove_url = '%s/removeElement?source_path=%s' % (
+                    design_url, path)
+
                 text = self.renderSourceHTML(
                     clipboard_path=path,
                     title=e.getTitle(),
                     text=text,
                     edit_url=e.getEditURL(),
-                    can_move_down=(index < (clen - 1)),
-                    can_move_up=(index > 0),
+                    moveup_url=move_up_url,
+                    movedown_url=move_down_url,
+                    remove_url=remove_url,
                     )
             res.append(text)