Hi list (again).

  I'm using AjaxGrid Widget to show some information, but refresh_url
can spend more than 2 seconds to return information. I want to show
some "Loading...." (can be replaced by an animated clock gif in the
future) message while wating.
  I'm getting some problems while trying it. First I tried to put the
message on template. And it works fine, but only when we're loading
the grid first time. When we push refresh_link we loose loading
message. Then I tried to use the same method AjaxGrid alredy use ...
swapDOM. So I rerwite AjaxGrid.refresh method but now AjaxGrid stops
working and I have JS errors "Erro: dest has no properties
Arquivo-fonte: http://localhost:8080/tg_widgets/turbogears/js/MochiKit.js
Linha: 2928"
  I don't know how to solve it... or how to reach this objective in
other ways. I just know I'm a JavaScript/Mochikit stupid yet, and I
need help!

  My code....

--- controllers.py ---
from turbogears import controllers, expose
from turbogears import identity, redirect
from cherrypy import request, response
import logging
log = logging.getLogger("ttg10.controllers")

from turbogears.widgets import DataGrid, AjaxGrid, JSLink, JSSource
from turbogears.widgets.base import register_static_directory, mochikit
from turbogears.widgets.base import static as widget_static
import pkg_resources
import os

pkg_path = pkg_resources.resource_filename('ttg10',
os.path.join("static", "javascript"))
register_static_directory("myajaxgrid.javascript", pkg_path)

class MyAjaxGrid(AjaxGrid):
    template = """<div id='${id}' xmlns:py='http://purl.org/kid/ns#'>
    <input py:if='refresh_text'
           type='button'
           value='${refresh_text}'
           onclick='javascript:${id}_AjaxGrid.refresh(${defaults});return
false;'
    />
    <div id='${id}_update'>Loading...</div>
    <script type='text/javascript'>
        addLoadEvent(partial(${id}_AjaxGrid.refresh, ${defaults}));
    </script>
    </div>
    """
    def __init__(self, refresh_url, *args, **kw):
        super(MyAjaxGrid, self).__init__(refresh_url,
                                         *args,
                                         **kw)
        target = "%s_update" % self.id
        self.javascript = [
            mochikit,
            JSLink("turbogears", "js/widget.js"),
            JSLink(widget_static, "ajaxgrid.js"),
            JSLink('myajaxgrid.javascript', 'myajaxgrid.js'),
            JSSource("""
                %(id)s_AjaxGrid = new AjaxGrid('%(refresh_url)s', '%(target)s');
            """ % dict(id=self.id, refresh_url=refresh_url, target=target)
            ),
        ]


dg = MyAjaxGrid(name = "UserList",
                refresh_url = "/updateMethod",
                refresh_text = "Update")

class Root(controllers.RootController):
    @expose(template="ttg10.templates.welcome")
    def index(self):
        return dict(userList = dg)

    @expose(format="json")
    def updateMethodt(self):
        import time

        time.sleep(2.0)
        userList = ["user1","user2","user3","user4"]
        userList.sort()

        headers = [_("Users")]
        rows = userList

        return dict(headers = headers,
                    rows = rows,
                    actions = {'remove':{'function':'removerow',
                                         'params':[]},
                               'edit': {'function':'editrow',
                                        'params':[]}})
--- cut ---

--- myajaxgrid.js ---
AjaxGrid.prototype.refresh = function(params) {
    /***

    Refresh the target DOM with new data from the server

    @param params: extra args to append to the request.
        Example:
            {'sort':'desc', 'offset'=20}

    @rtype: L{Deferred} returning the evaluated JSON response.

    ***/

    swapDOM(this.target_id, SPAN(null,
                                 BR(null),
                                 "Loading..."));
    params = eval(params);
    params['tg_random'] = new Date().getTime();
    params['tg_format'] = "json";
    var d = loadJSONDoc(this.refresh_url, params);
    d.addCallback(this.updateGrid);
    return e;
}
--- cut ---

  Any Idea?

  Regards!

-- 
 - Ulysses Almeida

--~--~---------~--~----~------------~-------~--~----~
 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to