| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-user-list' shows a list of users whitelisted on this Chrome OS | 7 * 'settings-user-list' shows a list of users whitelisted on this Chrome OS |
| 8 * device. | 8 * device. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| 11 * | 11 * |
| 12 * <settings-user-list prefs="{{prefs}}"> | 12 * <settings-user-list prefs="{{prefs}}"> |
| 13 * </settings-user-list> | 13 * </settings-user-list> |
| 14 */ | 14 */ |
| 15 Polymer({ | 15 Polymer({ |
| 16 is: 'settings-user-list', | 16 is: 'settings-user-list', |
| 17 | 17 |
| 18 behaviors: [ | 18 behaviors: [I18nBehavior, settings.RouteObserverBehavior], |
| 19 settings.RouteObserverBehavior, | |
| 20 ], | |
| 21 | 19 |
| 22 properties: { | 20 properties: { |
| 23 /** | 21 /** |
| 24 * Current list of whitelisted users. | 22 * Current list of whitelisted users. |
| 25 * @private {!Array<!chrome.usersPrivate.User>} | 23 * @private {!Array<!chrome.usersPrivate.User>} |
| 26 */ | 24 */ |
| 27 users_: { | 25 users_: { |
| 28 type: Array, | 26 type: Array, |
| 29 value: function() { return []; }, | 27 value: function() { |
| 28 return []; |
| 29 }, |
| 30 notify: true | 30 notify: true |
| 31 }, | 31 }, |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Whether the user list is disabled, i.e. that no modifications can be | 34 * Whether the user list is disabled, i.e. that no modifications can be |
| 35 * made. | 35 * made. |
| 36 * @type {boolean} | 36 * @type {boolean} |
| 37 */ | 37 */ |
| 38 disabled: { | 38 disabled: { |
| 39 type: Boolean, | 39 type: Boolean, |
| 40 value: false | 40 value: false, |
| 41 } | 41 } |
| 42 }, | 42 }, |
| 43 | 43 |
| 44 /** @override */ | 44 /** @override */ |
| 45 ready: function() { | 45 ready: function() { |
| 46 chrome.settingsPrivate.onPrefsChanged.addListener(function(prefs) { | 46 chrome.settingsPrivate.onPrefsChanged.addListener(function(prefs) { |
| 47 prefs.forEach(function(pref) { | 47 prefs.forEach(function(pref) { |
| 48 if (pref.key == 'cros.accounts.users') { | 48 if (pref.key == 'cros.accounts.users') { |
| 49 chrome.usersPrivate.getWhitelistedUsers(function(users) { | 49 chrome.usersPrivate.getWhitelistedUsers(function(users) { |
| 50 this.setUsers_(users); | 50 this.setUsers_(users); |
| 51 }.bind(this)); | 51 }.bind(this)); |
| 52 } | 52 } |
| 53 }, this); | 53 }, this); |
| 54 }.bind(this)); | 54 }.bind(this)); |
| 55 }, | 55 }, |
| 56 | 56 |
| 57 /** @protected */ | 57 /** @protected */ |
| 58 currentRouteChanged: function() { | 58 currentRouteChanged: function() { |
| 59 if (settings.getCurrentRoute() == settings.Route.ACCOUNTS) { | 59 if (settings.getCurrentRoute() == settings.Route.ACCOUNTS) { |
| 60 chrome.usersPrivate.getWhitelistedUsers(function(users) { | 60 chrome.usersPrivate.getWhitelistedUsers(function(users) { |
| 61 this.setUsers_(users); | 61 this.setUsers_(users); |
| 62 }.bind(this)); | 62 }.bind(this)); |
| 63 } | 63 } |
| 64 }, | 64 }, |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @param {!chrome.usersPrivate.User} user |
| 68 * @return {string} |
| 69 * @private |
| 70 */ |
| 71 getUserName_: function(user) { |
| 72 return user.isOwner ? this.i18n('deviceOwnerLabel', user.name) : user.name; |
| 73 }, |
| 74 |
| 75 /** |
| 67 * Helper function that sorts and sets the given list of whitelisted users. | 76 * Helper function that sorts and sets the given list of whitelisted users. |
| 68 * @param {!Array<!chrome.usersPrivate.User>} users List of whitelisted users. | 77 * @param {!Array<!chrome.usersPrivate.User>} users List of whitelisted users. |
| 69 */ | 78 */ |
| 70 setUsers_: function(users) { | 79 setUsers_: function(users) { |
| 71 this.users_ = users; | 80 this.users_ = users; |
| 72 this.users_.sort(function(a, b) { | 81 this.users_.sort(function(a, b) { |
| 73 if (a.isOwner != b.isOwner) | 82 if (a.isOwner != b.isOwner) |
| 74 return b.isOwner ? 1 : -1; | 83 return b.isOwner ? 1 : -1; |
| 75 else | 84 else |
| 76 return -1; | 85 return -1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 /** @private */ | 98 /** @private */ |
| 90 shouldHideCloseButton_: function(disabled, isUserOwner) { | 99 shouldHideCloseButton_: function(disabled, isUserOwner) { |
| 91 return disabled || isUserOwner; | 100 return disabled || isUserOwner; |
| 92 }, | 101 }, |
| 93 | 102 |
| 94 /** @private */ | 103 /** @private */ |
| 95 getProfilePictureUrl_: function(username) { | 104 getProfilePictureUrl_: function(username) { |
| 96 return 'chrome://userimage/' + username + '?id=' + Date.now(); | 105 return 'chrome://userimage/' + username + '?id=' + Date.now(); |
| 97 } | 106 } |
| 98 }); | 107 }); |
| OLD | NEW |