summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/ui/base/info_bar_group.html
blob: d095e4d99f920b4aee4fc8cba9d5bf754cf97853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel='import' href='/tracing/ui/base/info_bar.html'>

<dom-module id='tr-ui-b-info-bar-group'>
  <template>
    <style>
    :host {
      flex: 0 0 auto;
      flex-direction: column;
      display: flex;
    }
    </style>
    <div id='messages'></div>
  </template>
</dom-module>
<script>
'use strict';
Polymer({
  is: 'tr-ui-b-info-bar-group',

  ready() {
    this.messages_ = [];
  },

  clearMessages() {
    this.messages_ = [];
    this.updateContents_();
  },

  addMessage(text, opt_buttons) {
    opt_buttons = opt_buttons || [];
    for (let i = 0; i < opt_buttons.length; i++) {
      if (opt_buttons[i].buttonText === undefined) {
        throw new Error('buttonText must be provided');
      }
      if (opt_buttons[i].onClick === undefined) {
        throw new Error('onClick must be provided');
      }
    }

    this.messages_.push({
      text,
      buttons: opt_buttons || []
    });
    this.updateContents_();
  },

  updateContents_() {
    Polymer.dom(this.$.messages).textContent = '';
    this.messages_.forEach(function(message) {
      const bar = document.createElement('tr-ui-b-info-bar');
      bar.message = message.text;
      bar.visible = true;

      message.buttons.forEach(function(button) {
        bar.addButton(button.buttonText, button.onClick);
      }, this);

      Polymer.dom(this.$.messages).appendChild(bar);
    }, this);
  }
});
</script>