Permalink
Browse files

Adapting to latest review changes.

  • Loading branch information...
1 parent 1b208cd commit 03fa3f73641e31e63f8a87b0b03fcb2de46b68de @tuhlmann committed Nov 30, 2012
@@ -6,8 +6,6 @@ version := "1.0-SNAPSHOT"
scalaVersion := "2.9.1"
-resolvers += "Liftmodules repo" at "https://repository-liftmodules.forge.cloudbees.com/release"
-
{
val liftVersion = "2.4"
libraryDependencies ++= Seq(
@@ -17,14 +17,6 @@ import com.mongodb.MongoOptions
import com.mongodb.Mongo
import com.mongodb.DBAddress
-object BootHelpers {
-
- // A Loc function making sure only logged in users see the menu item
- val loggedIn = If(() => User.loggedIn_?, () => RedirectResponse("/user_mgt/login"))
-
-}
-
-
/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
@@ -109,3 +101,10 @@ class Boot {
}
+
+object BootHelpers {
+
+ // A Loc function making sure only logged in users see the menu item
+ val loggedIn = If(() => User.loggedIn_?, () => RedirectResponse("/user_mgt/login"))
+
+}
@@ -19,13 +19,6 @@ import code.lib.UserRest
case class DocumentInfo(docId: String)
-object BootHelpers {
-
- // A Loc function making sure only logged in users see the menu item
- val loggedIn = If(() => User.loggedIn_?, () => RedirectResponse("/user_mgt/login"))
-
-}
-
/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
@@ -129,3 +122,12 @@ class Boot {
}
}
+
+object BootHelpers {
+
+ // A Loc function making sure only logged in users see the menu item
+ val loggedIn = If(() => User.loggedIn_?, () => RedirectResponse("/user_mgt/login"))
+
+}
+
+
@@ -29,7 +29,7 @@ object AjaxExamples {
AppendHtml("ajax_example2_list", html) & FadeIn(id, 0 second, 1 second)
}
- "@name" #> ajaxText(name, s => {name = s; JqSetHtml("ajax_example2_name", Text(name))}) &
+ "@name" #> ajaxText(name, s => {name = s; SetHtml("ajax_example2_name", Text(name))}) &
"@city" #> (text(city, city = _) ++ hidden(process))
}
@@ -23,7 +23,7 @@ class ChatBrowserComponent extends CometActor with CometListener {
// listen for messages
override def lowPriority = {
- case m: Message => msgs :+= m; partialUpdate(appendMessage(m) & scrollToBottom)
+ case m: Message => msgs :+= m; partialUpdate(appendMessage(m) & ScrollToBottom())
case all: Vector[Message] => msgs = all; println("Received ALL Messages"); reRender()
}
@@ -37,14 +37,16 @@ class ChatBrowserComponent extends CometActor with CometListener {
*/
def render = {
println("CALLING RENDER")
- Script(SetHtml("chat-msg-tbody", msgs.flatMap(buildMessageHtml)) & scrollToBottom)
+ Script(SetHtml("chat-msg-tbody", msgs.flatMap(buildMessageHtml)) & ScrollToBottom())
}
/*
* Scroll down to make the last message visible
+ * Its an example how you can easily create your own JsCmds to encapsulate often used
+ * functionality.
*/
- def scrollToBottom() = {
- Run("$('#chat-msg-content').animate({scrollTop:$('#chat-msg-content')[0].scrollHeight}, 1000);")
+ case class ScrollToBottom extends JsCmd {
+ def toJsCmd = "$('#chat-msg-content').animate({scrollTop:$('#chat-msg-content')[0].scrollHeight}, 1000);"
}
}
@@ -7,28 +7,30 @@ import code.model.User
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
import net.liftweb.common.Box
+import net.liftweb.util.Helpers._
object UserRest extends RestHelper {
case class UserData(id: Long, name: String, email: String)
// This is what it looks like when you provide the full path in the case statement
serve {
+ case "api" :: "user" :: "list" :: Nil JsonGet _ if User.loggedIn_? => anyToJValue(listAllUsers)
case "api" :: "user" :: "list" :: Nil Get _ if User.loggedIn_? => anyToJValue(listAllUsers)
- case "api" :: "user" :: "list" :: id :: Nil Get _ if User.loggedIn_? => anyToJValue(listUser(id))
+ case "api" :: "user" :: "list" :: AsLong(id) :: Nil Get _ if User.loggedIn_? => anyToJValue(listUser(id))
}
// use this signature if you have multiple functions under the same URI path prefix
serve ("api2" / "user" prefix {
case "list" :: Nil Get _ if User.loggedIn_? => anyToJValue(listAllUsers)
- case "list" :: id :: Nil Get _ if User.loggedIn_? => anyToJValue(listUser(id))
+ case "list" :: AsLong(id) :: Nil Get _ if User.loggedIn_? => anyToJValue(listUser(id))
})
def listAllUsers(): List[UserData] = {
User.findAll.map{user => UserData(user.id.is, user.shortName, user.email.is)}
}
- def listUser(id: String): Box[UserData] = {
+ def listUser(id: Long): Box[UserData] = {
for (user <- User.find(id)) yield {
UserData(user.id.is, user.shortName, user.email.is)
}
@@ -25,6 +25,8 @@ object MainUserPostsPage {
class PostingUser(user: User) {
+ lazy val loc = User.listUsersMenu.toLoc
+
def listUsers = {
".back-to-users [href]" #> MainUserPostsPage.menu.loc.calcDefaultHref &
"li *" #> UserPost.findAll(By(UserPost.userId, user.id.is)).map(post =>
@@ -16,18 +16,18 @@
<p>
A template can be surrounded with a parent template, which in turn can also be surrounded. That gives you a
great way to to build a hierarchical set of templates with common parts all in one place. You do this with the line:
- <pre><code>&lt;div id="main" class="lift:surround?with=default;at=content"&gt;</code></pre>
+ <pre><code>&lt;div id="main" data-lift="surround?with=default;at=content"&gt;</code></pre>
The <code>with</code> attribute specifies the name of the parent template. Templates are found below the
"templates-hidden" directory.
In the parent template you just need to define the ID ("content" in this case) of the element that will receive the content.
</p>
<p>
You can also embed another template by using the <code>embed</code> tag:
- <pre><code>&lt;div class="l:embed?what=/examples/templates/awesome"&gt;&lt;/div&gt;</code></pre>
+ <pre><code>&lt;div data-lift="embed?what=/examples/templates/awesome"&gt;&lt;/div&gt;</code></pre>
The path to the template is relative to "templates-hidden".
</p>
- <div class="l:embed?what=/examples/templates/awesome"></div>
+ <div data-lift="embed?what=/examples/templates/awesome"></div>
<p>
We can also include a snippet programmatically. This may look a bit artificial right now. That's because it is :)
It's a constructed use case, but still, programmatic access to templates has valid reasons.
@@ -36,8 +36,8 @@
So here we define a snippet <code>EmbedTemplate</code> and we give it a parameter <code>what</code> that points
to the file to embed. Basically, we reimplement a simple version of the <code>embed</code> snippet.
</p>
- <pre><code>&lt;div class="l:EmbedTemplate?what=/examples/templates/awesome"&gt;&lt;/div&gt;</code></pre>
- <div class="l:EmbedTemplate?what=/examples/templates/awesome"></div>
+ <pre><code>&lt;div data-lift="EmbedTemplate?what=/examples/templates/awesome"&gt;&lt;/div&gt;</code></pre>
+ <div data-lift="EmbedTemplate?what=/examples/templates/awesome"></div>
</div>
@@ -5,10 +5,10 @@
<title>Home</title>
</head>
<body class="lift:content_id=main">
- <div id="main" class="lift:surround?with=default;at=content">
+ <div id="main" data-lift="surround?with=default;at=content">
<h2>Welcome to your project!</h2>
<p>
- <span class="lift:helloWorld.howdy">
+ <span data-lift="helloWorld.howdy">
Welcome to your Lift app at <span id="time">Time goes here</span>
</span>
</p>
@@ -85,11 +85,11 @@ <h1 class="alt">A Sample App<img alt="" id="ajax-loader" style="display:none; ma
<!--<span class="lift:Menu.builder"></span>
<hr class="space" >-->
- <span class="lift:Menu.builder?group=main"></span>
+ <span data-lift="Menu.builder?group=main"></span>
<hr class="space" >
- <span class="lift:Menu.builder?group=examples"></span>
+ <span data-lift="Menu.builder?group=examples"></span>
<hr class="space" >
- <span class="lift:Menu.builder?group=PostingUsers"></span>
+ <span data-lift="Menu.builder?group=PostingUsers"></span>
<div data-lift="Msgs">
<lift:error_class>errorMsg</lift:error_class>

0 comments on commit 03fa3f7

Please sign in to comment.