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 popup 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 * 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. | 25 * The currently signed in user and the custodian. |
36 * @private {?SignedInUser} | 26 * @private {?SignedInUser} |
37 */ | 27 */ |
38 signedInUser_: { | 28 signedInUser_: { |
39 type: Object, | 29 type: Object, |
40 value: function() { return null; } | 30 value: function() { return null; } |
41 }, | 31 }, |
42 | 32 |
43 /** | 33 /** |
44 * The list of supervised users managed by signedInUser_. | 34 * The list of supervised users managed by signedInUser_. |
45 * @private {!Array<!SupervisedUser>} | 35 * @private {!Array<!SupervisedUser>} |
46 */ | 36 */ |
47 supervisedUsers_: { | 37 supervisedUsers_: { |
48 type: Array, | 38 type: Array, |
49 value: function() { return []; } | 39 value: function() { return []; } |
50 }, | 40 }, |
51 | 41 |
52 /** | 42 /** |
53 * Index of the selected supervised user. | 43 * Index of the selected supervised user. |
54 * @private {number} | 44 * @private {number} |
55 */ | 45 */ |
56 supervisedUserIndex_: { | 46 supervisedUserIndex_: { |
57 type: Number, | 47 type: Number, |
58 value: NO_USER_SELECTED | 48 value: NO_USER_SELECTED |
59 } | 49 } |
60 }, | 50 }, |
61 | 51 |
| 52 /** override */ |
| 53 ready: function() { |
| 54 this.$.dialog.lastFocusableNode = this.$.cancel; |
| 55 }, |
| 56 |
62 /** | 57 /** |
63 * Displays the popup. | 58 * Displays the dialog. |
64 * @param {(!SignedInUser|undefined)} signedInUser | 59 * @param {(!SignedInUser|undefined)} signedInUser |
65 * @param {!Array<!SupervisedUser>} supervisedUsers | 60 * @param {!Array<!SupervisedUser>} supervisedUsers |
66 */ | 61 */ |
67 show: function(signedInUser, supervisedUsers) { | 62 show: function(signedInUser, supervisedUsers) { |
68 this.supervisedUsers_ = supervisedUsers; | 63 this.supervisedUsers_ = supervisedUsers; |
69 this.supervisedUsers_.sort(function(a, b) { | 64 this.supervisedUsers_.sort(function(a, b) { |
70 if (a.onCurrentDevice != b.onCurrentDevice) | 65 if (a.onCurrentDevice != b.onCurrentDevice) |
71 return a.onCurrentDevice ? 1 : -1; | 66 return a.onCurrentDevice ? 1 : -1; |
72 return a.name.localeCompare(b.name); | 67 return a.name.localeCompare(b.name); |
73 }); | 68 }); |
74 | 69 |
75 this.supervisedUserIndex_ = NO_USER_SELECTED; | 70 this.supervisedUserIndex_ = NO_USER_SELECTED; |
76 | 71 |
77 this.signedInUser_ = signedInUser || null; | 72 this.signedInUser_ = signedInUser || null; |
78 if (this.signedInUser_) | 73 if (this.signedInUser_) |
79 this.popupHidden_ = false; | 74 this.$.dialog.open(); |
80 | |
81 if (this.popupHidden_) | |
82 return; | |
83 | |
84 this.async(function() { | |
85 this.$$('paper-listbox').focus(); | |
86 }.bind(this)); | |
87 }, | 75 }, |
88 | 76 |
89 /** | 77 /** |
90 * Computed binding that returns the appropriate import message depending on | 78 * Computed binding that returns the appropriate import message depending on |
91 * whether or not there are any supervised users to import. | 79 * whether or not there are any supervised users to import. |
92 * @param {!Array<!SupervisedUser>} supervisedUsers | 80 * @param {!Array<!SupervisedUser>} supervisedUsers |
93 * @private | 81 * @private |
94 * @return {string} | 82 * @return {string} |
95 */ | 83 */ |
96 getMessage_: function(supervisedUsers) { | 84 getMessage_: function(supervisedUsers) { |
97 return supervisedUsers.length > 0 ? this.i18n('supervisedUserImportText') : | 85 return supervisedUsers.length > 0 ? this.i18n('supervisedUserImportText') : |
98 this.i18n('noSupervisedUserImportText'); | 86 this.i18n('noSupervisedUserImportText'); |
99 }, | 87 }, |
100 | 88 |
101 /** | 89 /** |
102 * Hides the popup. | 90 * param {number} supervisedUserIndex Index of the selected supervised user. |
103 * @private | 91 * @private |
| 92 * @return {boolean} Whether the 'Import' button should be disabled. |
104 */ | 93 */ |
105 onCancelTap_: function() { | 94 isImportDisabled_: function(supervisedUserIndex) { |
106 this.popupHidden_ = true; | 95 var disabled = supervisedUserIndex == NO_USER_SELECTED; |
| 96 if (!disabled) { |
| 97 this.$.dialog.lastFocusableNode = this.$.import; |
| 98 } |
| 99 return disabled; |
107 }, | 100 }, |
108 | 101 |
109 /** | 102 /** |
110 * Returns true if the 'Import' button should be enabled and false otherwise. | |
111 * @private | |
112 * @return {boolean} | |
113 */ | |
114 isImportDisabled_: function(supervisedUserIndex) { | |
115 return supervisedUserIndex == NO_USER_SELECTED; | |
116 }, | |
117 | |
118 /** | |
119 * Called when the user clicks the 'Import' button. it proceeds with importing | 103 * Called when the user clicks the 'Import' button. it proceeds with importing |
120 * the supervised user. | 104 * the supervised user. |
121 * @private | 105 * @private |
122 */ | 106 */ |
123 onImportTap_: function() { | 107 onImportTap_: function() { |
124 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; | 108 var supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_]; |
125 if (this.signedInUser_ && supervisedUser) { | 109 if (this.signedInUser_ && supervisedUser) { |
126 this.popupHidden_ = true; | 110 this.$.dialog.close(); |
127 // Event is caught by create-profile. | 111 // Event is caught by create-profile. |
128 this.fire('import', {supervisedUser: supervisedUser, | 112 this.fire('import', {supervisedUser: supervisedUser, |
129 signedInUser: this.signedInUser_}); | 113 signedInUser: this.signedInUser_}); |
130 } | 114 } |
131 } | 115 } |
132 }); | 116 }); |
133 })(); | 117 })(); |
OLD | NEW |