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

Side by Side Diff: chrome/browser/resources/options/language_options.js

Issue 410293004: Split OptionsPage into Page and PageManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed feedback Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // TODO(kochi): Generalize the notification as a component and put it 5 // TODO(kochi): Generalize the notification as a component and put it
6 // in js/cr/ui/notification.js . 6 // in js/cr/ui/notification.js .
7 7
8 cr.define('options', function() { 8 cr.define('options', function() {
9 /** @const */ var OptionsPage = options.OptionsPage; 9 /** @const */ var Page = cr.ui.pageManager.Page;
10 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
10 /** @const */ var LanguageList = options.LanguageList; 11 /** @const */ var LanguageList = options.LanguageList;
11 /** @const */ var ThirdPartyImeConfirmOverlay = 12 /** @const */ var ThirdPartyImeConfirmOverlay =
12 options.ThirdPartyImeConfirmOverlay; 13 options.ThirdPartyImeConfirmOverlay;
13 14
14 /** 15 /**
15 * Spell check dictionary download status. 16 * Spell check dictionary download status.
16 * @type {Enum} 17 * @type {Enum}
17 */ 18 */
18 /** @const*/ var DOWNLOAD_STATUS = { 19 /** @const*/ var DOWNLOAD_STATUS = {
19 IN_PROGRESS: 1, 20 IN_PROGRESS: 1,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 var ENABLE_TRANSLATE = 'translate.enabled'; 67 var ENABLE_TRANSLATE = 'translate.enabled';
67 68
68 ///////////////////////////////////////////////////////////////////////////// 69 /////////////////////////////////////////////////////////////////////////////
69 // LanguageOptions class: 70 // LanguageOptions class:
70 71
71 /** 72 /**
72 * Encapsulated handling of ChromeOS language options page. 73 * Encapsulated handling of ChromeOS language options page.
73 * @constructor 74 * @constructor
74 */ 75 */
75 function LanguageOptions(model) { 76 function LanguageOptions(model) {
76 OptionsPage.call(this, 'languages', 77 Page.call(this, 'languages',
77 loadTimeData.getString('languagePageTabTitle'), 78 loadTimeData.getString('languagePageTabTitle'), 'languagePage');
78 'languagePage');
79 } 79 }
80 80
81 cr.addSingletonGetter(LanguageOptions); 81 cr.addSingletonGetter(LanguageOptions);
82 82
83 // Inherit LanguageOptions from OptionsPage. 83 // Inherit LanguageOptions from Page.
84 LanguageOptions.prototype = { 84 LanguageOptions.prototype = {
85 __proto__: OptionsPage.prototype, 85 __proto__: Page.prototype,
86 86
87 /* For recording the prospective language (the next locale after relaunch). 87 /* For recording the prospective language (the next locale after relaunch).
88 * @type {?string} 88 * @type {?string}
89 * @private 89 * @private
90 */ 90 */
91 prospectiveUiLanguageCode_: null, 91 prospectiveUiLanguageCode_: null,
92 92
93 /* 93 /*
94 * Map from language code to spell check dictionary download status for that 94 * Map from language code to spell check dictionary download status for that
95 * language. 95 * language.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 /** 152 /**
153 * The value that indicates if Translate feature is enabled or not. 153 * The value that indicates if Translate feature is enabled or not.
154 * @type {boolean} 154 * @type {boolean}
155 * @private 155 * @private
156 */ 156 */
157 enableTranslate_: false, 157 enableTranslate_: false,
158 158
159 /** 159 /**
160 * Initializes LanguageOptions page. 160 * Initializes LanguageOptions page.
161 * Calls base class implementation to start preference initialization.
162 */ 161 */
163 initializePage: function() { 162 initializePage: function() {
164 OptionsPage.prototype.initializePage.call(this); 163 Page.prototype.initializePage.call(this);
165 164
166 var languageOptionsList = $('language-options-list'); 165 var languageOptionsList = $('language-options-list');
167 LanguageList.decorate(languageOptionsList); 166 LanguageList.decorate(languageOptionsList);
168 167
169 languageOptionsList.addEventListener('change', 168 languageOptionsList.addEventListener('change',
170 this.handleLanguageOptionsListChange_.bind(this)); 169 this.handleLanguageOptionsListChange_.bind(this));
171 languageOptionsList.addEventListener('save', 170 languageOptionsList.addEventListener('save',
172 this.handleLanguageOptionsListSave_.bind(this)); 171 this.handleLanguageOptionsListSave_.bind(this));
173 172
174 this.prospectiveUiLanguageCode_ = 173 this.prospectiveUiLanguageCode_ =
(...skipping 23 matching lines...) Expand all
198 // Set up add button. 197 // Set up add button.
199 var onclick = function(e) { 198 var onclick = function(e) {
200 // Add the language without showing the overlay if it's specified in 199 // Add the language without showing the overlay if it's specified in
201 // the URL hash (ex. lang_add=ja). Used for automated testing. 200 // the URL hash (ex. lang_add=ja). Used for automated testing.
202 var match = document.location.hash.match(/\blang_add=([\w-]+)/); 201 var match = document.location.hash.match(/\blang_add=([\w-]+)/);
203 if (match) { 202 if (match) {
204 var addLanguageCode = match[1]; 203 var addLanguageCode = match[1];
205 $('language-options-list').addLanguage(addLanguageCode); 204 $('language-options-list').addLanguage(addLanguageCode);
206 this.addBlockedLanguage_(addLanguageCode); 205 this.addBlockedLanguage_(addLanguageCode);
207 } else { 206 } else {
208 OptionsPage.navigateToPage('addLanguage'); 207 PageManager.showPageByName('addLanguage');
209 } 208 }
210 }; 209 };
211 $('language-options-add-button').onclick = onclick.bind(this); 210 $('language-options-add-button').onclick = onclick.bind(this);
212 211
213 if (!cr.isMac) { 212 if (!cr.isMac) {
214 // Set up the button for editing custom spelling dictionary. 213 // Set up the button for editing custom spelling dictionary.
215 $('edit-dictionary-button').onclick = function(e) { 214 $('edit-dictionary-button').onclick = function(e) {
216 OptionsPage.navigateToPage('editDictionary'); 215 PageManager.showPageByName('editDictionary');
217 }; 216 };
218 $('dictionary-download-retry-button').onclick = function(e) { 217 $('dictionary-download-retry-button').onclick = function(e) {
219 chrome.send('retryDictionaryDownload'); 218 chrome.send('retryDictionaryDownload');
220 }; 219 };
221 } 220 }
222 221
223 // Listen to add language dialog ok button. 222 // Listen to add language dialog ok button.
224 $('add-language-overlay-ok-button').addEventListener( 223 $('add-language-overlay-ok-button').addEventListener(
225 'click', this.handleAddLanguageOkButtonClick_.bind(this)); 224 'click', this.handleAddLanguageOkButtonClick_.bind(this));
226 225
(...skipping 19 matching lines...) Expand all
246 this.handleSpellCheckLanguageButtonClick_.bind(this)); 245 this.handleSpellCheckLanguageButtonClick_.bind(this));
247 } 246 }
248 247
249 if (cr.isChromeOS) { 248 if (cr.isChromeOS) {
250 $('language-options-ui-restart-button').onclick = function() { 249 $('language-options-ui-restart-button').onclick = function() {
251 chrome.send('uiLanguageRestart'); 250 chrome.send('uiLanguageRestart');
252 }; 251 };
253 } 252 }
254 253
255 $('language-confirm').onclick = 254 $('language-confirm').onclick =
256 OptionsPage.closeOverlay.bind(OptionsPage); 255 PageManager.closeOverlay.bind(PageManager);
257 256
258 // Public session users cannot change the locale. 257 // Public session users cannot change the locale.
259 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) 258 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount())
260 $('language-options-ui-language-section').hidden = true; 259 $('language-options-ui-language-section').hidden = true;
260 PageManager.closeOverlay.bind(PageManager);
261 }, 261 },
262 262
263 /** 263 /**
264 * Initializes the input method list. 264 * Initializes the input method list.
265 */ 265 */
266 initializeInputMethodList_: function() { 266 initializeInputMethodList_: function() {
267 var inputMethodList = $('language-options-input-method-list'); 267 var inputMethodList = $('language-options-input-method-list');
268 var inputMethodPrototype = $('language-options-input-method-template'); 268 var inputMethodPrototype = $('language-options-input-method-template');
269 269
270 // Add all input methods, but make all of them invisible here. We'll 270 // Add all input methods, but make all of them invisible here. We'll
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 this.translateBlockedLanguages_.filter( 377 this.translateBlockedLanguages_.filter(
378 function(langCodeNotTranslated) { 378 function(langCodeNotTranslated) {
379 return langCodeNotTranslated != langCode; 379 return langCodeNotTranslated != langCode;
380 }); 380 });
381 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, 381 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF,
382 this.translateBlockedLanguages_, true); 382 this.translateBlockedLanguages_, true);
383 } 383 }
384 }, 384 },
385 385
386 /** 386 /**
387 * Handles OptionsPage's visible property change event. 387 * Handles Page's visible property change event.
388 * @param {Event} e Property change event. 388 * @param {Event} e Property change event.
389 * @private 389 * @private
390 */ 390 */
391 handleVisibleChange_: function(e) { 391 handleVisibleChange_: function(e) {
392 if (this.visible) { 392 if (this.visible) {
393 $('language-options-list').redraw(); 393 $('language-options-list').redraw();
394 chrome.send('languageOptionsOpen'); 394 chrome.send('languageOptionsOpen');
395 } 395 }
396 }, 396 },
397 397
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 * @private 886 * @private
887 */ 887 */
888 handleAddLanguageOkButtonClick_: function(e) { 888 handleAddLanguageOkButtonClick_: function(e) {
889 var languagesSelect = $('add-language-overlay-language-list'); 889 var languagesSelect = $('add-language-overlay-language-list');
890 var selectedIndex = languagesSelect.selectedIndex; 890 var selectedIndex = languagesSelect.selectedIndex;
891 if (selectedIndex >= 0) { 891 if (selectedIndex >= 0) {
892 var selection = languagesSelect.options[selectedIndex]; 892 var selection = languagesSelect.options[selectedIndex];
893 var langCode = String(selection.value); 893 var langCode = String(selection.value);
894 $('language-options-list').addLanguage(langCode); 894 $('language-options-list').addLanguage(langCode);
895 this.addBlockedLanguage_(langCode); 895 this.addBlockedLanguage_(langCode);
896 OptionsPage.closeOverlay(); 896 PageManager.closeOverlay();
897 } 897 }
898 }, 898 },
899 899
900 /** 900 /**
901 * Checks if languageCode is deletable or not. 901 * Checks if languageCode is deletable or not.
902 * @param {string} languageCode the languageCode to check for deletability. 902 * @param {string} languageCode the languageCode to check for deletability.
903 */ 903 */
904 languageIsDeletable: function(languageCode) { 904 languageIsDeletable: function(languageCode) {
905 // Don't allow removing the language if it's a UI language. 905 // Don't allow removing the language if it's a UI language.
906 if (languageCode == this.prospectiveUiLanguageCode_) 906 if (languageCode == this.prospectiveUiLanguageCode_)
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 1358
1359 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { 1359 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) {
1360 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); 1360 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode);
1361 }; 1361 };
1362 1362
1363 // Export 1363 // Export
1364 return { 1364 return {
1365 LanguageOptions: LanguageOptions 1365 LanguageOptions: LanguageOptions
1366 }; 1366 };
1367 }); 1367 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698