OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library tracker.models; | 5 library tracker.models; |
6 | 6 |
7 import 'package:polymer/polymer.dart'; | 7 import 'package:polymer/polymer.dart'; |
8 | 8 |
9 final appModel = new Tracker(); | 9 final appModel = new Tracker(); |
10 | 10 |
11 /** | 11 /** |
12 * A model for the tracker app. | 12 * A model for the tracker app. |
13 * | 13 * |
14 * [tasks] contains all tasks used in this app. | 14 * [tasks] contains all tasks used in this app. |
15 */ | 15 */ |
16 class Tracker extends ObservableBase { | 16 class Tracker extends Observable { |
17 @observable List<Task> tasks; | 17 @observable List<Task> tasks; |
18 } | 18 } |
19 | 19 |
20 /** | 20 /** |
21 * A model for creating a single task. | 21 * A model for creating a single task. |
22 * | 22 * |
23 * A task can be saved or unsaved. Only a saved task has a taskID. | 23 * A task can be saved or unsaved. Only a saved task has a taskID. |
24 * | 24 * |
25 * This model defines validation rules for a Task. It is the responsibility of | 25 * This model defines validation rules for a Task. It is the responsibility of |
26 * the view layer to validate a task before assigning a taskID to the task. A | 26 * the view layer to validate a task before assigning a taskID to the task. A |
27 * task with a taskID is considered saved. | 27 * task with a taskID is considered saved. |
28 */ | 28 */ |
29 class Task extends ObservableBase { | 29 class Task extends Observable { |
30 static bool TITLE_REQUIRED = true; | 30 static bool TITLE_REQUIRED = true; |
31 static const MAX_TITLE_LENGTH = 40; | 31 static const MAX_TITLE_LENGTH = 40; |
32 static const MAX_DESCRIPTION_LENGTH = 200; | 32 static const MAX_DESCRIPTION_LENGTH = 200; |
33 static const CURRENT = 'current'; | 33 static const CURRENT = 'current'; |
34 static const PENDING = 'pending'; | 34 static const PENDING = 'pending'; |
35 static const COMPLETED = 'completed'; | 35 static const COMPLETED = 'completed'; |
36 | 36 |
37 @observable int taskID; | 37 @observable int taskID; |
38 @observable String title = ''; | 38 @observable String title = ''; |
39 @observable String description = ''; | 39 @observable String description = ''; |
40 @observable String status = PENDING; | 40 @observable String status = PENDING; |
41 @observable DateTime createdAt; | 41 @observable DateTime createdAt; |
42 @observable DateTime updatedAt; | 42 @observable DateTime updatedAt; |
43 | 43 |
44 Task.unsaved(); | 44 Task.unsaved(); |
45 | 45 |
46 Task(this.title, this.description, this.status); | 46 Task(this.title, this.description, this.status); |
47 | 47 |
48 bool get isValid { | 48 bool get isValid { |
49 var minTitleLength = TITLE_REQUIRED ? 1 : 0; | 49 var minTitleLength = TITLE_REQUIRED ? 1 : 0; |
50 return (title.length >= minTitleLength && | 50 return (title.length >= minTitleLength && |
51 title.length < MAX_TITLE_LENGTH && | 51 title.length < MAX_TITLE_LENGTH && |
52 description.length < MAX_DESCRIPTION_LENGTH); | 52 description.length < MAX_DESCRIPTION_LENGTH); |
53 } | 53 } |
54 | 54 |
55 bool get saved => taskID != null; | 55 bool get saved => taskID != null; |
56 } | 56 } |
OLD | NEW |