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