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

Unified Diff: chrome/browser/resources/md_user_manager/import_supervised_user.js

Issue 1901853002: Import supervised user dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md-user-manager-confirmation-page
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_user_manager/import_supervised_user.js
diff --git a/chrome/browser/resources/md_user_manager/import_supervised_user.js b/chrome/browser/resources/md_user_manager/import_supervised_user.js
new file mode 100644
index 0000000000000000000000000000000000000000..d671fb8f78ccfae5ae28ebaabaaf727868e25dea
--- /dev/null
+++ b/chrome/browser/resources/md_user_manager/import_supervised_user.js
@@ -0,0 +1,147 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview 'import-supervised-user' is a popup that allows user to select
+ * a supervised profile from a list of profiles to import on the current device.
+ */
+(function() {
+/**
+ * It means no supervised user is selected.
+ * @const {number}
+ */
+var NO_USER_SELECTED = -1;
+
+Polymer({
+ is: 'import-supervised-user',
+
+ behaviors: [
+ I18nBehavior,
+ ],
+
+ properties: {
+ /**
+ * True if the element is currently hidden.
+ * @private {boolean}
+ */
+ hidden_: {
tommycli 2016/04/18 23:27:18 Maybe clarify the var name and comment to indicate
Moe 2016/04/19 21:47:43 Done.
+ type: Boolean,
+ value: true
+ },
+
+ /**
+ * The currently signed in user and the custodian.
+ * @private {?SignedInUser}
+ */
+ signedInUser_: {
+ type: Object,
+ value: function() { return null; },
tommycli 2016/04/18 23:27:18 nit: all of the final values have no comma, except
Moe 2016/04/19 21:47:43 Done.
+ },
+
+ /**
+ * The list of supervised users managed by signedInUser_.
+ * @private {!Array<!SupervisedUser>}
+ */
+ supervisedUsers_: {
+ type: Array,
+ value: function() { return []; }
+ },
+
+ /**
+ * Index of the selected supervised user.
+ * @private {number}
+ */
+ supervisedUserIndex_: {
+ type: Number,
+ value: NO_USER_SELECTED
+ },
+
+ /**
+ * Supervised user import message.
+ * @private {string}
+ */
+ message_: {
+ type: String,
+ value: ''
+ }
+ },
+
+ /**
+ * Displays the popup.
+ * @param {SignedInUser} signedInUser
+ * @param {Array<!SupervisedUser>} supervisedUsers
+ */
+ show: function(signedInUser, supervisedUsers) {
+ this.signedInUser_ = signedInUser || null;
+ this.supervisedUsers_ = this.sortSupervisedUsers_(supervisedUsers || []);
+ this.supervisedUserIndex_ = NO_USER_SELECTED;
+ this.message_ = this.supervisedUsers_.length > 0 ?
+ this.i18n('supervisedUserImportText') :
+ this.i18n('noSupervisedUserImportText');
+ if (this.signedInUser_)
+ this.hidden_ = false;
+ },
+
+ /**
+ * Sorts supervised users.
+ * @param {!Array<!SupervisedUser>} supervisedUsers Array of supervised users.
+ * @return {!Array<!SupervisedUser>} Sorted array of supervised users.
+ * @private
+ */
+ sortSupervisedUsers_: function(supervisedUsers) {
tommycli 2016/04/18 23:27:18 Since this method is only used once and is private
Moe 2016/04/19 21:47:43 Done.
+ supervisedUsers.sort(function(a, b) {
+ if (a.onCurrentDevice != b.onCurrentDevice)
+ return a.onCurrentDevice ? 1 : -1;
+ return a.name.localeCompare(b.name);
+ });
+ return supervisedUsers;
+ },
+
+ /**
+ * Returns the appropriate class names for the HTML container of
+ * |supervisedUser| depending on if is currently located on the disk.
+ * @param {!SupervisedUser} supervisedUser
+ * @private
+ */
+ getUserClassNames_: function(supervisedUser) {
+ var classNames = 'list-item';
+ if (!supervisedUser.onCurrentDevice) {
+ classNames += ' selectable';
+ }
+ return classNames;
+ },
+
+ /**
+ * Hides the popup.
+ * @private
+ */
+ onCancelTap_: function() {
+ this.hidden_ = true;
+ },
+
+ /**
+ * Returns true if the 'Import' button should be enabled and false otherwise.
+ * @private
+ * @return {boolean}
+ */
+ isImportDisabled_: function(supervisedUserIndex) {
+ return supervisedUserIndex == NO_USER_SELECTED;
+ },
+
+ /**
+ * Called when the user clicks the 'Import' button. it proceeds with importing
+ * the supervised user.
+ * @private
+ */
+ onImportTap_: function() {
+ var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_];
+ if (this.signedInUser_ && supervisedUser) {
+ // Event is caught by create-profile.
+ this.fire('import', {supervisedUser: supervisedUser,
+ signedInUser: this.signedInUser_});
+ this.hidden_ = true;
+ }
+ }
+});
+})();

Powered by Google App Engine
This is Rietveld 408576698