1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7<link rel='import' href='/tracing/ui/base/info_bar.html'> 8 9<polymer-element name='tr-ui-b-info-bar-group' is='HTMLUnknownElement'> 10 <template> 11 <style> 12 :host { 13 flex: 0 0 auto; 14 flex-direction: column; 15 display: flex; 16 } 17 </style> 18 <div id='messages'></div> 19 </template> 20 21 <script> 22 'use strict'; 23 Polymer({ 24 ready: function() { 25 this.messages_ = []; 26 }, 27 28 clearMessages: function() { 29 this.messages_ = []; 30 this.updateContents_(); 31 }, 32 33 addMessage: function(text, opt_buttons) { 34 opt_buttons = opt_buttons || []; 35 for (var i = 0; i < opt_buttons.length; i++) { 36 if (opt_buttons[i].buttonText === undefined) 37 throw new Error('buttonText must be provided'); 38 if (opt_buttons[i].onClick === undefined) 39 throw new Error('onClick must be provided'); 40 } 41 42 this.messages_.push({ 43 text: text, 44 buttons: opt_buttons || [] 45 }); 46 this.updateContents_(); 47 }, 48 49 updateContents_: function() { 50 this.$.messages.textContent = ''; 51 this.messages_.forEach(function(message) { 52 var bar = document.createElement('tr-ui-b-info-bar'); 53 bar.message = message.text; 54 bar.visible = true; 55 56 message.buttons.forEach(function(button) { 57 bar.addButton(button.buttonText, button.onClick); 58 }, this); 59 60 this.$.messages.appendChild(bar); 61 }, this); 62 } 63 }); 64 </script> 65</polymer-element> 66