Skip to content

Commit

Permalink
category are displayed according to field anonymousPost
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Aug 10, 2011
1 parent 7a878a7 commit 0614f9f
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class Discussion extends LongKeyedMapper[Discussion] with IdPK {
/** Change date and time. */
object dateTime extends MappedDateTime(this)

/**Changed comment user name email if author is null. */
object name extends MappedString(this, 255)

/**Changed comment email if author is null. */
object email extends MappedEmail(this, 255)

/** Whether this change is still valid. */
object valid extends MappedBoolean(this) {
override def defaultValue = true
Expand All @@ -63,19 +69,19 @@ class Discussion extends LongKeyedMapper[Discussion] with IdPK {
/** Get change author's username. */
def userName: String = User.find(user.is) match {
case Full(u) => u.userName
case _ => ""
case _ => name.is
}

/** Link to user's profile. */
def authorProfileHyperlink = User.find(user.is) match {
case Full(u) => u.profileHyperlink
case _ => NodeSeq.Empty
case _ => <span>{name.is}</span>
}

/** Author's email. */
def authorEmail = User.find(user.is) match {
case Full(u) => u.email.is
case _ => ""
case _ => email.is
}

/** Get change author's username and date. */
Expand Down
71 changes: 69 additions & 2 deletions src/main/scala/scala/tools/colladoc/page/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import net.liftweb.mapper._
import net.liftweb.util.Helpers._

import tools.nsc.doc.model._
import xml.{NodeSeq, Text}
import lib.DependencyFactory._
import tools.nsc.util.NoPosition
import net.liftweb.widgets.gravatar.Gravatar
import xml.{Elem, NodeSeq, Text}

/**
* Page containing template entity documentation and user controls.
Expand Down Expand Up @@ -223,7 +223,9 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
d => discussionToHtmlWithActions(d, 0) }
}
</ul>
{ if (!User.banned_?) discussionCommentAddButton(c) }
{ if (!User.banned_?) discussionCommentAddButton(c)
else if (c.anonymousPost.is) discussionCommentAddButtonForAnonymous(c)
}
</div>
</div>

Expand Down Expand Up @@ -277,6 +279,11 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
SHtml.ajaxButton(Text("Add comment"), discussionEditor(category, None) _, ("class", "button"), ("id", id(category.name.is + "add_discussion_button")))
}

/** Render add comment button. */
private def discussionCommentAddButtonForAnonymous(category: Category) = {
SHtml.ajaxButton(Text("Add comment"), () => editorForAnonymous(category), ("class", "button"), ("id", id(category.name.is + "anonymous_add_content_button")))
}

/** Render editor. */
private def discussionEditor(category: Category, maybe: Option[Discussion] = None)(): JsCmd = {
maybe match {
Expand Down Expand Up @@ -324,6 +331,66 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
}
}

def editorForAnonymous(category: Category): JsCmd = {
var name, email, text = ""

def form(n: Elem) =
<lift:form class="edit anonymous_comment_form" method="GET">
<fieldset>
<p>
<label for="name">Name</label>
{
SHtml.text(name, (s: String) => {name = s},
("id", "name"),
("class", "text required ui-widget-content ui-corner-all"))
}
</p>
<p>
<label for="content_anonymous_email">Email</label>
{
SHtml.email(email, (s: String) => {email = s},
("id", "content_anonymous_email"),
("class", "email required ui-widget-content ui-corner-all"))
}
</p>
<p class="editor">
<label>Comment
{ n }
</label>
<div class="buttons">
<content:save />
{
SHtml.a(Text("Cancel"), reloadDiscussion(category))
}
</div>
</p>
<content:submit />
</fieldset>
</lift:form>

def bindedForm(n: Elem) = bind("content", form(n),
"submit" -> SHtml.hidden(() => saveContentWithEmail(category, text, name, email)),
"save" -> SHtml.a(Text("Save"), SubmitFormWithValidation(".anonymous_comment_form"), ("class", "button"))
)

Editor.editorObj("", preview _, text = _) match {
case (n, j) =>
Replace(id(category.name.is + "anonymous_add_content_button"), bindedForm(n)) & j & Jq(Str(".button")) ~> Button()
case _ => JsCmds.Noop
}
}

def saveContentWithEmail(category: Category, text: String, name: String, email: String) = {
val d = Discussion.create.category(category).qualifiedName(tpl.qualifiedName).comment(text).dateTime(now).name(name).email(email).valid(true)
d.validate match {
case Nil =>
d.save
case n =>
S.error(n)
}
reloadDiscussion(category)
}

/** Reload discussion block after new comment adding. */
private def reloadDiscussion(category: Category) =
Replace(id(category.name.is), categoryToHtml(category)) &
Expand Down
34 changes: 34 additions & 0 deletions src/main/webapp/cotemplate.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,37 @@ background-color: #E5E5E5;
.discussion_comment_actions > a:hover {
text-decoration: underline;
}

.anonymous_comment_form {
width: 400px;
}

.anonymous_comment_form label {
display: block;
font-weight: bold;
}

.anonymous_comment_form input {
/*width: 95%;*/
padding: .4em;
}

label.error {
color: #555555;
font-weight: normal;
font-size: 90%;
}

.anonymous_comment_form fieldset {
padding: 0;
border: 0;
margin-top: 8px;
}

.anonymous_comment_form p {
margin-bottom: 12px;
}

span.ui-button-text {
font-weight: normal;
}

0 comments on commit 0614f9f

Please sign in to comment.