[Checkins] SVN: z3c.jsontree/ Move implementation form private
repos to svn.zope.org
Roger Ineichen
roger at projekt01.ch
Sat Feb 16 11:02:16 EST 2008
Log message for revision 83892:
Move implementation form private repos to svn.zope.org
Changed:
A z3c.jsontree/branches/
A z3c.jsontree/tags/
A z3c.jsontree/trunk/
A z3c.jsontree/trunk/CHANGES.txt
A z3c.jsontree/trunk/README.txt
A z3c.jsontree/trunk/bootstrap.py
A z3c.jsontree/trunk/buildout.cfg
A z3c.jsontree/trunk/setup.py
A z3c.jsontree/trunk/src/
A z3c.jsontree/trunk/src/z3c/
A z3c.jsontree/trunk/src/z3c/__init__.py
A z3c.jsontree/trunk/src/z3c/jsontree/
A z3c.jsontree/trunk/src/z3c/jsontree/README.txt
A z3c.jsontree/trunk/src/z3c/jsontree/SETUP.cfg
A z3c.jsontree/trunk/src/z3c/jsontree/__init__.py
A z3c.jsontree/trunk/src/z3c/jsontree/base.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/
A z3c.jsontree/trunk/src/z3c/jsontree/browser/__init__.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/configure.zcml
A z3c.jsontree/trunk/src/z3c/jsontree/browser/img/
A z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeCollapsed.gif
A z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeExpanded.gif
A z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeStatic.gif
A z3c.jsontree/trunk/src/z3c/jsontree/browser/js/
A z3c.jsontree/trunk/src/z3c/jsontree/browser/js/z3c.jsontree-0.5.0.js
A z3c.jsontree/trunk/src/z3c/jsontree/browser/li.pt
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/__init__.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_1.txt
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_2.txt
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/test_view.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/util.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.pt
A z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.py
A z3c.jsontree/trunk/src/z3c/jsontree/browser/ul.pt
A z3c.jsontree/trunk/src/z3c/jsontree/browser/z3c.jsontree.css
A z3c.jsontree/trunk/src/z3c/jsontree/configure.zcml
A z3c.jsontree/trunk/src/z3c/jsontree/interfaces.py
A z3c.jsontree/trunk/src/z3c/jsontree/jsonrpc.py
A z3c.jsontree/trunk/src/z3c/jsontree/tests.py
A z3c.jsontree/trunk/src/z3c/jsontree/util.py
A z3c.jsontree/trunk/src/z3c/jsontree/z3c.jsontree-configure.zcml
-=-
Added: z3c.jsontree/trunk/CHANGES.txt
===================================================================
--- z3c.jsontree/trunk/CHANGES.txt (rev 0)
+++ z3c.jsontree/trunk/CHANGES.txt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+Version 0.5.0 (unreleased)
+-------------------------
+
+- Initial Release
Property changes on: z3c.jsontree/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/README.txt
===================================================================
--- z3c.jsontree/trunk/README.txt (rev 0)
+++ z3c.jsontree/trunk/README.txt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+This package provides an JSON-RPC item tree implementation for Zope3.
Property changes on: z3c.jsontree/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/bootstrap.py
===================================================================
--- z3c.jsontree/trunk/bootstrap.py (rev 0)
+++ z3c.jsontree/trunk/bootstrap.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 75940 2007-05-24 14:45:00Z srichter $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: z3c.jsontree/trunk/bootstrap.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/buildout.cfg
===================================================================
--- z3c.jsontree/trunk/buildout.cfg (rev 0)
+++ z3c.jsontree/trunk/buildout.cfg 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,15 @@
+[buildout]
+develop = .
+parts = test checker coverage
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.jsontree [test]
+
+[checker]
+recipe = lovely.recipe:importchecker
+path = src/z3c/jsontree
+
+[coverage]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
Added: z3c.jsontree/trunk/setup.py
===================================================================
--- z3c.jsontree/trunk/setup.py (rev 0)
+++ z3c.jsontree/trunk/setup.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Setup
+
+$Id:$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup (
+ name='z3c.jsontree',
+ version='0.5.0dev',
+ author = "Roger Ineichen and the Zope Community",
+ author_email = "zope3-dev at zope.org",
+ description = "JSON RPC item tree for Zope3",
+ long_description=(
+ read('README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ license = "ZPL 2.1",
+ keywords = "zope3 z3c json rpc tree",
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url = 'http://cheeseshop.python.org/pypi/z3c.jsontree',
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['z3c'],
+ extras_require = dict(
+ test = [
+ 'z3c.jsonrpc',
+ 'z3c.template',
+ 'z3c.testing',
+ 'zope.app.publication',
+ 'zope.app.publisher',
+ 'zope.app.security',
+ 'zope.app.testing',
+ 'zope.configuration',
+ 'zope.pagetemplate',
+ 'zope.publisher',
+ 'zope.testbrowser',
+ ],
+ ),
+ install_requires = [
+ 'setuptools',
+ 'z3c.json',
+ 'z3c.jsonrpc',
+ 'z3c.template',
+ 'zope.app.component',
+ 'zope.app.container',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.proxy',
+ 'zope.publisher',
+ 'zope.security',
+ 'zope.traversing',
+ 'zope.viewlet',
+ ],
+ zip_safe = False,
+)
Property changes on: z3c.jsontree/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/__init__.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/__init__.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/__init__.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ import pkgutil
+ __path__ = pkgutil.extend_path(__path__, __name__)
Property changes on: z3c.jsontree/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/README.txt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/README.txt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/README.txt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,59 @@
+============
+JSONRPC Tree
+============
+
+This package offers a JSONRPC tree view which can be used as navigation tree.
+Let's show how we can register our jsonrpc tree view:
+
+ >>> from zope.configuration import xmlconfig
+ >>> import z3c.jsonrpc
+ >>> context = xmlconfig.file('meta.zcml', z3c.jsonrpc)
+ >>> context = xmlconfig.string("""
+ ... <configure
+ ... xmlns:z3c="http://namespaces.zope.org/z3c">
+ ... <z3c:jsonrpc
+ ... for="*"
+ ... class="z3c.jsontree.jsonrpc.JSONTreeItems"
+ ... permission="zope.Public"
+ ... methods="loadJSONTreeItems"
+ ... layer="z3c.jsonrpc.testing.IJSONRPCTestSkin"
+ ... />
+ ... </configure>
+ ... """, context)
+
+Now we will setup some content structure based on the default zope folder class:
+
+ >>> from zope.app.folder.folder import Folder
+ >>> site = getRootFolder()
+ >>> content = Folder()
+ >>> site['content'] = content
+
+
+JSON-RPC proxy
+--------------
+
+If we call our JSON-RPC tree item method, we can see the different JSON data
+on the different contexts:
+
+ >>> from z3c.jsonrpc.testing import JSONRPCTestProxy
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.addHeader('Accept-Language', 'en')
+ >>> browser.addHeader('Content-Type', 'application/json')
+ >>> siteURL = 'http://localhost/++skin++JSONRPCTestSkin'
+ >>> proxy = JSONRPCTestProxy(siteURL)
+ >>> proxy.loadJSONTreeItems('z3cJSONTree')
+ {u'treeChilds': {u'childs':
+ [{u'hasChilds': False,
+ u'contextURL': u'http://localhost/++skin++JSONRPCTestSkin/content',
+ u'url': u'http://localhost/++skin++JSONRPCTestSkin/content/@@SelectedManagementView.html',
+ u'linkHandler': u'', u'content': u'content', u'iconURL': u'', u'id':
+ u'z3cJSONTree.::content'}],
+ u'id': u'z3cJSONTree'}}
+
+The content object has no items and returns some empty JSON data:
+
+ >>> proxy = JSONRPCTestProxy(siteURL + '/content')
+ >>> proxy.loadJSONTreeItems('z3cJSONTree')
+ {u'treeChilds': {u'childs': [], u'id': u'z3cJSONTree'}}
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/SETUP.cfg
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/SETUP.cfg (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/SETUP.cfg 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+ z3c.jsontree-*.zcml
+</data-files>
Added: z3c.jsontree/trunk/src/z3c/jsontree/__init__.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/__init__.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/__init__.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+# make a package
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/base.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/base.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/base.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,456 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = 'restructuredtext'
+
+import string
+import zope.interface
+import zope.component
+from zope.traversing import api
+from zope.security.interfaces import Unauthorized
+from zope.security.interfaces import Forbidden
+from zope.traversing.browser import absoluteURL
+from zope.traversing.namespace import getResource
+from zope.contentprovider.interfaces import IContentProvider
+from zope.app.container.interfaces import IReadContainer
+from zope.app.component import hooks
+
+from z3c.template.template import getPageTemplate
+
+from z3c.jsontree import interfaces
+from z3c.jsontree.interfaces import JSON_TREE_ID
+from z3c.jsontree.interfaces import JSON_TREE_VIEW_NAME
+from z3c.jsontree.interfaces import JSON_TOGGLE_ICON_COLLAPSED
+from z3c.jsontree.interfaces import JSON_TOGGLE_ICON_EXPANDED
+from z3c.jsontree.interfaces import JSON_TOGGLE_ICON_STATIC
+from z3c.jsontree.interfaces import JSON_LI_CSS_EXPANDED
+from z3c.jsontree.interfaces import JSON_LI_CSS_COLLAPSED
+from z3c.jsontree.interfaces import JSON_LI_CSS_STATIC
+from z3c.jsontree.interfaces import STATE_EXPANDED
+from z3c.jsontree.interfaces import STATE_COLLAPSED
+from z3c.jsontree.interfaces import STATE_STATIC
+from z3c.jsontree import util
+
+
+class TreeBase(object):
+ """Tree iterator base implementation."""
+
+ root = None
+ childTags = None
+ rootChilds = None
+ items = []
+
+ z3cJSONTreeId = JSON_TREE_ID
+ z3cJSONTreeName = JSON_TREE_ID
+ z3cJSONTreeClass = JSON_TREE_ID
+
+ viewName = JSON_TREE_VIEW_NAME
+
+ # LI tag CSS names
+ collapsedCSSName = JSON_LI_CSS_COLLAPSED
+ expandedCSSName = JSON_LI_CSS_EXPANDED
+ staticCSSName = JSON_LI_CSS_STATIC
+
+ # toggle icon names
+ collapsedIconName = JSON_TOGGLE_ICON_COLLAPSED
+ expandedIconNamen = JSON_TOGGLE_ICON_EXPANDED
+ staticIconName = JSON_TOGGLE_ICON_STATIC
+
+ def getRoot(self):
+ if not self.root:
+ self.root = hooks.getSite()
+ return self.root
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def getSubItems(self, item):
+ items = []
+ append = items.append
+ if IReadContainer.providedBy(item):
+ keys = list(item.keys())
+ else:
+ keys = []
+ for name in keys:
+ # Only include items we can traverse to
+ subItem = api.traverse(item, name, None)
+ if subItem is not None:
+ append(subItem)
+ return items
+
+ def getIconURL(self, item, request, name='icon'):
+ return util.getIconURL(item, request, name=name)
+
+ def getParents(self):
+ root = self.getRoot()
+ return util.getParentsFromContextToObject(self.context, root)
+
+ def hasSubItems(self, item):
+ res = False
+ if IReadContainer.providedBy(item):
+ try:
+ if len(item) > 0:
+ res = True
+ except(Unauthorized, Forbidden):
+ pass
+ return res
+
+ def update(self):
+ """Returns HTML code for representing a <ul> tag tree with the
+ siblings and parents of an object.
+
+ There is only one branch expanded, in other words, the tree is
+ filled with the object, its siblings and its parents with
+ their respective siblings. This tree is stateless.
+
+ If we access the tree via a virtual host, the root is adjusted to
+ the right root object.
+
+ """
+ childTags = None
+ stackItem = self.context
+ parents = self.getParents()
+
+ for item in parents:
+ tagList = []
+ append = tagList.append
+
+ for subItem in self.getSubItems(item):
+ if self.hasSubItems(subItem):
+
+ if subItem == stackItem:
+ append(self.renderUL(subItem, childTags))
+ else:
+ append(self.renderUL(subItem))
+
+ else:
+ append(self.renderLI(subItem))
+
+ childTags = ' '.join(tagList)
+ stackItem = item
+
+ self.childTags = childTags
+
+
+class PythonRenderer(object):
+ """Mixin class for template less tree generation.
+
+ This renderer is responsible for rendering all HTML elements for the items
+ found in the tree. This means evrey item will be presented in the same way.
+ Use this renderer only if you like to get the same representation for each
+ item. If you need custom representation for each item, use the template
+ based renderer which allows you to define for each item a custom class and
+ template.
+ """
+
+ zope.interface.implements(interfaces.IPythonRenderer)
+
+ @property
+ def rootName(self):
+ root = self.getRoot()
+ name = api.getName(self.root)
+ if not name:
+ name = u'[top]'
+ return name
+
+ def getToggleIcon(self, item, state):
+ """Returns a toggle icon including settings for json url."""
+ if state == STATE_COLLAPSED:
+ iconName = self.collapsedIconName
+ elif state == STATE_EXPANDED:
+ iconName = self.expandedIconNamen
+ else:
+ iconName = self.staticIconName
+ icon = zope.component.getMultiAdapter((item, self.request),
+ name=iconName)
+ resource = getResource(icon.context, icon.rname, self.request)
+ src = resource()
+ longDescURL = absoluteURL(item, self.request)
+ return ('<img src="%s" alt="toggle icon" width="%s" height="%s" '
+ 'border="0" longDesc="%s" />' % (src, icon.width,
+ icon.height, longDescURL))
+
+ def renderLI(self, item):
+ name = api.getName(item)
+ url = absoluteURL(item, self.request) +'/'+ self.viewName
+ iconURL = self.getIconURL(item, self.request)
+ id = self.getId(item)
+
+ res = u''
+ toggleIcon = self.getToggleIcon(item, STATE_STATIC)
+ res += '<li id="%s" class="%s">%s' % (id, self.staticCSSName,
+ toggleIcon)
+ if iconURL != '':
+ res += '<img src="%s" width="16" height="16" />' % iconURL
+ res += '<a href="%s">%s</a>' % (url, name)
+ res += '</li>'
+ return res
+
+ def renderUL(self, item, childTags=None):
+ """Renders <li> tag with already rendered child tags."""
+ name = api.getName(item)
+ url = absoluteURL(item, self.request) +'/'+ self.viewName
+ iconURL = self.getIconURL(item, self.request)
+ id = self.getId(item)
+
+ if item == self.context:
+ state = STATE_COLLAPSED
+ liClass = self.collapsedCSSName
+ else:
+ state = STATE_EXPANDED
+ liClass = self.expandedCSSName
+
+ if childTags is None:
+ state = STATE_COLLAPSED
+ liClass = self.collapsedCSSName
+
+ toggleIcon = self.getToggleIcon(item, state)
+
+ res = u''
+ res += '<li id="%s" class="%s">%s' % (id, liClass, toggleIcon)
+ if iconURL != '':
+ res += '<img src="%s" class="" width="16" height="16" />' % iconURL
+ res += '<a href="%s">%s</a>' % (url, name)
+ if childTags is not None:
+ res += ' <ul>%s</ul>' % childTags
+ res += '</li>'
+ return res
+
+ @property
+ def tree(self):
+ root = self.getRoot()
+ if root is None:
+ raise ValueError("Missing tree root object.")
+ id = self.getId(root)
+ rootName = self.rootName
+ url = absoluteURL(root, self.request) +'/'+ self.viewName
+
+ # setup root item
+ if self.childTags is None:
+ rootChilds = ''
+ liClass = self.collapsedCSSName
+ state = STATE_COLLAPSED
+ else:
+ rootChilds = '<ul>%s</ul>' % self.childTags
+ liClass = self.expandedCSSName
+ state = STATE_EXPANDED
+
+ # setup root toggle icon
+ toggleIcon = self.getToggleIcon(root, state)
+
+ # setup root link
+ rootLink = '<a href="%s">%s</a>' % (url, rootName)
+ rootItem = '<li id="%s" class="%s">%s%s%s</li>' % \
+ (id, liClass, toggleIcon, rootLink, rootChilds)
+
+ # render the <ul> tag tree
+ z3cJSONTree = u''
+ z3cJSONTree += '<ul class="%s" id="%s" name="%s">%s</ul>' % (
+ self.z3cJSONTreeClass, self.z3cJSONTreeId, self.z3cJSONTreeName, rootItem)
+ return z3cJSONTree
+
+
+class TemplateRenderer(object):
+ """Mixin class for template based tree generation.
+
+ This implementation uses IContentProvider for element tag rendering. This
+ makes it very flexible.
+
+ Note: Don't forget to define custom JSONTreeItems methods which reflect the
+ custom rendering. Or you will get the default rendering behavior for JSON
+ loaded items.
+ """
+
+ zope.interface.implements(interfaces.ITemplateRenderer)
+
+ liProviderName = 'li'
+ ulProviderName = 'ul'
+ treeProviderName = 'tree'
+
+ def renderLI(self, item):
+ provider = zope.component.getMultiAdapter(
+ (item, self.request, self), IContentProvider,
+ self.liProviderName)
+ provider.state = STATE_STATIC
+ provider.update()
+ return provider.render()
+
+ def renderUL(self, item, childTags=None):
+ """Renders <li> tag with already rendered child tags."""
+ if item == self.context:
+ state = STATE_COLLAPSED
+ else:
+ state = STATE_EXPANDED
+
+ if childTags is None:
+ state = STATE_COLLAPSED
+
+ provider = zope.component.getMultiAdapter(
+ (item, self.request, self), IContentProvider,
+ self.ulProviderName)
+ provider.childTags = childTags
+ provider.state = state
+ provider.update()
+ return provider.render()
+
+ @property
+ def tree(self):
+ root = self.getRoot()
+ if root is None:
+ raise ValueError("Missing tree root object.")
+
+ if self.childTags is None:
+ state = STATE_COLLAPSED
+ else:
+ state = STATE_EXPANDED
+
+ provider = zope.component.getMultiAdapter(
+ (root, self.request, self), IContentProvider,
+ self.treeProviderName)
+ provider.childTags = self.childTags
+ provider.state = state
+ provider.update()
+ return provider.render()
+
+
+class IdGenerator(object):
+ """This mixin class generates Object Ids based on the the objects path.
+
+ Note: The objects must be traversable by it's path. You can implement a
+ a custom path traverse concept in the getObjectByPath it you need to use
+ another traverse concept.
+
+ This ids must conform the w3c recommendation described in:
+ http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-name
+ """
+
+ def getId(self, item):
+ """Returns the DOM id for a given object.
+
+ Note: we encode the upper case letters because the Dom element id are
+ not case sensitive in HTML. We prefix each upper case letter with ':'.
+ """
+ path = api.getPath(item)
+ newPath = u''
+ for letter in path:
+ if letter in string.uppercase:
+ newPath += ':' + letter
+ else:
+ newPath += letter
+
+ # we use a dot as a root representation, this avoids to get the same id
+ # for the ul and the first li tag
+ if newPath == '/':
+ newPath = '.'
+ # add additinal dot which separates the tree id and the path, is used
+ # for get the tree id out of the string in the javascript using
+ # ids = id.split("."); treeId = ids[0];
+ id = self.z3cJSONTreeId +'.'+ newPath
+ # convert '/' path separator to marker '::', because the path '/'' is
+ # not allowed as DOM id. See also:
+ # http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-name
+ return id.replace('/', '::')
+
+ def id(self):
+ """Returns the DOM id for a given context."""
+ return self.getId(self.context)
+
+
+class ProviderBase(object):
+ """Base class for element provider."""
+
+ template = getPageTemplate()
+
+ root = None
+ state = None
+ childTags = None
+ iconName = 'icon'
+
+ z3cJSONTreeId = JSON_TREE_ID
+ z3cJSONTreeName = JSON_TREE_ID
+ z3cJSONTreeClass = JSON_TREE_ID
+
+ viewName = JSON_TREE_VIEW_NAME
+
+ # LI tag CSS names
+ collapsedCSSName = JSON_LI_CSS_COLLAPSED
+ expandedCSSName = JSON_LI_CSS_EXPANDED
+ staticCSSName = JSON_LI_CSS_STATIC
+
+ # toggle icon names
+ collapsedIconName = JSON_TOGGLE_ICON_COLLAPSED
+ expandedIconNamen = JSON_TOGGLE_ICON_EXPANDED
+ staticIconName = JSON_TOGGLE_ICON_STATIC
+
+ def __init__(self, context, request, view):
+ self.context = context
+ self.request = request
+ self.view = view
+
+ @property
+ def className(self):
+ if self.state == STATE_COLLAPSED:
+ return self.collapsedCSSName
+ elif self.state == STATE_EXPANDED:
+ return self.expandedCSSName
+ else:
+ return self.staticCSSName
+
+ @property
+ def toggleIcon(self):
+ """Returns a toggle icon including settings for json url."""
+ if self.state == STATE_COLLAPSED:
+ iconName = self.collapsedIconName
+ elif self.state == STATE_EXPANDED:
+ iconName = self.expandedIconNamen
+ else:
+ iconName = self.staticIconName
+ icon = zope.component.getMultiAdapter((self.context, self.request),
+ name=iconName)
+ resource = getResource(icon.context, icon.rname, self.request)
+ src = resource()
+ longDescURL = absoluteURL(self.context, self.request)
+ return ('<img src="%s" alt="toggle icon" width="%s" height="%s" '
+ 'border="0" longDesc="%s" />' % (src, icon.width,
+ icon.height, longDescURL))
+
+ def icon(self):
+ """Returns a toggle icon including settings for json url."""
+ icon = zope.component.queryMultiAdapter((self.context, self.request),
+ name=self.iconName)
+ if icon is not None:
+ resource = getResource(icon.context, icon.rname, self.request)
+ src = resource()
+ longDescURL = absoluteURL(self.context, self.request)
+ return ('<img src="%s" alt="toggle icon" width="%s" height="%s" '
+ 'border="0" />' % (src, icon.width, icon.height))
+ return u''
+
+ @property
+ def name(self):
+ return api.getName(self.context) or u'[top]'
+
+ @property
+ def url(self):
+ return absoluteURL(self.context, self.request) +'/'+ self.viewName
+
+ def update(self):
+ pass
+
+ def render(self):
+ return self.template()
+
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/base.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/__init__.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/__init__.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/__init__.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,23 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id: layer.py 197 2007-04-13 05:03:32Z rineichen $
+"""
+
+from zope.viewlet import viewlet
+
+
+Z3CJSONTreeCSSViewlet = viewlet.CSSViewlet('z3c.jsontree.css')
+Z3CJSONTreeJavaScriptViewlet = viewlet.JavaScriptViewlet(
+ 'z3c.jsontree.js')
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/configure.zcml
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/configure.zcml (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/configure.zcml 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,66 @@
+<configure
+ xmlns:zope="http://namespaces.zope.org/zope"
+ xmlns="http://namespaces.zope.org/browser"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c">
+
+ <!-- provider and template for content providers -->
+ <zope:adapter
+ name="tree"
+ factory=".tree.TreeProvider"
+ />
+ <z3c:template
+ template="tree.pt"
+ for="z3c.jsontree.interfaces.ITreeProvider"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <zope:adapter
+ name="li"
+ factory=".tree.LITagProvider"
+ />
+ <z3c:template
+ template="li.pt"
+ for="z3c.jsontree.interfaces.ILITagProvider"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <zope:adapter
+ name="ul"
+ factory=".tree.ULTagProvider"
+ />
+ <z3c:template
+ template="ul.pt"
+ for="z3c.jsontree.interfaces.IULTagProvider"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <resourceDirectory
+ name="z3cJSONTreeIMG"
+ directory="img"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <!-- default icons -->
+ <icon
+ name="z3cJSONTreeCollapsedIcon"
+ for="zope.interface.Interface"
+ file="img/z3cJSONTreeCollapsed.gif"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <icon
+ name="z3cJSONTreeExpandedIcon"
+ for="zope.interface.Interface"
+ file="img/z3cJSONTreeExpanded.gif"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+ <icon
+ name="z3cJSONTreeStaticIcon"
+ for="zope.interface.Interface"
+ file="img/z3cJSONTreeStatic.gif"
+ layer="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
+
+</configure>
\ No newline at end of file
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeCollapsed.gif
===================================================================
(Binary files differ)
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeCollapsed.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeExpanded.gif
===================================================================
(Binary files differ)
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeExpanded.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeStatic.gif
===================================================================
(Binary files differ)
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/img/z3cJSONTreeStatic.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/js/z3c.jsontree-0.5.0.js
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/js/z3c.jsontree-0.5.0.js (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/js/z3c.jsontree-0.5.0.js 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,159 @@
+//----------------------------------------------------------------------------
+/**
+ * @fileoverview JSON loading unordered list based tree
+ *
+ * @author Roger Ineichen dev at projekt01 dot org.
+ * @version Initial, not documented
+ */
+//----------------------------------------------------------------------------
+/* zrt-replace: "./z3cJSONTreeIMG" tal"string:${context/++resource++z3cJSONTreeIMG}" */
+
+/* Note: this script uses z3c.xmlhttp.js and z3c.jsonrpcproxy.js */
+/* TODO: use metadata plugin for get/set the json loader uri */
+
+//----------------------------------------------------------------------------
+// public API
+//----------------------------------------------------------------------------
+
+(function($) {
+$.fn.z3cJSONTree = function (settings) {
+ settings = $.extend({
+ z3cJSONTreeCollapsedGif: './z3cJSONTreeIMG/z3cJSONTreeCollapsed.gif',
+ z3cJSONTreeExpandedGif: './z3cJSONTreeIMG/z3cJSONTreeExpanded.gif',
+ z3cJSONTreeStaticGif: './z3cJSONTreeIMG/z3cJSONTreeStatic.gif',
+ z3cJSONTreeCollapsedClass: 'z3cJSONTreeCollapsed',
+ z3cJSONTreeExpandedClass: 'z3cJSONTreeExpanded',
+ z3cJSONTreeStaticClass: 'z3cJSONTreeItem',
+ z3cJSONTreeIconClass: 'z3cJSONTreeIcon',
+ loadItemsMethodName: 'loadJSONTreeItems'
+ }, settings);
+
+ function z3cJSONTreeToggleItem(img) {
+ ele = img.parentNode;
+ var uri = $(img).attr('longDesc');
+ if ($.className.has(ele, settings.z3cJSONTreeExpandedClass)) {
+ ele.className = settings.z3cJSONTreeCollapsedClass;
+ $(img).attr("src", settings.z3cJSONTreeCollapsedGif);
+ }
+ else {
+ /* check for sub items */
+ if ($(ele).find('li').length == 0){
+ /* load childs from server via JSON */
+ id = $(ele).attr('id');
+ z3cJSONTreeLoadItems(uri, id);
+ }
+ ele.className = settings.z3cJSONTreeExpandedClass;
+ $(img).attr("src", settings.z3cJSONTreeExpandedGif);
+ }
+ return false;
+ }
+
+ function z3cJSONTreeLoadItems(uri, id) {
+ /* each different json tree uses a own function for calling the childs */
+ loader = settings.loadItemsMethodName;
+ var jsonProxy = new JSONRPC(uri);
+ jsonProxy.addMethod(loader, z3cJSONTreeAddItems, id);
+ /* call the child loader method */
+ var loaderMethod = jsonProxy[loader];
+ loaderMethod(id);
+ }
+
+ function z3cJSONTreeAddItems(response, requestId) {
+ var res = response['treeChilds'];
+ var childs = res['childs'];
+ ele = document.getElementById(res['id']);
+ var ele = $(ele);
+ var ul = null;
+
+ /* find ul tag which will contain the new childs */
+ var ul = ele.find('ul')[0]
+ if (!ul){
+ ele.append('<ul></ul>')
+ }
+ var ul = ele.find('ul')[0]
+
+ /* render and append the new childs to the existing empty <ul> tag */
+ for (var i=0; i<childs.length; i++) {
+ var itemInfo = childs[i];
+ var iconSrc = itemInfo['iconURL'];
+ var hasChilds = itemInfo['hasChilds'];
+ var linkHandler = itemInfo['linkHandler'];
+ var contextURL = itemInfo['contextURL'];
+
+ /* create toggle icon */
+ if (iconSrc != '') {
+ var icon = $('<img></img>');
+ icon.attr("src", iconSrc);
+ }
+ /* create li tag */
+ var li = $('<li></li>');
+ li.attr("id", itemInfo['id']);
+
+ /* create toggle image */
+ var img = $('<img></img>');;
+ img.attr("width", "16");
+ img.attr("height", "16");
+ if (hasChilds) {
+ img.className = settings.z3cJSONTreeIconClass;
+ img.attr('longDesc', contextURL);
+ img.click(function(){
+ z3cJSONTreeToggleItem(this)
+ });
+ img.attr("src", settings.z3cJSONTreeCollapsedGif);
+ li.className = settings.z3cJSONTreeCollapsedClass;
+ }
+ else{
+ li.className = settings.z3cJSONTreeStaticClass;
+ img.attr("src", settings.z3cJSONTreeStaticGif);
+ }
+ /* create link or handler */
+ var a = $('<a href=""></a>');
+ if (linkHandler != '') {
+ a.click(eval(linkHandler));
+ a.attr("href", '#');
+ }else {
+ a.attr("href", itemInfo['url']);
+ }
+ /* append content to link */
+ a.html(itemInfo['content']);
+ li.append(a);
+ /* append link to to link */
+ if (iconSrc != '') {
+ icon.insertBefore(a);
+ img.insertBefore(icon);
+ }
+ else {
+ img.insertBefore(a);
+ }
+ $(ul).append(li);
+ }
+ }
+
+ // render tree
+ function renderTree(ul) {
+ if ($(ul).length == 0) {
+ return;
+ }
+ for (var i=0; i<ul.childNodes.length; i++) {
+ var item = ul.childNodes[i];
+ if (item.nodeName == "LI") {
+ for (var si=0; si<item.childNodes.length; si++) {
+ var subitem = item.childNodes[si];
+ if (subitem.nodeName == "UL") {
+ renderTree(subitem, false);
+ }
+ }
+ img = $(item.firstChild);
+ img.click(function(){
+ z3cJSONTreeToggleItem(this)
+ });
+ }
+ }
+ }
+
+ // initialize json trees
+ return $(this).each(function(){
+ renderTree(this);
+ });
+};
+})(jQuery);
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/li.pt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/li.pt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/li.pt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,11 @@
+<li id="" class=""
+ tal:attributes="id view/id;
+ class view/className"
+ ><img src="" width="16" height="16"
+ tal:replace="structure view/toggleIcon"
+ /><img src="" width="16" height="16"
+ tal:replace="structure view/icon"
+ /><a href=""
+ tal:attributes="href view/url"
+ tal:content="structure view/name"></a>
+</li>
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/li.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/__init__.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/__init__.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/__init__.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+# make a package
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_1.txt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_1.txt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_1.txt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+<ul class="z3cJSONTree" id="z3cJSONTree" name="z3cJSONTree"><li id="z3cJSONTree.." class="z3cJSONTreeExpanded"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeExpandedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder" /><a href="http://127.0.0.1/rootFolder/@@SelectedManagementView.html">[top]</a><ul><li id="z3cJSONTree.::folder1" class="z3cJSONTreeCollapsed"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeCollapsedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder1" /><a href="http://127.0.0.1/rootFolder/folder1/@@SelectedManagementView.html">folder1</a></li><li id="z3cJSONTree.::folder2" class="z3cJSONTreeCollapsed"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeCollapsedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder2" /><a href="http://127.0.0.1/rootFolder/folder2/@@SelectedManagementView.html">folder2</a></li><li id="z3cJSONTree.::папка3" class="z3cJSONTreeCollapsed"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeCollapsedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/%D0%BF%D0%B0%D0%BF%D0%BA%D0%B03" /><a href="http://127.0.0.1/rootFolder/%D0%BF%D0%B0%D0%BF%D0%BA%D0%B03/@@SelectedManagementView.html">папка3</a></li></ul></li></ul>
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_1.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_2.txt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_2.txt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_2.txt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+<ul class="z3cJSONTree" id="z3cJSONTree" name="z3cJSONTree"><li id="z3cJSONTree.." class="z3cJSONTreeExpanded"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeExpandedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder" /><a href="http://127.0.0.1/rootFolder/@@SelectedManagementView.html">[top]</a><ul><li id="z3cJSONTree.::folder1" class="z3cJSONTreeCollapsed"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeCollapsedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder1" /><a href="http://127.0.0.1/rootFolder/folder1/@@SelectedManagementView.html">folder1</a></li><li id="z3cJSONTree.::folder2" class="z3cJSONTreeExpanded"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeExpandedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder2" /><a href="http://127.0.0.1/rootFolder/folder2/@@SelectedManagementView.html">folder2</a><ul><li id="z3cJSONTree.::folder2::folder2_1" class="z3cJSONTreeExpanded"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeExpandedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder2/folder2_1" /><a href="http://127.0.0.1/rootFolder/folder2/folder2_1/@@SelectedManagementView.html">folder2_1</a><ul><li id="z3cJSONTree.::folder2::folder2_1::folder2_1_1" class="z3cJSONTreeStatic"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeStaticIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/folder2/folder2_1/folder2_1_1" /><a href="http://127.0.0.1/rootFolder/folder2/folder2_1/folder2_1_1/@@SelectedManagementView.html">folder2_1_1</a></li></ul></li></ul></li><li id="z3cJSONTree.::папка3" class="z3cJSONTreeCollapsed"><img src="http://127.0.0.1/rootFolder/@@/zope-interface-Interface-z3cJSONTreeCollapsedIcon.gif" alt="toggle icon" width="16" height="16" border="0" longDesc="http://127.0.0.1/rootFolder/%D0%BF%D0%B0%D0%BF%D0%BA%D0%B03" /><a href="http://127.0.0.1/rootFolder/%D0%BF%D0%B0%D0%BF%D0%BA%D0%B03/@@SelectedManagementView.html">папка3</a></li></ul></li></ul>
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/output/tree_2.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/test_view.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/test_view.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/test_view.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,108 @@
+##############################################################################
+#
+# Copyright (c) 2008 Projekt01 GmbH and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id: __init__.py 6 2006-04-16 01:28:45Z roger.ineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+
+import zope.component
+import zope.app.security
+from zope.app.component import hooks
+from zope.configuration.xmlconfig import XMLConfig
+from zope.pagetemplate.tests.util import check_xml
+from zope.publisher.browser import TestRequest
+from zope.app.component import testing
+
+from z3c.testing import TestCase
+from z3c.jsontree.browser.tests import util
+from z3c.jsontree.browser import tree
+
+
+class SimpleJSONTreeView(tree.SimpleJSONTree):
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+class GenericJSONTreeView(tree.GenericJSONTree):
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+
+class TestJSONTreeView(testing.PlacefulSetup, TestCase):
+
+ def setUp(self):
+ testing.PlacefulSetup.setUp(self, site=True)
+ self.rootFolder.__name__ = 'rootFolder'
+ hooks.setSite(self.rootFolder)
+ import zope.app.publication
+ import zope.app.publisher.browser
+ import z3c.template
+ import z3c.jsontree
+ import z3c.jsonrpc
+ XMLConfig('meta.zcml', zope.component)()
+ XMLConfig('meta.zcml', zope.app.security)()
+ XMLConfig('meta.zcml', zope.app.publication)()
+ XMLConfig('meta.zcml', zope.app.publisher.browser)()
+ XMLConfig('meta.zcml', z3c.template)()
+ XMLConfig('meta.zcml', z3c.jsonrpc)()
+ XMLConfig('configure.zcml', z3c.jsontree)()
+
+ def test_simple_tree_view_1(self):
+ context = self.rootFolder['folder1']
+ request = TestRequest()
+ view = SimpleJSONTreeView(context, request)
+ view.update()
+ ultree = view.tree
+ check_xml(ultree, util.read_output('tree_1.txt'))
+
+ def test_simple_tree_view_2(self):
+ """This test includes cyrillic letters."""
+ context = self.rootFolder['folder2']['folder2_1']['folder2_1_1']
+ request = TestRequest()
+ view = SimpleJSONTreeView(context, request)
+ view.update()
+ ultree = view.tree
+ check_xml(ultree, util.read_output('tree_2.txt'))
+
+ def test_generic_tree_view_1(self):
+ context = self.rootFolder['folder1']
+ request = TestRequest()
+ view = GenericJSONTreeView(context, request)
+ view.update()
+ ultree = view.tree
+ check_xml(ultree, util.read_output('tree_1.txt'))
+
+ def test_generic_tree_view_2(self):
+ """This test includes cyrillic letters."""
+ context = self.rootFolder['folder2']['folder2_1']['folder2_1_1']
+ request = TestRequest()
+ view = GenericJSONTreeView(context, request)
+ view.update()
+ ultree = view.tree
+ check_xml(ultree, util.read_output('tree_2.txt'))
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(TestJSONTreeView),
+ ))
+
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/test_view.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/util.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/util.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/util.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2008 Projekt01 GmbH and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id: __init__.py 6 2006-04-16 01:28:45Z roger.ineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import os
+
+def read_output(filename):
+ import z3c.jsontree.browser.tests
+ dir = os.path.dirname(z3c.jsontree.browser.tests.__file__)
+ output_dir = os.path.join(dir, 'output')
+ filename = os.path.join(output_dir, filename)
+ return open(filename, 'r').read().decode("utf-8")
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tests/util.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.pt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.pt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.pt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,21 @@
+<ul class="" id="" name=""
+ tal:attributes="id view/z3cJSONTreeId;
+ class view/z3cJSONTreeClass;
+ name view/z3cJSONTreeName">
+ <li id="" class=""
+ tal:define="childTags view/childTags"
+ tal:attributes="id view/id;
+ class view/className"
+ ><img src="" width="16" height="16"
+ tal:replace="structure view/toggleIcon"
+ /><img src="" width="16" height="16"
+ tal:replace="structure view/icon"
+ />
+ <a href=""
+ tal:attributes="href view/url"
+ tal:content="structure view/name"></a>
+ <ul tal:condition="childTags"
+ tal:content="structure childTags">
+ </ul>
+ </li>
+</ul>
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,102 @@
+##############################################################################
+#
+# Copyright (c) 2007 Projekt01 GmbH and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+
+"""
+$Id: __init__.py 6 2006-04-16 01:28:45Z roger.ineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.interface
+import zope.component
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.viewlet.interfaces import IViewlet
+
+from z3c.jsontree import interfaces
+from z3c.jsontree import base
+
+
+# simple trees
+class SimpleJSONTree(base.TreeBase, base.PythonRenderer,
+ base.IdGenerator):
+ """Simple JSON tree using inline methods for rendering elements and
+ using traversable path for item lookup.
+ """
+
+ zope.interface.implements(interfaces.ISimpleJSONTree)
+
+
+# simple tree viewlet
+class SimpleJSONTreeViewlet(SimpleJSONTree):
+ """Simple JSON tree viewlet."""
+
+ zope.interface.implements(IViewlet)
+
+ def __init__(self, context, request, view, manager):
+ super(SimpleJSONTreeViewlet, self).__init__(context, request)
+ self.__parent__ = view
+ self.context = context
+ self.request = request
+ self.manager = manager
+
+
+# generic template based tree
+class LITagProvider(base.ProviderBase, base.IdGenerator):
+ """LI tag content provider."""
+
+ zope.interface.implements(interfaces.ILITagProvider)
+ zope.component.adapts(zope.interface.Interface, IBrowserRequest,
+ interfaces.ITemplateRenderer)
+
+
+class ULTagProvider(base.ProviderBase, base.IdGenerator):
+ """UL tag contet provider."""
+
+ zope.interface.implements(interfaces.IULTagProvider)
+ zope.component.adapts(zope.interface.Interface, IBrowserRequest,
+ interfaces.ITemplateRenderer)
+
+
+class TreeProvider(base.ProviderBase, base.IdGenerator):
+ """UL tag contet provider."""
+
+ zope.interface.implements(interfaces.ITreeProvider)
+ zope.component.adapts(zope.interface.Interface, IBrowserRequest,
+ interfaces.ITemplateRenderer)
+
+
+class GenericJSONTree(base.TreeBase, base.TemplateRenderer,
+ base.IdGenerator):
+ """IntId base object lookup and template base rendering.
+
+ This implementation uses IContentProvider for element tag rendering.
+ This content provider are resonsible for represent a node. This allows us
+ to embed html or javascript calls in the html representation in a smart
+ way.
+ """
+
+ zope.interface.implements(interfaces.IGenericJSONTree)
+
+
+# generic tree viewlet
+class GenericJSONTreeViewlet(GenericJSONTree):
+ """Generic JSON tree viewlet."""
+
+ zope.interface.implements(IViewlet)
+
+ def __init__(self, context, request, view, manager):
+ super(GenericJSONTreeViewlet, self).__init__(context, request)
+ self.__parent__ = view
+ self.context = context
+ self.request = request
+ self.manager = manager
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/tree.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/ul.pt
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/ul.pt (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/ul.pt 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,15 @@
+<li id="" class=""
+ tal:define="childTags view/childTags"
+ tal:attributes="id view/id;
+ class view/className"
+ ><img src="" width="16" height="16"
+ tal:replace="structure view/toggleIcon"
+ /><img src="" width="16" height="16"
+ tal:replace="structure view/icon"
+ /><a href=""
+ tal:attributes="href view/url"
+ tal:content="structure view/name"></a>
+ <ul tal:condition="childTags"
+ tal:content="structure childTags">
+ </ul>
+</li>
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/browser/ul.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/browser/z3c.jsontree.css
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/browser/z3c.jsontree.css (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/browser/z3c.jsontree.css 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,42 @@
+
+ul.z3cJSONTree {
+ list-style-type: none;
+ margin: 0px;
+ padding: 0px;
+}
+
+ul.z3cJSONTree ul {
+ margin-left: 12px;
+ padding: 0px;
+}
+
+ul.z3cJSONTree li {
+ list-style: none;
+ white-space: nowrap;
+ margin: 0px;
+ padding: 0px;
+}
+
+ul.z3cJSONTree img {
+ height: 16px;
+}
+
+ul.z3cJSONTree a {
+ text-decoration: none;
+}
+
+ul.z3cJSONTree .z3cJSONTreeIcon {
+ cursor: pointer;
+}
+
+ul.z3cJSONTree li.z3cJSONTreeItem .z3cJSONTreeIcon {
+ cursor: default;
+}
+
+ul.z3cJSONTree li.z3cJSONTreeExpanded ul {
+ display: block;
+}
+
+ul.z3cJSONTree li.z3cJSONTreeCollapsed ul {
+ display: none;
+}
Added: z3c.jsontree/trunk/src/z3c/jsontree/configure.zcml
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/configure.zcml (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/configure.zcml 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,18 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c">
+
+ <!-- Note: this method only returns what the user has permission for
+ the permission check is done inside based on the different permission
+ the different items have -->
+ <z3c:jsonrpc
+ for="*"
+ class="z3c.jsontree.jsonrpc.JSONTreeItems"
+ permission="zope.Public"
+ methods="loadJSONTreeItems"
+ />
+
+ <include package=".browser" />
+
+</configure>
\ No newline at end of file
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/interfaces.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/interfaces.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/interfaces.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,162 @@
+##############################################################################
+#
+# Copyright (c) 2008 Projekt01 GmbH and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id: __init__.py 6 2006-04-16 01:28:45Z roger.ineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.interface
+from zope.contentprovider.interfaces import IContentProvider
+
+# DOM id and name for json tree ``<UL>`` tag
+JSON_TREE_ID = u'z3cJSONTree'
+JSON_TREE_VIEW_NAME = u'@@SelectedManagementView.html'
+
+JSON_TOGGLE_ICON_COLLAPSED = 'z3cJSONTreeCollapsedIcon'
+JSON_TOGGLE_ICON_EXPANDED = 'z3cJSONTreeExpandedIcon'
+JSON_TOGGLE_ICON_STATIC = 'z3cJSONTreeStaticIcon'
+
+JSON_LI_CSS_EXPANDED = u'z3cJSONTreeExpanded'
+JSON_LI_CSS_COLLAPSED = u'z3cJSONTreeCollapsed'
+JSON_LI_CSS_STATIC = u'z3cJSONTreeStatic'
+
+STATE_EXPANDED = 'expanded'
+STATE_COLLAPSED = 'collapsed'
+STATE_STATIC = 'static'
+
+
+class IElementProvider(IContentProvider):
+
+ state = zope.interface.Attribute(
+ """The collapsed, expanded or static state .""")
+
+ childTags = zope.interface.Attribute(
+ """A list of rendered child tags.""")
+
+ viewName = zope.interface.Attribute(
+ """The view name which get called on the context.""")
+
+ collapsedCSSName = zope.interface.Attribute(
+ """Class name for the collapsed <LI> tag.""")
+ expandedCSSName = zope.interface.Attribute(
+ """Class name for the expanded <LI> tag.""")
+ staticCSSName = zope.interface.Attribute(
+ """Class name for the static <LI> tag.""")
+
+ # context icon
+ iconName = zope.interface.Attribute(
+ """The icon name for the context icon.""")
+
+ # toggle icon
+ collapsedIconName = zope.interface.Attribute(
+ """The icon name for the collapsed icon.""")
+ expandedIconNamen = zope.interface.Attribute(
+ """The icon name for the expanded icon.""")
+ staticIconName = zope.interface.Attribute(
+ """The icon name for the static icon.""")
+
+ # properties
+ className = zope.interface.Attribute(
+ """The CSS class name for the rendered <LI> tag.""")
+
+ toggleIcon = zope.interface.Attribute(
+ """The toggle icon including settings for json url.""")
+
+ icon = zope.interface.Attribute("""The icon for the given context.""")
+
+ name = zope.interface.Attribute("""The context name""")
+
+ url = zope.interface.Attribute("""The context url""")
+
+ def update():
+ """Must get called before render."""
+
+ def render():
+ """Render the template."""
+
+
+# content provider using templates
+class ILITagProvider(IElementProvider):
+ """Content provider for ``LI`` tag."""
+
+
+class IULTagProvider(IElementProvider):
+ """Content provider for ``UL`` tag."""
+
+
+class ITreeProvider(IElementProvider):
+ """Content provider for tree (main) ``UL`` tag."""
+
+
+# tree renderer interfaces
+class ITreeRenderer(zope.interface.Interface):
+ """Knows how to render elements fo the tree items."""
+
+ def renderLI(item):
+ """Renders <LI> tags."""
+
+ def renderUL(item, childTags=None):
+ """Renders <li> tag including rendered child tags."""
+
+ tree = zope.interface.Attribute(
+ """Renders <ul> tree tag including rendered child tags.""")
+
+
+class IPythonRenderer(ITreeRenderer):
+ """Uses python methods for rendering the tree items."""
+
+
+class ITemplateRenderer(ITreeRenderer):
+ """Uses IContentProvider classes within templates for rendereing the items.
+ """
+
+
+class IIdGenerator(zope.interface.Interface):
+ """Knows how to get ids for the tree items."""
+
+ def getId(item):
+ """Returns the DOM id for a given object.
+
+ Note: we encode the upper case letters because the Dom element id are
+ not case sensitive in HTML. We prefix each upper case letter with ':'.
+ """
+
+ def id():
+ """Returns the DOM id for a given context."""
+
+
+class IJSONTree(ITreeRenderer, IIdGenerator):
+ """Complete JSON tree definition.
+
+ Don't care about the javascript part, just implement all methods define in
+ this interfaces.
+ """
+
+
+class ISimpleJSONTree(IJSONTree):
+ """Simple JSON tree implementation.
+
+ Simple JSON tree using inline methods for rendering elements and
+ traversable path for item lookup.
+ """
+
+
+class IGenericJSONTree(IJSONTree):
+ """Generic template based JSON tree implementation.
+
+ This implementation uses IContentProvider for element tag rendering.
+ This content provider are responsible for represent a node. This allows us
+ to embed html or javascript code in the html representation in a smart
+ way. This makes it possible to include html forms in a tree node.
+ """
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/interfaces.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/jsonrpc.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/jsonrpc.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/jsonrpc.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,104 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.traversing import api
+from zope.security.interfaces import Unauthorized
+from zope.security.interfaces import Forbidden
+from zope.traversing.browser import absoluteURL
+from zope.app.container.interfaces import IReadContainer
+
+from z3c.jsonrpc.publisher import MethodPublisher
+
+from z3c.jsontree.interfaces import JSON_TREE_ID
+from z3c.jsontree.interfaces import JSON_TREE_VIEW_NAME
+from z3c.jsontree import base
+from z3c.jsontree import util
+
+
+class JSONTreeItems(MethodPublisher, base.IdGenerator):
+ """Returns the data of the childs from the path for the json tree.
+
+ This is a simple implementation which uses the traversal concept.
+ If you need to lookup items for other conponents then containers,
+ e.g. for a widget, you need to implement your own child loader class.
+ """
+
+ viewName = JSON_TREE_VIEW_NAME
+ z3cJSONTreeId = JSON_TREE_ID
+ linkHandler = ''
+
+ @property
+ def subItems(self):
+ """Returns a list of items for the given context."""
+ items = []
+ keys = []
+ append = items.append
+ if IReadContainer.providedBy(self.context):
+ try:
+ keys = list(self.context.keys())
+ except(Unauthorized, Forbidden):
+ return items
+ for name in keys:
+ # Only include items we can traverse to
+ subItem = api.traverse(self.context, name, None)
+ if subItem is not None:
+ append(subItem)
+ return items
+
+ def hasSubItems(self, item):
+ """Returns a True or False if the sub item has subitems."""
+ res = False
+ if IReadContainer.providedBy(item):
+ try:
+ if len(item) > 0:
+ res = True
+ except(Unauthorized, Forbidden):
+ pass
+ return res
+
+ def getIconURL(self, item, request, name='icon'):
+ return util.getIconURL(item, request, name=name)
+
+ def loadJSONTreeItems(self, id):
+ """Returns child information for the object with the given path in a
+ JSON format."""
+ res = {}
+ childs = []
+ append = childs.append
+
+ for subItem in self.subItems:
+
+ if self.hasSubItems(subItem):
+ hasChilds = True
+ else:
+ hasChilds = False
+
+ info = {}
+ url = absoluteURL(subItem, self.request)
+ info['id'] = self.getId(subItem)
+ info['content'] = api.getName(subItem)
+ info['url'] = url +'/'+ self.viewName
+ info['iconURL'] = util.getIconURL(subItem, self.request)
+ info['linkHandler'] = self.linkHandler
+ info['hasChilds'] = hasChilds
+ info['contextURL'] = url
+ append(info)
+
+ res['treeChilds'] = {'id':id, 'childs':childs}
+
+ return res
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/jsonrpc.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/tests.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/tests.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/tests.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,165 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = "reStructuredText"
+
+import os
+import unittest
+import zope.interface
+import zope.component
+from zope.testing import doctest
+from zope.publisher.browser import TestRequest
+from zope.app.testing import setup
+
+import z3c.testing
+import z3c.jsonrpc.testing
+from z3c.jsontree import browser
+from z3c.template.zcml import TemplateFactory
+from z3c.template.interfaces import IContentTemplate
+from z3c.jsontree import interfaces
+from z3c.jsontree.browser import tree
+
+
+class ResourceStub(object):
+ """Resource stub"""
+ zope.interface.implements(zope.interface.Interface)
+ zope.component.adapts(zope.interface.Interface)
+
+ def __init__(self, request):
+ self.request = request
+
+ def __call__(self):
+ return u'http://icon'
+
+ def url(self):
+ return u''
+
+
+class IconStub(object):
+ """Icon stub"""
+ zope.interface.implements(zope.interface.Interface)
+ zope.component.adapts(zope.interface.Interface, zope.interface.Interface)
+
+ def __init__(self, rname):
+ self.rname = rname
+ self.alt = u'icon'
+ self.width = 16
+ self.height = 16
+
+ def __call__(self, context, request):
+ self.context = context
+ self.request = request
+ return self
+
+
+class TestSimpleJSONTree(z3c.testing.InterfaceBaseTest):
+
+ def setUp(test):
+ setup.placefulSetUp(True)
+ # register icon resource
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeCollapsedIcon')
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeExpandedIcon')
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeStaticIcon')
+
+ # register icon
+ zope.component.provideAdapter(IconStub('z3cJSONTreeCollapsedIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeCollapsedIcon')
+ zope.component.provideAdapter(IconStub('z3cJSONTreeExpandedIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeExpandedIcon')
+ zope.component.provideAdapter(IconStub('z3cJSONTreeStaticIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeStaticIcon')
+
+ def tearDown(test):
+ setup.placefulTearDown()
+
+ def getTestInterface(self):
+ return interfaces.ISimpleJSONTree
+
+ def getTestClass(self):
+ return tree.SimpleJSONTree
+
+ def getTestPos(self):
+ return (None, TestRequest())
+
+
+class TestGenericJSONTree(z3c.testing.InterfaceBaseTest):
+
+ def setUp(test):
+ setup.placefulSetUp(True)
+ # register icon resource
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeCollapsedIcon')
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeExpandedIcon')
+ zope.component.provideAdapter(ResourceStub,
+ name='z3cJSONTreeStaticIcon')
+
+ # register icon
+ zope.component.provideAdapter(IconStub('z3cJSONTreeCollapsedIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeCollapsedIcon')
+ zope.component.provideAdapter(IconStub('z3cJSONTreeExpandedIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeExpandedIcon')
+ zope.component.provideAdapter(IconStub('z3cJSONTreeStaticIcon'),
+ (zope.interface.Interface, zope.interface.Interface),
+ provides=zope.interface.Interface, name='z3cJSONTreeStaticIcon')
+
+ # register tree content provider
+ zope.component.provideAdapter(tree.TreeProvider, name='tree')
+ zope.component.provideAdapter(tree.ULTagProvider, name='ul')
+ zope.component.provideAdapter(tree.LITagProvider, name='li')
+
+ # register tree content template
+ treeTemplate = os.path.join(os.path.dirname(browser.__file__),
+ 'tree.pt')
+ factory = TemplateFactory(treeTemplate, 'text/html')
+ zope.component.provideAdapter(factory, (zope.interface.Interface,
+ zope.interface.Interface), IContentTemplate)
+
+ def tearDown(test):
+ setup.placefulTearDown()
+
+ def getTestInterface(self):
+ return interfaces.IGenericJSONTree
+
+ def getTestClass(self):
+ return tree.GenericJSONTree
+
+ def getTestPos(self):
+ return (None, TestRequest())
+
+
+def test_suite():
+ return unittest.TestSuite((
+ z3c.jsonrpc.testing.FunctionalDocFileSuite('README.txt',
+ setUp=z3c.jsonrpc.testing.setUp,
+ tearDown=z3c.jsonrpc.testing.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
+ unittest.makeSuite(TestSimpleJSONTree),
+ unittest.makeSuite(TestGenericJSONTree),
+ ))
+
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/tests.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/util.py
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/util.py (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/util.py 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.component
+from zope.traversing import api
+from zope.proxy import sameProxiedObjects
+from zope.traversing.interfaces import TraversalError
+
+
+def getIconURL(item, request, name='icon'):
+ url = ''
+ icon = zope.component.queryMultiAdapter((item, request), name=name)
+ if icon is not None:
+ try:
+ url = icon.url()
+ except TraversalError:
+ return url
+ return url
+
+
+def isChildOf(child, parent):
+ """Check if object is a child of the parent."""
+ if parent in api.getParents(child):
+ return True
+ else:
+ return False
+
+
+def getParentsFromContextToObject(context, obj):
+ """Returns a list starting with the given context's parent followed by
+ each of its parents till we reach the object.
+
+ If the child object is not a child of the parent a empty list
+ will return.
+ """
+ if not isChildOf(context, obj):
+ return []
+
+ if sameProxiedObjects(context, obj):
+ return []
+
+ parents = []
+ w = context
+
+ while 1:
+ w = w.__parent__
+ if sameProxiedObjects(w, obj):
+ parents.append(w)
+ break
+ if w is None:
+ break
+
+ parents.append(w)
+
+ return parents
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/util.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.jsontree/trunk/src/z3c/jsontree/z3c.jsontree-configure.zcml
===================================================================
--- z3c.jsontree/trunk/src/z3c/jsontree/z3c.jsontree-configure.zcml (rev 0)
+++ z3c.jsontree/trunk/src/z3c/jsontree/z3c.jsontree-configure.zcml 2008-02-16 16:02:16 UTC (rev 83892)
@@ -0,0 +1 @@
+<include package="z3c.jsontree" />
Property changes on: z3c.jsontree/trunk/src/z3c/jsontree/z3c.jsontree-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list