OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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 'dart:async'; |
| 7 |
| 8 import 'package:observatory/app.dart'; |
| 9 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 10 import 'package:observatory/src/elements/shims/binding.dart'; |
| 11 import 'package:observatory/src/elements/nav/refresh.dart'; |
| 12 |
| 13 class NavRefreshElementWrapper extends HtmlElement { |
| 14 static final binder = new Binder<NavRefreshElementWrapper>( |
| 15 const [const Binding('callback'), const Binding('label')]); |
| 16 |
| 17 static const tag = const Tag<NavRefreshElementWrapper>('nav-refresh'); |
| 18 |
| 19 Function _callback; |
| 20 String _label; |
| 21 Function get callback => _callback; |
| 22 String get label => _label; |
| 23 set callback(Function value) { |
| 24 _callback = value; render(); |
| 25 } |
| 26 set label(String value) { |
| 27 _label = value; render(); |
| 28 } |
| 29 |
| 30 NavRefreshElementWrapper.created() : super.created() { |
| 31 binder.registerCallback(this); |
| 32 _label = getAttribute('label') ?? 'Refresh'; |
| 33 createShadowRoot(); |
| 34 render(); |
| 35 } |
| 36 |
| 37 @override |
| 38 void attached() { |
| 39 super.attached(); |
| 40 render(); |
| 41 } |
| 42 |
| 43 void render() { |
| 44 shadowRoot.children = []; |
| 45 if (_callback == null || _label == null) return; |
| 46 |
| 47 shadowRoot.children = [ |
| 48 new StyleElement() |
| 49 ..text = '''nav-refresh-wrapped > li > button { |
| 50 color: #000; |
| 51 margin: 3px; |
| 52 padding: 8px; |
| 53 border-width: 2px; |
| 54 line-height: 13px; |
| 55 font: 400 13px 'Montserrat', sans-serif; |
| 56 } |
| 57 nav-refresh-wrapped > li > button[disabled] { |
| 58 color: #aaa; |
| 59 cursor: wait; |
| 60 } |
| 61 nav-refresh-wrapped > li { |
| 62 float: right; |
| 63 margin: 0; |
| 64 }''', |
| 65 new NavRefreshElement(label: _label, |
| 66 queue: ObservatoryApplication.app.queue) |
| 67 ..onRefresh.listen((event) async{ |
| 68 event.element.disabled = true; |
| 69 try { |
| 70 var future = callback(); |
| 71 if (future is Future) await future; |
| 72 } finally { |
| 73 event.element.disabled = false; |
| 74 } |
| 75 }) |
| 76 ]; |
| 77 } |
| 78 } |
OLD | NEW |