Created
January 14, 2011 01:02
-
-
Save lopex/778963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Upload extends LongKeyedMapper[Upload] with IdPK { | |
override def getSingleton = Upload | |
object fileName extends CustomMappedString(this, 256) with ValRequired with ResourceDisplay { | |
override def size = 80 | |
override def asHtml = <div>{image} {link}</div> | |
def link = <a href={"download/" + id.is} title={fileName.is}>{is.trimToLength(30)}</a> | |
def image = { | |
val n = fileName.is.split('.') | |
val img = if (n.size > 1) Upload.typeMap.get(n.last.toLowerCase).getOrElse(Upload.unknown) else Upload.unknown | |
<img src={"/images/" + img} class="thumb"/> | |
} | |
} | |
object mimeType extends CustomMappedString(this, 100) with ValRequired with ResourceDisplay { | |
override def size = 80 | |
override def asHtml = Text(is.trimToLength(30)) | |
} | |
object bytes extends MappedBinary(this) with ResourceDisplay with SkipInList { | |
override def dbDisplay_? = false | |
} | |
} | |
object Upload extends Upload with LongKeyedMetaMapper[Upload] with LongCustomCRUDify[Upload] { | |
override def dbTableName = "szkupload" | |
override def menuIcon = "/images/disk.png" | |
override def fieldOrder = List(fileName, mimeType, bytes) | |
val typeMap = Map("doc" -> "microsoft-word-icon.png", | |
"xls" -> "microsoft-excel-icon.png", | |
"pdf" -> "adobe-acrobat-icon.png", | |
"ppt" -> "microsoft-powerpoint-icon.png") | |
val unknown = "adobe-flash-icon.png" | |
override def canCreate_? = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment