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 /** |
114 * @param {!SettingsRoute} newRoute | 104 * @param {!SettingsRoute} newRoute |
115 * @private | 105 * @private |
116 */ | 106 */ |
117 currentRouteChanged_: function(newRoute) { | 107 currentRouteChanged_: function(newRoute) { |
118 var isSubpage = !!newRoute.subpage.length; | 108 this.inSubpage_ = newRoute.subpage.length > 0; |
109 this.style.height = this.inSubpage_ ? '100%' : ''; | |
119 | 110 |
120 this.showAboutPage_ = newRoute.page == 'about'; | 111 if (newRoute.page == 'about') { |
112 this.showPages_ = {about: true, basic: false, advanced: false}; | |
113 } else { | |
114 this.showPages_ = { | |
115 about: false, | |
116 basic: newRoute.page == 'basic' || !this.inSubpage_, | |
117 advanced: newRoute.page == 'advanced' || | |
118 (!this.inSubpage_ && this.advancedToggleExpanded_), | |
119 }; | |
121 | 120 |
122 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | 121 if (this.showPages_.advanced) |
123 | 122 this.advancedToggleExpanded_ = true; |
dschuyler
2016/07/21 19:02:05
When would this be needed (when would it not
be s
michaelpg
2016/07/21 19:55:28
When you navigate to chrome://md-settings/advanced
michaelpg
2016/07/22 15:12:17
So this definitely needs to change to fix Advanced
| |
124 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | 123 } |
125 | |
126 this.showAdvancedPage_ = | |
127 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) || | |
128 newRoute.page == 'advanced'; | |
129 | |
130 this.style.height = isSubpage ? '100%' : ''; | |
131 }, | 124 }, |
132 | 125 |
133 /** @private */ | 126 /** @private */ |
134 toggleAdvancedPage_: function() { | 127 toggleAdvancedPage_: function() { |
135 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); | 128 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
136 }, | 129 }, |
137 | 130 |
138 /** | 131 /** |
139 * Navigates to the default search page (if necessary). | 132 * Navigates to the default search page (if necessary). |
140 * @private | 133 * @private |
141 */ | 134 */ |
142 ensureInDefaultSearchPage_: function() { | 135 ensureInDefaultSearchPage_: function() { |
143 if (this.currentRoute.page != 'basic' || | 136 if (this.currentRoute.page != 'basic' || |
144 this.currentRoute.section != '' || | 137 this.currentRoute.section != '' || |
145 this.currentRoute.subpage.length != 0) { | 138 this.currentRoute.subpage.length != 0) { |
146 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | 139 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; |
147 } | 140 } |
148 }, | 141 }, |
149 | 142 |
150 /** | 143 /** |
151 * @param {string} query | 144 * @param {string} query |
152 */ | 145 */ |
153 searchContents: function(query) { | 146 searchContents: function(query) { |
154 this.ensureInDefaultSearchPage_(); | 147 this.ensureInDefaultSearchPage_(); |
155 | 148 |
156 // Trigger rendering of the basic and advanced pages and search once ready. | 149 // 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 | 150 // Even if those are already rendered, yield to the message loop before |
158 // initiating searching. | 151 // initiating searching. |
159 this.showBasicPage_ = true; | 152 this.set('showPages_.basic', true); |
dschuyler
2016/07/21 19:02:05
With the new struct to set the basic, advanced, ab
michaelpg
2016/07/21 19:55:28
You'd have to ask dpapad whether it matters. I don
dpapad
2016/07/21 22:31:27
I believe that setting both booleans at once here
michaelpg
2016/07/22 15:12:18
Nah, the struct of booleans is good step forward.
| |
160 setTimeout(function() { | 153 setTimeout(function() { |
161 settings.getSearchManager().search( | 154 settings.getSearchManager().search( |
162 query, assert(this.$$('settings-basic-page'))); | 155 query, assert(this.$$('settings-basic-page'))); |
163 }.bind(this), 0); | 156 }.bind(this), 0); |
164 | 157 |
165 this.showAdvancedPage_ = true; | 158 this.set('showPages_.advanced', true); |
166 setTimeout(function() { | 159 setTimeout(function() { |
167 settings.getSearchManager().search( | 160 settings.getSearchManager().search( |
168 query, assert(this.$$('settings-advanced-page'))); | 161 query, assert(this.$$('settings-advanced-page'))); |
169 }.bind(this), 0); | 162 }.bind(this), 0); |
170 }, | 163 }, |
171 }); | 164 }); |
OLD | NEW |