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

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: Created 4 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
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 /** Preferences state. */
14 prefs: {
15 type: Object,
16 notify: true,
17 },
18
19 /** @type {!LanguagesModel|undefined} */
20 languages: {
21 type: Object,
22 notify: true,
23 },
24
25 /** @type {!LanguageHelper} */
26 languageHelper: Object,
27
28 /** @private {!Set<string>} */
29 languagesToAdd_: {
30 type: Object,
31 value: function() { return new Set(); },
32 },
33
34 /** @private */
35 disableActionButton_: {
36 type: Boolean,
37 value: true,
38 },
39 },
40
41 attached: function() {
42 this.$.dialog.showModal();
43 },
44
45 /**
46 * Returns the supported languages that are not yet enabled.
47 * @param {!Array<!chrome.languageSettingsPrivate.Language>}
48 * supportedLanguages
49 * @return {!Array<!chrome.languageSettingsPrivate.Language>}
50 * @private
51 */
52 getAvailableLanguages_: function(supportedLanguages) {
53 return supportedLanguages.filter(function(language) {
54 return !this.languageHelper.isLanguageEnabled(language.code);
55 }.bind(this));
56 },
57
58 /**
59 * True if the user has chosen to add this language (checked its checkbox).
60 * @return {boolean}
61 * @private
62 */
63 willAdd_: function(languageCode) {
64 return this.languagesToAdd_.has(languageCode);
65 },
66
67 /**
68 * Handler for checking or unchecking a language item.
69 * @param {!{model: !{item: !chrome.languageSettingsPrivate.Language},
70 * target: !PaperCheckboxElement}} e
71 * @private
72 */
73 onLanguageCheckboxChange_: function(e) {
74 // Add or remove the item to the Set. No need to worry about data binding:
75 // willAdd_ is called to initialize the checkbox state (in case the
76 // iron-list re-uses a previous checkbox), and the checkbox can only be
77 // changed after that by user action.
78 var code = e.model.item.code;
79 if (e.target.checked)
80 this.languagesToAdd_.add(code);
81 else
82 this.languagesToAdd_.delete(code);
83
84 this.disableActionButton_ = !this.languagesToAdd_.size;
85 },
86
87 /** @private */
88 onCancelButtonTap_: function() {
89 this.$.dialog.close();
90 },
91
92 /**
93 * Enables the checked languages.
94 * @private
95 */
96 onActionButtonTap_: function() {
97 this.$.dialog.close();
98 for (var languageCode of this.languagesToAdd_)
99 this.languageHelper.enableLanguage(languageCode);
100 },
101 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698