PageRenderTime 101ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/scala/com/mycotrack/snippet/ManageProject.scala

http://github.com/JanxSpirit/mycotrack_mongo
Scala | 62 lines | 46 code | 11 blank | 5 comment | 0 complexity | 5318017339fb3f9ecad02510ada0ea92 MD5 | raw file
  1. package com.mycotrack.snippet
  2. import xml.NodeSeq
  3. import com.mongodb.casbah.commons.MongoDBObject
  4. import _root_.net.liftweb.util.Helpers
  5. import com.mycotrack.db.MycoMongoDb
  6. import xml.{Group, NodeSeq, Text}
  7. import Helpers._
  8. import net.liftweb.http.{RequestVar, S, TemplateFinder, SHtml}
  9. import com.mycotrack.model.{Species, Project, User}
  10. import net.liftweb.common.{Empty, Full}
  11. import com.mycotrack.lib.ChartGenerator
  12. /**
  13. * @author chris_carrier
  14. * @version Nov 28, 2010
  15. */
  16. class ManageProject extends ChartGenerator {
  17. def qrCode(xhtml: NodeSeq): NodeSeq = {
  18. val project = SelectedProject.is.open_!
  19. Helpers.bind("project", xhtml,
  20. "image" -> {
  21. val photo = MycoMongoDb.gridFs.findOne(MongoDBObject("mapped_id" -> project.id))
  22. photo match {
  23. case None => Text("No QR code found")
  24. case Some(photo) => {
  25. val url = "/images/%s" format photo.id
  26. <img src={url}/>
  27. }
  28. }
  29. }
  30. )
  31. }
  32. def splitProject(xhtml: NodeSeq): NodeSeq = {
  33. val project = SelectedProject.is.open_!
  34. val tempUser = User.currentUser.open_!
  35. val newProject = Project.createRecord
  36. val createdDate = newProject.createdDate
  37. Helpers.bind("entry", xhtml,
  38. "substratePreparation" -> SHtml.select(List("none" -> "none", "pasteurized" -> "pasteurized", "sterilized" -> "sterilized"), Full("none"), newProject.preparation(_)),
  39. "container" -> SHtml.select(List("none" -> "none", "Jar - quart" -> "Jar - quart", "Jar - pint" -> "Jar - pint", "Bag - filter" -> "Bag - filter"), Full("none"), newProject.container(_)),
  40. "substrate" -> SHtml.text("", newProject.substrate(_)),
  41. "createdDate" -> createdDate.toForm,
  42. "submit" -> SHtml.submit("Create", () => {
  43. newProject.userId.set(project.userId.is)
  44. newProject.parentProject(project.id)
  45. //proj.createdDate(new Date)
  46. newProject.save;
  47. createQRCode("www.google.com", Empty, Empty, newProject.id)
  48. S.redirectTo("/manage")
  49. }))
  50. }
  51. }