Contact: secondary navigation
authorTomas Zeman <tzeman@volny.cz>
Thu, 12 Apr 2012 10:52:42 +0200
changeset 50 d67905a2c39d
parent 49 c24112f0f084
child 51 523c5c5b84e5
Contact: secondary navigation
src/main/scala/fis/crm/ui/ContactSnippet.scala
--- a/src/main/scala/fis/crm/ui/ContactSnippet.scala	Thu Apr 12 10:52:42 2012 +0200
+++ b/src/main/scala/fis/crm/ui/ContactSnippet.scala	Thu Apr 12 10:52:42 2012 +0200
@@ -30,44 +30,49 @@
 object ContactSnippet extends ContactCrud with EntitySnippet[Contact] {
   val prefix = "contact"
 
-  val listOp = Menu("contact.list", l10n("Contacts")) / prefix >>
+  private val listPre = Menu("contact.list", l10n("Contacts")) / prefix >>
     Title(_ => i18n("Contacts")) >>
     locTpl("entity/list") >> Snippet("list", list)
 
-  val createOp = Menu("contact.create", l10n("Create")) / prefix / ADD >>
+  private val createPre = Menu("contact.create", l10n("Create")) / prefix / ADD >>
     Title(_ => i18n("Create contact")) >>
     locTpl("entity/form") >> Snippet("form", form) >> Hidden
 
-  val viewOp = Menu.param[Contact]("contact.view", l10n("Contact"), parse,
+  private val viewPre = Menu.param[Contact]("contact.view", l10n("Contact"), parse,
     encode) / prefix / * >> Title(c => i18n("Contact %s", c.linkName)) >>
-    locTpl("entity/view") >> Snippet("panel", panel) >>
-    Hidden
+    locTpl("entity/view") >> Snippet("panel", panel) >> Hidden
 
-  val editOp = Menu.param[Contact]("contact.edit", l10n("Edit"), parse,
+  private val editPre = Menu.param[Contact]("contact.edit", l10n("Edit"), parse,
     encode) / prefix / * / EDIT >>
     Title(c => i18n("Edit contact %s", c.linkName)) >>
     locTpl("entity/form") >> Snippet("form", form) >> Hidden
 
-  val deleteOp = Menu.param[Contact]("contact.delete", l10n("Delete"),
+  private val deletePre = Menu.param[Contact]("contact.delete", l10n("Delete"),
     parse, encode) / prefix / * / DELETE >>
     Title(c => i18n("Delete contact %s", c.linkName)) >>
     locTpl("entity/delete") >> Snippet("form", deleteF) >> Hidden
 
-  private lazy val viewLoc: Loc[Contact] = viewOp.toLoc
-  private lazy val editLoc = editOp.toLoc
-  private lazy val deleteLoc = deleteOp.toLoc
+  private val listM = listPre >> SecNav(createPre).build
+  private val createM = createPre >> SecNav(listPre).build
+  private val viewM = viewPre >> (SecNav(editPre) + deletePre).build
+  private val editM = editPre >> SecNav(viewPre).build
+  private val deleteM = deletePre >> SecNav(viewPre).build
 
-  val menu = listOp submenus (viewOp, editOp, createOp, deleteOp)
+  private lazy val viewLoc = viewM.toLoc
+  private lazy val editLoc = editM.toLoc
+  private lazy val deleteLoc = deleteM.toLoc
 
-  def list: CssTr = ContactTable(CrmSchema.allContacts)
+  val menu = listM submenus(viewM, editM, createM, deleteM)
 
-  def panel: CssTr = "*" #> viewLoc.currentValue.map { ContactPanel(_) }
+  private def list: CssTr = ContactTable(CrmSchema.allContacts)
+
+  private def panel: CssTr = "*" #> viewLoc.currentValue.map { ContactPanel(_) }
 
   object url {
     def view: Contact => Box[String] = (viewLoc.calcHref _) andThen (Box !! _)
   }
 
-  object form extends HorizontalScreen with CancelButton with SaveButton {
+  private object form extends HorizontalScreen with CancelButton with SaveButton {
 
     object c extends ScreenVar[Contact](Contact.createRecord)
 
@@ -83,11 +88,11 @@
     }}
   }
 
-  object deleteF extends LiftScreen {
+  private object deleteF extends HorizontalScreen with CancelButton with
+    DeleteButton {
+
     val confirm = field(l10n("Really delete this contact?"), false)
 
-    override def finishButton: Elem = <button>{l10n("Delete")}</button>
-
     def finish() {
       for {
         c <- deleteLoc.currentValue if confirm
@@ -95,13 +100,11 @@
         n <- r.box(c.linkName)
       } {
         S notice l10n("Contact %s deleted", n)
-        S redirectTo listOp.loc.calcDefaultHref
+        S redirectTo listM.loc.calcDefaultHref
       }
     }
   }
 
-
 }
 
-
 // vim: set ts=2 sw=2 et: