OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 'import-supervised-user' is a dialog that allows user to select | 6 * @fileoverview 'import-supervised-user' is a dialog that allows user to select |
7 * a supervised profile from a list of profiles to import on the current device. | 7 * a supervised profile from a list of profiles to import on the current device. |
8 */ | 8 */ |
9 (function() { | 9 (function() { |
10 /** | 10 /** |
11 * It means no supervised user is selected. | 11 * It means no supervised user is selected. |
12 * @const {number} | 12 * @const {number} |
13 */ | 13 */ |
14 var NO_USER_SELECTED = -1; | 14 var NO_USER_SELECTED = -1; |
15 | 15 |
16 Polymer({ | 16 Polymer({ |
17 is: 'import-supervised-user', | 17 is: 'import-supervised-user', |
18 | 18 |
19 behaviors: [ | 19 behaviors: [ |
20 I18nBehavior, | 20 I18nBehavior, |
21 ], | 21 ], |
22 | 22 |
23 properties: { | 23 properties: { |
24 /** | 24 /** |
25 * The currently signed in user and the custodian. | 25 * The currently signed in user and the custodian. |
26 * @private {?SignedInUser} | 26 * @private {?SignedInUser} |
27 */ | 27 */ |
28 signedInUser_: { | 28 signedInUser_: { |
29 type: Object, | 29 type: Object, |
30 value: function() { return null; } | 30 value: function() { |
| 31 return null; |
| 32 } |
| 33 }, |
| 34 |
| 35 /** |
| 36 * The list of supervised users managed by signedInUser_. |
| 37 * @private {!Array<!SupervisedUser>} |
| 38 */ |
| 39 supervisedUsers_: { |
| 40 type: Array, |
| 41 value: function() { |
| 42 return []; |
| 43 } |
| 44 }, |
| 45 |
| 46 /** |
| 47 * Index of the selected supervised user. |
| 48 * @private {number} |
| 49 */ |
| 50 supervisedUserIndex_: {type: Number, value: NO_USER_SELECTED} |
| 51 }, |
| 52 |
| 53 /** override */ |
| 54 ready: function() { |
| 55 this.$.dialog.lastFocusableNode = this.$.cancel; |
31 }, | 56 }, |
32 | 57 |
33 /** | 58 /** |
34 * The list of supervised users managed by signedInUser_. | 59 * Displays the dialog. |
35 * @private {!Array<!SupervisedUser>} | 60 * @param {(!SignedInUser|undefined)} signedInUser |
| 61 * @param {!Array<!SupervisedUser>} supervisedUsers |
36 */ | 62 */ |
37 supervisedUsers_: { | 63 show: function(signedInUser, supervisedUsers) { |
38 type: Array, | 64 this.supervisedUsers_ = supervisedUsers; |
39 value: function() { return []; } | 65 this.supervisedUsers_.sort(function(a, b) { |
| 66 if (a.onCurrentDevice != b.onCurrentDevice) |
| 67 return a.onCurrentDevice ? 1 : -1; |
| 68 return a.name.localeCompare(b.name); |
| 69 }); |
| 70 |
| 71 this.supervisedUserIndex_ = NO_USER_SELECTED; |
| 72 |
| 73 this.signedInUser_ = signedInUser || null; |
| 74 if (this.signedInUser_) |
| 75 this.$.dialog.open(); |
40 }, | 76 }, |
41 | 77 |
42 /** | 78 /** |
43 * Index of the selected supervised user. | |
44 * @private {number} | |
45 */ | |
46 supervisedUserIndex_: { | |
47 type: Number, | |
48 value: NO_USER_SELECTED | |
49 } | |
50 }, | |
51 | |
52 /** override */ | |
53 ready: function() { | |
54 this.$.dialog.lastFocusableNode = this.$.cancel; | |
55 }, | |
56 | |
57 /** | |
58 * Displays the dialog. | |
59 * @param {(!SignedInUser|undefined)} signedInUser | |
60 * @param {!Array<!SupervisedUser>} supervisedUsers | |
61 */ | |
62 show: function(signedInUser, supervisedUsers) { | |
63 this.supervisedUsers_ = supervisedUsers; | |
64 this.supervisedUsers_.sort(function(a, b) { | |
65 if (a.onCurrentDevice != b.onCurrentDevice) | |
66 return a.onCurrentDevice ? 1 : -1; | |
67 return a.name.localeCompare(b.name); | |
68 }); | |
69 | |
70 this.supervisedUserIndex_ = NO_USER_SELECTED; | |
71 | |
72 this.signedInUser_ = signedInUser || null; | |
73 if (this.signedInUser_) | |
74 this.$.dialog.open(); | |
75 }, | |
76 | |
77 /** | |
78 * param {number} supervisedUserIndex Index of the selected supervised user. | 79 * param {number} supervisedUserIndex Index of the selected supervised user. |
79 * @private | 80 * @private |
80 * @return {boolean} Whether the 'Import' button should be disabled. | 81 * @return {boolean} Whether the 'Import' button should be disabled. |
81 */ | 82 */ |
82 isImportDisabled_: function(supervisedUserIndex) { | 83 isImportDisabled_: function(supervisedUserIndex) { |
83 var disabled = supervisedUserIndex == NO_USER_SELECTED; | 84 var disabled = supervisedUserIndex == NO_USER_SELECTED; |
84 if (!disabled) { | 85 if (!disabled) { |
85 this.$.dialog.lastFocusableNode = this.$.import; | 86 this.$.dialog.lastFocusableNode = this.$.import; |
| 87 } |
| 88 return disabled; |
| 89 }, |
| 90 |
| 91 /** |
| 92 * Called when the user clicks the 'Import' button. it proceeds with |
| 93 * importing |
| 94 * the supervised user. |
| 95 * @private |
| 96 */ |
| 97 onImportTap_: function() { |
| 98 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; |
| 99 if (this.signedInUser_ && supervisedUser) { |
| 100 this.$.dialog.close(); |
| 101 // Event is caught by create-profile. |
| 102 this.fire( |
| 103 'import', |
| 104 {supervisedUser: supervisedUser, signedInUser: this.signedInUser_}); |
| 105 } |
86 } | 106 } |
87 return disabled; | 107 }); |
88 }, | |
89 | |
90 /** | |
91 * Called when the user clicks the 'Import' button. it proceeds with importing | |
92 * the supervised user. | |
93 * @private | |
94 */ | |
95 onImportTap_: function() { | |
96 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; | |
97 if (this.signedInUser_ && supervisedUser) { | |
98 this.$.dialog.close(); | |
99 // Event is caught by create-profile. | |
100 this.fire('import', {supervisedUser: supervisedUser, | |
101 signedInUser: this.signedInUser_}); | |
102 } | |
103 } | |
104 }); | |
105 })(); | 108 })(); |
OLD | NEW |