(refs #34)Link conversion checks existence of accounts and issues.

This commit is contained in:
takezoe
2013-07-12 15:15:58 +09:00
parent 71a3d79c82
commit f163e348e0
15 changed files with 152 additions and 80 deletions

View File

@@ -0,0 +1,26 @@
package view
import service.RequestCache
import twirl.api.Html
import util.StringUtil
trait AvatarImageProvider { self: RequestCache =>
/**
* Returns <img> which displays the avatar icon.
* Looks up Gravatar if avatar icon has not been configured in user settings.
*/
protected def getAvatarImageHtml(userName: String, size: Int, tooltip: Boolean = false)(implicit context: app.Context): Html = {
val src = getAccountByUserName(userName).collect { case account if(account.image.isEmpty) =>
s"""http://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress)}?s=${size}"""
} getOrElse {
s"""${context.path}/${userName}/_avatar"""
}
if(tooltip){
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" data-toggle="tooltip" title=${userName}/>""")
} else {
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" />""")
}
}
}