set up ajax.dojo - first use: batching by inner html/dojo.io.updateNode()
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1273 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
9897a60a73
commit
698df39f4c
12 changed files with 153 additions and 21 deletions
3
ajax/__init__.py
Normal file
3
ajax/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
$Id$
|
||||
"""
|
3
ajax/dojo/__init__.py
Normal file
3
ajax/dojo/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
$Id$
|
||||
"""
|
20
ajax/dojo/configure.zcml
Normal file
20
ajax/dojo/configure.zcml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!-- $Id$ -->
|
||||
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/browser"
|
||||
xmlns:zope="http://namespaces.zope.org/zope"
|
||||
i18n_domain="zope">
|
||||
|
||||
<resourceDirectory
|
||||
name="ajax.dojo"
|
||||
directory="dojo"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="*"
|
||||
name="ajax.dojo"
|
||||
template="macros.pt"
|
||||
permission="zope.Public"
|
||||
/>
|
||||
|
||||
</configure>
|
1
ajax/dojo/dojo
Symbolic link
1
ajax/dojo/dojo
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/helmutm/download/build/dojo-0.3.1-ajax
|
14
ajax/dojo/macros.pt
Normal file
14
ajax/dojo/macros.pt
Normal file
|
@ -0,0 +1,14 @@
|
|||
<metal:def define-macro="main">
|
||||
|
||||
<script type="text/javascript">
|
||||
djConfig = { isDebug: true };
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="ajax.dojo/dojo.js"
|
||||
tal:attributes="src context/++resource++ajax.dojo/dojo.js" />
|
||||
|
||||
<script type="text/javascript">
|
||||
dojo.require("dojo.io.*");
|
||||
</script>
|
||||
|
||||
</metal:def>
|
4
ajax/innerHtml.pt
Normal file
4
ajax/innerHtml.pt
Normal file
|
@ -0,0 +1,4 @@
|
|||
<tal:def define="macroName view/macroName;
|
||||
tpl view/template;">
|
||||
<metal:use use-macro="tpl/macros/?macroName" />
|
||||
</tal:def>
|
47
container/base.py
Normal file
47
container/base.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Ordered container implementation.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app import zapi
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.app.container.browser.contents import JustContents
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
from zope.interface import Interface
|
||||
|
||||
|
||||
class ContainerView(JustContents):
|
||||
|
||||
def checkMoveAction(self):
|
||||
pass
|
||||
|
||||
orderable = False
|
||||
|
||||
# informations for the ajax.inner.html view (template):
|
||||
|
||||
def template(self):
|
||||
basicView = zapi.getMultiAdapter((self.context, self.request),
|
||||
Interface, name=u'contents.html')
|
||||
return basicView.index
|
||||
|
||||
macroName = 'contents'
|
||||
|
|
@ -14,6 +14,15 @@
|
|||
menu="zmi_views" title="Contents"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="zope.app.container.interfaces.IOrderedContainer"
|
||||
name="ajax.inner.html"
|
||||
template="../ajax/innerHtml.pt"
|
||||
class="cybertools.container.ordered.OrderedContainerView"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Contents"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="zope.app.container.interfaces.IContainer"
|
||||
name="contents.html"
|
||||
|
@ -23,4 +32,13 @@
|
|||
menu="zmi_views" title="Contents"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="zope.app.container.interfaces.IContainer"
|
||||
name="ajax.inner.html"
|
||||
template="../ajax/innerHtml.pt"
|
||||
class="cybertools.container.ordered.ContainerView"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Contents"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
<html metal:use-macro="context/@@standard_macros/view"
|
||||
i18n:domain="zope">
|
||||
<body>
|
||||
|
||||
|
||||
<metal:ecmascript fill-slot="ecmascript_slot">
|
||||
<metal:use use-macro="views/ajax.dojo/main" />
|
||||
</metal:ecmascript>
|
||||
|
||||
|
||||
<div metal:fill-slot="body">
|
||||
<div metal:define-macro="contents">
|
||||
|
||||
<div metal:define-macro="contents"
|
||||
id="body.contents">
|
||||
|
||||
<tal:checkmove define="dummy view/checkMoveAction">
|
||||
<form name="containerContentsForm" method="post" action="."
|
||||
|
@ -145,22 +154,26 @@
|
|||
next batch/next/title;
|
||||
last batch/last/title;">
|
||||
<a href="#"
|
||||
tal:attributes="href batch/first/url"
|
||||
tal:attributes="href batch/first/url;
|
||||
onclick batch/first/navOnClick"
|
||||
tal:content="first"
|
||||
tal:condition="python: first != current">1</a>
|
||||
<span tal:condition="python: first < previous-1">...</span>
|
||||
<a href="#"
|
||||
tal:attributes="href batch/previous/url"
|
||||
tal:attributes="xhref batch/previous/url;
|
||||
onclick batch/previous/navOnClick"
|
||||
tal:content="batch/previous/title"
|
||||
tal:condition="python: first != previous and previous != current">2</a>
|
||||
<b tal:content="batch/current/title">3</b>
|
||||
<a href="#"
|
||||
tal:attributes="href batch/next/url"
|
||||
tal:attributes="href batch/next/url;
|
||||
onclick batch/next/navOnClick"
|
||||
tal:content="batch/next/title"
|
||||
tal:condition="python: last != next and next != current">3</a>
|
||||
<span tal:condition="python: last > next+1">...</span>
|
||||
<a href="#"
|
||||
tal:attributes="href batch/last/url"
|
||||
tal:attributes="href batch/last/url;
|
||||
onclick batch/last/navOnClick"
|
||||
tal:content="batch/last/title"
|
||||
tal:condition="python: last != current">5</a>
|
||||
</metal:nav>
|
||||
|
@ -257,6 +270,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -25,16 +25,9 @@ $Id$
|
|||
from zope.app import zapi
|
||||
from zope.app.container.ordered import OrderedContainer as BaseOrderedContainer
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.app.container.browser.contents import JustContents
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
|
||||
|
||||
class ContainerView(JustContents):
|
||||
|
||||
def checkMoveAction(self):
|
||||
pass
|
||||
|
||||
orderable = False
|
||||
from zope.interface import Interface
|
||||
from base import ContainerView
|
||||
|
||||
|
||||
class OrderedContainerView(ContainerView):
|
||||
|
|
|
@ -44,7 +44,9 @@ We are now ready to use the corresponding browser view:
|
|||
>>> bview.items()
|
||||
[3, 4, 5, 6]
|
||||
>>> bview.last
|
||||
{'url': 'http://127.0.0.1?b_size=4&b_overlap=1&b_page=5&b_orphan=0', 'title': 5}
|
||||
{'url': 'http://127.0.0.1?b_size=4&b_overlap=1&b_page=5&b_orphan=0',
|
||||
'navOnClick': "dojo.io.updateNode(...); return false;",
|
||||
'title': 5}
|
||||
|
||||
The real reporting stuff
|
||||
------------------------
|
||||
|
|
|
@ -84,8 +84,21 @@ class BatchView(object):
|
|||
def url(self, page):
|
||||
return str(self.request.URL) + self.urlParams(page)
|
||||
|
||||
def ajaxUrl(self, page):
|
||||
try:
|
||||
url = self.request.URL[-1]
|
||||
except KeyError: # make DocTest/TestRequest happy
|
||||
url = `self.request.URL`
|
||||
return ''.join((url, '/@@ajax.inner.html', self.urlParams(page)))
|
||||
|
||||
def navOnClick(self, page):
|
||||
return ("dojo.io.updateNode('body.contents', '%s'); "
|
||||
"return false;" % self.ajaxUrl(page))
|
||||
|
||||
def info(self, page):
|
||||
return {'title': page+1, 'url': self.url(page)}
|
||||
return {'title': page+1,
|
||||
'url': self.url(page),
|
||||
'navOnClick': self.navOnClick(page)}
|
||||
|
||||
def showNavigation(self):
|
||||
return self.first['title'] != self.last['title']
|
||||
|
|
Loading…
Add table
Reference in a new issue