Skip to content

Commit

Permalink
Content deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 28, 2011
1 parent a5cf377 commit 999b1bc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 289 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import _root_.net.liftweb.mapper.{DB, Schemifier, DefaultConnectionIdentifier, S

import tools.colladoc.api.ExportService
import tools.colladoc.lib.sitemap._
import tools.colladoc.model.mapper.{User, Comment, Content, Properties, Discussion}
import tools.colladoc.model.mapper.{User, Comment, Properties, Discussion}
import tools.colladoc.lib.js.JqUI._
import tools.colladoc.api.{GridAPI, RestAPI}
import tools.colladoc.lib.openid.ColladocOpenIDVendor
Expand All @@ -61,7 +61,7 @@ class Boot {

// where to search snippet
LiftRules.addToPackages("scala.tools.colladoc")
Schemifier.schemify(true, Schemifier.infoF _, User, Comment, Content, Properties, Discussion)
Schemifier.schemify(true, Schemifier.infoF _, User, Comment, Properties, Discussion)

ColladocBoot.boot

Expand Down
91 changes: 0 additions & 91 deletions src/main/scala/scala/tools/colladoc/model/mapper/Content.scala

This file was deleted.

199 changes: 3 additions & 196 deletions src/main/scala/scala/tools/colladoc/page/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import lib.js.JqUI._
import lib.widgets.Editor
import model.Model
import model.Model.factory._
import model.mapper.{Discussion, Comment, Content, User}
import model.mapper.{Discussion, Comment, User}

import net.liftweb.common._
import net.liftweb.http.{S, SHtml}
Expand All @@ -42,7 +42,7 @@ import net.liftweb.mapper._
import net.liftweb.util.Helpers._

import tools.nsc.doc.model._
import xml.{Elem, NodeSeq, Text}
import xml.{NodeSeq, Text}
import lib.DependencyFactory._
import tools.nsc.util.NoPosition
import net.liftweb.widgets.gravatar.Gravatar
Expand Down Expand Up @@ -109,8 +109,6 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
}
</div>

{ content }

{ if (User.loggedIn_?) discussion }

{ if (constructors.isEmpty) NodeSeq.Empty else
Expand Down Expand Up @@ -347,197 +345,6 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
private def updateDiscussionComment(d: Discussion)(text: String) {
d.comment(text).save
}

/** Render content block. */
private def content: NodeSeq =
<div id="content">
<h3 id="content_header">Content ({contentCommentsCount})</h3>
<div id="content_wrapper">
<ul id="content_thread">
{contentComments map (d => contentToHtmlWithActions(d))}
</ul>
{
if (User.loggedIn_? && !User.banned_?)
contentCommentAddButton
else
contentCommentAddButtonForAnonymous
}
</div>
</div>

/** Get content comments for current template. */
private def contentComments = Content.findAll(
By(Content.qualifiedName, tpl.qualifiedName),
By(Content.valid, true),
OrderBy(Content.dateTime, Ascending))

/** Get content comments count for current template. */
private def contentCommentsCount = contentComments.length

/** Render content comment. */
def contentToHtml(c: Content) =
<li id={"content_comment_" + c.id} class="content_comment">
<div class="content_avatar">{Gravatar(c.authorEmail, 20)}</div>
<div class="content_content">{bodyToHtml(parseWiki(c.comment.is, NoPosition))}</div>
<div class="content_info">
<span class="datetime" title={c.atomDateTime}>{c.humanDateTime}</span>
by
<span class="author">{c.authorProfileHyperlink}</span>
<content_comment:link />
<div class="content_comment_actions">
<content_comment:edit />
<content_comment:delete />
</div>
</div>
</li>

/** Render content comment with actions. */
private def contentToHtmlWithActions(d: Content) = bind("content_comment", contentToHtml(d),
"edit" -> {if (User.validSuperUser_?) { editContentButton(d) } else NodeSeq.Empty},
"delete" -> {if (User.validSuperUser_?) { deleteContentButton(d) } else NodeSeq.Empty}
)

/** Render add comment button. */
private def contentCommentAddButton = {
SHtml.ajaxButton(Text("Add comment"), contentEditor(None) _, ("class", "button"), ("id", "add_content_button"))
}

/** Render add comment button. */
private def contentCommentAddButtonForAnonymous = {
SHtml.ajaxButton(Text("Add comment"), () => contentEditorForAnonymous, ("class", "button"), ("id", "add_content_button"))
}

/** Render editor. */
private def contentEditor(maybe: Option[Content] = None)(): JsCmd = {
maybe match {
case Some(d) =>
Editor.editorObj(d.comment.is, preview _, updateContentComment(d) _) match {
case (n, j) =>
Replace("content_comment_" + d.id,
<form id={"edit_form_" + d.id} class="edit" method="GET">
<div class="editor">
{ n }
<div class="buttons">
{ SHtml.ajaxButton(Text("Save"), () => SHtml.submitAjaxForm("edit_form_" + d.id, () => reloadContent)) }
{ SHtml.a(Text("Cancel"),
Replace("edit_form_" + d.id,
contentToHtmlWithActions(d)) &
PrettyDate &
Jq(Str("button")) ~> Button(),
("class", "button"))
}
</div>
</div>
</form>) & j & Jq(Str("button")) ~> Button()
case _ => JsCmds.Noop
}
case None =>
Editor.editorObj("", preview _, saveContentComment _) match {
case (n, j) =>
Replace("add_content_button",
<form id="content_form" class="edit" method="GET">
<div class="editor">
{ n }
<div class="buttons">
{ SHtml.ajaxButton(Text("Save"), () => SHtml.submitAjaxForm("content_form", () => reloadContent)) }
{ SHtml.a(Text("Cancel"),
Replace("content_form", contentCommentAddButton) &
PrettyDate &
Jq(Str("button")) ~> Button(),
("class", "button"))
}
</div>
</div>
</form>) & j & Jq(Str("button")) ~> Button()
case _ => JsCmds.Noop
}
}
}

/** Reload content block after new comment adding. */
private def reloadContent = Replace("content", content) &
JsRaw("$('#content_wrapper').toggle();") &
PrettyDate &
Jq(Str("button")) ~> Button()

/** Save content comment to database. */
private def saveContentComment(text: String) {
Content.create.qualifiedName(tpl.qualifiedName).comment(text).dateTime(now).user(User.currentUser.open_!).valid(true).save
}

def contentEditorForAnonymous: JsCmd = {
var name, email, text = ""

def form(n: Elem) =
<lift:form class="edit content_form" method="GET">
<fieldset>
<div>
<label for="name">Name</label>
{
SHtml.text(name, (s: String) => {name = s},
("id", "name"),
("class", "text required ui-widget-content ui-corner-all"))
}
</div>
<div>
<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"))
}
</div>
<div class="editor">
<label>Comment
{ n }
</label>
<div class="buttons">
<content:save />
{
SHtml.a(Text("Cancel"),
reloadContent,
("class", "button"))
}
</div>
</div>
<content:submit />
</fieldset>
</lift:form>

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

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

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

/** Render delete button for content comment. */
def deleteContentButton(d: Content) = SHtml.a(
ColladocConfirm("Confirm delete"), () => {d.valid(false).save; reloadContent}, Text("Delete"))

/** Render delete button for content comment. */
def editContentButton(d: Content) = SHtml.a(contentEditor(Some(d)) _, Text("Edit"))

/** Update content comment record in database. */
private def updateContentComment(d: Content)(text: String) {
d.comment(text).save
}

override def memberToHtml(mbr: MemberEntity): NodeSeq =
super.memberToHtml(mbr) \% Map("data-istype" -> (mbr.isAbstractType || mbr.isAliasType).toString)
Expand Down Expand Up @@ -813,4 +620,4 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
}
}
}
}
}

0 comments on commit 999b1bc

Please sign in to comment.