summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js')
-rw-r--r--third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js
new file mode 100644
index 0000000000..0de7fbf116
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs-debug/source/app/components/todo-item.js
@@ -0,0 +1,49 @@
+import Ember from 'ember';
+
+export default Ember.Component.extend({
+ repo: Ember.inject.service(),
+ tagName: 'li',
+ editing: false,
+ classNameBindings: ['todo.completed', 'editing'],
+
+ actions: {
+ startEditing() {
+ this.get('onStartEdit')();
+ this.set('editing', true);
+ Ember.run.scheduleOnce('afterRender', this, 'focusInput');
+ },
+
+ doneEditing(todoTitle) {
+ if (!this.get('editing')) { return; }
+ if (Ember.isBlank(todoTitle)) {
+ this.send('removeTodo');
+ } else {
+ this.set('todo.title', todoTitle.trim());
+ this.set('editing', false);
+ this.get('onEndEdit')();
+ }
+ },
+
+ handleKeydown(e) {
+ if (e.keyCode === 13) {
+ e.target.blur();
+ } else if (e.keyCode === 27) {
+ this.set('editing', false);
+ }
+ },
+
+ toggleCompleted(e) {
+ let todo = this.get('todo');
+ Ember.set(todo, 'completed', e.target.checked);
+ this.get('repo').persist();
+ },
+
+ removeTodo() {
+ this.get('repo').delete(this.get('todo'));
+ }
+ },
+
+ focusInput() {
+ this.element.querySelector('input.edit').focus();
+ }
+});