OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'settings-basic-page' is the settings page containing the basic settings. | 7 * 'settings-basic-page' is the settings page containing the actual settings. |
8 */ | 8 */ |
9 Polymer({ | 9 Polymer({ |
10 is: 'settings-basic-page', | 10 is: 'settings-basic-page', |
11 | 11 |
12 behaviors: [SettingsPageVisibility, MainPageBehavior], | 12 behaviors: [SettingsPageVisibility, MainPageBehavior], |
13 | 13 |
14 properties: { | 14 properties: { |
15 /** Preferences state. */ | 15 /** Preferences state. */ |
16 prefs: { | 16 prefs: { |
17 type: Object, | 17 type: Object, |
18 notify: true, | 18 notify: true, |
19 }, | 19 }, |
20 | 20 |
21 showAndroidApps: Boolean, | 21 showAndroidApps: Boolean, |
22 | 22 |
23 /** | 23 /** |
| 24 * Dictionary defining page visibility. |
| 25 * @type {!GuestModePageVisibility} |
| 26 */ |
| 27 pageVisibility: Object, |
| 28 |
| 29 advancedToggleExpanded: { |
| 30 type: Boolean, |
| 31 notify: true, |
| 32 }, |
| 33 |
| 34 /** |
| 35 * True if a section is fully expanded to hide other sections beneath it. |
| 36 * False otherwise (even while animating a section open/closed). |
| 37 * @private {boolean} |
| 38 */ |
| 39 hasExpandedSection_: { |
| 40 type: Boolean, |
| 41 value: false, |
| 42 }, |
| 43 |
| 44 /** |
24 * True if the basic page should currently display the reset profile banner. | 45 * True if the basic page should currently display the reset profile banner. |
25 * @private {boolean} | 46 * @private {boolean} |
26 */ | 47 */ |
27 showResetProfileBanner_: { | 48 showResetProfileBanner_: { |
28 type: Boolean, | 49 type: Boolean, |
29 value: function() { | 50 value: function() { |
30 return loadTimeData.getBoolean('showResetProfileBanner'); | 51 return loadTimeData.getBoolean('showResetProfileBanner'); |
31 }, | 52 }, |
32 }, | 53 }, |
| 54 |
| 55 /** @private {!settings.Route|undefined} */ |
| 56 currentRoute_: Object, |
| 57 }, |
| 58 |
| 59 listeners: { |
| 60 'subpage-expand': 'onSubpageExpanded_', |
| 61 }, |
| 62 |
| 63 /** @override */ |
| 64 attached: function() { |
| 65 this.currentRoute_ = settings.getCurrentRoute(); |
| 66 }, |
| 67 |
| 68 /** |
| 69 * Overrides MainPageBehaviorImpl from MainPageBehavior. |
| 70 * @param {!settings.Route} newRoute |
| 71 * @param {settings.Route} oldRoute |
| 72 */ |
| 73 currentRouteChanged: function(newRoute, oldRoute) { |
| 74 this.currentRoute_ = newRoute; |
| 75 |
| 76 if (settings.Route.ADVANCED.contains(newRoute)) |
| 77 this.advancedToggleExpanded = true; |
| 78 |
| 79 if (oldRoute && oldRoute.isSubpage()) { |
| 80 // If the new route isn't the same expanded section, reset |
| 81 // hasExpandedSection_ for the next transition. |
| 82 if (!newRoute.isSubpage() || newRoute.section != oldRoute.section) |
| 83 this.hasExpandedSection_ = false; |
| 84 } else { |
| 85 assert(!this.hasExpandedSection_); |
| 86 } |
| 87 |
| 88 MainPageBehaviorImpl.currentRouteChanged.call(this, newRoute, oldRoute); |
| 89 }, |
| 90 |
| 91 /** |
| 92 * Queues a task to search the basic sections, then another for the advanced |
| 93 * sections. |
| 94 * @param {string} query The text to search for. |
| 95 * @return {!Promise<!settings.SearchRequest>} A signal indicating that |
| 96 * searching finished. |
| 97 */ |
| 98 searchContents: function(query) { |
| 99 var whenSearchDone = settings.getSearchManager().search( |
| 100 query, assert(this.$$('#basicPage'))); |
| 101 |
| 102 if (this.pageVisibility.advancedSettings !== false) { |
| 103 assert(whenSearchDone === settings.getSearchManager().search( |
| 104 query, assert(this.$$('#advancedPage')))); |
| 105 } |
| 106 |
| 107 return whenSearchDone; |
33 }, | 108 }, |
34 | 109 |
35 /** @private */ | 110 /** @private */ |
36 onResetDone_: function() { | 111 onResetDone_: function() { |
37 this.showResetProfileBanner_ = false; | 112 this.showResetProfileBanner_ = false; |
38 }, | 113 }, |
39 | 114 |
40 /** | 115 /** |
41 * @return {boolean} | 116 * @return {boolean} |
42 * @private | 117 * @private |
43 */ | 118 */ |
44 shouldShowAndroidApps_: function() { | 119 shouldShowAndroidApps_: function() { |
45 var visibility = /** @type {boolean|undefined} */ ( | 120 var visibility = /** @type {boolean|undefined} */ ( |
46 this.get('pageVisibility.androidApps')); | 121 this.get('pageVisibility.androidApps')); |
47 return this.showAndroidApps && this.showPage(visibility); | 122 return this.showAndroidApps && this.showPage(visibility); |
48 }, | 123 }, |
| 124 |
| 125 /** |
| 126 * Hides everything but the newly expanded subpage. |
| 127 * @private |
| 128 */ |
| 129 onSubpageExpanded_: function() { |
| 130 this.hasExpandedSection_ = true; |
| 131 }, |
| 132 |
| 133 /** |
| 134 * @param {boolean} inSearchMode |
| 135 * @param {boolean} hasExpandedSection |
| 136 * @return {boolean} |
| 137 * @private |
| 138 */ |
| 139 showAdvancedToggle_: function(inSearchMode, hasExpandedSection) { |
| 140 return !inSearchMode && !hasExpandedSection; |
| 141 }, |
| 142 |
| 143 /** |
| 144 * @param {!settings.Route} currentRoute |
| 145 * @param {boolean} inSearchMode |
| 146 * @param {boolean} hasExpandedSection |
| 147 * @return {boolean} Whether to show the basic page, taking into account |
| 148 * both routing and search state. |
| 149 * @private |
| 150 */ |
| 151 showBasicPage_: function(currentRoute, inSearchMode, hasExpandedSection) { |
| 152 return !hasExpandedSection || settings.Route.BASIC.contains(currentRoute); |
| 153 }, |
| 154 |
| 155 /** |
| 156 * @param {!settings.Route} currentRoute |
| 157 * @param {boolean} inSearchMode |
| 158 * @param {boolean} hasExpandedSection |
| 159 * @param {boolean} advancedToggleExpanded |
| 160 * @return {boolean} Whether to show the advanced page, taking into account |
| 161 * both routing and search state. |
| 162 * @private |
| 163 */ |
| 164 showAdvancedPage_: function(currentRoute, inSearchMode, hasExpandedSection, |
| 165 advancedToggleExpanded) { |
| 166 return hasExpandedSection ? |
| 167 settings.Route.ADVANCED.contains(currentRoute) : |
| 168 advancedToggleExpanded || inSearchMode; |
| 169 }, |
| 170 |
| 171 /** |
| 172 * @param {(boolean|undefined)} visibility |
| 173 * @return {boolean} True unless visibility is false. |
| 174 * @private |
| 175 */ |
| 176 showAdvancedSettings_: function(visibility) { |
| 177 return visibility !== false; |
| 178 }, |
| 179 |
| 180 /** |
| 181 * @param {boolean} opened Whether the menu is expanded. |
| 182 * @return {string} Icon name. |
| 183 * @private |
| 184 */ |
| 185 getArrowIcon_: function(opened) { |
| 186 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 187 }, |
49 }); | 188 }); |
OLD | NEW |