[GTK] Test gardening
[WebKit-https.git] / Websites / browserbench.org / Speedometer2.0 / resources / todomvc / architecture-examples / emberjs / source / app / components / todo-item.js
1 import Ember from 'ember';
2
3 export default Ember.Component.extend({
4     repo: Ember.inject.service(),
5     tagName: 'li',
6     editing: false,
7     classNameBindings: ['todo.completed', 'editing'],
8
9     actions: {
10         startEditing() {
11             this.get('onStartEdit')();
12             this.set('editing', true);
13             Ember.run.scheduleOnce('afterRender', this, 'focusInput');
14         },
15
16         doneEditing(todoTitle) {
17             if (!this.get('editing')) { return; }
18             if (Ember.isBlank(todoTitle)) {
19                 this.send('removeTodo');
20             } else {
21                 this.set('todo.title', todoTitle.trim());
22                 this.set('editing', false);
23                 this.get('onEndEdit')();
24             }
25         },
26
27         handleKeydown(e) {
28             if (e.keyCode === 13) {
29                 e.target.blur();
30             } else if (e.keyCode === 27) {
31                 this.set('editing', false);
32             }
33         },
34
35         toggleCompleted(e) {
36             let todo = this.get('todo');
37             Ember.set(todo, 'completed', e.target.checked);
38             this.get('repo').persist();
39         },
40
41         removeTodo() {
42             this.get('repo').delete(this.get('todo'));
43         }
44     },
45
46     focusInput() {
47         this.element.querySelector('input.edit').focus();
48     }
49 });