[Lift] Re: Snippets creating snippets with embedded 'attributes'

2009-07-17 Thread Jonathan Meeks

Thanks for the tips, Naftoli and David.

On Jul 17, 10:46 am, David Pollak 
wrote:
> On Fri, Jul 17, 2009 at 7:30 AM, Jonathan Meeks 
> wrote:
>
>
>
> > I don't see how it would help. How would the SHtml.hidden callback,
> > presumably defined deleteFileForm snippet method, know the filename?
> > That value somehow needs to be passed from the fileManager method to
> > the deleteFileForm.
>
> > I was hoping that the a snippet tag could take attributes where I
> > could pass this data through, instead of writing the hidden input
> > explicitly.
>
> def fileManager(xhtml : NodeSeq) : NodeSeq = {
>    
>    {
>      for(file <- fileList(folderName))
>        yield
>          
>            {file.getName}
>            
>              
>                 {s.submit("delete", () => doFileDelete(file.getName))}
>              
>            
>          
>    }
>    
>  }
>
> No need to do more.  The current value of the file instance will be
> preserved on the callback.
>
>
>
>
>
> > On Jul 17, 12:38 am, Naftoli Gugenheim  wrote:
> > > Why don't you use a SHtml.hidden with a callback?
>
> > > -
>
> > > Jonathan Meeks wrote:
>
> > > I have a snippet (call it the "file manager" snippet) that creates a
> > > list of snippet tags (each called "file deletion" snippets) to create
> > > a virtual file listing with a deletion form next to each of the file
> > > names.
>
> > > These "file deletion" snippet methods need to somehow know their
> > > corresponding file names so that the submit binding can delete the
> > > correct file.
>
> > > I accomplished it with something like the code at the bottom of this
> > > message.
>
> > > The general solution was to create the "file deletion" snippet tags
> > > with a hidden input that contains the file name. The "file deletion"
> > > snippet method, in turn, extracts the value out of the NodeSeq.
>
> > > It works but seems inelegant. Is there a preferred method to do this?
> > > Any feedback is welcome.
>
> > > Regards,
>
> > > Jonathan
>
> > > def fileManager(xhtml : NodeSeq) : NodeSeq = {
> > >     
> > >     {
> > >       for(file <- fileList(folderName))
> > >         yield
> > >           
> > >             {file.getName}
> > >             
> > >               
> > >                  > > value={file.getName}/>
> > >                 
> > >               
> > >             
> > >           
> > >     }
> > >     
> > >   }
>
> > > def extractHiddenInputValue(name: String, xhtml: NodeSeq) : String = {
> > >     (xhtml \\ "input").filter(_ \ "@type" == "hidden").filter(_ \
> > > "@value" != "").find(_ \ "@name" == name) match {
> > >       case Some(node) => (node \ "@value").toString
> > >       case _ => null
> > >     }
> > >   }
>
> > > def deleteFileForm(xhtml : NodeSeq) : NodeSeq = {
> > >     def deleteFile() = {
> > >       val fileToDelete = extractHiddenInputValue
> > > (fileKeyHiddenFieldName, xhtml)
> > > ...
> > >     }
>
> > >     bind("deleteFile", xhtml,
> > >       "submit" -> SHtml.submit ("delete", deleteFile))
> > >   }
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Git some:http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---



[Lift] Re: Snippets creating snippets with embedded 'attributes'

2009-07-17 Thread Jonathan Meeks

I don't see how it would help. How would the SHtml.hidden callback,
presumably defined deleteFileForm snippet method, know the filename?
That value somehow needs to be passed from the fileManager method to
the deleteFileForm.

I was hoping that the a snippet tag could take attributes where I
could pass this data through, instead of writing the hidden input
explicitly.

On Jul 17, 12:38 am, Naftoli Gugenheim  wrote:
> Why don't you use a SHtml.hidden with a callback?
>
> -----
>
> Jonathan Meeks wrote:
>
> I have a snippet (call it the "file manager" snippet) that creates a
> list of snippet tags (each called "file deletion" snippets) to create
> a virtual file listing with a deletion form next to each of the file
> names.
>
> These "file deletion" snippet methods need to somehow know their
> corresponding file names so that the submit binding can delete the
> correct file.
>
> I accomplished it with something like the code at the bottom of this
> message.
>
> The general solution was to create the "file deletion" snippet tags
> with a hidden input that contains the file name. The "file deletion"
> snippet method, in turn, extracts the value out of the NodeSeq.
>
> It works but seems inelegant. Is there a preferred method to do this?
> Any feedback is welcome.
>
> Regards,
>
> Jonathan
>
> def fileManager(xhtml : NodeSeq) : NodeSeq = {
>     
>     {
>       for(file <- fileList(folderName))
>         yield
>           
>             {file.getName}
>             
>               
>                  value={file.getName}/>
>                 
>               
>             
>           
>     }
>     
>   }
>
> def extractHiddenInputValue(name: String, xhtml: NodeSeq) : String = {
>     (xhtml \\ "input").filter(_ \ "@type" == "hidden").filter(_ \
> "@value" != "").find(_ \ "@name" == name) match {
>       case Some(node) => (node \ "@value").toString
>       case _ => null
>     }
>   }
>
> def deleteFileForm(xhtml : NodeSeq) : NodeSeq = {
>     def deleteFile() = {
>       val fileToDelete = extractHiddenInputValue
> (fileKeyHiddenFieldName, xhtml)
> ...
>     }
>
>     bind("deleteFile", xhtml,
>       "submit" -> SHtml.submit ("delete", deleteFile))
>   }

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---



[Lift] Snippets creating snippets with embedded 'attributes'

2009-07-16 Thread Jonathan Meeks

I have a snippet (call it the "file manager" snippet) that creates a
list of snippet tags (each called "file deletion" snippets) to create
a virtual file listing with a deletion form next to each of the file
names.

These "file deletion" snippet methods need to somehow know their
corresponding file names so that the submit binding can delete the
correct file.

I accomplished it with something like the code at the bottom of this
message.

The general solution was to create the "file deletion" snippet tags
with a hidden input that contains the file name. The "file deletion"
snippet method, in turn, extracts the value out of the NodeSeq.

It works but seems inelegant. Is there a preferred method to do this?
Any feedback is welcome.

Regards,

Jonathan

def fileManager(xhtml : NodeSeq) : NodeSeq = {

{
  for(file <- fileList(folderName))
yield
  
{file.getName}

  


  

  
}

  }

def extractHiddenInputValue(name: String, xhtml: NodeSeq) : String = {
(xhtml \\ "input").filter(_ \ "@type" == "hidden").filter(_ \
"@value" != "").find(_ \ "@name" == name) match {
  case Some(node) => (node \ "@value").toString
  case _ => null
}
  }

def deleteFileForm(xhtml : NodeSeq) : NodeSeq = {
def deleteFile() = {
  val fileToDelete = extractHiddenInputValue
(fileKeyHiddenFieldName, xhtml)
...
}

bind("deleteFile", xhtml,
  "submit" -> SHtml.submit ("delete", deleteFile))
  }

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---



[Lift] Re: multiSelectObj

2009-06-10 Thread Jonathan Meeks

Here's what I came up with. It seems to work.

I don't know how well it will appear inlined in a posting. Let if you
want it delivered in another fashion.

diff --git a/lift/src/main/scala/net/liftweb/http/SHtml.scala b/lift/
src/main/scala/net/liftweb/http/SHtml.scala
index 22c4832..58e6069 100644
--- a/lift/src/main/scala/net/liftweb/http/SHtml.scala
+++ b/lift/src/main/scala/net/liftweb/http/SHtml.scala
@@ -430,13 +430,28 @@ object SHtml {
   private[http] def secureOptions[T](options: Seq[(T, String)],
default: Box[T],
  onSubmit: T => Unit): (Seq
[(String, String)], Box[String], AFuncHolder) = {
 val secure = options.map{case (obj, txt) => (obj, randomString
(20), txt)}
-val defaultNonce = default.flatMap(d => secure.find(_._1 == d).map
(_._2))
+val defaultNonce = default.map(secureDefaultNonce(secure, _))
 val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)}
 def process(nonce: String): Unit =
 secure.find(_._2 == nonce).map(x => onSubmit(x._1))
 (nonces, defaultNonce, SFuncHolder(process))
   }

+  private[http] def secureOptions[T](options: Seq[(T, String)],
default: Seq[T],
+ onSubmit: T => Any): (Seq
[(String, String)], Seq[String], LFuncHolder) = {
+val secure = options.map{case (obj, txt) => (obj, randomString
(20), txt)}
+val defaultNonce = default.map(secureDefaultNonce(secure, _))
+val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)}
+def process(nonces: List[String]): Any =
+nonces.map(nonce => secure.find(_._2 == nonce).map(x => onSubmit
(x._1)))
+(nonces, defaultNonce, LFuncHolder(process))
+  }
+
+  private def secureDefaultNonce[T](secureOptions: Seq[(T, String,
String)], default: T): String = {
+secureOptions.find(_._1 == default).get._2
+  }
+
+
   /**
* Create a select box based on the list with a default value and
the function to be executed on
* form submission
@@ -518,6 +533,22 @@ object SHtml {
   func: List[String] => Any, attrs: (String, String)
*): Elem =
   multiSelect_*(opts, deflt, LFuncHolder(func), attrs :_*)

+  /**
+   * Create a select box based on the list with a default value and
the function
+   * to be executed on form submission
+   *
+   * @param options  -- a list of value and text pairs (value, text
to display)
+   * @param default  -- the default value (or Empty if no default
value)
+   * @param onSubmit -- the function to execute on form submission
+   */
+  def multiSelectObj[T](options: Seq[(T, String)], default: Seq[T],
+   onSubmit: T => Unit, attrs: (String, String)*):
Elem = {
+val (nonces, defaultNonce, secureOnSubmit) =
+secureOptions(options, default, onSubmit)
+
+multiSelect_*(nonces, defaultNonce, secureOnSubmit, attrs:_*)
+  }
+
   def multiSelect_*(opts: Seq[(String, String)],
 deflt: Seq[String],
 func: AFuncHolder, attrs: (String, String)*):
Elem =


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---



[Lift] Re: multiSelectObj

2009-06-10 Thread Jonathan Meeks

I was actually going to volunteer to add one. I'd learn something as
I'm new to Lift and Scala.

You'd probably be able to do it faster, but if you wanted to see what
I came up with and give feedback I'd be most appreciative.

--Jonathan

On Jun 10, 6:05 pm, David Pollak 
wrote:
> On Wed, Jun 10, 2009 at 1:56 PM, Jonathan Meeks 
> wrote:
>
>
>
> > While looking at SHtml.selectObj (correponding to select), I noticed
> > there is no multiSelectObj -- only multiSelect. Is there any
> > particular reason for this? Would it make sense to add one?
>
> No good reason... I'll add one.
>
>
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Git some:http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---



[Lift] multiSelectObj

2009-06-10 Thread Jonathan Meeks

While looking at SHtml.selectObj (correponding to select), I noticed
there is no multiSelectObj -- only multiSelect. Is there any
particular reason for this? Would it make sense to add one?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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=en
-~--~~~~--~~--~--~---