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