--- a/src/main/scala/fis/aaa/model/AaaSchema.scala Fri Apr 20 09:45:51 2012 +0200
+++ b/src/main/scala/fis/aaa/model/AaaSchema.scala Fri Apr 20 13:47:03 2012 +0200
@@ -16,7 +16,7 @@
package fis.aaa.model
import fis.base.model.BaseSchema
-import fis.crm.model.{Contact, CrmSchema, EntityContact}
+import fis.crm.model.{Contact, ContactEntities, CrmSchema, EntityContact}
import net.liftweb.squerylrecord.RecordTypeMode._
/**
@@ -47,7 +47,7 @@
))
userContacts.leftForeignKeyDeclaration.constrainReference(onDelete cascade)
userContacts.rightForeignKeyDeclaration.constrainReference(onDelete cascade)
-
+ ContactEntities.register(userContacts)
}
object AaaSchema extends AaaSchema
--- a/src/main/scala/fis/crm/model/CrmSchema.scala Fri Apr 20 09:45:51 2012 +0200
+++ b/src/main/scala/fis/crm/model/CrmSchema.scala Fri Apr 20 13:47:03 2012 +0200
@@ -15,7 +15,7 @@
*/
package fis.crm.model
-import fis.base.model.BaseSchema
+import fis.base.model.{BaseSchema, Entity}
import fis.geo.model.GeoSchema
import net.liftweb.squerylrecord.RecordTypeMode._
@@ -62,6 +62,7 @@
))
companyContacts.leftForeignKeyDeclaration.constrainReference(onDelete cascade)
companyContacts.rightForeignKeyDeclaration.constrainReference(onDelete cascade)
+ ContactEntities.register(companyContacts)
def allCompanies: Iterable[Company] = from(companyT) (c =>
select(c) orderBy(c.name asc))
@@ -80,6 +81,21 @@
import org.squeryl.KeyedEntity
import org.squeryl.dsl._
+object ContactEntities {
+ type T = ManyToManyRelation[Entity[_], Contact, _]
+
+ import java.util.concurrent.{ConcurrentHashMap => CHash}
+ import scala.collection.JavaConversions._
+ private val rels = new CHash[String, T]
+
+ def register[L <: Entity[_], A <: KeyedEntity[_]](
+ rel: ManyToManyRelation[L, Contact, A])(implicit man:Manifest[L]) {
+ rels.put(man.toString, rel.asInstanceOf[T])
+ }
+
+ def apply(c: Contact): Iterable[Entity[_]] = rels.values flatMap { _.right(c) }
+}
+
trait EntityContact[T] extends KeyedEntity[CompositeKey2[Long, Long]] {
def entity: Long
def contact: Long
--- a/src/main/scala/fis/crm/ui/ContactSnippet.scala Fri Apr 20 09:45:51 2012 +0200
+++ b/src/main/scala/fis/crm/ui/ContactSnippet.scala Fri Apr 20 13:47:03 2012 +0200
@@ -15,10 +15,12 @@
*/
package fis.crm.ui
+import fis.base.model._
import fis.base.ui._
import fis.crm.model._
import net.liftweb.common._
import net.liftweb.http._
+import net.liftweb.record.Record
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import net.liftweb.util._
@@ -40,7 +42,8 @@
private val viewPre = Menu.param[Contact]("contact.view", l10n("Contact"), parse,
encode) / prefix / * >> Title(c => i18n("Contact %s", c.linkName)) >>
- locTpl("entity/view") >> Snippet("panel", panel) >> Hidden
+ locTpl("contact/view") >> Snippet("panel", panel) >>
+ Snippet("entities", entities) >> Hidden
private val editPre = Menu.param[Contact]("contact.edit", l10n("Edit"), parse,
encode) / prefix / * / EDIT >>
@@ -68,6 +71,19 @@
private def panel: CssTr = "*" #> viewLoc.currentValue.map { ContactPanel(_) }
+ private def entities: CssTr = "*" #> viewLoc.currentValue.map { c =>
+ FieldTable[EntityWrapper[Contact]](_.fields, EntityWrapper(Contact.createRecord))(
+ ContactEntities(c) map { e => EntityWrapper(e.asInstanceOf[Entity[Contact]]) })
+ }
+
+ private case class EntityWrapper[T <: Record[T]](e: Entity[T]) {
+ val note = e.note
+ val linkField = EntityLink(e)(scala.reflect.Manifest.classType(e.getClass))
+ val typeField = new ReadOnlyField("type", l10n("Entity type"),
+ i18n(e.getClass.getSimpleName), Empty)
+ val fields = linkField.toSeq :+ typeField :+ note
+ }
+
object url {
def view: Contact => Box[String] = (viewLoc.calcHref _) andThen (Box !! _)
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/contact/view.html Fri Apr 20 13:47:03 2012 +0200
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
+ <title>Entity View</title>
+ </head>
+ <body class="lift:content_id=main">
+ <div id="main" class="lift:surround?with=default;at=content">
+ <div class="row">
+ <div class="span12">
+ <span class="lift:panel"></span>
+ </div>
+ </div> <!-- /row -->
+ <div class="row section">
+ <div class="span12">
+ <h3><span class="lift:loc?locid=contact.entities"></span></h3>
+ <span class="lift:entities"></span>
+ </div>
+ </div> <!-- /row -->
+ </div>
+ </body>
+</html>
+
+
--- a/src/main/webapp/templates-hidden/_resources.html Fri Apr 20 09:45:51 2012 +0200
+++ b/src/main/webapp/templates-hidden/_resources.html Fri Apr 20 13:47:03 2012 +0200
@@ -10,6 +10,7 @@
<res name="linkName" lang="en" default="true">Name</res>
<!--
Remove
+ Entity type
-->
<!-- authn -->
@@ -61,6 +62,7 @@
<res name="contact.workPhone" lang="en" default="true">Work phone</res>
<res name="contact.privatePhone" lang="en" default="true">Private phone</res>
<res name="contact.fax" lang="en" default="true">Fax</res>
+ <res name="contact.entities" lang="en" default="true">Assigned objects</res>
<!-- user
--- a/src/main/webapp/templates-hidden/_resources_cs.html Fri Apr 20 09:45:51 2012 +0200
+++ b/src/main/webapp/templates-hidden/_resources_cs.html Fri Apr 20 13:47:03 2012 +0200
@@ -9,6 +9,7 @@
<res name="Add" lang="cs">Přidat</res>
<res name="linkName" lang="cs">Název</res>
<res name="Remove" lang="cs">Odebrat</res>
+ <res name="Entity type" lang="cs">Typ</res>
<!-- authn -->
@@ -58,6 +59,7 @@
<res name="contact.workPhone" lang="cs">Pracovní tel.č.</res>
<res name="contact.privatePhone" lang="cs">Soukromé tel.č.</res>
<res name="contact.fax" lang="cs">Fax</res>
+ <res name="contact.entities" lang="cs">Přiřazeno k</res>
<!-- user -->
@@ -117,6 +119,7 @@
<!-- company -->
+ <res name="Company" lang="cs">Společnost</res>
<res name="Companies" lang="cs">Společnosti</res>
<res name="Create company" lang="cs">Vytvořit společnost</res>
<res name="Company %s" lang="cs">Společnost %s</res>