# HG changeset patch # User Tomas Zeman # Date 1334903183 -7200 # Node ID f8f8cac057a79cbf214ffcef490f0f4de7c4ef06 # Parent a62b754b945a29535cffebcdd27abe5103782447 City UI diff -r a62b754b945a -r f8f8cac057a7 src/main/scala/bootstrap/liftweb/Boot.scala --- a/src/main/scala/bootstrap/liftweb/Boot.scala Fri Apr 20 08:26:23 2012 +0200 +++ b/src/main/scala/bootstrap/liftweb/Boot.scala Fri Apr 20 08:26:23 2012 +0200 @@ -19,7 +19,7 @@ import fis.base.ui._ import fis.aaa.ui.UserSnippet import fis.crm.ui.ContactSnippet -import fis.geo.ui.CountrySnippet +import fis.geo.ui.{CitySnippet, CountrySnippet} import fis.db.SquerylTxMgr import net.liftweb.common._ import net.liftweb.http._ @@ -44,7 +44,8 @@ val menus = List(Menu("/", "FIS Main page") / "index" >> Hidden, Menu.i("Home") / "" , ContactSnippet.menu, UserSnippet.menu, - CountrySnippet.menu) + CountrySnippet.menu, + CitySnippet.menu) LiftRules.setSiteMap(SiteMap(menus:_*)) diff -r a62b754b945a -r f8f8cac057a7 src/main/scala/fis/geo/ui/CitySnipppet.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/geo/ui/CitySnipppet.scala Fri Apr 20 08:26:23 2012 +0200 @@ -0,0 +1,124 @@ +/* + * Copyright 2012 Tomas Zeman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fis.geo.ui + +import fis.base.ui._ +import fis.geo.model._ +import net.liftweb.common._ +import net.liftweb.http._ +import net.liftweb.sitemap._ +import net.liftweb.sitemap.Loc._ +import net.liftweb.util._ +import net.liftweb.util.Helpers._ +import net.tz.lift.model._ +import net.tz.lift.snippet._ +import scala.xml.{Elem, NodeSeq, Text} + +object CitySnippet extends CityCrud with EntitySnippet[City] { + val prefix = "city" + + private val listPre = Menu("city.list", l10n("Cities")) / prefix >> + Title(_ => i18n("Cities")) >> + locTpl("entity/list") >> Snippet("list", list) + + private val createPre = Menu("city.create", l10n("Create")) / prefix / ADD >> + Title(_ => i18n("Create city")) >> + locTpl("entity/form") >> Snippet("form", form) >> Hidden + + private val viewPre = Menu.param[City]("city.view", l10n("City"), parse, + encode) / prefix / * >> Title(c => i18n("City %s", c.linkName)) >> + locTpl("entity/view") >> Snippet("panel", panel) >> Hidden + + private val editPre = Menu.param[City]("city.edit", l10n("Edit"), parse, + encode) / prefix / * / EDIT >> + Title(c => i18n("Edit city %s", c.linkName)) >> + locTpl("entity/form") >> Snippet("form", form) >> Hidden + + private val deletePre = Menu.param[City]("city.delete", l10n("Delete"), + parse, encode) / prefix / * / DELETE >> + Title(c => i18n("Delete city %s", c.linkName)) >> + locTpl("entity/delete") >> Snippet("form", deleteF) >> Hidden + + 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 + + private lazy val viewLoc = viewM.toLoc + private lazy val editLoc = editM.toLoc + private lazy val deleteLoc = deleteM.toLoc + + val menu = listM submenus(viewM, editM, createM, deleteM) + + private def cur = viewLoc.currentValue or editLoc.currentValue or + deleteLoc.currentValue + + private def list: CssTr = { _ => CityTable(City.cities()) } + + private def panel: CssTr = "*" #> cur.map { c => ViewPanel(fields(c)) } + + object url { + def view: City => Box[String] = (viewLoc.calcHref _) andThen (Box !! _) + } + + private def fields(c: City) = List(c.name, c.country, c.note) + + private object CityTable extends FieldTable[City] { + def fields(c: City) = EntityLink(c) ++ Seq(c.country, c.note) + def apply(l: Iterable[City]) = build(City, l) + } + + private case class CityLink(c: City) extends EntityLink[City](c, url.view) + + EntityLink.register[City](CityLink(_)) + + private object form extends HorizontalScreen with CancelButton with SaveButton { + + private object city extends ScreenVar[City](City.createRecord) + + override def screenFields: List[BaseField] = fields(city) + + override def localSetup() { + cur.foreach(city(_)) + } + + def finish() { save(city) foreach { v => + S notice l10n("City %s saved.", v.linkName) + S.redirectTo(viewLoc.calcHref(v)) + }} + } + + private object deleteF extends HorizontalScreen with CancelButton with + DeleteButton { + + val confirm = field(l10n("Really delete this city?"), false) + + def finish() { + for { + c <- deleteLoc.currentValue if confirm + r <- delete(c) + n <- r.box(c.linkName) + } { + S notice l10n("City %s deleted.", n) + S redirectTo listM.loc.calcDefaultHref + } + } + } + +} + +// vim: set ts=2 sw=2 et: diff -r a62b754b945a -r f8f8cac057a7 src/main/webapp/templates-hidden/_resources.html --- a/src/main/webapp/templates-hidden/_resources.html Fri Apr 20 08:26:23 2012 +0200 +++ b/src/main/webapp/templates-hidden/_resources.html Fri Apr 20 08:26:23 2012 +0200 @@ -79,6 +79,25 @@ ISO2 ISO3 + + + + Name + Note + Country + + diff -r a62b754b945a -r f8f8cac057a7 src/main/webapp/templates-hidden/_resources_cs.html --- a/src/main/webapp/templates-hidden/_resources_cs.html Fri Apr 20 08:26:23 2012 +0200 +++ b/src/main/webapp/templates-hidden/_resources_cs.html Fri Apr 20 08:26:23 2012 +0200 @@ -78,6 +78,23 @@ ISO3 kód + + Města + Vytvořit město + Město %s + Město + Upravit město %s + Smazat město %s + Město %s uloženo. + Skutečně smazat město? + Město %s smazáno. + + + Název + Poznámka + Stát + +