[Zope-CVS] CVS: Products/PageDesign - utils.py:1.1.2.1 PageDesign.py:1.2.2.4 Slot.py:1.1.2.3
Shane Hathaway
shane@cvs.zope.org
Tue, 6 Aug 2002 22:37:23 -0400
Update of /cvs-repository/Products/PageDesign
In directory cvs.zope.org:/tmp/cvs-serv25738
Modified Files:
Tag: page-redesign-branch
PageDesign.py Slot.py
Added Files:
Tag: page-redesign-branch
utils.py
Log Message:
It now opens the palette add element dialog. Now we just need a palette!
=== Added File Products/PageDesign/utils.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
import os
import Globals
import OFS
def registerIcon(product_id, icon_filepath):
dir, name = os.path.split(icon_filepath)
icon = Globals.ImageFile(name, dir)
icon.__roles__ = None # Public.
if not hasattr(OFS.misc_.misc_, product_id):
setattr(OFS.misc_.misc_, product_id, OFS.misc_.Misc_(product_id, {}))
getattr(OFS.misc_.misc_, product_id)[name] = icon
return 'misc_/%s/%s' % (product_id, name)
=== Products/PageDesign/PageDesign.py 1.2.2.3 => 1.2.2.4 ===
head_html = '''
<!-- Page design scripts and styles -->
- <link type="text/css" href="%(url)s/pagedesign_css" rel="stylesheet" />
+ <link type="text/css" href="%(design_url)s/pagedesign_css"
+ rel="stylesheet" />
<script type="text/javascript">
%(scripts)s
- design_url = '%(url)s';
+ design_url = '%(design_url)s';
</script>
<!-- End page design scripts -->
'''
@@ -114,6 +115,12 @@
raise NotImplementedError
+ security.declareProtected(change_page_designs, 'getPalette')
+ def getPalette(self):
+ # To be overridden
+ raise NotImplementedError
+
+
security.declareProtected(change_page_designs, 'addSlot')
def addSlot(self, name):
"""Creates a slot if it doesn't already exist.
@@ -169,15 +176,23 @@
return res
+ security.declareProtected(change_page_designs, 'addElementDialog')
+ def addElementDialog(self, target_path):
+ """Shows the add element dialog box."""
+ palette = self.getPalette()
+ return palette.addElementDialog(target_path=target_path)
+
+
security.declarePrivate('insertEditScripts')
def insertEditScripts(self, s):
match = start_of_head_search(s)
if match is None:
raise DesignError, 'The template needs a HEAD element'
index = match.end(0)
- url = self.absolute_url()
- head_prefix = self.head_html % {'url': url,
- 'scripts': self.scripts_js()}
+ head_prefix = self.head_html % {
+ 'design_url': self.absolute_url(),
+ 'scripts': self.scripts_js()
+ }
s = '%s%s%s' % (s[:index], head_prefix, s[index:])
match = end_of_body_search(s)
if match is None:
@@ -188,8 +203,7 @@
match = m
m = end_of_body_search(s, match.end(0))
index = match.start(0)
- #palette = self.getPaletteHTML()
- footer = self.footer_html #% {'palette': palette}
+ footer = self.footer_html
s = '%s%s%s' % (s[:index], footer, s[index:])
return s
@@ -250,25 +264,27 @@
manage_options = (PageDesignBase.manage_options +
SimpleItem.manage_options)
- _properties = ({'id': 'title', 'type': 'string', 'mode': 'w'},
- {'id': 'template_id', 'type': 'string', 'mode': 'w'},)
+ _properties = (
+ {'id': 'title', 'type': 'string', 'mode': 'w'},
+ {'id': 'template_id', 'type': 'string', 'mode': 'w'},
+ {'id': 'palette_id', 'type': 'string', 'mode': 'w'},
+ )
template_id = None
+ palette_id = None
title = ''
- security.declareProtected(change_page_designs, 'listAvailableElementIds')
- def listAvailableElementIds(self):
- # This implementation uses a simple ID.
- return aq_parent(aq_inner(self)).objectIds()
-
- security.declareProtected(change_page_designs, 'getElement')
- def getElement(self, element_id):
- return aq_parent(aq_inner(self))[element_id]
-
security.declareProtected(change_page_designs, 'getTemplate')
def getTemplate(self):
id = self.template_id
if not id:
- raise DesignError, 'Template not set'
+ raise DesignError, 'No template configured'
+ return getattr(aq_parent(aq_inner(self)), id)
+
+ security.declareProtected(change_page_designs, 'getPalette')
+ def getPalette(self):
+ id = self.palette_id
+ if not id:
+ raise DesignError, 'No palette configured'
return getattr(aq_parent(aq_inner(self)), id)
security.declareProtected(change_page_designs, 'manage_propertiesForm')
=== Products/PageDesign/Slot.py 1.1.2.2 => 1.1.2.3 ===
$Id$
"""
+import os
+import sys
+from cgi import escape
+
from Persistence import Persistent
import Acquisition
from Acquisition import aq_inner, aq_parent
@@ -29,6 +33,13 @@
from SlotElementClipboardTarget \
import SlotElementClipboardTarget, SlotElementClipboardLastTarget
from SlotElementTraverser import SlotElementTraverser
+import utils
+
+_www = os.path.join(os.path.dirname(__file__), 'www')
+
+
+target_icon = '/' + utils.registerIcon(
+ 'PageDesign', os.path.join(_www, 'element_add.gif'))
class Slot (Persistent, Acquisition.Explicit, Traversable):
@@ -49,15 +60,19 @@
security = ClassSecurityInfo()
- # Traversal helpers for the clipboard.
- elementSources = SlotElementTraverser('elementSources',
- SlotElementClipboardSource)
- elementTargets = SlotElementTraverser('elementTargets',
- SlotElementClipboardTarget)
+ # Clipboard traversal helpers.
+ elementSources = SlotElementTraverser(
+ 'elementSources', SlotElementClipboardSource)
+ elementTargets = SlotElementTraverser(
+ 'elementTargets', SlotElementClipboardTarget)
lastElementTarget = SlotElementClipboardLastTarget
- target_html = '''<div class="design-target"
- id="%(clipboard_path)s"><a href=""><img src="" /></a></div>'''
+ target_html = '''<div class="design-target" align="center"
+ id="%(clipboard_path)s"><a href="#"
+ onclick="addElementDialog('%(clipboard_path)s'); return false;"><img
+ src="%(target_icon)s" border="0"
+ alt="Add element to slot: %(slot_name)s"
+ title="Add element to slot: %(slot_name)s" /></a></div>'''
element_html = '''<div class="design-element"
id="%(clipboard_path)s">%(text)s</div>'''
@@ -73,6 +88,7 @@
def renderTargetHTML(self, **kw):
+ kw['target_icon'] = target_icon
return self.target_html % kw
@@ -129,7 +145,12 @@
slot_index=index,
))
- text = e.render(design=design, editable=editable, index=index)
+ try:
+ text = e.render(design=design, editable=editable, index=index)
+ except:
+ # Show the exception.
+ text = escape(('%s: %s' % (sys.exc_info()[:2]))[:80])
+
if editable:
path = '%s/elementSources/%d' % (phys_path, index)
text = self.renderSourceHTML(