Chromium Code Reviews| 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. | |
| 26 * @private {boolean} | |
| 27 */ | |
| 28 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.
| |
| 29 type: Boolean, | |
| 30 value: true | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * The currently signed in user and the custodian. | |
| 35 * @private {?SignedInUser} | |
| 36 */ | |
| 37 signedInUser_: { | |
| 38 type: Object, | |
| 39 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.
| |
| 40 }, | |
| 41 | |
| 42 /** | |
| 43 * The list of supervised users managed by signedInUser_. | |
| 44 * @private {!Array<!SupervisedUser>} | |
| 45 */ | |
| 46 supervisedUsers_: { | |
| 47 type: Array, | |
| 48 value: function() { return []; } | |
| 49 }, | |
| 50 | |
| 51 /** | |
| 52 * Index of the selected supervised user. | |
| 53 * @private {number} | |
| 54 */ | |
| 55 supervisedUserIndex_: { | |
| 56 type: Number, | |
| 57 value: NO_USER_SELECTED | |
| 58 }, | |
| 59 | |
| 60 /** | |
| 61 * Supervised user import message. | |
| 62 * @private {string} | |
| 63 */ | |
| 64 message_: { | |
| 65 type: String, | |
| 66 value: '' | |
| 67 } | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Displays the popup. | |
| 72 * @param {SignedInUser} signedInUser | |
| 73 * @param {Array<!SupervisedUser>} supervisedUsers | |
| 74 */ | |
| 75 show: function(signedInUser, supervisedUsers) { | |
| 76 this.signedInUser_ = signedInUser || null; | |
| 77 this.supervisedUsers_ = this.sortSupervisedUsers_(supervisedUsers || []); | |
| 78 this.supervisedUserIndex_ = NO_USER_SELECTED; | |
| 79 this.message_ = this.supervisedUsers_.length > 0 ? | |
| 80 this.i18n('supervisedUserImportText') : | |
| 81 this.i18n('noSupervisedUserImportText'); | |
| 82 if (this.signedInUser_) | |
| 83 this.hidden_ = false; | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Sorts supervised users. | |
| 88 * @param {!Array<!SupervisedUser>} supervisedUsers Array of supervised users. | |
| 89 * @return {!Array<!SupervisedUser>} Sorted array of supervised users. | |
| 90 * @private | |
| 91 */ | |
| 92 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.
| |
| 93 supervisedUsers.sort(function(a, b) { | |
| 94 if (a.onCurrentDevice != b.onCurrentDevice) | |
| 95 return a.onCurrentDevice ? 1 : -1; | |
| 96 return a.name.localeCompare(b.name); | |
| 97 }); | |
| 98 return supervisedUsers; | |
| 99 }, | |
| 100 | |
| 101 /** | |
| 102 * Returns the appropriate class names for the HTML container of | |
| 103 * |supervisedUser| depending on if is currently located on the disk. | |
| 104 * @param {!SupervisedUser} supervisedUser | |
| 105 * @private | |
| 106 */ | |
| 107 getUserClassNames_: function(supervisedUser) { | |
| 108 var classNames = 'list-item'; | |
| 109 if (!supervisedUser.onCurrentDevice) { | |
| 110 classNames += ' selectable'; | |
| 111 } | |
| 112 return classNames; | |
| 113 }, | |
| 114 | |
| 115 /** | |
| 116 * Hides the popup. | |
| 117 * @private | |
| 118 */ | |
| 119 onCancelTap_: function() { | |
| 120 this.hidden_ = true; | |
| 121 }, | |
| 122 | |
| 123 /** | |
| 124 * Returns true if the 'Import' button should be enabled and false otherwise. | |
| 125 * @private | |
| 126 * @return {boolean} | |
| 127 */ | |
| 128 isImportDisabled_: function(supervisedUserIndex) { | |
| 129 return supervisedUserIndex == NO_USER_SELECTED; | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * Called when the user clicks the 'Import' button. it proceeds with importing | |
| 134 * the supervised user. | |
| 135 * @private | |
| 136 */ | |
| 137 onImportTap_: function() { | |
| 138 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; | |
| 139 if (this.signedInUser_ && supervisedUser) { | |
| 140 // Event is caught by create-profile. | |
| 141 this.fire('import', {supervisedUser: supervisedUser, | |
| 142 signedInUser: this.signedInUser_}); | |
| 143 this.hidden_ = true; | |
| 144 } | |
| 145 } | |
| 146 }); | |
| 147 })(); | |
| OLD | NEW |