Author: jmorliaguet Date: Sun Jun 25 20:42:38 2006 New Revision: 3521 Modified: cpsskins/branches/paris-sprint-2006/locations/configure.zcml cpsskins/branches/paris-sprint-2006/locations/interfaces.py cpsskins/branches/paris-sprint-2006/locations/location.py cpsskins/branches/paris-sprint-2006/storage/locations.py cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/configure.zcml cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/negotiation_section.pt cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/site_manager.css cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py cpsskins/branches/paris-sprint-2006/utils.py
Log: - added the UI to add / edit / delete locations Modified: cpsskins/branches/paris-sprint-2006/locations/configure.zcml ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/configure.zcml (original) +++ cpsskins/branches/paris-sprint-2006/locations/configure.zcml Sun Jun 25 20:42:38 2006 @@ -9,6 +9,11 @@ interface=".interfaces.ILocation" /> + <require + permission="zope.ManageContent" + set_schema=".interfaces.ILocation" + /> + </class> <utility Modified: cpsskins/branches/paris-sprint-2006/locations/interfaces.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/interfaces.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/interfaces.py Sun Jun 25 20:42:38 2006 @@ -17,9 +17,9 @@ """ __docformat__ = "reStructuredText" -from zope.interface import Interface, alsoProvides +from zope.interface import Interface, alsoProvides, Attribute from zope.i18nmessageid import MessageFactory -from zope.schema import TextLine, Tuple, Choice +from zope.schema import TextLine, Tuple, Choice, Int from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleVocabulary @@ -28,21 +28,21 @@ class ILocation(Interface): """Location""" - name = TextLine( - title=u"Name", - ) + _path_tuple = Attribute("representation of the path as a tuple") + + root = Attribute("Location root") - path = Tuple( + path = TextLine( title=u"Path", ) - data = TextLine( - title=u"Data", + scope = Choice( + title=u"Scope", + vocabulary="location scopes", ) - scope = Tuple( - title=u"Scope", - value_type=Choice(vocabulary="location scopes"), + data = TextLine( + title=u"Data", ) def __call__(): Modified: cpsskins/branches/paris-sprint-2006/locations/location.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/locations/location.py (original) +++ cpsskins/branches/paris-sprint-2006/locations/location.py Sun Jun 25 20:42:38 2006 @@ -27,8 +27,7 @@ """ implements(ILocation) - def __init__(self, title=u'', path=u'', data=u'', scope=(0, 0), root=u''): - self.title = title + def __init__(self, path=u'', data=u'', scope=(0, 0), root=u''): self.data = data self.scope = scope self.root = root @@ -38,7 +37,7 @@ path = self.path if self.root: path = u"%s for '%s'" % (path, self.root) - return "<Location '%s' at %s>" % (self.title, path) + return "<Location at %s>" % path def __call__(self): return self.data Modified: cpsskins/branches/paris-sprint-2006/storage/locations.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/storage/locations.py (original) +++ cpsskins/branches/paris-sprint-2006/storage/locations.py Sun Jun 25 20:42:38 2006 @@ -44,6 +44,9 @@ def getLocations(root): """Return the list of locations by root.""" + def getLocation(root, path): + """Return a location by root and path""" + class LocationStorage(Storage): """A BTree-based location storage @@ -113,3 +116,8 @@ locations.append(value) return locations + def getLocation(self, root=u'', path=u''): + path = tuple(path.split(u'/')) + key = (root, ) + path + return self[key] + Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/configure.zcml ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/configure.zcml (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/configure.zcml Sun Jun 25 20:42:38 2006 @@ -87,6 +87,26 @@ attribute="getLocationInfo" /> + <page + name="getLocationWidgets" + attribute="getLocationWidgets" + /> + + <page + name="addLocation" + attribute="addLocation" + /> + + <page + name="deleteLocation" + attribute="deleteLocation" + /> + + <page + name="updateLocation" + attribute="updateLocation" + /> + </pages> <!-- Panels --> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/negotiation_section.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/negotiation_section.pt (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/negotiation_section.pt Sun Jun 25 20:42:38 2006 @@ -1,20 +1,61 @@ <div class="sections" i18n:domain="cpsskins" tal:define="section request/form/section|nothing; + edited request/form/edited|nothing; + add request/form/add|nothing; location_info context/@@getLocationInfo; infos location_info/?section|nothing"> + <form action="@@updateLocation" method="post"> <table style="width: 100%;" class="items"> <tr> <th>path</th> <th>scope</th> <th>data</th> + <th></th> </tr> <tr tal:repeat="path infos"> - <tal:block define="location python:infos[path]"> - <td tal:content="location/path" /> - <td tal:content="location/scope" /> - <td tal:content="location/data" /> + <tal:block define="location python:infos[path]; + location_path location/path; + edit python: edited == location_path"> + + <tal:block condition="not:edit"> + <td tal:content="location_path" /> + <td tal:content="location/scope" /> + <td tal:content="location/data" /> + <a class="button" i18n:translate="" + tal:attributes="href string:javascript:CPSSkins.getModelById('negotiation-section').setData({'form': {'section': '$section', 'edited': '${location/path}' }})">edit</a> + </tal:block> + + <tal:block condition="edit"> + <tal:block define="widgets nocall:context/@@getLocationWidgets" + repeat="widget python: widgets(location['path'], section)"> + <td tal:content="structure widget" /> + </tal:block> + <input type="hidden" name="root" tal:attributes="value section" /> + <input type="hidden" name="location_path" + tal:attributes="value location_path" /> + <input class="submit" type="submit" value="save" /> + </tal:block> + + <a class="button" + tal:attributes="href string:@@deleteLocation?root=$section&location_path=$location_path"> + delete + </a> + </tal:block> </tr> </table> + </form> + + <a class="button" i18n:translate="" tal:condition="not:add" + tal:attributes="href string:javascript:CPSSkins.getModelById('negotiation-section').setData({'form': {'section': '$section', 'add': true }})">add a location</a> + + <form action="@@addLocation" method="post" tal:condition="add"> + <input type="hidden" name="root" tal:attributes="value section" /> + <input type="text" name="location_path" value="/" /> + <input class="submit" type="submit" value="add" /> + <a class="button" i18n:translate="" + tal:attributes="href string:javascript:CPSSkins.getModelById('negotiation-section').setData({'form': {'section': '$section'}})">cancel</a> + </form> + </div> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/site_manager.css ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/site_manager.css (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/site_manager.css Sun Jun 25 20:42:38 2006 @@ -65,10 +65,6 @@ list-style: square; } -.sections ul { - list-style: none; -} - table.panel { width: 100%; } @@ -101,6 +97,10 @@ padding: 1em; } +.sections ul { + list-style: none; +} + .sections ul.items { padding-left: 0.15em; } @@ -122,15 +122,31 @@ border-bottom: 1px solid #ccc; } -input.text { +.sections table.items td { + margin: 0; + padding: 0; +} + +form { + font-family: arial; +} + +input { border: 1px solid #999; padding: 0 + font-size: 11px; } -input.submit { +a.button, input.submit, button.submit { border: none; padding: 0; background-color: #fff; - font-size: 12px; + font-size: 11px; color: #006; + margin: 0; +} + +select { + font-size: 11px; + border: none; } Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Sun Jun 25 20:42:38 2006 @@ -18,8 +18,12 @@ __docformat__ = "reStructuredText" from zope.component import getUtility +from zope.formlib import form +from zope.schema import getFields from cpsskins import minjson as json +from cpsskins.locations import Location +from cpsskins.locations.interfaces import ILocation from cpsskins.setup.interfaces import IType, IIdentifiable from cpsskins.setup.interfaces import IResourceManager, IResource from cpsskins.setup.io import importSite, exportSite @@ -145,7 +149,57 @@ 'path': location.path, 'data': location.data, 'scope': location.scope, + 'object': location, } return info + def getLocationWidgets(self, path, root): + locations = self.getLocationInfo() + location = locations[root][path][u'object'] + return LocationForm(location, self.request)() + + def deleteLocation(self): + request = self.request + form = request.form + root = form[u'root'] + path = form[u'location_path'] + locations = getThemeManager(self.context).getLocationStorage() + location = locations.getLocation(root, path) + locations.remove(location) + + def addLocation(self): + request = self.request + form = request.form + locations = getThemeManager(self.context).getLocationStorage() + path = form[u'location_path'] + root = form[u'root'] + location = Location(path=path, root=root) + locations.add(location) + + def updateLocation(self): + context = self.context + request = self.request + form = request.form + root = form[u'root'] + location_path = form[u'location_path'] + locations = getThemeManager(context).getLocationStorage() + location = locations.getLocation(root, location_path) + location.path = form[u'form.path'] + location.data = form[u'form.data'] + location.scope = form[u'form.scope'] + self.request.response.setHeader('content-type', 'text/x-json') + return json.write({'form': {'section': root}}) + +class LocationForm(object): + form_fields = form.Fields(ILocation, omit_readonly=True, + render_context=True) + + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self): + widgets = form.setUpWidgets(self.form_fields, 'form', self.context, + self.request) + return widgets Modified: cpsskins/branches/paris-sprint-2006/utils.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/utils.py (original) +++ cpsskins/branches/paris-sprint-2006/utils.py Sun Jun 25 20:42:38 2006 @@ -73,9 +73,9 @@ # XXX testing from cpsskins.locations import Location - l1 = Location(title=u'Sections', path=u'/sections', root=u'pages', data=u'Theme:ThemePage') - l2 = Location(title=u'Section 1', path=u'/sections/section1', root=u'pages', data=u'Theme-2:ThemePage') - l3 = Location(title=u'Workspaces', path=u'/workspaces', root=u'pages', data=u'Theme-3:ThemePage') + l1 = Location(path=u'/sections', root=u'pages', data=u'Theme:ThemePage') + l2 = Location(path=u'/sections/section1', root=u'pages', data=u'Theme-2:ThemePage') + l3 = Location(path=u'/workspaces', root=u'pages', data=u'Theme-3:ThemePage') locations = context.getLocationStorage() locations.add(l1) locations.add(l2) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins