--- 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:_*))
--- /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 <tzeman@volny.cz>
+ *
+ * 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:
--- /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 <tzeman@volny.cz>
+ *
+ * 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:
--- /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 <tzeman@volny.cz>
+ *
+ * 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:
--- 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 @@
<res name="user.deleted" lang="en" default="true">Deleted</res>
+ <!-- country
+ default strings:
+ Countries
+ Create country
+ Country
+ Edit country %s
+ Delete country %s
+ Country %s saved.
+ Really delete this country?
+ Country %s deleted.
+ -->
+ <!-- country fields -->
+ <res name="country.name" lang="en" default="true">Name</res>
+ <res name="country.note" lang="en" default="true">Note</res>
+ <res name="country.iso2" lang="en" default="true">ISO2</res>
+ <res name="country.iso3" lang="en" default="true">ISO3</res>
+
<!--
vim: et sw=2 ts=2
-->
--- 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 @@
<res name="user.deleted" lang="cs">Smazán</res>
+ <!-- country -->
+ <res name="Countries" lang="cs">Státy</res>
+ <res name="Create country" lang="cs">Vytvořit stát</res>
+ <res name="Country" lang="cs">Stát</res>
+ <res name="Edit country %s" lang="cs">Upravit stát %s</res>
+ <res name="Delete country %s" lang="cs">Smazat stát %s</res>
+ <res name="Country %s saved." lang="cs">Stát %s uložen.</res>
+ <res name="Really delete this country?" lang="cs">Skutečně smazat stát?</res>
+ <res name="Country %s deleted." lang="cs">Stát %s smazán.</res>
+
+ <!-- country fields -->
+ <res name="country.name" lang="cs">Název</res>
+ <res name="country.note" lang="cs">Poznámka</res>
+ <res name="country.iso2" lang="cs">ISO2 kód</res>
+ <res name="country.iso3" lang="cs">ISO3 kód</res>
+
+
<!--
vim: et sw=2 ts=2
-->