Skip to content

Commit

Permalink
#107 closed: "Add delete button for categories"
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Aug 3, 2011
1 parent 1ad68d8 commit 5653418
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object Category extends Category with LongKeyedMetaMapper[Category] {
override def dbTableName = "categories"

/** Get all categories with non empty names. */
def all = findAll filter { c => c.name.is.trim.length > 0 }
def all = findAll filter { c => c.valid.is && c.name.is.trim.length > 0 }

def get(d: Discussion) = Category.find(d.category).open_!
}
26 changes: 17 additions & 9 deletions src/main/scala/scala/tools/colladoc/model/mapper/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import js.JsCmds._
import net.liftweb.util.Helpers._
import net.liftweb.http.SHtml.ElemAttr._
import xml.{NodeSeq, Text}
import lib.js.JqUI.{SubmitFormWithValidation, SubmitForm, OpenDialog}
import lib.js.JqUI._

/**
* Mapper for user table storing registered users.
Expand Down Expand Up @@ -281,9 +281,15 @@ object User extends User with KeyedMetaMapper[Long, User] {
var name = ""

def doSave(): JsCmd = {
Category.create.name(name).save
S.notice("Category " + name + " successfully created.")
Replace("categories_table", categoriesList)
Category.find(By(Category.name, name)) match {
case Full(c) =>
S.notice("Category " + name + " already exists.")
Noop
case _ =>
Category.create.name(name).save
S.notice("Category " + name + " successfully created.")
Replace("categories_table", categoriesList) & Jq(Str(".button")) ~> Button()
}
}

def categoryToHtml(c: Category) =
Expand Down Expand Up @@ -318,23 +324,25 @@ object User extends User with KeyedMetaMapper[Long, User] {
</td>
<td>
{
SHtml.ajaxCheckbox(
c.valid,
bool => { c.valid(bool).save; Noop }
SHtml.a(
ColladocConfirm("Confirm delete"),
() => { c.valid(false).save; Replace("categories_table", categoriesList) & Jq(Str(".button")) ~> Button() },
Text("Delete"),
("class", "button")
)
}
</td>
</tr>

def categoriesList =
def categoriesList: NodeSeq =
<div id="categories_table">
<h3>Categories list</h3>
<table>
<tr>
<th>Name</th>
<th>Anonymous viewable</th>
<th>Anonymous postable</th>
<th>Valid</th>
<th></th>
</tr>
{ Category.all map categoryToHtml _ }
</table>
Expand Down

0 comments on commit 5653418

Please sign in to comment.