| 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 survey.web.selection; | 5 library survey.web.selection; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'package:polymer/polymer.dart'; | 9 import 'package:polymer/polymer.dart'; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * The SelectionElement view. A selection element can be used as a substitute | 12 * The SelectionElement view. A selection element can be used as a substitute |
| 13 * for radios and checkboxes. When passed with a [multi] set to true, this | 13 * for radios and checkboxes. When passed with a [multi] set to true, this |
| 14 * element permits the user to select 0 or more options, otherwise it permits | 14 * element permits the user to select 0 or more options, otherwise it permits |
| 15 * the user to select 0 or 1 option. | 15 * the user to select 0 or 1 option. |
| 16 */ | 16 */ |
| 17 @CustomTag('selection-element') | 17 @CustomTag('selection-element') |
| 18 class SelectionElement extends PolymerElement with ObservableMixin { | 18 class SelectionElement extends PolymerElement with Observable { |
| 19 bool get applyAuthorStyles => true; | 19 bool get applyAuthorStyles => true; |
| 20 | 20 |
| 21 @observable List<String> values = toObservable([]); | 21 @observable List<String> values = toObservable([]); |
| 22 @observable List<int> selectedIndices = toObservable([]); | 22 @observable List<int> selectedIndices = toObservable([]); |
| 23 @observable bool multi = false; | 23 @observable bool multi = false; |
| 24 | 24 |
| 25 inserted() { | 25 inserted() { |
| 26 super.inserted(); | 26 super.inserted(); |
| 27 var root = getShadowRoot('selection-element'); | 27 var root = getShadowRoot('selection-element'); |
| 28 var items = root.queryAll('li'); | 28 var items = root.queryAll('li'); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 dispatchSelectionResults() { | 63 dispatchSelectionResults() { |
| 64 List<String> results = []; | 64 List<String> results = []; |
| 65 for (var index in selectedIndices) { | 65 for (var index in selectedIndices) { |
| 66 results.add(values[index]); | 66 results.add(values[index]); |
| 67 } | 67 } |
| 68 dispatchEvent(new CustomEvent('selectionmade', detail: results)); | 68 dispatchEvent(new CustomEvent('selectionmade', detail: results)); |
| 69 } | 69 } |
| 70 } | 70 } |
| OLD | NEW |