Chris Lewis <burningodzi...@gmail.com> writes:

> Classic use case: a user chooses to view/edit and object by clicking on 
> a link. This causes the app to fetch an edit view (form) and render it 
> asynchronously, probably rendering it as a modal dialog. To specify the 
> case a bit more, consider a table of like objects that allows you to 
> edit them (orders or accounts). As far as the user experience, clicking 
> edit for one would yield the same edit form as any other - only the 
> contents (the target of the edit) would change.

Seems you're a few steps ahead of me. I'll be looking at basically the same
use case soon :-)

> Normal ajax forms in lift are simple - just wrap the bind in an ajax 
> form (http://is.gd/4Z61Z) and you get an async submit with essentially 
> the same template code.
>
> But what about ajax forms delivered by ajax? What's the best way to 
> implement this in lift? It seems like there are two routes: client and 
> server-based.

Agreed

> 1) In the client-based approach, I can declare an invisible form in the 
> template, as well as write some static javascript to do the heavy 
> lifting (no pun intended). This JS would be responsible for receiving 
> the data representing the object to edit from the server as json, 
> unpacking it into the form for editing, rendering the form, handling the 
> submit as ajax, and finally hiding the form.
>
> This means writing a good bit more JS by hand, but it keeps the 
> (compiled) snippet code smaller. Ordinarily I'd see that as good, but 
> more and more snippets seem like they are intended for such heavy view 
> meddling.

Probably depends on the app. If it's mostly a single-url, js based app
this would work. Personally (and since I'm not a JS ninja :-) I try to
limit the amount of client side code to the where it makes sense. I
think the development experience (for me) is better with a statically
typed languagne (tdd etc).

> 2) The server-based approach would require very little of the main 
> template: basically just a containing element (w/ dom id) to host the 
> delivered form. The snippet itself would yield a form on an ajax call 
> via SetHtml. It would also have to set up the handlers and populate the 
> form contents with the target object.
>
> This is the part that I'm not clear on. I know I can just inline the XML 
> with bind points as if it were in a form, but that just feels strange. 
> Would it make more sense to use an external template, similar to a rails 
> partial? Is there a template loading facility for this?

I've been doing this (external templates) and it works great. Very easy
for designers to modify layout etc.

Here's a simple example the changes several page elements when a select
is changed:

 bind("select", in, 
             "type" -> ajaxSelectObj(reportTypes, currentType.is,
                        (f:ResultF) => {
                          currentResult(Empty)
                          currentType(Full(f))
                          val nodeseq = 
TemplateFinder.findAnyTemplate(List("tender", "results")).open_!
                          SetHtml("comparison", resultComparison(tender, 
chooseTemplate("lift", "tender.result_comparison", nodeseq))) &
                          SetHtml("summary", segmentSummary(tender, 
chooseTemplate("lift", "tender.segment_summary", nodeseq)))
                          })
        )

Here the two elements are read from the same template file but it could
easily be split...

/Jeppe

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=.


Reply via email to