| author | Tomas Zeman <tzeman@volny.cz> |
| Mon, 02 Apr 2012 00:06:52 +0200 | |
| changeset 21 | 641c7190c566 |
| parent 15 | 995184977e9b |
| child 22 | 94ed9cfdb123 |
| permissions | -rw-r--r-- |
|
5
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
/* |
| 21 | 2 |
* Copyright 2011-2012 Tomas Zeman <tzeman@volny.cz> |
|
5
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
* |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
* you may not use this file except in compliance with the License. |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
* You may obtain a copy of the License at |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
* |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
* |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
13 |
* See the License for the specific language governing permissions and |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
14 |
* limitations under the License. |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
15 |
*/ |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
16 |
package net.tz.lift.snippet |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
17 |
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
18 |
import net.liftweb.mapper.MappedField |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
19 |
import scala.xml.{NodeSeq, Text}
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
20 |
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
21 |
object AttrRow {
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
22 |
def apply(name: => NodeSeq, value: => NodeSeq) = new AttrRow(name, value, |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
23 |
"attr-name", "attr-value") |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
24 |
def apply(f: MappedField[_, _]) = new AttrRow(Text(f.displayName), f.asHtml, |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
25 |
"attr-name", "attr-value") |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
26 |
def formRow(name: => NodeSeq, input: => NodeSeq) = new AttrRow(name, input, |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
27 |
"form-name", "form-value") |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
28 |
def submitRow(button: => NodeSeq) = new SpanRow(button) |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
29 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
30 |
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
31 |
class AttrRow(name: => NodeSeq, value: => NodeSeq, nameCss: String, |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
32 |
valueCss: String) extends Function0[NodeSeq] {
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
33 |
def tdN = <td class={nameCss}>{name}</td>
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
34 |
def tdV = <td class={valueCss}>{value}</td>
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
35 |
def apply(): NodeSeq = <tr>{tdN :: tdV :: Nil}</tr>
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
36 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
37 |
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
38 |
class SpanRow(value: => NodeSeq) extends AttrRow(NodeSeq.Empty, value, "", "") |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
39 |
{
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
40 |
override def apply(): NodeSeq = <tr><td colspan="2">{value}</td></tr>
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
41 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
42 |
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
43 |
object Panel {
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
44 |
def apply(attrs: Iterable[AttrRow]) = new Panel(attrs) |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
45 |
def fromFields(fields: Iterable[MappedField[_,_]]) = |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
46 |
new Panel(fields.map(AttrRow(_))) |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
47 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
48 |
|
| 15 | 49 |
class Panel(attrs: => Iterable[AttrRow]) extends CssTr {
|
|
5
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
50 |
def apply(in: NodeSeq): NodeSeq = <table>{attrs.map(_())}</table>
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
51 |
def &(other: Function1[NodeSeq, NodeSeq]) = new Function1[NodeSeq, NodeSeq] {
|
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
52 |
def apply(in: NodeSeq): NodeSeq = List(Panel.this, other) flatMap (_(in)) |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
53 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
54 |
} |
|
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
55 |
|
| 21 | 56 |
import net.liftweb.http.Templates |
| 15 | 57 |
import net.liftweb.util.Helpers._ // CSS transforms |
58 |
||
59 |
/** |
|
60 |
* A panel using template in <code>/templates-hidden/panel</code> for |
|
61 |
* values rendering. |
|
62 |
*/ |
|
63 |
class TplPanel(cells: List[(NodeSeq, NodeSeq)]) extends CssTr {
|
|
| 21 | 64 |
def apply(in: NodeSeq): NodeSeq = Templates( |
| 15 | 65 |
List("templates-hidden", "panel")) map { xml =>
|
66 |
(".row *" #> cells.map { r =>
|
|
67 |
".n *" #> r._1 & |
|
68 |
".v *" #> r._2 |
|
69 |
})(xml) |
|
70 |
} openOr NodeSeq.Empty |
|
71 |
} |
|
72 |
||
|
5
993582ca8d2e
Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
73 |
// vim: set ts=2 sw=2 et: |