All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.liftmodules.widgets.tree.TreeView.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2007-2010 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftmodules {
package widgets {
package tree {

import _root_.scala.xml._
import _root_.net.liftweb.util.Helpers._
import _root_.net.liftweb.common.{Box, Full, Empty}
import _root_.net.liftweb.http.S._
import _root_.net.liftweb.http.LiftRules
import _root_.net.liftweb.http.{LiftResponse, JsonResponse}
import _root_.net.liftweb.http.js._
import _root_.net.liftweb.http.js.jquery._
import JsCmds._
import JE._
import JqJsCmds._
import JqJE._

object TreeView {

  def apply(id: String, jsObj: JsObj) = new TreeView().onLoad(id, jsObj)
  def apply(id: String, jsObj: JsObj, loadTree : () => List[Tree], loadNode: (String) => List[Tree]) =
    new TreeView().onLoadAsync(id, jsObj, loadTree, loadNode)

  /**
   * Call this function typically in boot
   */
  def init() {
    import _root_.net.liftweb.http.ResourceServer
    ResourceServer.allow({
      case "tree" :: _ => true
    })

  }
}

class TreeView {

  /**
   * Makes a static tree out of the 
  • lists. The tree is buid when page loads. * * @param id - the id of the empty
      element that will be populated with the tree * @param jsObj - the JSON object passed to the treeview function * */ def onLoad(id: String, jsObj: JsObj) : NodeSeq = {