| 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 curly_block_element; | 5 library curly_block_element; |
| 6 | 6 |
| 7 import 'package:polymer/polymer.dart'; | 7 import 'package:polymer/polymer.dart'; |
| 8 import 'observatory_element.dart'; |
| 8 | 9 |
| 9 @CustomTag('curly-block') | 10 @CustomTag('curly-block') |
| 10 class CurlyBlockElement extends PolymerElement { | 11 class CurlyBlockElement extends ObservatoryElement { |
| 11 CurlyBlockElement.created() : super.created(); | 12 CurlyBlockElement.created() : super.created(); |
| 12 | 13 |
| 13 @observable bool expanded = false; | 14 @observable bool expanded = false; |
| 14 @observable bool busy = false; | 15 @observable bool busy = false; |
| 15 @published var callback = null; | 16 @published var callback = null; |
| 16 @published bool expand = false; | 17 @published bool expand = false; |
| 18 @published String expandKey; |
| 17 | 19 |
| 18 void expandChanged(oldValue) { | 20 void expandChanged(oldValue) { |
| 19 expanded = expand; | 21 expanded = expand; |
| 20 } | 22 } |
| 21 | 23 |
| 24 void expandKeyChanged(oldValue) { |
| 25 if (expandKey != null) { |
| 26 var value = app.expansions[expandKey]; |
| 27 if (value != null) { |
| 28 if (expanded != value) { |
| 29 toggleExpand(null, null, null); |
| 30 } |
| 31 } |
| 32 } |
| 33 } |
| 34 |
| 22 void doneCallback() { | 35 void doneCallback() { |
| 23 expanded = !expanded; | 36 expanded = !expanded; |
| 37 if (expandKey != null) { |
| 38 app.expansions[expandKey] = expanded; |
| 39 } |
| 24 busy = false; | 40 busy = false; |
| 25 } | 41 } |
| 26 | 42 |
| 27 void toggleExpand(var event, var b, var c) { | 43 void toggleExpand(var event, var b, var c) { |
| 28 assert(callback == null || expand == false); | 44 assert(callback == null || expand == false); |
| 29 if (busy) { | 45 if (busy) { |
| 30 return; | 46 return; |
| 31 } | 47 } |
| 48 busy = true; |
| 32 if (callback != null) { | 49 if (callback != null) { |
| 33 busy = true; | |
| 34 callback(!expanded, doneCallback); | 50 callback(!expanded, doneCallback); |
| 35 } else { | 51 } else { |
| 36 expanded = !expanded; | 52 doneCallback(); |
| 37 } | 53 } |
| 38 } | 54 } |
| 39 } | 55 } |
| OLD | NEW |