| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 05 Jun 2012 15:40:45 +0200 | |
| changeset 105 | 66aeb6b3a3a7 |
| parent 99 | 49eb72a46208 |
| permissions | -rw-r--r-- |
|
58
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
/* |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
2 |
* Copyright 2011-2012 Tomas Zeman <tzeman@volny.cz> |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
* |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
* you may not use this file except in compliance with the License. |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
* You may obtain a copy of the License at |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
* |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
* |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
13 |
* See the License for the specific language governing permissions and |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
14 |
* limitations under the License. |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
15 |
*/ |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
16 |
package fis.base.ui |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
17 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
18 |
import net.liftweb.http.Templates |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
19 |
import net.liftweb.util._ |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
20 |
import net.liftweb.util.Helpers._ // CSS transforms |
| 99 | 21 |
import scala.xml.{NodeSeq, Text}
|
|
58
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
22 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
23 |
/** |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
24 |
* Template driven table, compatible w/ datatables.net. |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
25 |
* Template location: <code>/templates-hidden/datatable</code>. |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
26 |
*/ |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
27 |
trait FieldTable[T] {
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
28 |
protected def load: NodeSeq = |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
29 |
Templates(List("templates-hidden", "datatable")) openOr NodeSeq.Empty
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
30 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
31 |
protected def cols(cs: Iterable[ReadableField]) = |
| 99 | 32 |
".field-name *" #> (cs map { f =>
|
33 |
f.displayNameHtml openOr Text(f.displayName) }) |
|
|
58
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
34 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
35 |
protected def cells(cs: Iterable[T]) = |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
36 |
".r" #> cs.map { v => "td *" #> (fields(v) map { _.asHtml }) }
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
37 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
38 |
protected def fields(v: T): Iterable[ReadableField] |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
39 |
|
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
40 |
protected def build(header: T, rows: Iterable[T]): NodeSeq = |
|
105
66aeb6b3a3a7
85bf710ab532dcaa Datatables date sorting
Tomas Zeman <tzeman@volny.cz>
parents:
99
diff
changeset
|
41 |
(decorate & cols(fields(header)) & cells(rows))(load) |
|
66aeb6b3a3a7
85bf710ab532dcaa Datatables date sorting
Tomas Zeman <tzeman@volny.cz>
parents:
99
diff
changeset
|
42 |
|
|
66aeb6b3a3a7
85bf710ab532dcaa Datatables date sorting
Tomas Zeman <tzeman@volny.cz>
parents:
99
diff
changeset
|
43 |
protected def decorate = "table [class+]" #> "datatable" |
|
58
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
44 |
} |
|
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
45 |
|
| 72 | 46 |
object FieldTable {
|
47 |
def apply[T](fieldsF: T => Iterable[ReadableField], header: T)(rows: Iterable[T]): |
|
48 |
NodeSeq = (new FieldTable[T] {
|
|
49 |
def fields(v: T) = fieldsF(v) |
|
50 |
}).build(header, rows) |
|
51 |
} |
|
52 |
||
|
58
4fa878322e47
Field table: datatable of columns of fields
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
53 |
// vim: set ts=2 sw=2 et: |