Robo,
The particular view I was describing returns a jsonified  dictionary that
(if all goes well) contains a form, a history table, and a messages table.
If things do not go well, it will return either a jsonified dictionary
containing either an error or a login_error depending on what went wrong.

The template for the individual forms is pretty basic as are the templates
for the history and messages tables:
form template:
{% if form %}
    <form id='deviceForm' name='Device' method="POST'
action='javascript:submitForm("deviceForm", {{ id }},  "Device")'>
    {{ form.as_p }}
    {% if editable %}
        <button>Save</button>
    {% endif %}
{% endif %}

the history table template:

<div id='logTableDiv'>
    <table id='logTable'>
        <thead><tr><th>User</th><th>Action</th><th>Date</th></tr></thead>
        <tbody>
            {$ for l in logs %}
                <tr><td>{{ l.user }}</td><td>{{ l.action }}</td><td>{{
l.datefield }}</td></tr>
            {% endfor %}
       </tbody>
    </table>
</div>

the messages table template looks exactly like the history template with
just different headers and contents

Here is the function that initiates the ajax call and evaluates the ajax
response, but remember this is YUI specific, this will not work using
mochikit, prototype, or any other javascript library:

function loadDetailData(node){
var sUrl = ("get_asset_detail/" + node.nodeId + "/" + node.nodeType + "/" +
Math.ceil(Math.random() * 500000) + "/");

//the math.random call is needed as the current version of the YIU treeview
widget uses a default mode to cache all expand calls.  I want users to be
able to see all nodes that may have been added by others during a user
session without doing a page refresh.  the view called by get_asset_detail
ignores the random number.

var callback = {
success: function(oResponse) {
    var response_obj = eval('(' + oResponse.responseText + ')');
   if (response_obj.Login_Error){
        alert('Your session has expired, please login again.');
        var authWindow = window.open("", "loginWindow");
        authWindow.document.write(response_obj.Login_error);
    }
    else{
        var detailTabl = new YAHOO.widget.TabView('tab-div');
        var myobj = response_obj.form; // Get the form html from the json
dictionary
        var tab = detailTab.getTab(0);    // Get the form tab
        tab.set("content", myobj, true);  //Put the form on the tabview
widget
        var myobj = response_obj.log; //get the history table html from the
json dictionary
        var tab = detailTab.getTab(1);    //Get the history tab
        tab.set("content", myobj, true);  //Put the history table on the
tabview widget
        buildLogTable();  //call the function that turns the raw html table
into a YUI datatable
        }
    }
    failure: function(oResponse) {
        alert("Failed to process XHR transaction.",
    },
    argument: {
        "node": node, // This is the treeview node that is passed into the
function to initiate the async request
    },
    timeout: 7000
};

YAHOO.util.Connect.asyncRequest('GET', sUrl, callback):
}


Let me know if you need any clarification on any point.
-richard


On 9/18/07, robo <[EMAIL PROTECTED]> wrote:
>
>
> Hi Richard,
>
> I think I got the idea of your view. What I'd like to see is an
> example of your template and javascript to see how you are accessing
> the json data.
>
> Thanks a lot,
>
> robo
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to