Thanks for the feedback Jeppe. I can't completely infer the context of 
your example, but I get the idea (and I hadn't known about 
TemplateFinder). Here's what I've hacked together so far.

In my normal snippet, I have a render loop that binds orders to template 
names. One of the bind points looks like this:

..
"label" -> SHtml.a(viewOrder _, Text("View")),
..

Here, viewOrder is a function called by ajax, so a () => JsCmd. I've 
defined it as follows (assume i've imported TemplateFinder.findAnyTemplate):

def viewOrder(): JsCmd = {
   SetHtml("order", SHtml.ajaxForm(
     bind("order", findAnyTemplate(List("orders/_edit_order")).open_!,
       "orderNo" -> Text(order.orderNo),
       "submit" -> SHtml.submit("submit", () => println(" -- submit!"))
     ) ++ SHtml.hidden(() => println(" -- submit!"))
   ))
}

Using the usual ajaxForm technique, I wrap the result of a bind which 
results in the contents passed to SetHtml. The funny part is that I 
directly load a template file as a NodeSeq and use that as the arg to 
bind. That template file doesn't call a snippet, but it uses the bind 
points bound in the call - and it works! Here's the full _edit_order.html:

<div>
   <order:orderNo/>
   <order:submit/>
</div>

It's just raw xml. No snippet calls, yet bind still processes it 
correctly - even the ajax wiring! I think this is all in all a pretty 
good way to handle the common-edit-dialog problem, and certainly the 
cleanest I've seen yet. I wonder though, is it intentional that bind 
points work when not explicitly wrapped in a snippet call tag?

thanks!

chris

Jeppe Nejsum Madsen wrote:
> 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=.
> 
> 
> 

--

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