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

Side by Side Diff: chrome/browser/resources/settings/languages_page/add_languages_dialog.js

Issue 2519853005: MD Settings: Enable to search "Add languages" list. (Closed)
Patch Set: Fix to follow JavaScript Style Guide Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 'settings-add-languages-dialog' is a dialog for enabling 6 * @fileoverview 'settings-add-languages-dialog' is a dialog for enabling
7 * languages. 7 * languages.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-add-languages-dialog', 10 is: 'settings-add-languages-dialog',
(...skipping 12 matching lines...) Expand all
23 languagesToAdd_: { 23 languagesToAdd_: {
24 type: Object, 24 type: Object,
25 value: function() { return new Set(); }, 25 value: function() { return new Set(); },
26 }, 26 },
27 27
28 /** @private */ 28 /** @private */
29 disableActionButton_: { 29 disableActionButton_: {
30 type: Boolean, 30 type: Boolean,
31 value: true, 31 value: true,
32 }, 32 },
33
34 /** @private */
35 filterValue_: {
36 type: String,
37 value: '',
38 },
33 }, 39 },
34 40
35 attached: function() { 41 attached: function() {
36 this.$.dialog.showModal(); 42 this.$.dialog.showModal();
37 // Fire iron-resize after the list initially displays to prevent flickering. 43 // Fire iron-resize after the list initially displays to prevent flickering.
38 setTimeout(function() { 44 setTimeout(function() {
39 this.$$('iron-list').fire('iron-resize'); 45 this.$$('iron-list').fire('iron-resize');
40 }.bind(this)); 46 }.bind(this));
41 }, 47 },
42 48
43 /** 49 /**
44 * Returns the supported languages that are not yet enabled, based on 50 * Returns the supported languages that are not yet enabled
51 * and matching with filter keyword, based on
45 * the LanguageHelper's enabled languages list. 52 * the LanguageHelper's enabled languages list.
46 * @param {!Array<!chrome.languageSettingsPrivate.Language>} 53 * @param {!Array<!chrome.languageSettingsPrivate.Language>}
47 * supportedLanguages 54 * supportedLanguages
48 * @param {!Object} enabledLanguagesChange Polymer change record for 55 * @param {!Object} enabledLanguagesChange Polymer change record for
49 * |enabledLanguages|. 56 * |enabledLanguages|.
57 * @param {string} filterValue Keyword to filter languages in
58 * supported languages.
50 * @return {!Array<!chrome.languageSettingsPrivate.Language>} 59 * @return {!Array<!chrome.languageSettingsPrivate.Language>}
51 * @private 60 * @private
52 */ 61 */
53 getAvailableLanguages_: function(supportedLanguages, enabledLanguagesChange) { 62 getAvailableLanguages_: function(supportedLanguages,
63 enabledLanguagesChange,
64 filterValue) {
54 return supportedLanguages.filter(function(language) { 65 return supportedLanguages.filter(function(language) {
55 return !this.languageHelper.isLanguageEnabled(language.code); 66 var isAvailableLanguage =
67 !this.languageHelper.isLanguageEnabled(language.code);
68 if (!filterValue) {
69 return isAvailableLanguage;
70 } else {
71 return isAvailableLanguage &&
72 Boolean(~language.displayName.indexOf(filterValue));
michaelpg 2016/12/02 03:56:41 the ~ trick is a bit too clever; much more readabl
michaelpg 2016/12/02 03:56:41 This comparison should be case-insensitive (e.g. c
73 }
56 }.bind(this)); 74 }.bind(this));
57 }, 75 },
58 76
59 /** 77 /**
60 * True if the user has chosen to add this language (checked its checkbox). 78 * True if the user has chosen to add this language (checked its checkbox).
61 * @return {boolean} 79 * @return {boolean}
62 * @private 80 * @private
63 */ 81 */
64 willAdd_: function(languageCode) { 82 willAdd_: function(languageCode) {
65 return this.languagesToAdd_.has(languageCode); 83 return this.languagesToAdd_.has(languageCode);
(...skipping 27 matching lines...) Expand all
93 /** 111 /**
94 * Enables the checked languages. 112 * Enables the checked languages.
95 * @private 113 * @private
96 */ 114 */
97 onActionButtonTap_: function() { 115 onActionButtonTap_: function() {
98 this.$.dialog.close(); 116 this.$.dialog.close();
99 for (var languageCode of this.languagesToAdd_) 117 for (var languageCode of this.languagesToAdd_)
100 this.languageHelper.enableLanguage(languageCode); 118 this.languageHelper.enableLanguage(languageCode);
101 }, 119 },
102 }); 120 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698