--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
They all would be great additions to Lift imho, some small comments below:
On Fri, Apr 6, 2012 at 5:44 PM, Antonio Salazar Cardozo
<savedf...@gmail.com> wrote:
> There are a variety things in the OpenStudy toolbox that I'd love to move
> into Lift as I have time, but I wanted some feedback on a few of them:
>
> - We currently have a submitFormToIframe function that makes it so an ajax
> form with a file upload component can upload via “ajax” transparently to the
> developer and the user. I'd like to move that into liftAjax.js and, ideally,
> have some code that will automatically convert any generated forms with an
> input type file into iframed, fully functional ajax forms from a developer's
> perspective. Is this something people would like to see in Lift?
More and more often people ask how to do an ajax upload in Lift, so
having a builtin way would be great.
>As a user
> of the framework, my goal would be to make this completely transparent*.
> - Add a LiftRules.noCometSessionCmd for handling server reloads. This would
> be an extension of LiftRules.noCometSessionPage that would default to using
> noCometSessionPage for a redirect, but could be overridable to produce an
> arbitrary JsCmd. That seems the best way to go for backwards compatibility,
> though it makes me nervous that if you changed noCometSessionCmd,
> noCometSessionPage would be ignored. Thoughts?
I would think that if someone changes noCometSessionCmd, it is because
they know about it, so ignoring noCometSessionPage would be ok. Maybe
adding a warning on the api doc on both method would help too.
> - Potentially make it so that setting LiftRules.noCometSessionPage/Cmd
> would automatically turn off LiftRules.redirectAjaxOnSessionLoss, or
> something of the sort. It seems counterintuitive on its face (though not so
> with a deeper understanding of the internals) that redirectAjaxOnSessionLoss
> has to be turned off for noCometSession* to take effect. Definitely looking
> for some feedback on that front. Notably, it may be enough to make it so
> that redirectAjaxOnSessionLoss only matters if you're doing an ajax request.
> I think right now both ajax and comet requests pay attention to that
> setting, and if we made comet requests ignore it we may be able to mitigate
> the issue without any further complications.
From the outside (as in I haven;t looked at redirectAjaxOnSessionLoss
yet), separating it makes sense. I wonder if there is any benefit in
having noCometSessionPage changed but keep redirectAjaxOnSessionLoss
as true.
> - The addition of an xhr_? function to Req. This would return true iff the
> request has an X-Requested-With header equal to XMLHttpRequest (most
> client-side frameworks set this on all ajax requests). We've used this in
> the past to include/exclude layouts based on whether a page was requested
> via ajax or not. Maybe ajax_? would be a better name?
I'm ok with either name, but we do use ajax* on several places in Lift.
> - Equivalents for SHtml inputs that just provide a name for various types
> of fields. We use this in conjunction with knockout.js to bind input names
> client-side for Lift form management sent via JSON instead of as pure HTML.
> We have nameForStringField((s:String) => handler),
> nameForFileUploadField((fph:FileParamHolder) => handler), and
> nameForSubmitButton(() => JsCmd return). This may be one of those things
> that is better provided alongside Lift rather than as part of Lift proper,
> but I wanted to hear what people thought about it.
Sounds interesting but I don't fully follow what it does, does it
change the way Lift generates names for forms?
>
> So, thoughts, feedback, things you definitely think shouldn't be in there?
I think you should add them all :) !
Thanks
Diego
> Let me know!
> Thanks,
> Antonio
>
> * - notably, I don't intend on including any progress indicator stuff. I
> just want ajax forms that have file upload components to behave exactly the
> same as those that have no such components with no further developer effort.
>
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com
It might be nice to avoid the iframe and use the JavaScript FormData API when present (seems to work in Safari, Chrome, Firefox, haven't tried IE)
http://hacks.mozilla.org/2010/05/formdata-interface-coming-to-firefox/
http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#interface-formdata
> - Equivalents for SHtml inputs that just provide a name for various types of fields. We use this in conjunction with knockout.js to bind input names client-side for Lift form management sent via JSON instead of as pure HTML. We have nameForStringField((s:String) => handler), nameForFileUploadField((fph:FileParamHolder) => handler), and nameForSubmitButton(() => JsCmd return). This may be one of those things that is better provided alongside Lift rather than as part of Lift proper, but I wanted to hear what people thought about it.
I agree this would be nice. Maybe instead of returning a string return an object like
trait FormElement {
def name: String
def html: NodeSeq
}
Hi Antonio,They all would be great additions to Lift imho, some small comments below:
On Fri, Apr 6, 2012 at 5:44 PM, Antonio Salazar Cardozo
<savedf...@gmail.com> wrote:
> - Add a LiftRules.noCometSessionCmd for handling server reloads. This would
> be an extension of LiftRules.noCometSessionPage that would default to using
> noCometSessionPage for a redirect, but could be overridable to produce an
> arbitrary JsCmd. That seems the best way to go for backwards compatibility,
> though it makes me nervous that if you changed noCometSessionCmd,
> noCometSessionPage would be ignored. Thoughts?I would think that if someone changes noCometSessionCmd, it is because
they know about it, so ignoring noCometSessionPage would be ok. Maybe
adding a warning on the api doc on both method would help too.
> - Potentially make it so that setting LiftRules.noCometSessionPage/Cmd
> would automatically turn off LiftRules.redirectAjaxOnSessionLoss, or
> something of the sort. It seems counterintuitive on its face (though not so
> with a deeper understanding of the internals) that redirectAjaxOnSessionLoss
> has to be turned off for noCometSession* to take effect. Definitely looking
> for some feedback on that front. Notably, it may be enough to make it so
> that redirectAjaxOnSessionLoss only matters if you're doing an ajax request.
> I think right now both ajax and comet requests pay attention to that
> setting, and if we made comet requests ignore it we may be able to mitigate
> the issue without any further complications.From the outside (as in I haven;t looked at redirectAjaxOnSessionLoss
yet), separating it makes sense. I wonder if there is any benefit in
having noCometSessionPage changed but keep redirectAjaxOnSessionLoss
as true.
> - The addition of an xhr_? function to Req. This would return true iff the
> request has an X-Requested-With header equal to XMLHttpRequest (most
> client-side frameworks set this on all ajax requests). We've used this in
> the past to include/exclude layouts based on whether a page was requested
> via ajax or not. Maybe ajax_? would be a better name?I'm ok with either name, but we do use ajax* on several places in Lift.
> - Equivalents for SHtml inputs that just provide a name for various types
> of fields. We use this in conjunction with knockout.js to bind input names
> client-side for Lift form management sent via JSON instead of as pure HTML.
> We have nameForStringField((s:String) => handler),
> nameForFileUploadField((fph:FileParamHolder) => handler), and
> nameForSubmitButton(() => JsCmd return). This may be one of those things
> that is better provided alongside Lift rather than as part of Lift proper,
> but I wanted to hear what people thought about it.Sounds interesting but I don't fully follow what it does, does it
change the way Lift generates names for forms?
> So, thoughts, feedback, things you definitely think shouldn't be in there?
I think you should add them all :) !
> - We currently have a submitFormToIframe function that makes it so an ajax form with a file upload component can upload via “ajax” transparently to the developer and the user. I'd like to move that into liftAjax.js and, ideally, have some code that will automatically convert any generated forms with an input type file into iframed, fully functional ajax forms from a developer's perspective. Is this something people would like to see in Lift? As a user of the framework, my goal would be to make this completely transparent*.It might be nice to avoid the iframe and use the JavaScript FormData API when present (seems to work in Safari, Chrome, Firefox, haven't tried IE)
http://hacks.mozilla.org/2010/05/formdata-interface-coming-to-firefox/
http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#interface-formdata
> - Equivalents for SHtml inputs that just provide a name for various types of fields. We use this in conjunction with knockout.js to bind input names client-side for Lift form management sent via JSON instead of as pure HTML. We have nameForStringField((s:String) => handler), nameForFileUploadField((fph:FileParamHolder) => handler), and nameForSubmitButton(() => JsCmd return). This may be one of those things that is better provided alongside Lift rather than as part of Lift proper, but I wanted to hear what people thought about it.
I agree this would be nice. Maybe instead of returning a string return an object like
trait FormElement {
def name: String
def html: NodeSeq
}
Thanks,Antonio
Definitely an interesting thought. I guess the only downside is we'd be generating NodeSeqs even in cases where they're completely unnecessary, but it would reduce the number of functions for doing these things.
Maybe this one is worth breaking out into its own, possibly larger, discussion come Monday when more people can give feedback?
On Apr 7, 2012, at 5:00 PM, Antonio Salazar Cardozo wrote:Definitely an interesting thought. I guess the only downside is we'd be generating NodeSeqs even in cases where they're completely unnecessary, but it would reduce the number of functions for doing these things.No I don't think you would :) As long as it's a method on the trait it won't do any computations unless you ask for the html.. right?Maybe this one is worth breaking out into its own, possibly larger, discussion come Monday when more people can give feedback?I think that's a good idea yeah :)
So, this is something I just recently did on a side project I am/was
working. Reading that this is still a common issue, I question if I
did something dumb. The code is at
http://code.google.com/p/commuters-connect/source/browse/web/src/main/scala/com/commutersconnect/snippet/NewReport.scala.
The only twist I had to do in putting this on an ajax form, was I had
to change the "action" of the form such that it hit the rest service I
exposed instead of being javascript://. Am I messing something up in
that strategy? Only place I've found that this doesn't work right off
is on older android devices. Works on the newer ones just fine.
-josh
Apologies, I shouldn't have indicated I didn't have those things.
More that I lucked up and got David's example ajax test working inside
a lift:form.ajax with very little trouble. The jquery file upload
plugin is doing most of the heavy lifting, I believe. I just had to
change the action of the form to be a rest service returning what it
(the file upload plugin) is expecting. The rest of the form works as
expected.
That make since? I certainly still have a few spots that have been
ignored. In particular, I have not written something that will cause
any uploaded files to expire when the form expires. I was thinking I
could just use a weak hashmap for that, so that when the form is
collected, they could be as well.
Yeah, looking back I'm not sure what I was trying to say, honestly.
It just sounded like folks have had trouble getting file uploads
working in a lift:form.ajax and I wasn't sure if there was a bullet
heading my way or not. I see on the wiki there is special effort made
at making the entire form submit over an iframe, whereas I was able to
let the jquery plugin handle that. Looking at the wiki more, I am
guessing that I could have gotten away from writing a REST service
method for the uploads if I had followed the wiki? (My first google
for this showed up the example David put together, so I had the REST
part written before I realized you couldn't have more of a form around
it. I fiddled with changing the action on my own, as that was so
quick, before seeing the rest of the wiki.)