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

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: indent 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 /** @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, based on
41 * the LanguageHelper's enabled languages list.
42 * @param {!Array<!chrome.languageSettingsPrivate.Language>}
43 * supportedLanguages
44 * @param {!Object} enabledLanguagesChange Polymer change record for
45 * |enabledLanguages|.
46 * @return {!Array<!chrome.languageSettingsPrivate.Language>}
47 * @private
48 */
49 getAvailableLanguages_: function(supportedLanguages, enabledLanguagesChange) {
50 return supportedLanguages.filter(function(language) {
51 return !this.languageHelper.isLanguageEnabled(language.code);
52 }.bind(this));
53 },
54
55 /**
56 * True if the user has chosen to add this language (checked its checkbox).
57 * @return {boolean}
58 * @private
59 */
60 willAdd_: function(languageCode) {
61 return this.languagesToAdd_.has(languageCode);
62 },
63
64 /**
65 * Handler for checking or unchecking a language item.
66 * @param {!{model: !{item: !chrome.languageSettingsPrivate.Language},
67 * target: !PaperCheckboxElement}} e
68 * @private
69 */
70 onLanguageCheckboxChange_: function(e) {
71 // Add or remove the item to the Set. No need to worry about data binding:
72 // willAdd_ is called to initialize the checkbox state (in case the
73 // iron-list re-uses a previous checkbox), and the checkbox can only be
74 // changed after that by user action.
75 var code = e.model.item.code;
76 if (e.target.checked)
77 this.languagesToAdd_.add(code);
78 else
79 this.languagesToAdd_.delete(code);
80
81 this.disableActionButton_ = !this.languagesToAdd_.size;
82 },
83
84 /** @private */
85 onCancelButtonTap_: function() {
86 this.$.dialog.close();
87 },
88
89 /**
90 * Enables the checked languages.
91 * @private
92 */
93 onActionButtonTap_: function() {
94 this.$.dialog.close();
95 for (var languageCode of this.languagesToAdd_)
96 this.languageHelper.enableLanguage(languageCode);
97 },
98 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698