Question

There are several explanations for SiteMap definition with submenus. But they all rely on a Menu definition in this form:

Menu.i("Info") / "info" submenus(
  Menu.i("About") / "about" >> Hidden >> LocGroup("bottom"),
  Menu.i("Contact") / "contact",
  Menu.i("Feedback") / "feedback" >> LocGroup("bottom"))

However, my menu definition looks like this, rather:

  val AdminLoginRequired = User.loginFirst
  val sitemap = List(
    Menu(Loc("Home", "index" :: Nil, "Home")),
    Menu(Loc("Admin", "admin" :: Nil, "Admin", AdminLoginRequired, LocGroup("admin")))
  ) ::: Customer.menus ::: User.menus ::: Product.menus

I now have Product.admin_menus:

def viewProductMenuLoc = Full(Menu(Loc("ViewProduct" + menuNameSuffix, viewPath, S.?("view.product"))))

def editProductMenuLoc = Full(Menu(Loc("EditProduct" + menuNameSuffix, editPath, S.?("edit.product"))))

def listProductsMenuLoc = Full(Menu(Loc("ListProducts" + menuNameSuffix, listPath, S.?("list.products"))))

def indexProductsMenuLoc = Full(Menu(Loc("IndexProducts" + menuNameSuffix, indexPath, S.?("index.products"))))

def createProductMenuLoc = Full(Menu(Loc("CreateProduct" + menuNameSuffix, createPath, S.?("create.product"))))

lazy val admin_sitemap: List[Menu] = List(editProductMenuLoc, createProductMenuLoc, indexProductsMenuLoc).flatten(a => a)

I would like to make admin_sitemap a submenu to the admin menu above. Is that even possible with this definition?

Was it helpful?

Solution

I believe you just pass the submenus as the second parameter to Menu. So:

val AdminLoginRequired = User.loginFirst
val sitemap = List(
  Menu(Loc("Home", "index" :: Nil, "Home")),
  Menu(
    Loc("Admin", "admin" :: Nil, "Admin", AdminLoginRequired, LocGroup("admin")),
    admin_sitemap: _*
  )
) ::: Customer.menus ::: User.menus ::: Product.menus

However you can convert the old "direct" format to the new dsl format. Assuming you don't need to localize the menu labels, and you don't care about the menus' internal names:

val sitemap = List(
  Menu("Home") / "index",
  Menu("Admin" / "admin" >> AdminLoginRequired >> LocGroup("admin") submenus (admin_sitemap: _*)
)) ::: Customer.menus ::: User.menus ::: Product.menus

To make the label localizable, use Menu.i instead of plain Menu, and to specify the internal name pass it first, as in Menu("MenuHome", "Home"). Apparently you can't do that with Menu.i (I guess no one thought of it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top