# HG changeset patch # User Tomas Zeman # Date 1334903183 -7200 # Node ID a62b754b945a29535cffebcdd27abe5103782447 # Parent f8c666b75c312d462ca717d2afd85dfa0c6515d8 Country UI diff -r f8c666b75c31 -r a62b754b945a 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,6 +19,7 @@ import fis.base.ui._ import fis.aaa.ui.UserSnippet import fis.crm.ui.ContactSnippet +import fis.geo.ui.CountrySnippet import fis.db.SquerylTxMgr import net.liftweb.common._ import net.liftweb.http._ @@ -42,7 +43,8 @@ val menus = List(Menu("/", "FIS Main page") / "index" >> Hidden, Menu.i("Home") / "" , ContactSnippet.menu, - UserSnippet.menu) + UserSnippet.menu, + CountrySnippet.menu) LiftRules.setSiteMap(SiteMap(menus:_*)) diff -r f8c666b75c31 -r a62b754b945a src/main/scala/fis/geo/ui/CountryPanel.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/geo/ui/CountryPanel.scala Fri Apr 20 08:26:23 2012 +0200 @@ -0,0 +1,31 @@ +/* + * 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.geo.model._ +import fis.base.ui.ViewPanel +import net.liftweb.util.BaseField + +object CountryPanel { + + def fields(c: Country): List[BaseField] = List(c.name, c.iso2, c.iso3, c.note) + + def apply(c: Country) = ViewPanel(fields(c)) +} + + + +// vim: set ts=2 sw=2 et: diff -r f8c666b75c31 -r a62b754b945a src/main/scala/fis/geo/ui/CountrySnippet.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/geo/ui/CountrySnippet.scala Fri Apr 20 08:26:23 2012 +0200 @@ -0,0 +1,119 @@ +/* + * 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 CountrySnippet extends CountryCrud with EntitySnippet[Country] { + val prefix = "country" + + private val listPre = Menu("country.list", l10n("Countries")) / prefix >> + Title(_ => i18n("Countries")) >> + locTpl("entity/list") >> Snippet("list", list) + + private val createPre = Menu("country.create", l10n("Create")) / prefix / ADD >> + Title(_ => i18n("Create country")) >> + locTpl("entity/form") >> Snippet("form", form) >> Hidden + + private val viewPre = Menu.param[Country]("country.view", l10n("Country"), parse, + encode) / prefix / * >> Title(c => i18n("Country %s", c.linkName)) >> + locTpl("entity/view") >> Snippet("panel", panel) >> Hidden + + private val editPre = Menu.param[Country]("country.edit", l10n("Edit"), parse, + encode) / prefix / * / EDIT >> + Title(c => i18n("Edit country %s", c.linkName)) >> + locTpl("entity/form") >> Snippet("form", form) >> Hidden + + private val deletePre = Menu.param[Country]("country.delete", l10n("Delete"), + parse, encode) / prefix / * / DELETE >> + Title(c => i18n("Delete country %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 = { _ => CountryTable(Country.countries()) } + + private def panel: CssTr = "*" #> cur.map(CountryPanel(_)) + + object url { + def view: Country => Box[String] = (viewLoc.calcHref _) andThen (Box !! _) + } + + private case class CountryLink(c: Country) extends EntityLink[Country](c, + url.view) + + EntityLink.register[Country](CountryLink(_)) + + + private object form extends HorizontalScreen with CancelButton with SaveButton { + + private object country extends ScreenVar[Country](Country.createRecord) + + override def screenFields: List[BaseField] = CountryPanel.fields(country) + + override def localSetup() { + cur.foreach(country(_)) + } + + def finish() { save(country) foreach { v => + S notice l10n("Country %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 country?"), false) + + def finish() { + for { + c <- deleteLoc.currentValue if confirm + r <- delete(c) + n <- r.box(c.linkName) + } { + S notice l10n("Country %s deleted.", n) + S redirectTo listM.loc.calcDefaultHref + } + } + } + +} + +// vim: set ts=2 sw=2 et: diff -r f8c666b75c31 -r a62b754b945a src/main/scala/fis/geo/ui/CountryTable.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/geo/ui/CountryTable.scala Fri Apr 20 08:26:23 2012 +0200 @@ -0,0 +1,27 @@ +/* + * 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.geo.model._ +import fis.base.ui._ + +object CountryTable extends FieldTable[Country] { + def fields(c: Country) = EntityLink(c) ++ Seq(c.iso2, c.iso3, c.note) + + def apply(l: Iterable[Country]) = build(Country, l) +} + +// vim: set ts=2 sw=2 et: diff -r f8c666b75c31 -r a62b754b945a 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 @@ -62,6 +62,23 @@ Deleted + + + Name + Note + ISO2 + ISO3 + diff -r f8c666b75c31 -r a62b754b945a 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 @@ -61,6 +61,23 @@ Smazán + + Státy + Vytvořit stát + Stát + Upravit stát %s + Smazat stát %s + Stát %s uložen. + Skutečně smazat stát? + Stát %s smazán. + + + Název + Poznámka + ISO2 kód + ISO3 kód + +