| 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-main' displays the selected settings page. | 7 * 'settings-main' displays the selected settings page. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-main', | 10 is: 'settings-main', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private */ | |
| 14 isAdvancedMenuOpen_: { | |
| 15 type: Boolean, | |
| 16 value: false, | |
| 17 }, | |
| 18 | |
| 19 /** | 13 /** |
| 20 * Preferences state. | 14 * Preferences state. |
| 21 */ | 15 */ |
| 22 prefs: { | 16 prefs: { |
| 23 type: Object, | 17 type: Object, |
| 24 notify: true, | 18 notify: true, |
| 25 }, | 19 }, |
| 26 | 20 |
| 27 /** | 21 /** |
| 28 * The current active route. | 22 * The current active route. |
| 29 * @type {!SettingsRoute} | 23 * @type {!SettingsRoute} |
| 30 */ | 24 */ |
| 31 currentRoute: { | 25 currentRoute: { |
| 32 type: Object, | 26 type: Object, |
| 33 notify: true, | 27 notify: true, |
| 34 observer: 'currentRouteChanged_', | 28 observer: 'currentRouteChanged_', |
| 35 }, | 29 }, |
| 36 | 30 |
| 37 /** @private */ | 31 /** @private */ |
| 38 showAdvancedPage_: { | 32 advancedToggleExpanded_: { |
| 39 type: Boolean, | 33 type: Boolean, |
| 40 value: false, | 34 value: false, |
| 41 }, | 35 }, |
| 42 | 36 |
| 43 /** @private */ | 37 /** @private */ |
| 44 showAdvancedToggle_: { | 38 inSubpage_: Boolean, |
| 45 type: Boolean, | |
| 46 value: true, | |
| 47 }, | |
| 48 | 39 |
| 49 /** @private */ | 40 /** |
| 50 showBasicPage_: { | 41 * Controls which main pages are displayed via dom-ifs. |
| 51 type: Boolean, | 42 * @type {!{about: boolean, basic: boolean, advanced: boolean}} |
| 52 value: true, | 43 * @private |
| 53 }, | 44 */ |
| 54 | 45 showPages_: { |
| 55 /** @private */ | 46 type: Object, |
| 56 showAboutPage_: { | 47 value: function() { |
| 57 type: Boolean, | 48 return {about: false, basic: false, advanced: false}; |
| 58 value: false, | 49 }, |
| 59 }, | 50 }, |
| 60 | 51 |
| 61 toolbarSpinnerActive: { | 52 toolbarSpinnerActive: { |
| 62 type: Boolean, | 53 type: Boolean, |
| 63 value: false, | 54 value: false, |
| 64 notify: true, | 55 notify: true, |
| 65 }, | 56 }, |
| 66 }, | 57 }, |
| 67 | 58 |
| 68 /** @override */ | 59 /** @override */ |
| 69 created: function() { | 60 created: function() { |
| 70 /** @private {!PromiseResolver} */ | 61 /** @private {!PromiseResolver} */ |
| 71 this.resolver_ = new PromiseResolver; | 62 this.resolver_ = new PromiseResolver; |
| 72 settings.main.rendered = this.resolver_.promise; | 63 settings.main.rendered = this.resolver_.promise; |
| 73 }, | 64 }, |
| 74 | 65 |
| 75 /** @override */ | 66 /** @override */ |
| 76 ready: function() { | 67 ready: function() { |
| 77 settings.getSearchManager().setCallback(function(isRunning) { | 68 settings.getSearchManager().setCallback(function(isRunning) { |
| 78 this.toolbarSpinnerActive = isRunning; | 69 this.toolbarSpinnerActive = isRunning; |
| 79 }.bind(this)); | 70 }.bind(this)); |
| 80 }, | 71 }, |
| 81 | 72 |
| 82 /** @override */ | 73 /** @override */ |
| 83 attached: function() { | 74 attached: function() { |
| 84 document.addEventListener('toggle-advanced-page', function(e) { | 75 document.addEventListener('toggle-advanced-page', function(e) { |
| 85 this.showAdvancedPage_ = e.detail; | 76 this.advancedToggleExpanded_ = e.detail; |
| 86 this.isAdvancedMenuOpen_ = e.detail; | |
| 87 this.currentRoute = { | 77 this.currentRoute = { |
| 88 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', | 78 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic', |
| 89 section: '', | 79 section: '', |
| 90 subpage: [], | 80 subpage: [], |
| 91 }; | 81 }; |
| 92 }.bind(this)); | 82 }.bind(this)); |
| 93 | 83 |
| 94 doWhenReady( | 84 doWhenReady( |
| 95 function() { | 85 function() { |
| 96 var basicPage = this.$$('settings-basic-page'); | 86 var basicPage = this.$$('settings-basic-page'); |
| 97 return !!basicPage && basicPage.scrollHeight > 0; | 87 return !!basicPage && basicPage.scrollHeight > 0; |
| 98 }.bind(this), | 88 }.bind(this), |
| 99 function() { | 89 function() { |
| 100 this.resolver_.resolve(); | 90 this.resolver_.resolve(); |
| 101 }.bind(this)); | 91 }.bind(this)); |
| 102 }, | 92 }, |
| 103 | 93 |
| 104 /** | 94 /** |
| 105 * @param {boolean} opened Whether the menu is expanded. | 95 * @param {boolean} opened Whether the menu is expanded. |
| 106 * @return {string} Which icon to use. | 96 * @return {string} Which icon to use. |
| 107 * @private | 97 * @private |
| 108 * */ | 98 */ |
| 109 arrowState_: function(opened) { | 99 arrowState_: function(opened) { |
| 110 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 100 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 111 }, | 101 }, |
| 112 | 102 |
| 113 /** | 103 /** |
| 104 * @param {boolean} showBasicPage |
| 105 * @param {boolean} inSubpage |
| 106 * @return {boolean} |
| 107 */ |
| 108 showAdvancedToggle_: function(showBasicPage, inSubpage) { |
| 109 return showBasicPage && !inSubpage; |
| 110 }, |
| 111 |
| 112 /** |
| 114 * @param {!SettingsRoute} newRoute | 113 * @param {!SettingsRoute} newRoute |
| 115 * @private | 114 * @private |
| 116 */ | 115 */ |
| 117 currentRouteChanged_: function(newRoute) { | 116 currentRouteChanged_: function(newRoute) { |
| 118 var isSubpage = !!newRoute.subpage.length; | 117 this.inSubpage_ = newRoute.subpage.length > 0; |
| 118 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 119 | 119 |
| 120 this.showAboutPage_ = newRoute.page == 'about'; | 120 if (newRoute.page == 'about') { |
| 121 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 122 } else { |
| 123 this.showPages_ = { |
| 124 about: false, |
| 125 basic: newRoute.page == 'basic' || !this.inSubpage_, |
| 126 advanced: newRoute.page == 'advanced' || |
| 127 (!this.inSubpage_ && this.advancedToggleExpanded_), |
| 128 }; |
| 121 | 129 |
| 122 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | 130 if (this.showPages_.advanced) |
| 123 | 131 this.advancedToggleExpanded_ = true; |
| 124 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | 132 } |
| 125 | |
| 126 this.showAdvancedPage_ = | |
| 127 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) || | |
| 128 newRoute.page == 'advanced'; | |
| 129 | |
| 130 this.style.height = isSubpage ? '100%' : ''; | |
| 131 }, | 133 }, |
| 132 | 134 |
| 133 /** @private */ | 135 /** @private */ |
| 134 toggleAdvancedPage_: function() { | 136 toggleAdvancedPage_: function() { |
| 135 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); | 137 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
| 136 }, | 138 }, |
| 137 | 139 |
| 138 /** | 140 /** |
| 139 * Navigates to the default search page (if necessary). | 141 * Navigates to the default search page (if necessary). |
| 140 * @private | 142 * @private |
| 141 */ | 143 */ |
| 142 ensureInDefaultSearchPage_: function() { | 144 ensureInDefaultSearchPage_: function() { |
| 143 if (this.currentRoute.page != 'basic' || | 145 if (this.currentRoute.page != 'basic' || |
| 144 this.currentRoute.section != '' || | 146 this.currentRoute.section != '' || |
| 145 this.currentRoute.subpage.length != 0) { | 147 this.currentRoute.subpage.length != 0) { |
| 146 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | 148 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; |
| 147 } | 149 } |
| 148 }, | 150 }, |
| 149 | 151 |
| 150 /** | 152 /** |
| 151 * @param {string} query | 153 * @param {string} query |
| 152 */ | 154 */ |
| 153 searchContents: function(query) { | 155 searchContents: function(query) { |
| 154 this.ensureInDefaultSearchPage_(); | 156 this.ensureInDefaultSearchPage_(); |
| 155 | 157 |
| 156 // Trigger rendering of the basic and advanced pages and search once ready. | 158 // Trigger rendering of the basic and advanced pages and search once ready. |
| 157 // Even if those are already rendered, yield to the message loop before | 159 // Even if those are already rendered, yield to the message loop before |
| 158 // initiating searching. | 160 // initiating searching. |
| 159 this.showBasicPage_ = true; | 161 this.showPages_ = {about: false, basic: true, advanced: true}; |
| 160 setTimeout(function() { | 162 setTimeout(function() { |
| 161 settings.getSearchManager().search( | 163 settings.getSearchManager().search( |
| 162 query, assert(this.$$('settings-basic-page'))); | 164 query, assert(this.$$('settings-basic-page'))); |
| 163 }.bind(this), 0); | 165 }.bind(this), 0); |
| 164 | |
| 165 this.showAdvancedPage_ = true; | |
| 166 setTimeout(function() { | 166 setTimeout(function() { |
| 167 settings.getSearchManager().search( | 167 settings.getSearchManager().search( |
| 168 query, assert(this.$$('settings-advanced-page'))); | 168 query, assert(this.$$('settings-advanced-page'))); |
| 169 }.bind(this), 0); | 169 }.bind(this), 0); |
| 170 }, | 170 }, |
| 171 }); | 171 }); |
| OLD | NEW |