1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr
.define('options', function() {
6 /** @const */ var ControlledSettingIndicator
=
7 options
.ControlledSettingIndicator
;
10 * A variant of the {@link ControlledSettingIndicator} that shows the status
11 * of the hotword search setting, including a bubble to show setup errors
12 * (such as failures to download extension resources).
14 * @extends {options.ControlledSettingIndicator}
16 var HotwordSearchSettingIndicator
= cr
.ui
.define('span');
18 HotwordSearchSettingIndicator
.prototype = {
19 __proto__
: ControlledSettingIndicator
.prototype,
22 * Decorates the base element to show the proper icon.
25 decorate: function() {
26 ControlledSettingIndicator
.prototype.decorate
.call(this);
31 * Handle changes to the associated pref by hiding any currently visible
33 * @param {Event} event Pref change event.
36 handlePrefChange: function(event
) {
37 PageManager
.hideBubble();
41 * Sets the variable tracking the section which becomes disabled if an
43 * @param {HTMLElement} section The section to disable.
45 set disabledOnErrorSection(section
) {
46 // TODO(kcarattini): Instead of this, add a cr.EventTarget and have
47 // the element to disable register an event on it.
48 this.disabledOnErrorSection_
= section
;
52 * Returns the current error.
53 * @return {string} The error message to be displayed. May be undefined if
57 return this.errorText_
;
61 * Checks for errors and records them.
62 * @param {string} errorMsg The error message to be displayed. May be
63 * undefined if there is no error.
65 setError: function(errorMsg
) {
66 this.setAttribute('controlled-by', 'policy');
67 this.errorText_
= errorMsg
;
71 * Changes the display to be visible if there are errors and disables
74 updateBasedOnError: function() {
77 if (this.disabledOnErrorSection_
)
78 this.disabledOnErrorSection_
.disabled
= !!this.errorText_
;
82 * Toggles showing and hiding the error message bubble. An empty
83 * |errorText_| indicates that there is no error message. So the bubble
84 * only be shown if |errorText_| has a value.
87 toggleBubble: function() {
88 if (this.showingBubble
) {
89 PageManager
.hideBubble();
97 // Create the DOM tree for the bubble content.
98 var closeButton
= document
.createElement('div');
99 closeButton
.classList
.add('close-button');
101 var text
= document
.createElement('p');
102 text
.innerHTML
= this.errorText_
;
104 var textDiv
= document
.createElement('div');
105 textDiv
.appendChild(text
);
107 var container
= document
.createElement('div');
108 container
.appendChild(closeButton
);
109 container
.appendChild(textDiv
);
111 var content
= document
.createElement('div');
112 content
.appendChild(container
);
114 PageManager
.showBubble(content
, this.image
, this, this.location
);
120 HotwordSearchSettingIndicator
: HotwordSearchSettingIndicator