Hi all,
First, I'm a completely new when it comes to scala and liftweb. It is
a uni subject for this semester and coming from a C/C++ background,
lets say i'm having some difficulties understanding this.
The project i'm working on is a simplified Reddit or Digg clone. I
currently have a "LinkActor.scala" extending CometActor which has a
list of links submitted by users offering a "Vote Up" button and "Vote
Down" button options to the user. The code compiles and run, but when
i click on the vote up or down buttons, nothing happen. the console
doesn't print any requests or error messages. I tried both firefox and
chrome (developing on Ubuntu 10.04)
The Actor;
http://github.com/sayo9349/Scala_Reddit_Clone/blob/clone_with_comet/src/main/scala/com/redditclone/comet/LinkActor.scala
The Controller:
http://github.com/sayo9349/Scala_Reddit_Clone/blob/clone_with_comet/src/main/scala/com/redditclone/controller/RedditClone.scala
The code is available here;
http://github.com/sayo9349/Scala_Reddit_Clone
(feel free to download and check it out)
Thank you very much for your help guys.
cheers,
Simon
LinkActor.scala;
package com.redditclone.comet
import net.liftweb.http._
import net.liftweb.http.S._
import net.liftweb.http.SHtml._
import net.liftweb.http.js.JsCmd
import net.liftweb.http.js.JsCmds._
import net.liftweb.http.js.JE._
import net.liftweb.util.Helpers._
import net.liftweb.util._
import scala.xml.{NodeSeq,Text}
import com.redditclone.model._
import com.redditclone.controller._
import java.lang.Long
class LinkActor extends CometActor {
override def defaultPrefix = Full("linkactor")
var lnkViews: List[ReditLink] = Nil
def render = {
def lnkView(lnk: ReditLink): NodeSeq = {
val rank = lnk.rank
val voteUpButton = <button type="button">{S.?("Vote Up!")}
</button> %
("onclick" -> ajaxCall(JsRaw(
lnk.title.is), voteUp
_))
val voteDownButton = <button type="button">{S.?("Vote
Down!")}</button> %
("onclick" -> ajaxCall(JsRaw(
lnk.title.is), voteDown
_))
(<div>
<strong>Title:</strong> {lnk.title}
<br/>
<strong>Rank:</strong> {lnk.rank}
<br/>
<div>
<a href={"/reditLink/" +
lnk.title.is}
>{
lnk.title.is}</a>: by {
lnk.owner.name}
</div>
<div>
{voteUpButton} {voteDownButton}
</div>
<strong>Description:</strong> {lnk.description}<br/
><br/>
</div>)
}
bind("foo" -> <div>{lnkViews.flatMap(lnkView _)}</div>)
}
def voteUp(title:String): JsCmd = {
val user = User.currentUser.open_!
ReditClone ! VoteUp(title,user)
Noop
}
def voteDown(title:String): JsCmd = {
val user = User.currentUser.open_!
println("title: "+title)
println("user: "+user)
ReditClone ! VoteDown(title,user)
Noop
}
override def localSetup {
ReditClone !? AddListener(this) match {
case UpdateLinks => lnkViews = ReditLink.findAllLinks
case _ => println("Other ls")
}
}
override def localShutdown {
ReditClone ! RemoveListener(this)
}
override def lowPriority : PartialFunction[Any, Unit] = {
case UpdateLinks => lnkViews = ReditLink.findAllLinks;
reRender(false)
case _ => println("Other lp")
}
}