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:
helmutm 2006-07-14 11:53:24 +00:00
parent 9897a60a73
commit 698df39f4c
12 changed files with 153 additions and 21 deletions

3
ajax/__init__.py Normal file
View file

@ -0,0 +1,3 @@
"""
$Id$
"""

3
ajax/dojo/__init__.py Normal file
View file

@ -0,0 +1,3 @@
"""
$Id$
"""

20
ajax/dojo/configure.zcml Normal file
View 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
View file

@ -0,0 +1 @@
/home/helmutm/download/build/dojo-0.3.1-ajax

14
ajax/dojo/macros.pt Normal file
View 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
View 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
View 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'

View file

@ -14,6 +14,15 @@
menu="zmi_views" title="Contents" 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 <page
for="zope.app.container.interfaces.IContainer" for="zope.app.container.interfaces.IContainer"
name="contents.html" name="contents.html"
@ -23,4 +32,13 @@
menu="zmi_views" title="Contents" 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> </configure>

View file

@ -1,8 +1,17 @@
<html metal:use-macro="context/@@standard_macros/view" <html metal:use-macro="context/@@standard_macros/view"
i18n:domain="zope"> i18n:domain="zope">
<body> <body>
<metal:ecmascript fill-slot="ecmascript_slot">
<metal:use use-macro="views/ajax.dojo/main" />
</metal:ecmascript>
<div metal:fill-slot="body"> <div metal:fill-slot="body">
<div metal:define-macro="contents">
<div metal:define-macro="contents"
id="body.contents">
<tal:checkmove define="dummy view/checkMoveAction"> <tal:checkmove define="dummy view/checkMoveAction">
<form name="containerContentsForm" method="post" action="." <form name="containerContentsForm" method="post" action="."
@ -18,7 +27,7 @@
value value" /> value value" />
</tal:param> </tal:param>
</metal:keep-batch> </metal:keep-batch>
<input type="hidden" name="type_name" value="" <input type="hidden" name="type_name" value=""
tal:attributes="value request/type_name" tal:attributes="value request/type_name"
tal:condition="request/type_name|nothing" tal:condition="request/type_name|nothing"
@ -137,7 +146,7 @@
tal:condition="batch/showNavigation"> tal:condition="batch/showNavigation">
<td colspan="6" <td colspan="6"
style="text-align: center"> style="text-align: center">
Pages: Pages:
<metal:nav define-macro="batch_navigation" <metal:nav define-macro="batch_navigation"
tal:define="first batch/first/title; tal:define="first batch/first/title;
previous batch/previous/title; previous batch/previous/title;
@ -145,22 +154,26 @@
next batch/next/title; next batch/next/title;
last batch/last/title;"> last batch/last/title;">
<a href="#" <a href="#"
tal:attributes="href batch/first/url" tal:attributes="href batch/first/url;
onclick batch/first/navOnClick"
tal:content="first" tal:content="first"
tal:condition="python: first != current">1</a> tal:condition="python: first != current">1</a>
<span tal:condition="python: first &lt; previous-1">...</span> <span tal:condition="python: first &lt; previous-1">...</span>
<a href="#" <a href="#"
tal:attributes="href batch/previous/url" tal:attributes="xhref batch/previous/url;
onclick batch/previous/navOnClick"
tal:content="batch/previous/title" tal:content="batch/previous/title"
tal:condition="python: first != previous and previous != current">2</a> tal:condition="python: first != previous and previous != current">2</a>
<b tal:content="batch/current/title">3</b> <b tal:content="batch/current/title">3</b>
<a href="#" <a href="#"
tal:attributes="href batch/next/url" tal:attributes="href batch/next/url;
onclick batch/next/navOnClick"
tal:content="batch/next/title" tal:content="batch/next/title"
tal:condition="python: last != next and next != current">3</a> tal:condition="python: last != next and next != current">3</a>
<span tal:condition="python: last > next+1">...</span> <span tal:condition="python: last > next+1">...</span>
<a href="#" <a href="#"
tal:attributes="href batch/last/url" tal:attributes="href batch/last/url;
onclick batch/last/navOnClick"
tal:content="batch/last/title" tal:content="batch/last/title"
tal:condition="python: last != current">5</a> tal:condition="python: last != current">5</a>
</metal:nav> </metal:nav>
@ -197,10 +210,10 @@
/> />
<div tal:condition="view/hasAdding" tal:omit-tag=""> <div tal:condition="view/hasAdding" tal:omit-tag="">
<div tal:omit-tag="" <div tal:omit-tag=""
tal:define="adding nocall:context/@@+; tal:define="adding nocall:context/@@+;
addingInfo adding/addingInfo; addingInfo adding/addingInfo;
has_custom_add_view adding/hasCustomAddView; has_custom_add_view adding/hasCustomAddView;
names_required adding/nameAllowed" names_required adding/nameAllowed"
tal:condition="adding/isSingleMenuItem"> tal:condition="adding/isSingleMenuItem">
<input type="submit" name="container_add_button" value="Add" <input type="submit" name="container_add_button" value="Add"
@ -213,7 +226,7 @@
/> />
<input type="hidden" name="single_type_name" <input type="hidden" name="single_type_name"
value="" value=""
tal:attributes="value python:addingInfo[0]['action']" tal:attributes="value python:addingInfo[0]['action']"
/> />
</div> </div>
</div> </div>
@ -257,6 +270,7 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View file

@ -25,16 +25,9 @@ $Id$
from zope.app import zapi from zope.app import zapi
from zope.app.container.ordered import OrderedContainer as BaseOrderedContainer from zope.app.container.ordered import OrderedContainer as BaseOrderedContainer
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.app.container.browser.contents import JustContents
from zope.app.i18n import ZopeMessageFactory as _ from zope.app.i18n import ZopeMessageFactory as _
from zope.interface import Interface
from base import ContainerView
class ContainerView(JustContents):
def checkMoveAction(self):
pass
orderable = False
class OrderedContainerView(ContainerView): class OrderedContainerView(ContainerView):

View file

@ -44,7 +44,9 @@ We are now ready to use the corresponding browser view:
>>> bview.items() >>> bview.items()
[3, 4, 5, 6] [3, 4, 5, 6]
>>> bview.last >>> 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 The real reporting stuff
------------------------ ------------------------

View file

@ -84,8 +84,21 @@ class BatchView(object):
def url(self, page): def url(self, page):
return str(self.request.URL) + self.urlParams(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): 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): def showNavigation(self):
return self.first['title'] != self.last['title'] return self.first['title'] != self.last['title']