I'm also in the process of learning how to use widgets with AJAX, and I 
really liked your example here.  Although I would really like to put the 
"getStuff" function inside the widget code instead of the controller, do 
anyone know if this is possible, and if so, how?

Kaan wrote:
> I recently went through the process of learning a couple of these
> things, too, so here is what helped me out, given that the
> documentation is a bit scattered right now.
>
> For the widgets, the single thing that helped me out the most was to
> look at the widget descriptions in the code. These are in the source
> code usually right next to the widgets themselves. It used to be easy
> to do this in IPython using 'widgetnameDesc??' but for whatever reason
> the Descriptions aren't showing up in the autocomplete right now. You
> can take a look at the source in the trac at
> http://trac.turbogears.org/turbogears/browser/tags/0.9a6/turbogears/widgets
> and look at the {widgetname}Desc class right after the actual widget
> class. In the class it should show putting the widget together and
> sometimes it will have a template variable showing how it appears in
> the kid template. The latter isn't needed, anyways, since it's almost
> always just widgetinstance.display() anyways.
>
> As for the mochikit stuff, the DOM manipulation was pretty
> straightforward for me and MochiKit has pretty good documentation. The
> async stuff, however, was unnecessarily confusing to me for awhile. The
> mochikit documentation wasn't very specific for, obviously, and Brian
> Beck's tutorial did some very weird and complex stuff that I didn't
> understand. I eventually found out how incredibly easy it is to do that
> kind of stuff from the TurboTunes tutorial, which was otherwise
> overwhelming as a lot of other stuff is going on in there. This is
> pretty much what you need to know:
>
> In the template, you have the element calling the javascript function:
> <blah blah onclick="niftyAJAX()" />
>
> Then you have the javascript function:
> function niftyAJAX() {              #Standard function stuff
> var e = loadJSON('getStuff') ;  #More on this later
> e.addCallback(doAJAX) ;  }      #The function to call afterwards
>
> Since you said you use twisted, you probably understand the addCallback
> stuff but it's pretty much the javascript function to call after it
> gets a response from the controller. The loadJSON does the request for
> you on the getStuff url, much like a GET request, and it is an
> extremely useful function. I'm not sure why Brian Beck had all those
> extra functions in his tutorial, since this one line seems to do the
> same thing. Anyways, hopefully you have a getStuff method in your
> controllers.py:
>
> @expose(format="json", allow_json=True)
> def getStuff(self)
>     return dict(stuff=stuff)
>
> The dictionary gets passed to the doAJAX javascript function you
> specified in your callback from before and then you do whatever.
>
> function doAJAX(results) {    #results contains the response info
> var whatever = results.stuff ; #from the dict you passed above!
> blah blah DOM stuff blah blah ;
> }
>
> And that's it! Once I understood this it was easy to follow along with
> the rest of the TurboTunes example, which also doubles as a more real
> world example of how this stuff is used. Also, this is all from my
> limited understanding of the process so pay special attention to anyone
> who may correct this post.
>
> Hope this helps!
> -Kaan
>
> X-Google-Language: ENGLISH,ASCII-7-bit
> Received: by 10.11.53.63 with SMTP id b63mr135785cwa;
>         Mon, 22 May 2006 13:57:55 -0700 (PDT)
> X-Google-Token: -uZCrgwAAABEdXMtRpm7l3lw1FblGfFh
> Received: from 63.229.31.12 by i39g2000cwa.googlegroups.com with HTTP;
>       Mon, 22 May 2006 20:57:55 +0000 (UTC)
> From: "Kaan" <[EMAIL PROTECTED]>
> To: "TurboGears" <[email protected]>
> Subject: Re: Widgets For Beginers Request
> Date: Mon, 22 May 2006 13:57:55 -0700
> Message-ID: <[EMAIL PROTECTED]>
> In-Reply-To: <[EMAIL PROTECTED]>
> References: <[EMAIL PROTECTED]>
> User-Agent: G2/0.2
> X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.3) 
> Gecko/20060504 Fedora/1.5.0.3-1.1.fc5 Firefox/1.5.0.3 
> pango-text,gzip(gfe),gzip(gfe)
> Mime-Version: 1.0
> Content-Type: text/plain
>
> I recently went through the process of learning a couple of these
> things, too, so here is what helped me out, given that the
> documentation is a bit scattered right now.
>
> For the widgets, the single thing that helped me out the most was to
> look at the widget descriptions in the code. These are in the source
> code usually right next to the widgets themselves. It used to be easy
> to do this in IPython using 'widgetnameDesc??' but for whatever reason
> the Descriptions aren't showing up in the autocomplete right now. You
> can take a look at the source in the trac at
> http://trac.turbogears.org/turbogears/browser/tags/0.9a6/turbogears/widgets
> and look at the {widgetname}Desc class right after the actual widget
> class. In the class it should show putting the widget together and
> sometimes it will have a template variable showing how it appears in
> the kid template. The latter isn't needed, anyways, since it's almost
> always just widgetinstance.display() anyways.
>
> As for the mochikit stuff, the DOM manipulation was pretty
> straightforward for me and MochiKit has pretty good documentation. The
> async stuff, however, was unnecessarily confusing to me for awhile. The
> mochikit documentation wasn't very specific for, obviously, and Brian
> Beck's tutorial did some very weird and complex stuff that I didn't
> understand. I eventually found out how incredibly easy it is to do that
> kind of stuff from the TurboTunes tutorial, which was otherwise
> overwhelming as a lot of other stuff is going on in there. This is
> pretty much what you need to know:
>
> In the template, you have the element calling the javascript function:
> <blah blah onclick="niftyAJAX()" />
>
> Then you have the javascript function:
> function niftyAJAX() {              #Standard function stuff
> var e = loadJSON('getStuff') ;  #More on this later
> e.addCallback(doAJAX) ;  }      #The function to call afterwards
>
> Since you said you use twisted, you probably understand the addCallback
> stuff but it's pretty much the javascript function to call after it
> gets a response from the controller. The loadJSON does the request for
> you on the getStuff url, much like a GET request, and it is an
> extremely useful function. I'm not sure why Brian Beck had all those
> extra functions in his tutorial, since this one line seems to do the
> same thing. Anyways, hopefully you have a getStuff method in your
> controllers.py:
>
> @expose(format="json", allow_json=True)
> def getStuff(self)
>     return dict(stuff=stuff)
>
> The dictionary gets passed to the doAJAX javascript function you
> specified in your callback from before and then you do whatever.
>
> function doAJAX(results) {    #results contains the response info
> var whatever = results.stuff ; #from the dict you passed above!
> blah blah DOM stuff blah blah ;
> }
>
> And that's it! Once I understood this it was easy to follow along with
> the rest of the TurboTunes example, which also doubles as a more real
> world example of how this stuff is used. Also, this is all from my
> limited understanding of the process so pay special attention to anyone
> who may correct this post.
>
> Hope this helps!
> -Kaan
>
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to