Hedley Roos schrieb:
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
Thanks for that, but i've a working viewlet refreshing after a click,
blur, [whatever] action.
But is there a possibility to refresh it every minute?
Sure i could set up a jquery-setInterval-based solution - but i asked
for the nicest way to do this.
BTW: Use refreshViewlet instead of deprecated macroContent. See:
http://dev.plone.org/plone/ticket/7879
saily
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers