Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / hotword_search_setting_indicator.js
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.
4
5 cr.define('options', function() {
6   /** @const */ var ControlledSettingIndicator =
7                     options.ControlledSettingIndicator;
8
9   /**
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).
13    * @constructor
14    * @extends {options.ControlledSettingIndicator}
15    */
16   var HotwordSearchSettingIndicator = cr.ui.define('span');
17
18   HotwordSearchSettingIndicator.prototype = {
19     __proto__: ControlledSettingIndicator.prototype,
20
21     /**
22      * Decorates the base element to show the proper icon.
23      * @override
24      */
25     decorate: function() {
26       ControlledSettingIndicator.prototype.decorate.call(this);
27       this.hidden = true;
28     },
29
30     /**
31      * Handle changes to the associated pref by hiding any currently visible
32      * bubble.
33      * @param {Event} event Pref change event.
34      * @override
35      */
36     handlePrefChange: function(event) {
37       PageManager.hideBubble();
38     },
39
40     /**
41      * Returns the current error.
42      * @return {string} The error message to be displayed. May be undefined if
43      *     there is no error.
44      */
45     get errorText() {
46       return this.errorText_;
47     },
48
49     /**
50      * Checks for errors and records them.
51      * @param {string} errorMsg The error message to be displayed. May be
52      *     undefined if there is no error.
53      */
54     setError: function(errorMsg) {
55       this.setAttribute('controlled-by', 'policy');
56       this.errorText_ = errorMsg;
57     },
58
59     /**
60      * Changes the display to be visible if there are errors and disables
61      * the section.
62      */
63     updateBasedOnError: function() {
64       if (this.errorText_)
65         this.hidden = false;
66     },
67
68     /**
69      * Toggles showing and hiding the error message bubble. An empty
70      * |errorText_| indicates that there is no error message. So the bubble
71      * only be shown if |errorText_| has a value.
72      * @override
73      */
74     toggleBubble: function() {
75       if (this.showingBubble) {
76         PageManager.hideBubble();
77         return;
78       }
79
80       if (!this.errorText_)
81         return;
82
83       var self = this;
84       // Create the DOM tree for the bubble content.
85       var closeButton = document.createElement('div');
86       closeButton.classList.add('close-button');
87
88       var text = document.createElement('p');
89       text.innerHTML = this.errorText_;
90
91       var textDiv = document.createElement('div');
92       textDiv.appendChild(text);
93
94       var container = document.createElement('div');
95       container.appendChild(closeButton);
96       container.appendChild(textDiv);
97
98       var content = document.createElement('div');
99       content.appendChild(container);
100
101       PageManager.showBubble(content, this.image, this, this.location);
102     },
103   };
104
105   // Export
106   return {
107     HotwordSearchSettingIndicator: HotwordSearchSettingIndicator
108   };
109 });