Permalink
Browse files

initial checking

  • Loading branch information...
0 parents commit 76808b63cf2a37e69f87613a4c9b5e0f90eb983b @adamw committed Jan 13, 2010
162 pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.liftworkshop</groupId>
+ <artifactId>ajax-submit-test</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>war</packaging>
+ <name>ajax-submit-test Project</name>
+ <inceptionYear>2010</inceptionYear>
+ <properties>
+ <scala.version>2.7.7</scala.version>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>scala-tools.releases</id>
+ <name>Scala-Tools Maven2 Repository for Releases</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ <repository>
+ <id>scala-tools.snapshots</id>
+ <name>Scala-Tools Maven2 Repository for Snapshots</name>
+ <url>http://scala-tools.org/repo-snapshots</url>
+ <snapshots/>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>net.liftweb</groupId>
+ <artifactId>lift-mapper</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.121</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-tools.testing</groupId>
+ <artifactId>specs</artifactId>
+ <version>1.6.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>[6.1.6,7.0)</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- for LiftConsole -->
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-compiler</artifactId>
+ <version>${scala.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.13.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.22</version>
+ <configuration>
+ <contextPath>/</contextPath>
+ <scanIntervalSeconds>5</scanIntervalSeconds>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>net.sf.alchim</groupId>
+ <artifactId>yuicompressor-maven-plugin</artifactId>
+ <version>0.7.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compress</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <nosuffix>true</nosuffix>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-idea-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.7</version>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ <additionalProjectnatures>
+ <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
+ </additionalProjectnatures>
+ <additionalBuildcommands>
+ <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
+ </additionalBuildcommands>
+ <classpathContainers>
+ <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ </classpathContainers>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.13.1</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
No changes.
@@ -0,0 +1,70 @@
+package bootstrap.liftweb
+
+import _root_.net.liftweb.util._
+import _root_.net.liftweb.common._
+import _root_.net.liftweb.http._
+import _root_.net.liftweb.http.provider._
+import _root_.net.liftweb.sitemap._
+import _root_.net.liftweb.sitemap.Loc._
+import Helpers._
+import _root_.net.liftweb.mapper.{DB, ConnectionManager, Schemifier, DefaultConnectionIdentifier, StandardDBVendor}
+import _root_.java.sql.{Connection, DriverManager}
+import _root_.com.liftworkshop.model._
+
+
+/**
+ * A class that's instantiated early and run. It allows the application
+ * to modify lift's environment
+ */
+class Boot {
+ def boot {
+ if (!DB.jndiJdbcConnAvailable_?) {
+ val vendor =
+ new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
+ Props.get("db.url") openOr
+ "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
+ Props.get("db.user"), Props.get("db.password"))
+
+ LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
+
+ DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
+ }
+
+ // where to search snippet
+ LiftRules.addToPackages("com.liftworkshop")
+ Schemifier.schemify(true, Log.infoF _, User)
+
+ // Build SiteMap
+ val entries = Menu(Loc("Home", List("index"), "Home")) ::
+ Menu(Loc("Static", Link(List("static"), true, "/static/index"),
+ "Static Content")) ::
+ User.sitemap
+
+ LiftRules.setSiteMap(SiteMap(entries:_*))
+
+ /*
+ * Show the spinny image when an Ajax call starts
+ */
+ LiftRules.ajaxStart =
+ Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
+
+ /*
+ * Make the spinny image go away when it ends
+ */
+ LiftRules.ajaxEnd =
+ Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
+
+ LiftRules.early.append(makeUtf8)
+
+ LiftRules.loggedInTest = Full(() => User.loggedIn_?)
+
+ S.addAround(DB.buildLoanWrapper)
+ }
+
+ /**
+ * Force the request to be UTF-8
+ */
+ private def makeUtf8(req: HTTPRequest) {
+ req.setCharacterEncoding("UTF-8")
+ }
+}
No changes.
@@ -0,0 +1,54 @@
+package com.liftworkshop.lib
+
+import net.liftweb._
+import http._
+import util._
+import common._
+import _root_.java.util.Date
+
+/**
+ * A factory for generating new instances of Date. You can create
+ * factories for each kind of thing you want to vend in your application.
+ * An example is a payment gateway. You can change the default implementation,
+ * or override the default implementation on a session, request or current call
+ * stack basis.
+ */
+object DependencyFactory extends Factory {
+ implicit object time extends FactoryMaker(Helpers.now _)
+
+ /**
+ * objects in Scala are lazily created. The init()
+ * method creates a List of all the objects. This
+ * results in all the objects getting initialized and
+ * registering their types with the dependency injector
+ */
+ private def init() {
+ List(time)
+ }
+ init()
+}
+
+/*
+/**
+ * Examples of changing the implementation
+ */
+sealed abstract class Changer {
+ def changeDefaultImplementation() {
+ DependencyFactory.time.default.set(() => new Date())
+ }
+
+ def changeSessionImplementation() {
+ DependencyFactory.time.session.set(() => new Date())
+ }
+
+ def changeRequestImplementation() {
+ DependencyFactory.time.request.set(() => new Date())
+ }
+
+ def changeJustForCall(d: Date) {
+ DependencyFactory.time.doWith(d) {
+ // perform some calculations here
+ }
+ }
+}
+*/
@@ -0,0 +1,34 @@
+package com.liftworkshop.model
+
+import _root_.net.liftweb.mapper._
+import _root_.net.liftweb.util._
+import _root_.net.liftweb.common._
+
+/**
+ * The singleton that has methods for accessing the database
+ */
+object User extends User with MetaMegaProtoUser[User] {
+ override def dbTableName = "users" // define the DB table name
+ override def screenWrap = Full(<lift:surround with="default" at="content">
+ <lift:bind /></lift:surround>)
+ // define the order fields will appear in forms and output
+ override def fieldOrder = List(id, firstName, lastName, email,
+ locale, timezone, password, textArea)
+
+ // comment this line out to require email validations
+ override def skipEmailValidation = true
+}
+
+/**
+ * An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it
+ */
+class User extends MegaProtoUser[User] {
+ def getSingleton = User // what's the "meta" server
+
+ // define an additional field for a personal essay
+ object textArea extends MappedTextarea(this, 2048) {
+ override def textareaRows = 10
+ override def textareaCols = 50
+ override def displayName = "Personal Essay"
+ }
+}
@@ -0,0 +1,61 @@
+package com.liftworkshop.snippet
+
+import _root_.net.liftweb.util._
+import _root_.net.liftweb.common._
+import _root_.java.util.Date
+import com.liftworkshop.lib._
+import Helpers._
+import net.liftweb.http.js.JsCmds.SetHtml
+import net.liftweb.http.js.JsCmd
+import xml.{Elem, NodeSeq, Text}
+import net.liftweb.http.js.JE.{JsRaw, Str}
+import collection.mutable.{ListBuffer, Buffer}
+import net.liftweb.http.{S, RequestVar, SHtml, LiftRules}
+import S._
+import SHtml._
+
+object CurrentContainer extends RequestVar({ new Container })
+
+class HelloWorld {
+ def edit(containerTemplate: NodeSeq): NodeSeq = {
+ val cont = CurrentContainer.is
+
+ def reDraw = SetHtml("cont_edit", edit(containerTemplate))
+
+ def editRoom(roomTemplate: NodeSeq): NodeSeq = {
+ cont.rooms.flatMap { room: Room =>
+ bind("room", roomTemplate,
+ "name" -> { println("bind room name " + room.name); SHtml.text(room.name,
+ (s: String) => {println("set room name " + s); room.name = s; }) }
+ )
+ }
+ }
+
+ bind("cont", containerTemplate,
+ "name" -> { println("bind container name " + cont.name); SHtml.text(cont.name,
+ (s: String) => {println("set container name " + s); cont.name = s; }) },
+ "rooms" -> editRoom _,
+ "addRoom" -> ajaxButton(Text("Add"), "cont_edit",
+ () => { println("executing funtion"); cont.rooms += new Room; reDraw })
+ )
+ }
+
+ def ajaxButton(text: NodeSeq, formId: String, func: () => JsCmd,
+ attrs: (String, String)*): Elem = {
+ attrs.foldLeft(fmapFunc(contextFuncBuilder(func))(name =>
+ <button onclick={makeAjaxCall(JsRaw(
+ LiftRules.jsArtifacts.serialize(formId).toJsCmd + " + " + Str("&" + name + "=true").toJsCmd)).toJsCmd +
+ "; return false;"}>{text}</button>))(_ % _)
+ }
+}
+
+class Container {
+ var name: String = ""
+ var rooms = new ListBuffer[Room]
+}
+
+class Room {
+ var name: String = ""
+}
+
+
No changes.
Oops, something went wrong.

0 comments on commit 76808b6

Please sign in to comment.