Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 1227413005: Disable Delete option for custom wallpapers when 'Surprise Me' is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Biao's comment. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 * WallpaperManager constructor. 6 * WallpaperManager constructor.
7 * 7 *
8 * WallpaperManager objects encapsulate the functionality of the wallpaper 8 * WallpaperManager objects encapsulate the functionality of the wallpaper
9 * manager extension. 9 * manager extension.
10 * 10 *
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 * onChanged event. Event handler for that event is in event_page.js. 195 * onChanged event. Event handler for that event is in event_page.js.
196 * @private 196 * @private
197 */ 197 */
198 WallpaperManager.prototype.toggleSurpriseMe_ = function() { 198 WallpaperManager.prototype.toggleSurpriseMe_ = function() {
199 var self = this; 199 var self = this;
200 var checkbox = $('surprise-me').querySelector('#checkbox'); 200 var checkbox = $('surprise-me').querySelector('#checkbox');
201 var shouldEnable = !checkbox.classList.contains('checked'); 201 var shouldEnable = !checkbox.classList.contains('checked');
202 var onSuccess = function() { 202 var onSuccess = function() {
203 if (chrome.runtime.lastError == null) { 203 if (chrome.runtime.lastError == null) {
204 if (shouldEnable) { 204 if (shouldEnable) {
205 self.document_.body.removeAttribute('surprise-me-disabled');
205 checkbox.classList.add('checked'); 206 checkbox.classList.add('checked');
206 // Hides the wallpaper set by message if there is any. 207 // Hides the wallpaper set by message if there is any.
207 $('wallpaper-set-by-message').textContent = ''; 208 $('wallpaper-set-by-message').textContent = '';
208 } else { 209 } else {
209 // Unchecking the "Surprise me" checkbox falls back to the previous 210 // Unchecking the "Surprise me" checkbox falls back to the previous
210 // wallpaper before "Surprise me" was turned on. 211 // wallpaper before "Surprise me" was turned on.
211 if (self.wallpaperGrid_.activeItem) { 212 if (self.wallpaperGrid_.activeItem) {
212 self.setSelectedWallpaper_(self.wallpaperGrid_.activeItem); 213 self.setSelectedWallpaper_(self.wallpaperGrid_.activeItem);
213 self.onWallpaperChanged_(self.wallpaperGrid_.activeItem, 214 self.onWallpaperChanged_(self.wallpaperGrid_.activeItem,
214 self.currentWallpaper_); 215 self.currentWallpaper_);
215 } 216 }
216 checkbox.classList.remove('checked'); 217 checkbox.classList.remove('checked');
218 self.document_.body.setAttribute('surprise-me-disabled', '');
217 } 219 }
218 $('categories-list').disabled = shouldEnable; 220 $('categories-list').disabled = shouldEnable;
219 $('wallpaper-grid').disabled = shouldEnable; 221 $('wallpaper-grid').disabled = shouldEnable;
220 } else { 222 } else {
221 // TODO(bshe): show error message to user. 223 // TODO(bshe): show error message to user.
222 console.error('Failed to save surprise me option to chrome storage.'); 224 console.error('Failed to save surprise me option to chrome storage.');
223 } 225 }
224 }; 226 };
225 227
226 // To prevent the onChanged event being fired twice, we only save the value 228 // To prevent the onChanged event being fired twice, we only save the value
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 $('set-wallpaper-layout').addEventListener( 276 $('set-wallpaper-layout').addEventListener(
275 'change', this.onWallpaperLayoutChanged_.bind(this)); 277 'change', this.onWallpaperLayoutChanged_.bind(this));
276 278
277 if (loadTimeData.valueExists('wallpaperAppName')) { 279 if (loadTimeData.valueExists('wallpaperAppName')) {
278 $('wallpaper-set-by-message').textContent = loadTimeData.getStringF( 280 $('wallpaper-set-by-message').textContent = loadTimeData.getStringF(
279 'currentWallpaperSetByMessage', str('wallpaperAppName')); 281 'currentWallpaperSetByMessage', str('wallpaperAppName'));
280 } 282 }
281 283
282 if (this.enableOnlineWallpaper_) { 284 if (this.enableOnlineWallpaper_) {
283 var self = this; 285 var self = this;
286 self.document_.body.setAttribute('surprise-me-disabled', '');
284 $('surprise-me').hidden = false; 287 $('surprise-me').hidden = false;
285 $('surprise-me').addEventListener('click', 288 $('surprise-me').addEventListener('click',
286 this.toggleSurpriseMe_.bind(this)); 289 this.toggleSurpriseMe_.bind(this));
287 var onSurpriseMeEnabled = function() { 290 var onSurpriseMeEnabled = function() {
288 $('surprise-me').querySelector('#checkbox').classList.add('checked'); 291 $('surprise-me').querySelector('#checkbox').classList.add('checked');
289 $('categories-list').disabled = true; 292 $('categories-list').disabled = true;
290 $('wallpaper-grid').disabled = true; 293 $('wallpaper-grid').disabled = true;
294 self.document_.body.removeAttribute('surprise-me-disabled');
291 }; 295 };
292 296
293 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { 297 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) {
294 // Surprise me has been moved from local to sync storage, prefer 298 // Surprise me has been moved from local to sync storage, prefer
295 // values from sync, but if unset check local and update synced pref 299 // values from sync, but if unset check local and update synced pref
296 // if applicable. 300 // if applicable.
297 if (syncEnabled) { 301 if (syncEnabled) {
298 Constants.WallpaperSyncStorage.get( 302 Constants.WallpaperSyncStorage.get(
299 Constants.AccessSyncSurpriseMeEnabledKey, function(items) { 303 Constants.AccessSyncSurpriseMeEnabledKey, function(items) {
300 if (items.hasOwnProperty( 304 if (items.hasOwnProperty(
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 } 1110 }
1107 this.wallpaperGrid_.dataModel = wallpapersDataModel; 1111 this.wallpaperGrid_.dataModel = wallpapersDataModel;
1108 if (selectedItem) { 1112 if (selectedItem) {
1109 this.wallpaperGrid_.selectedItem = selectedItem; 1113 this.wallpaperGrid_.selectedItem = selectedItem;
1110 this.wallpaperGrid_.activeItem = selectedItem; 1114 this.wallpaperGrid_.activeItem = selectedItem;
1111 } 1115 }
1112 } 1116 }
1113 }; 1117 };
1114 1118
1115 })(); 1119 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698