Chromium Code Reviews| 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.web.task_form_element; | 5 library tracker.web.task_form_element; |
| 6 | 6 |
| 7 import 'package:polymer/polymer.dart'; | 7 import 'package:polymer/polymer.dart'; |
| 8 import 'package:tracker/models.dart'; | 8 import 'package:tracker/models.dart'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:math'; | 10 import 'dart:math'; |
| 11 | 11 |
| 12 @CustomTag('task-form-element') | 12 @CustomTag('task-form-element') |
| 13 class TaskFormElement extends PolymerElement { | 13 class TaskFormElement extends PolymerElement { |
| 14 bool get applyAuthorStyles => true; | 14 bool get applyAuthorStyles => true; |
| 15 @observable Task task; | 15 @observable Task task; |
| 16 @observable String titleErrorMessage = ''; | 16 @observable String titleErrorMessage = ''; |
| 17 @observable int maxTitleLength = Task.MAX_TITLE_LENGTH; | 17 @observable int maxTitleLength = Task.MAX_TITLE_LENGTH; |
| 18 @observable String descriptionErrorMessage = ''; | 18 @observable String descriptionErrorMessage = ''; |
| 19 @observable int maxDescriptionLength = Task.MAX_DESCRIPTION_LENGTH; | 19 @observable int maxDescriptionLength = Task.MAX_DESCRIPTION_LENGTH; |
| 20 @observable final List<String> taskStatusOptions = toObservable([ | 20 @observable final List<String> taskStatusOptions = toObservable([ |
| 21 Task.CURRENT, Task.PENDING, Task.COMPLETED]); | 21 Task.CURRENT, Task.PENDING, Task.COMPLETED]); |
| 22 @observable int statusSelectedIndex = 1; | 22 @observable int statusSelectedIndex = 1; |
| 23 @observable String previousStatus = ''; | 23 @observable String previousStatus = ''; |
| 24 @observable String submitLabel = ''; | 24 @observable String submitLabel = ''; |
| 25 | 25 |
| 26 // Define variables, getters, and setters to get around Polymer Element | |
|
Siggi Cherem (dart-lang)
2013/11/12 18:53:54
Consider rephrasing this. This is really a restric
| |
| 27 // restrictions. | |
| 28 @observable bool titleErrorMessageIsEmpty; | |
| 29 @observable bool descriptionErrorMessageIsEmpty; | |
| 30 @observable bool taskSaved; | |
|
Siggi Cherem (dart-lang)
2013/11/12 18:53:54
Let's move some of these workarounds to Task so th
| |
| 31 | |
| 32 int _taskTitleLength = 0; | |
| 33 int get taskTitleLength => _taskTitleLength; | |
| 34 void set taskTitleLength(int c) { | |
| 35 _taskTitleLength = notifyPropertyChange(#taskTitleLength, | |
| 36 _taskTitleLength, c); | |
| 37 } | |
| 38 | |
| 39 int _taskDescriptionLength = 0; | |
| 40 int get taskDescriptionLength => _taskDescriptionLength; | |
| 41 void set taskDescriptionLength(int c) { | |
| 42 _taskDescriptionLength = notifyPropertyChange(#taskDescriptionLength, | |
| 43 _taskDescriptionLength, c); | |
| 44 } | |
|
Siggi Cherem (dart-lang)
2013/11/12 18:53:54
with my suggestion above you should be able to get
| |
| 45 | |
| 46 titleErrorMessageChanged(String oldValue) { | |
| 47 titleErrorMessageIsEmpty = titleErrorMessage.isEmpty; | |
| 48 } | |
|
Siggi Cherem (dart-lang)
2013/11/12 18:53:54
FYI - this trick s very similar to what I'm sugges
| |
| 49 | |
| 50 descriptionErrorMessageChanged(String oldValue) { | |
| 51 descriptionErrorMessageIsEmpty = descriptionErrorMessage.isEmpty; | |
| 52 } | |
| 53 | |
| 26 TaskFormElement.created() : super.created(); | 54 TaskFormElement.created() : super.created(); |
| 27 | 55 |
| 28 enteredView() { | 56 enteredView() { |
| 29 super.enteredView(); | 57 super.enteredView(); |
| 30 submitLabel = task.saved ? 'Update' : 'Create'; | 58 submitLabel = task.saved ? 'Update' : 'Create'; |
| 31 statusSelectedIndex = taskStatusOptions.indexOf(task.status); | 59 statusSelectedIndex = taskStatusOptions.indexOf(task.status); |
| 32 if (!task.saved) { | 60 if (!task.saved) { |
| 33 statusSelectedIndex = taskStatusOptions.indexOf(task.status); | 61 statusSelectedIndex = taskStatusOptions.indexOf(task.status); |
| 34 previousStatus = task.status; | 62 previousStatus = task.status; |
| 35 } | 63 } |
| 64 | |
| 65 taskTitleLength = task.title.length; | |
| 66 taskDescriptionLength = task.description.length; | |
| 67 taskSaved = task.saved; | |
| 36 } | 68 } |
| 37 | 69 |
| 38 bool validateTitle() { | 70 bool validateTitle() { |
| 39 int len = task.title.length; | 71 taskTitleLength = task.title.length; |
| 40 bool valid = false; | 72 bool valid = false; |
| 41 if (len == 0 && Task.TITLE_REQUIRED) { | 73 if (taskTitleLength == 0 && Task.TITLE_REQUIRED) { |
| 42 titleErrorMessage = 'Title is required'; | 74 titleErrorMessage = 'Title is required'; |
| 43 } else if (len > maxTitleLength) { | 75 } else if (taskTitleLength > maxTitleLength) { |
| 44 titleErrorMessage = 'Title must be less than $maxTitleLength characters'; | 76 titleErrorMessage = 'Title must be less than $maxTitleLength characters'; |
| 45 } else { | 77 } else { |
| 46 titleErrorMessage = ''; | 78 titleErrorMessage = ''; |
| 47 valid = true; | 79 valid = true; |
| 48 } | 80 } |
| 49 return valid; | 81 return valid; |
| 50 } | 82 } |
| 51 | 83 |
| 52 bool validateDescription() { | 84 bool validateDescription() { |
| 53 int len = task.description.length; | 85 taskDescriptionLength = task.description.length; |
| 54 bool valid = false; | 86 bool valid = false; |
| 55 if (len >= maxDescriptionLength) { | 87 if (taskDescriptionLength >= maxDescriptionLength) { |
| 56 descriptionErrorMessage = 'Description must be less than ' | 88 descriptionErrorMessage = 'Description must be less than ' |
| 57 '$maxDescriptionLength characters'; | 89 '$maxDescriptionLength characters'; |
| 58 } else { | 90 } else { |
| 59 descriptionErrorMessage = ''; | 91 descriptionErrorMessage = ''; |
| 60 valid = true; | 92 valid = true; |
| 61 } | 93 } |
| 62 return valid; | 94 return valid; |
| 63 } | 95 } |
| 64 | 96 |
| 65 createOrUpdateTask(Event event, detail, sender) { | 97 createOrUpdateTask(Event event, detail, sender) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 appModel.tasks.add(task); | 138 appModel.tasks.add(task); |
| 107 } | 139 } |
| 108 } | 140 } |
| 109 | 141 |
| 110 deleteTask() { | 142 deleteTask() { |
| 111 if (window.confirm('Are you sure you want to delete this?')) { | 143 if (window.confirm('Are you sure you want to delete this?')) { |
| 112 appModel.tasks.remove(task); | 144 appModel.tasks.remove(task); |
| 113 } | 145 } |
| 114 } | 146 } |
| 115 } | 147 } |
| OLD | NEW |