# HG changeset patch # User Tomas Zeman # Date 1334351545 -7200 # Node ID 14557aef62872a7a144470e1772d32dd46dbdd7a # Parent 9409e7ab3f9da882ad66a04ff5cd5264cb215499 Entity link diff -r 9409e7ab3f9d -r 14557aef6287 src/main/scala/fis/base/ui/EntityLink.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/base/ui/EntityLink.scala Fri Apr 13 23:12:25 2012 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright 2011-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.base.ui + +import fis.base.model.Entity +import java.util.concurrent.{ConcurrentHashMap => CHash} +import net.liftweb.common._ +import net.liftweb.util._ +import net.tz.lift.model._ +import net.tz.lift.snippet._ +import scala.xml.Text + +abstract class EntityLink[T <: Entity[_]](val e: T, link: T => Box[String]) + extends ReadableField { + + type ValueType = String + def name = "linkName" + override def displayName = l10n(name) + override def asHtml = a(link(e))(Text(e.linkName)) + def get = e.linkName + def is = e.linkName +} + +object EntityLink { + + type GenFunc[T <: Entity[_]] = T => EntityLink[T] + + private val globalLinks: CHash[String, GenFunc[_]] = new CHash + + def apply[T <: Entity[_]](v: T)(implicit man: Manifest[T]): + Box[EntityLink[T]] = { + + val n = man.toString + val f = globalLinks.containsKey(n).box { + globalLinks.get(n).asInstanceOf[GenFunc[T]] } + f map { _(v) } + } + + def register[T <: Entity[_]](func: GenFunc[T])(implicit man: Manifest[T]) = { + globalLinks.put(man.toString, func) + this + } +} + +// vim: set ts=2 sw=2 et: diff -r 9409e7ab3f9d -r 14557aef6287 src/main/webapp/templates-hidden/_resources.html --- a/src/main/webapp/templates-hidden/_resources.html Thu Apr 12 17:07:35 2012 +0200 +++ b/src/main/webapp/templates-hidden/_resources.html Fri Apr 13 23:12:25 2012 +0200 @@ -7,6 +7,7 @@ Create Edit Add + Name <-- contact --> diff -r 9409e7ab3f9d -r 14557aef6287 src/main/webapp/templates-hidden/_resources_cs.html --- a/src/main/webapp/templates-hidden/_resources_cs.html Thu Apr 12 17:07:35 2012 +0200 +++ b/src/main/webapp/templates-hidden/_resources_cs.html Fri Apr 13 23:12:25 2012 +0200 @@ -7,6 +7,7 @@ Vytvořit Upravit Přidat + Název <-- contact -->