OLD | NEW |
| (Empty) |
1 library todomvc.web.elements.td_item; | |
2 | |
3 import 'dart:html'; | |
4 import 'package:polymer/polymer.dart'; | |
5 import 'td_model.dart'; | |
6 | |
7 @CustomTag('td-item') | |
8 class TodoItem extends LIElement with Polymer, Observable { | |
9 @published bool editing = false; | |
10 @published Todo item; | |
11 | |
12 factory TodoItem() => new Element.tag('li', 'td-item'); | |
13 TodoItem.created() : super.created() { polymerCreated(); } | |
14 | |
15 editAction() { | |
16 editing = true; | |
17 // schedule focus for the end of microtask, when the input will be visible | |
18 async((_) => $['edit'].focus()); | |
19 } | |
20 | |
21 commitAction() { | |
22 if (editing) { | |
23 editing = false; | |
24 item.title = item.title.trim(); | |
25 if (item.title == '') { | |
26 destroyAction(); | |
27 } | |
28 fire('td-item-changed'); | |
29 } | |
30 } | |
31 | |
32 cancelAction() { | |
33 editing = false; | |
34 } | |
35 | |
36 itemChangeAction() { | |
37 // TODO(jmesserly): asyncFire is needed because "click" fires before | |
38 // "item.checked" is updated on Firefox. Need to check Polymer.js. | |
39 asyncFire('td-item-changed'); | |
40 } | |
41 | |
42 destroyAction() { | |
43 fire('td-destroy-item', detail: item); | |
44 } | |
45 } | |
OLD | NEW |