Chromium Code Reviews| 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'; | |
|
Cutch
2016/07/07 19:50:57
fully qualify imports with package:
cbernaschina
2016/07/07 22:08:13
Done.
| |
| 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 super.attributeChanged(name, oldValue, newValue); | |
| 69 switch (name){ | |
| 70 case 'expand': | |
| 71 expand = !(newValue == null || newValue == 'false'); | |
| 72 break; | |
| 73 case 'busy': | |
| 74 busy = !(newValue == null || newValue == 'false'); | |
| 75 break; | |
| 76 case 'expandKey': | |
| 77 busy = !(newValue == null || newValue == 'false'); | |
| 78 break; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 | |
| 83 void render() { | |
| 84 print('expanded ' + getAttribute('expand')); | |
| 85 shadowRoot.children = [ | |
| 86 new CurlyBlockElement(expanded: expand, disabled: busy) | |
| 87 ..children = [new ContentElement()] | |
| 88 ..onToggle.listen(_toggle) | |
| 89 ]; | |
| 90 } | |
| 91 | |
| 92 ObservatoryApplication get application => ObservatoryApplication.app; | |
| 93 | |
| 94 void _toggle(CurlyBlockToggleEvent e) { | |
| 95 _expand = e.control.expanded; | |
| 96 if (callback != null) { | |
| 97 busy = true; | |
| 98 callback(expand, () { | |
| 99 if (expandKey != null) { | |
| 100 application.expansions[expandKey] = expand; | |
| 101 } | |
| 102 busy = false; | |
| 103 }); | |
| 104 } else { | |
| 105 application.expansions[expandKey] = expand; | |
| 106 } | |
| 107 } | |
| 108 } | |
| OLD | NEW |