| OLD | NEW |
| (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 'import-supervised-user' is a popup that allows user to select |
| 7 * a supervised profile from a list of profiles to import on the current device. |
| 8 */ |
| 9 (function() { |
| 10 /** |
| 11 * It means no supervised user is selected. |
| 12 * @const {number} |
| 13 */ |
| 14 var NO_USER_SELECTED = -1; |
| 15 |
| 16 Polymer({ |
| 17 is: 'import-supervised-user', |
| 18 |
| 19 behaviors: [ |
| 20 I18nBehavior, |
| 21 ], |
| 22 |
| 23 properties: { |
| 24 /** |
| 25 * True if the element is currently hidden. The element toggles this in |
| 26 * order to display itself or hide itself once done. |
| 27 * @private {boolean} |
| 28 */ |
| 29 popupHidden_: { |
| 30 type: Boolean, |
| 31 value: true |
| 32 }, |
| 33 |
| 34 /** |
| 35 * The currently signed in user and the custodian. |
| 36 * @private {?SignedInUser} |
| 37 */ |
| 38 signedInUser_: { |
| 39 type: Object, |
| 40 value: function() { return null; } |
| 41 }, |
| 42 |
| 43 /** |
| 44 * The list of supervised users managed by signedInUser_. |
| 45 * @private {!Array<!SupervisedUser>} |
| 46 */ |
| 47 supervisedUsers_: { |
| 48 type: Array, |
| 49 value: function() { return []; } |
| 50 }, |
| 51 |
| 52 /** |
| 53 * Index of the selected supervised user. |
| 54 * @private {number} |
| 55 */ |
| 56 supervisedUserIndex_: { |
| 57 type: Number, |
| 58 value: NO_USER_SELECTED |
| 59 } |
| 60 }, |
| 61 |
| 62 /** |
| 63 * Displays the popup. |
| 64 * @param {SignedInUser} signedInUser |
| 65 * @param {Array<!SupervisedUser>} supervisedUsers |
| 66 */ |
| 67 show: function(signedInUser, supervisedUsers) { |
| 68 this.supervisedUsers_ = supervisedUsers || []; |
| 69 this.supervisedUsers_.sort(function(a, b) { |
| 70 if (a.onCurrentDevice != b.onCurrentDevice) |
| 71 return a.onCurrentDevice ? 1 : -1; |
| 72 return a.name.localeCompare(b.name); |
| 73 }); |
| 74 |
| 75 this.supervisedUserIndex_ = NO_USER_SELECTED; |
| 76 |
| 77 this.signedInUser_ = signedInUser || null; |
| 78 if (this.signedInUser_) |
| 79 this.popupHidden_ = false; |
| 80 }, |
| 81 |
| 82 /** |
| 83 * Computed binding that returns the appropriate import message depending on |
| 84 * whether or not there are any supervised users to import. |
| 85 * @param {!Array<!SupervisedUser>} supervisedUsers |
| 86 * @private |
| 87 * @return {string} |
| 88 */ |
| 89 getMessage_: function(supervisedUsers) { |
| 90 return supervisedUsers.length > 0 ? this.i18n('supervisedUserImportText') : |
| 91 this.i18n('noSupervisedUserImportText'); |
| 92 }, |
| 93 |
| 94 /** |
| 95 * Computed binding that returns the appropriate class names for the HTML |
| 96 * container of |supervisedUser| depending on whether it is on this device. |
| 97 * @param {!SupervisedUser} supervisedUser |
| 98 * @private |
| 99 * @return {string} |
| 100 */ |
| 101 getUserClassNames_: function(supervisedUser) { |
| 102 var classNames = 'list-item'; |
| 103 if (!supervisedUser.onCurrentDevice) { |
| 104 classNames += ' selectable'; |
| 105 } |
| 106 return classNames; |
| 107 }, |
| 108 |
| 109 /** |
| 110 * Hides the popup. |
| 111 * @private |
| 112 */ |
| 113 onCancelTap_: function() { |
| 114 this.popupHidden_ = true; |
| 115 }, |
| 116 |
| 117 /** |
| 118 * Returns true if the 'Import' button should be enabled and false otherwise. |
| 119 * @private |
| 120 * @return {boolean} |
| 121 */ |
| 122 isImportDisabled_: function(supervisedUserIndex) { |
| 123 return supervisedUserIndex == NO_USER_SELECTED; |
| 124 }, |
| 125 |
| 126 /** |
| 127 * Called when the user clicks the 'Import' button. it proceeds with importing |
| 128 * the supervised user. |
| 129 * @private |
| 130 */ |
| 131 onImportTap_: function() { |
| 132 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; |
| 133 if (this.signedInUser_ && supervisedUser) { |
| 134 // Event is caught by create-profile. |
| 135 this.fire('import', {supervisedUser: supervisedUser, |
| 136 signedInUser: this.signedInUser_}); |
| 137 this.popupHidden_ = true; |
| 138 } |
| 139 } |
| 140 }); |
| 141 })(); |
| OLD | NEW |