Hedley Roos wrote:
what's the smartest/nicest way to refresh a viewlet periodically?
there is a kss-timeout-event that is periodical per default but I'm
not sure this can be done using kss...
thanks
saily
My response is a bit long. Wiring in the KSS is the easy part.
You'll need a DOM identifier (eg. some-id) in your viewlet, because you
need to know what DOM element to replace.
Example of viewlet template:
<metal:macro define-macro="comment">
<span id="some-id"></span>
</metal:macro>
Typically in trusted code you do
self.macroContent('template/macros/body', **request.form), but AFAIK
macroContent has not yet been modified to be able to do this for
viewlets. I might be wrong.
First you need to get a hold of the viewlet:
def getViewlet(context, manager_name, viewlet_name):
"""
This function is typically called from browser views
"""
manager = queryMultiAdapter(
(context.context, context.request, context),
IViewletManager,
name=manager_name)
viewlets = getAdapters(
(manager.context, manager.request, manager.__parent__, manager),
IViewlet)
target = None
for order, (name, viewlet) in enumerate(viewlets):
if name == viewlet_name:
return viewlet
return None
Then you can do viewlet = getViewlet(self, 'plone.belowcontentbody',
'myproduct.commentviewlet')
Now instead of showing you my (long) workaround for macroContent first
just try this in your KSS view:
html = self.macroContent(viewlet.render.macros['comment'])
selector = ksscore.getHtmlIdSelector('some-id')
ksscore.replaceHTML(selector, html)
If you encounter any problems post back to the list and I'll send you
some working code snippets on pastebin.
Hedley
Take a look at archetypes/kss/fields.py :
ksscore = self.getCommandSet('core')
zopecommands = self.getCommandSet('zope')
<snip>
ksscore.getHtmlIdSelector('plone-lock-status')
zopecommands.refreshViewlet(selector, 'plone.abovecontent',
'plone.lockinfo')
Should be easier.
--
Godefroid Chapelle (aka __gotcha) http://bubblenet.be
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers