| OLD | NEW |
| 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 Loading... |
| 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 | 43 |
| 38 // Prevent flashing the Cancel button's focus state. | 44 // Prevent flashing the Cancel button's focus state. |
| 39 this.$$('.cancel-button').blur(); | 45 this.$$('.cancel-button').blur(); |
| 40 setTimeout(this.afterShown_.bind(this)); | 46 setTimeout(this.afterShown_.bind(this)); |
| 41 }, | 47 }, |
| 42 | 48 |
| 43 /** | 49 /** |
| 44 * Re-initializes the dialog after it is shown. | 50 * Re-initializes the dialog after it is shown. |
| 45 * @private | 51 * @private |
| 46 */ | 52 */ |
| 47 afterShown_: function() { | 53 afterShown_: function() { |
| 48 // Only fire iron-resize after the list displayed to prevent flickering. | 54 // Only fire iron-resize after the list displayed to prevent flickering. |
| 49 this.$$('iron-list').fire('iron-resize'); | 55 this.$$('iron-list').fire('iron-resize'); |
| 50 | 56 |
| 51 // Focus the top checkbox, assuming there are languages left to enable. | 57 // Focus the top checkbox, assuming there are languages left to enable. |
| 52 var firstCheckbox = this.$$('iron-list paper-checkbox'); | 58 var firstCheckbox = this.$$('iron-list paper-checkbox'); |
| 53 if (firstCheckbox) | 59 if (firstCheckbox) |
| 54 firstCheckbox.focus(); | 60 firstCheckbox.focus(); |
| 55 }, | 61 }, |
| 56 | 62 |
| 57 /** | 63 /** |
| 58 * Returns the supported languages that are not yet enabled, based on | 64 * Returns the supported languages that are not yet enabled |
| 65 * and matching with filter keyword, based on |
| 59 * the LanguageHelper's enabled languages list. | 66 * the LanguageHelper's enabled languages list. |
| 60 * @param {!Array<!chrome.languageSettingsPrivate.Language>} | 67 * @param {!Array<!chrome.languageSettingsPrivate.Language>} |
| 61 * supportedLanguages | 68 * supportedLanguages |
| 62 * @param {!Object} enabledLanguagesChange Polymer change record for | 69 * @param {!Object} enabledLanguagesChange Polymer change record for |
| 63 * |enabledLanguages|. | 70 * |enabledLanguages|. |
| 71 * @param {string} filterValue Keyword to filter languages in |
| 72 * supported languages. |
| 64 * @return {!Array<!chrome.languageSettingsPrivate.Language>} | 73 * @return {!Array<!chrome.languageSettingsPrivate.Language>} |
| 65 * @private | 74 * @private |
| 66 */ | 75 */ |
| 67 getAvailableLanguages_: function(supportedLanguages, enabledLanguagesChange) { | 76 getAvailableLanguages_: function(supportedLanguages, |
| 77 enabledLanguagesChange, |
| 78 filterValue) { |
| 68 return supportedLanguages.filter(function(language) { | 79 return supportedLanguages.filter(function(language) { |
| 69 return !this.languageHelper.isLanguageEnabled(language.code); | 80 var isAvailableLanguage = |
| 81 !this.languageHelper.isLanguageEnabled(language.code); |
| 82 if (!filterValue) { |
| 83 return isAvailableLanguage; |
| 84 } else { |
| 85 return isAvailableLanguage && |
| 86 language.displayName |
| 87 .toLowerCase().includes(filterValue.toLowerCase()); |
| 88 } |
| 70 }.bind(this)); | 89 }.bind(this)); |
| 71 }, | 90 }, |
| 72 | 91 |
| 73 /** | 92 /** |
| 74 * True if the user has chosen to add this language (checked its checkbox). | 93 * True if the user has chosen to add this language (checked its checkbox). |
| 75 * @return {boolean} | 94 * @return {boolean} |
| 76 * @private | 95 * @private |
| 77 */ | 96 */ |
| 78 willAdd_: function(languageCode) { | 97 willAdd_: function(languageCode) { |
| 79 return this.languagesToAdd_.has(languageCode); | 98 return this.languagesToAdd_.has(languageCode); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 * Enables the checked languages. | 127 * Enables the checked languages. |
| 109 * @private | 128 * @private |
| 110 */ | 129 */ |
| 111 onActionButtonTap_: function() { | 130 onActionButtonTap_: function() { |
| 112 this.$.dialog.close(); | 131 this.$.dialog.close(); |
| 113 this.languagesToAdd_.forEach(function(language) { | 132 this.languagesToAdd_.forEach(function(language) { |
| 114 this.languageHelper.enableLanguage(language); | 133 this.languageHelper.enableLanguage(language); |
| 115 }.bind(this)); | 134 }.bind(this)); |
| 116 }, | 135 }, |
| 117 }); | 136 }); |
| OLD | NEW |