Skip to content

Commit

Permalink
#112 closed: "Add profile tab to user profiles"
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Aug 3, 2011
1 parent a6f52c1 commit a09e337
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/scala/tools/colladoc/model/mapper/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class User extends ProtoUser[User] with OneToMany[Long, User] {
override def defaultValue = false
}

object info extends MappedText(this) {
override def defaultValue = ""
}

def userNameDisplayName = S.??("user.name")

def deleted_? = deleted.is == true
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/scala/tools/colladoc/page/Profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ class Profile(rootPack: Package) extends scala.tools.colladoc.page.Template(root
<div id="profile_tabs">
<ul>
<li><a href="#profile_tab">Public Profile</a></li>
<li><a href="#info_tab">Profile</a></li>
<li id="account_href"><a href="#account_admin_tab">Account Admin</a></li>
<li><a href="#comments_tab">Comments</a></li>
<li id="discussion_href"><a href="#discussion_comments_tab">Discussions</a></li>
</ul>
<div id="profile_tab">
<profile:form />
</div>
<div id="info_tab">
<profile:info />
</div>
<div id="account_admin_tab">
<profile:change_password />
<profile:delete_profile />
Expand Down
55 changes: 52 additions & 3 deletions src/main/scala/scala/tools/colladoc/snippet/ProfileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@
package scala.tools.colladoc
package snippet

import model.Model.factory._
import model.mapper.{Discussion,Comment, User}
import lib.DependencyFactory._
import xml.{NodeSeq, Text}
import net.liftweb.util.BindHelpers._
import net.liftweb.http.{SHtml, S, RequestVar}
import net.liftweb.mapper.{Ascending, By, OrderBy}
import lib.js.JqUI.{ColladocConfirm, SubmitFormWithValidation}
import net.liftweb.http.js.JsCmds.{Noop, RedirectTo, SetValById}
import net.liftweb.http.js.JE.{Str, JsRaw, AnonFunc}
import net.liftweb.http.js.JE.Str
import page.{Template, History, Profile}
import net.liftweb.common.Full
import net.liftweb.http.js.{JsCmds, JsCommands, JsCmd}
import net.liftweb.http.js.{JsCmds, JsCmd}
import tools.nsc.util.NoPosition
import lib.widgets.Editor
import net.liftweb.http.js.jquery.JqJE.Jq
import lib.js.JqUI.Button
import net.liftweb.http.js.JsCmds._

/**
* User profile snippet.
Expand Down Expand Up @@ -144,6 +149,49 @@ class ProfileOps {
</lift:form>
}

def info(user: User): NodeSeq = {
<div id="public_info">
<div id="info_render">
{ profile.bodyToHtml(parseWiki(user.info.is, NoPosition)) }
</div>
{ if (!public_?) {
SHtml.a(editor(user) _, Text("Edit"), ("class", "button"), ("id", "edit_info_button"))
} }
</div>
}

def editor(user: User)(): JsCmd = Editor.editorObj(user.info.is, preview _, user.info(_).save) match {
case (n, j) =>
Replace("public_info",
<form id="public_info" class="edit" method="GET">
<div class="editor">
{ n }
<div class="buttons">
{ SHtml.ajaxButton(Text("Save"),
() => SHtml.submitAjaxForm("public_info",
() => Replace("public_info", info(user)) & Jq(Str(".button")) ~> Button())) }
{ SHtml.a(Text("Cancel"),
Replace("public_info", info(user)) & Jq(Str(".button")) ~> Button(),
("class", "button")) }
</div>
</div>
</form>) & j & Jq(Str("button")) ~> Button()
case _ => JsCmds.Noop
}

private def preview(text: String) =
<html>
<head>
<link href="/lib/template.css" media="screen" type="text/css" rel="stylesheet" />
<link href="/copreview.css" media="screen" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="preview">
{ profile.bodyToHtml(parseWiki(text, NoPosition)) }
</div>
</body>
</html>

def changePasswordForm(user: User) = {
var oldPass, newPass, confirm: String = ""

Expand Down Expand Up @@ -289,6 +337,7 @@ class ProfileOps {
bind("profile",
profile.body,
"form" -> { if (!public_?) userForm(user) else publicProfile(user) },
"info" -> info(user),
"change_password" -> { if (!public_?) changePasswordForm(user) else NodeSeq.Empty },
"delete_profile" -> { if (!public_?) deleteProfile(user) else NodeSeq.Empty },
"superuser" -> { if (User.validSuperUser_?) superuser(user) else NodeSeq.Empty },
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/coprofile.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@

#available_wrapper > label {
font-weight: bold;
}

#edit_info_button {
margin-top: 8px;
}
4 changes: 4 additions & 0 deletions src/main/webapp/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
<script src="/scripts/coprofile.js" type="text/javascript"/>
<script src="/scripts/cohistory.js" type="text/javascript" />
<script src="/scripts/jquery.prettydate.js" type="text/javascript" />
<script src="/scripts/markitup/jquery.markitup.js" type="text/javascript" />
<script src="/scripts/markitup/jquery.markitup.set.js" type="text/javascript" />
<link href="/lib/template.css" media="screen" type="text/css" rel="stylesheet" />
<link href="/cotemplate.css" media="screen" type="text/css" rel="stylesheet"/>
<link href="/coprofile.css" media="screen" type="text/css" rel="stylesheet"/>
<link href="/cohistory.css" media="screen" type="text/css" rel="stylesheet"/>
<link href="/scripts/markitup/jquery.markitup.css" media="screen" type="text/css" rel="stylesheet"/>
<link href="/scripts/markitup/jquery.markitup.set.css" media="screen" type="text/css" rel="stylesheet"/>
</lift:with-resource-id>
</head>
<lift:profileOps.body />
Expand Down

0 comments on commit a09e337

Please sign in to comment.