Archive for March, 2010

Fun with liftweb and jquery dialogs

Here’s a sample of jquery-ui (version 1.8) dialogs in lift,
the code (a little ugly) can be found here : http://github.com/jgoday/liftweb-jquery-dialogs-sample

The sample has two main classes

  • 1: JQueryDialog

    Allow create generic dialogs from templates or with explicit content
    We can create a dialog like this :

    
    new JQueryDialog(<div>Dialog content</div>) {
        override def elementId = "dialog_id"
        override def options = "modal:true" ::
                               "title:'dialog title!'" ::
                               "open: function (event, ui) {alert('dialog is opening!');}" ::
                                super.options
    }
    
    
  • 2: FormDialog
    To create generic dialogs from templates and with default actions (close)

    
    val item = new Item
    def _template: NodeSeq = bind("item",
                TemplateFinder.findAnyTemplate("templates-hidden/item" :: Nil) openOr
                                               <div>{"Cannot find template"}</div>,
                "name" -> item.name.toForm)
    
    val dialog = new FormDialog(true) {
        override def getFormContent = _template
        override def confirmDialog: NodeSeq = SHtml.ajaxSubmit("save",
                () => {println(item);this.closeCmd}) ++ super.confirmDialog
    }