Re: [Zope3-dev] Re: Ajax in Zope 3

2005-12-06 Thread Jean-Marc Orliaguet

Tarek Ziadé wrote:


Florent Guillaume wrote:

 


Tarek Ziadé wrote:

   


Hi all,

Some UI works have been done lately around and in Zope 3.  I am thinking
about the work that has been done at Neckar sprint (Zope3.org website,
Viewlets, etc..),  and on projects like CPSSkins for Z3 at ECM.

I am planning to work on UI things as well, and on Ajax things in
particular, both for Zope 2 and Zope 3 applications, and trying to
choose the right Javascript toolkit for this.

Before starting it up, I was thinking that it would be nice if the whole
Z3 community would be using the same toolkit, and maybe, even integrate
it into Z3 itself.

This would allow developers to start some js things today under Z2/Five
and port them. This would also probably lead into a Z3 way to do ajax
and javascript things.

What people think ?

If this sounds like a good Idea, I would like to start a Z3 proposal on
this topic, and contribute on its integration in Z3.

 


Myself I absolutely love the approach taken by CrackAjax
(http://www.aminus.org/blogs/index.php/phunt/2005/10/06/subway_s_new_ajax_framework)


I'm sure lots could be improved like improving python-javascript
translation, allowing for explicit javascript when really needed,
improving the testability, etc.
   



Yes it needs inprovment indeed: the problem I had with this approach at
this time is that the python written that is meant to be translated in
js via an ast engine. it makes the Python code looks like pseudo-javascript.

see in this example:
http://svn.subway.python-hosting.com/crackajax/trunk/itunes.py

the update_list() is using things like document.getElementById() and
the 'document' variable is not existing at all in python side, if i get
it right.

I was wondering in fact what was the benefit of doing it, beside having
a strong aversion of doing js coding (and that aversion can be
really improved by using toolkits like mochikit)

Tarek

 




I haven't done it yet, but I'd like to see what patterns Ruby-on-Rails, 
and other frameworks (e.g . TurboGears) are using, and why it makes such 
a difference in terms of productivity.


one of the important factors that I've noticed tend to complicate the 
code uselessly are:


* the lack of transparency when dealing with client-side and server-side 
data structures (the need to convert data back and forth)
* the need to temporary store and pass data in an artificial way 
(through URL parameters, storing temporary data in the request, inside 
javascript temporary objects)
* representing a same thing with different names, for instance there are 
in zope3 many options for naming objects:


 - using one-word strings or strings without spaces (works best in 
URLs, good as nicknames)
 - using dotted names (less ambiguous than short strings because of the 
namespace)
 - using zope interfaces (works best with z3 components, adapters, 
utilities - useless in javascript)

 - using unique ids (intids)
 - using object names inside containers
 - using interface identifiers ( IFoo.__identifier__ ) ...
 - using interface names ( IFoo.__class__.__name__ )

once you've solved these issues, the rest is much easier.

/JM
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: Ajax in Zope 3

2005-12-06 Thread Benji York

Florent Guillaume wrote:

Myself I absolutely love the approach taken by CrackAjax
(http://www.aminus.org/blogs/index.php/phunt/2005/10/06/subway_s_new_ajax_framework) 


It's funny you mention that.  I was intrigued by that too, but I can 
only characterize his implementation as a toy. :(


I've been working on something similar but have tried to be a bit more 
professional about it (unit tests, trying to be a good designer, 
etc.).  Like CrackAjax it only does translation of Python syntax to 
JavaScript, but it does a good job and I really like the ability to 
define client-side methods on the view.  Here's an example from my 
prototype (the canvas tag only works in Safari, Konquerer, and Firefox 1.5):


from anguine.view import AnguineView
from anguine.decorator import clientside
from zope.app.publisher.browser import BrowserView

class TestView1(BrowserView, AnguineView):

@clientside
def getContext():
canvas = document.getElementById('test_canvas')
return canvas.getContext('2d')

@clientside
def draw():
ctx = getContext()
ctx.translate(75,75)
for i in range(6):
ctx.save()
ctx.fillStyle = 'rgb('+(51*i)+','+(255-51*i)+',255)'
for i in range(6):
ctx.rotate(Math.PI*2/(i*6))
ctx.beginPath()
ctx.arc(0,i*12.5,5,0,Math.PI*2,true)
ctx.fill()
ctx.restore()

@clientside
def clearCanvas():
ctx = getContext()
ctx.clearRect(0, 0, 150, 150)

Here's the ZPT:

html metal:use-macro=context/@@standard_macros/view
  script
  metal:fill-slot=headers
  tal:content=structure view/_anguine__js_code/
  body metal:fill-slot=body tal:omit-tag=
br
canvas id=test_canvas width=150 height=150
style=border: 1px solid black;/canvas
button onclick=draw()Draw/button
button onclick=clearCanvas()Clear/button
  /body
/html

I consider this a mad scientist experiment, so I don't expect it to be 
officially included anywhere or even get any work from me once the 
novelty wears off.  You are warned; I don't want angry villagers with 
pitchforks and torches coming to my castle. :)

--
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com