Sure.

jDiv1 = Customer Detail/Form
jDiv2 = Invoice List
jDiv3 = Invoice Detail/Invoice Form

The above jDiv's are partials that are re-used in a number of
different views. jDiv2 is not always used in a view where jDiv3 is
used for example.

One of the views does use all of the above jDivs. In this view the
user may:

A. View/Edit the Customer Detail. This is accomplished using an edit
link with onclick="editCustomer()". editCustomer() calls jDivLoad for
jDiv1, providing the URL to the customer form request handler, thus
replacing the customer detail view with the customer edit form. Upon
submitting the form, jDiv1 is reloaded with the customer detail view,
showing any changes. While the reload can be accomplished by doing a
redirect to the customer detail after form accept, this is not the
behavior always required when this form is used within a jDiv. To
ensure the form can be re-used, I need to either pass additional
parameters to the customer form request handler and take the
appropriate action there after form submit based on what view the form
is being used in, or I can keep the form handler generic, and instead,
using javascript in the view that uses the form, call jDivLoad with
the appropriate URL after successful form submit.

B. When view is first loaded and invoice list jDiv2 is populated, the
first invoice is selected and shown in jDiv3. I could have jDiv2's
request handler force a load of jDiv3 with the first item in the list,
but this means jDiv2 must know about jDiv3 in jDiv2's request handler.
This is not always how jDiv2 is used in a view. Better solution is to
simply use jquery after jDiv2 is loaded, to select the first <a> in
the invoice list, set it's class to "selected" so that CSS can
highlight it, and then call jDivLoad with the appropriate URL to load
jDiv3. This makes sense as I would re-use that same javascript code
for the onclick event of each invoice item in the list, allowing the
user to select an invoice in the list, highlight it and see it
displayed in jDiv3.

C. Like the customer form, the invoice detail can be edited. When the
user chooses to edit, jDiv3 is reloaded with the form view. When the
form is submitted, jDiv3 is reloaded with the detail view. Again, the
invoice form is not always used in this manner (redirecting back to
the detail view), so it does not make sense to code this behavior in
the request handler for the invoice form. It makes more sense to call
jDivLoad as a result of clicking the edit link from a javascript
function in the view and display the form. Then once the form is
submitted, callback to a javascript function that does a jDivLoad to
reload the invoice detail for display.

So what I'm trying to illustrate in a very long winded way, is that
while there is a way to accomplish the three actions listed above by
using redirection and setting the trigger command for the jDiv in the
request handler, it means that I would have to have code in the
request handlers for each of the different use cases of the jDivs. It
would be preferable to keep the jDiv's generic and not dependent on
one another, and instead use javascript in the view to dictate how the
jDiv's behave with one another.

Which leads me finally, to my previous suggestion:

My understanding is that currently, the only way to have a javascript
function called upon completion of a jDivLoad is to specify that
function by using jDiv.set in the request handler of the URL being
loaded. To keep jDiv's loosely coupled from one another and thus more
re-useable, it would be preferable to have the option to also set the
completion callback when jDivLoad is being called directly from
javascript within the view. Currently jDivLoad only accepts target,
url and params as parameters. It then sets up the beforeSend, success
and complete options of the jquery .ajax call that is used to load the
URL for the jDiv.

Since jDivLoad is encapsulating the behavior of the jQuery .ajax call,
you cannot specify callbacks for beforeSend, success, or complete,
which you would normally use when using jquery .ajax. Ideally, if
jDivLoad extended the behavior of the jQuery .ajax by introducing its
custom behavior, but still allowed you to specify the callbacks, you
would have the option of controlling interaction of the jDivs with one
another completely through javascript without involving the request
handlers.

I hope I've explained this well enough.

Ted

On May 4, 6:37 pm, mdipierro <[email protected]> wrote:
> Can you provide an example? I am not sure this cannot be done already.
>
> On May 4, 4:28 pm, Ted G <[email protected]> wrote:
>
> > A bit more follow up on this topic of taking action after an ajax load
> > call on the jDiv.
>
> > Right now the jDivLoad function in the provided web2py_ajax.html makes
> > the assumption that the command to be evaluated on completion of the
> > load will be provided by the web2py host application. As mentioned in
> > my other response to Wes, while I feel this is definitely a valuable
> > option for those who wish to control the flow of the client from the
> > host, in more complex apps where there is re-use of partials among web
> > pages, it may be preferable to control the flow of the client via
> > javascript in the client itself in order to have a looser coupling
> > between jDiv's.
>
> > Also, there are many cases where the function you wish to call upon
> > loading a jDiv is something other than the default provided by
> > jDivLoad (like auto selecting the first item in a list of items for
> > showing in another jDiv). Right now, this can be specified by jDiv.set
> > ('command') on the host side prior to completing the request handler,
> > but, again, this requires that my request handler have knowledge of
> > the function in the view that will be called.
>
> > Since jDivLoad is wrapping up the jquery .ajax call for the
> > implementation of the load, can we have jDivLoad also accept
> > parameters for the jQuery .ajax beforeSend, success and complete
> > options and evaluate those commands along with the custom commands
> > that might be passed back from the host in the response? This would
> > allow the client more options for sophisticated behavior.
>
> > Ted
>
> > On May 1, 3:59 pm, Wes James <[email protected]> wrote:
>
> > > Right now with my time tracker i have:
>
> > > FormjDiv
> > > HoursjDiv
> > > Last20itemsjDiv
>
> > > When I submit FormjDiv it goes away (the lower part of the jDiv), but it
> > > refreshes HoursjDiv on the callback.  At the end of the code for 
> > > HoursjDiv i
> > > have it trigger FormjDiv to open it up again with a new form (like click 
> > > the
> > > first top button) and also to refresh contents in Last20itemsjDiv.
>
> > > There's probably a better way to do this, but this works for now.
>
> > > -wj
>
> > > On Fri, May 1, 2009 at 4:52 PM, Ted G <[email protected]> wrote:
>
> > > > On a related note:
>
> > > > What is the best way to trigger a Javascript function upon a jDiv load
> > > > or form submit within a jDiv? For example:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to