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

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

Issue 2265253002: Replace Manage Languages with dialog and dropdown item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@EnableDisableLanguage
Patch Set: remove unused prefs object Created 4 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview 'settings-add-languages-dialog' is a dialog for enabling
7 * languages.
8 */
9 Polymer({
10 is: 'settings-add-languages-dialog',
11
12 properties: {
13 /** @type {!LanguagesModel|undefined} */
14 languages: {
15 type: Object,
16 notify: true,
17 },
18
19 /** @type {!LanguageHelper} */
20 languageHelper: Object,
21
22 /** @private {!Set<string>} */
23 languagesToAdd_: {
24 type: Object,
25 value: function() { return new Set(); },
26 },
27
28 /** @private */
29 disableActionButton_: {
30 type: Boolean,
31 value: true,
32 },
33 },
34
35 attached: function() {
36 this.$.dialog.showModal();
37 },
38
39 /**
40 * Returns the supported languages that are not yet enabled.
stevenjb 2016/08/23 17:08:04 The dependencies for this are subtle, we should do
michaelpg 2016/08/23 23:37:06 Done.
41 * @param {!Array<!chrome.languageSettingsPrivate.Language>}
42 * supportedLanguages
43 * @return {!Array<!chrome.languageSettingsPrivate.Language>}
44 * @private
45 */
46 getAvailableLanguages_: function(supportedLanguages) {
47 return supportedLanguages.filter(function(language) {
48 return !this.languageHelper.isLanguageEnabled(language.code);
49 }.bind(this));
50 },
51
52 /**
53 * True if the user has chosen to add this language (checked its checkbox).
54 * @return {boolean}
55 * @private
56 */
57 willAdd_: function(languageCode) {
58 return this.languagesToAdd_.has(languageCode);
59 },
60
61 /**
62 * Handler for checking or unchecking a language item.
63 * @param {!{model: !{item: !chrome.languageSettingsPrivate.Language},
64 * target: !PaperCheckboxElement}} e
65 * @private
66 */
67 onLanguageCheckboxChange_: function(e) {
68 // Add or remove the item to the Set. No need to worry about data binding:
69 // willAdd_ is called to initialize the checkbox state (in case the
70 // iron-list re-uses a previous checkbox), and the checkbox can only be
71 // changed after that by user action.
72 var code = e.model.item.code;
73 if (e.target.checked)
74 this.languagesToAdd_.add(code);
75 else
76 this.languagesToAdd_.delete(code);
77
78 this.disableActionButton_ = !this.languagesToAdd_.size;
79 },
80
81 /** @private */
82 onCancelButtonTap_: function() {
83 this.$.dialog.close();
84 },
85
86 /**
87 * Enables the checked languages.
88 * @private
89 */
90 onActionButtonTap_: function() {
91 this.$.dialog.close();
92 for (var languageCode of this.languagesToAdd_)
93 this.languageHelper.enableLanguage(languageCode);
94 },
95 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698