| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:html'; |
| 6 import 'package:observatory/app.dart'; |
| 7 import 'shims/binding.dart'; |
| 8 import 'helpers/tag.dart'; |
| 9 import 'curly_block.dart'; |
| 10 |
| 11 typedef _callback(); |
| 12 typedef CurlyBlockToggleCallback(bool a, _callback b); |
| 13 |
| 14 class CurlyBlockElementWrapper extends HtmlElement { |
| 15 |
| 16 static final binder = new Binder<CurlyBlockElementWrapper>( |
| 17 const [const Binding('expand'), const Binding('busy'), |
| 18 const Binding('expandKey'), const Binding('callback')]); |
| 19 |
| 20 static const tag = const Tag<CurlyBlockElementWrapper>('curly-block'); |
| 21 |
| 22 bool _expand; |
| 23 bool get expand => _expand; |
| 24 set expand(bool expanded) { |
| 25 _expand = !(expanded == null || expanded == false); |
| 26 render(); |
| 27 } |
| 28 |
| 29 bool _busy; |
| 30 bool get busy => _busy; |
| 31 set busy(bool busy) { |
| 32 _busy = !(busy == null || busy == false); |
| 33 render(); |
| 34 } |
| 35 |
| 36 String _expandKey; |
| 37 String get expandKey => _expandKey; |
| 38 set expandKey(String expandKey) { |
| 39 _expandKey = expandKey; |
| 40 if (expandKey != null) { |
| 41 var value = application.expansions[expandKey]; |
| 42 if (value != null && expand != value) { |
| 43 |
| 44 } |
| 45 } |
| 46 render(); |
| 47 } |
| 48 |
| 49 CurlyBlockToggleCallback _callback; |
| 50 CurlyBlockToggleCallback get callback => _callback; |
| 51 set callback(CurlyBlockToggleCallback callback) { |
| 52 _callback = callback; |
| 53 render(); |
| 54 } |
| 55 |
| 56 CurlyBlockElementWrapper.created() : super.created() { |
| 57 createShadowRoot(); |
| 58 } |
| 59 |
| 60 @override |
| 61 void attached() { |
| 62 super.attached(); |
| 63 render(); |
| 64 } |
| 65 |
| 66 @override |
| 67 void attributeChanged(String name, String oldValue, String newValue){ |
| 68 switch (name){ |
| 69 case 'expand': |
| 70 expand = !(newValue == null || newValue == 'false'); |
| 71 break; |
| 72 case 'busy': |
| 73 busy = !(newValue == null || newValue == 'false'); |
| 74 break; |
| 75 case 'expandKey': |
| 76 busy = !(newValue == null || newValue == 'false'); |
| 77 break; |
| 78 } |
| 79 } |
| 80 |
| 81 |
| 82 void render() { |
| 83 print('expanded ' + getAttribute('expand')); |
| 84 shadowRoot.children = [ |
| 85 new CurlyBlockElement() |
| 86 ..expanded = expand |
| 87 ..busy = busy |
| 88 ..children = [new ContentElement()] |
| 89 ..onToggle.listen(_toggle) |
| 90 ]; |
| 91 } |
| 92 |
| 93 ObservatoryApplication get application => ObservatoryApplication.app; |
| 94 |
| 95 void _toggle(CurlyBlockToggleEvent e) { |
| 96 _expand = e.control.expanded; |
| 97 if (callback != null) { |
| 98 busy = true; |
| 99 callback(expand, () { |
| 100 if (expandKey != null) { |
| 101 application.expansions[expandKey] = expand; |
| 102 } |
| 103 busy = false; |
| 104 }); |
| 105 } else { |
| 106 application.expansions[expandKey] = expand; |
| 107 } |
| 108 } |
| 109 } |
| OLD | NEW |