|
1 /* |
|
2 * Copyright 2012 Tomas Zeman <tzeman@volny.cz> |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 package net.tz.lift.model |
|
17 |
|
18 import net.liftweb.record.{LifecycleCallbacks, Record} |
|
19 import net.liftweb.record.field.DateTimeField |
|
20 import net.liftweb.util.Helpers |
|
21 import java.util.Calendar |
|
22 |
|
23 /** |
|
24 * Created field. |
|
25 */ |
|
26 class CreatedField[OwnerType <: Record[OwnerType]](rec: OwnerType) |
|
27 extends JodaDateTimeField[OwnerType](rec) { |
|
28 |
|
29 override def defaultValue = Calendar.getInstance() |
|
30 override def displayName = l10n(name) |
|
31 |
|
32 } |
|
33 |
|
34 /** |
|
35 * Updated field. |
|
36 */ |
|
37 class UpdatedField[OwnerType <: Record[OwnerType]](rec: OwnerType) |
|
38 extends JodaDateTimeField[OwnerType](rec) with LifecycleCallbacks { |
|
39 |
|
40 override def defaultValue = Calendar.getInstance() |
|
41 override def beforeSave { |
|
42 set(Calendar.getInstance) |
|
43 } |
|
44 override def displayName = l10n(name) |
|
45 } |
|
46 |
|
47 /** |
|
48 * Created trait. |
|
49 */ |
|
50 trait CreatedTrait[T <: Record[T]] { self: T => |
|
51 val createdAt = new CreatedField(this.asInstanceOf[T]) |
|
52 } |
|
53 |
|
54 /** |
|
55 * Updated trait. |
|
56 */ |
|
57 trait UpdatedTrait[T <: Record[T]] { self: T => |
|
58 val updatedAt = new UpdatedField(this.asInstanceOf[T]) |
|
59 } |
|
60 |
|
61 /** |
|
62 * Created/updated trait. |
|
63 */ |
|
64 trait CreatedUpdated[T <: Record[T]] extends CreatedTrait[T] with |
|
65 UpdatedTrait[T] { self: T => |
|
66 } |
|
67 |
|
68 // vim: set ts=2 sw=2 et: |