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 Polymer({ | |
tommycli
2016/02/03 01:13:21
Also needs the fileoverview.
Moe
2016/02/05 17:58:39
Done.
| |
7 is: 'create-profile', | |
8 | |
9 properties: { | |
10 | |
tommycli
2016/02/03 01:13:21
extra line
Moe
2016/02/05 17:58:39
Done.
| |
11 supervisedUserCheckboxDisabled_: { | |
12 type: Boolean, | |
13 computed: | |
14 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)' | |
15 }, | |
16 | |
17 errorMessage_: { | |
18 type: String, | |
19 value: '', | |
20 observer: 'errorMessageChanged_' | |
21 } | |
22 }, | |
23 | |
24 ready: function() { | |
tommycli
2016/02/03 01:13:22
This should be on "attached" with the override ann
Moe
2016/02/05 17:58:39
Done.
| |
25 cr.ui.ProfileApi.setProfileCreateSuccessCallback( | |
tommycli
2016/02/03 01:13:21
All of these callbacks should be unset in the corr
Moe
2016/02/05 17:58:39
Done.
| |
26 this.handleSuccess_.bind(this)); | |
27 cr.ui.ProfileApi.setProfileCreateWarningCallback( | |
28 this.handleWarning_.bind(this)); | |
29 cr.ui.ProfileApi.setProfileCreateErrorCallback( | |
30 this.handleError_.bind(this)); | |
31 | |
32 this.parentNode.addEventListener('iron-select', | |
33 this.onPageSelect_.bind(this)); | |
34 }, | |
35 | |
36 /* | |
37 * Handler for |iron-select| events. Resets the form and makes calls to | |
38 * ProfileApi every time the page becomes visible. | |
tommycli
2016/02/03 01:13:21
annotate the param. Here and in all the below func
Moe
2016/02/05 17:58:39
Done.
| |
39 */ | |
40 onPageSelect_: function(e) { | |
41 if (e.target.selected == 'create-user-page') { | |
42 this.resetForm_(); | |
43 cr.ui.ProfileApi.getAvailableIcons(this.handleAvailableIcons_.bind(this)); | |
44 cr.ui.ProfileApi.getSignedInUsers( | |
45 this.handleUpdateSignedInUsers_.bind(this)); | |
46 } | |
47 }, | |
48 | |
49 /* | |
tommycli
2016/02/03 01:13:22
Two stars to begin these block comments.
Moe
2016/02/05 17:58:39
Done.
| |
50 * Resets the form. | |
51 */ | |
52 resetForm_: function() { | |
53 // The current profile name. | |
54 this.profileName = ''; | |
55 // The currently selected profile icon URL. May be a data URL. | |
56 this.profileIconUrl = ''; | |
57 // Whether a profile is being created or imported. | |
58 this.createInProgress_ = false; | |
59 // The current error/warning message. | |
60 this.errorMessage_ = ''; | |
61 // Whether the new profile is a supervised profile. | |
62 this.isSupervised_ = false; | |
63 }, | |
64 | |
65 /** | |
66 * Handler for when the available icons are pushed from ProfileApi. | |
67 */ | |
68 handleAvailableIcons_: function(iconUrls) { | |
69 this.availableIconUrls = iconUrls; | |
70 this.profileIconUrl = iconUrls[0]; | |
71 }, | |
72 | |
73 /** | |
74 * Updates the signed-in email addresses. | |
75 */ | |
76 handleUpdateSignedInUsers_: function(signedIn_users) { | |
tommycli
2016/02/03 01:13:21
camelCase preferred
Moe
2016/02/05 17:58:39
Done.
| |
77 this.signedInUsers_ = signedIn_users; | |
78 this.selectedEmail_ = 0; | |
79 this.signedIn_ = signedIn_users.length > 0; | |
80 }, | |
81 | |
82 /** | |
83 * |Learn More| button click handler. | |
84 */ | |
85 onLearnMore_: function(e) { | |
86 this.fire('change-page', {page: 'supervised-learn-more-page'}); | |
87 }, | |
88 | |
89 /** | |
90 * |Ok| button click handler. | |
91 */ | |
92 onOk_: function() { | |
93 this.createInProgress_ = true; | |
94 chrome.send('createProfile', | |
95 [this.profileName, this.profileIconUrl, false, | |
96 this.isSupervised_, '', | |
97 this.signedInUsers_[this.selectedEmail_].profile_path]); | |
98 }, | |
99 | |
100 /** | |
101 * |Cancel| button click handler. | |
102 */ | |
103 onCancel_: function() { | |
104 if (this.createInProgress_) { | |
105 this.createInProgress_ = false; | |
106 chrome.send('cancelCreateProfile'); | |
107 } else { | |
108 this.fire('change-page', {page: 'user-pods-page'}); | |
109 } | |
110 }, | |
111 | |
112 /** | |
113 * Handler for when the user clicks a new profile icon. | |
114 */ | |
115 onIconTap_: function(event) { | |
116 var element = Polymer.dom(event).rootTarget; | |
117 | |
118 if (element.nodeName == 'IMG') | |
119 this.profileIconUrl = element.src; | |
120 else if (element.dataset && element.dataset.iconUrl) | |
121 this.profileIconUrl = element.dataset.iconUrl; | |
122 | |
123 // Button toggle state is controlled by the selected icon URL. Prevent | |
124 // tap events from changing the toggle state. | |
125 event.preventDefault(); | |
126 }, | |
127 | |
128 /** | |
129 * Handles profile create/import success message pushed by ProfileApi. | |
130 */ | |
131 handleSuccess_: function(profileInfo) { | |
132 this.createInProgress_ = false; | |
133 this.fire('change-page', {page: 'user-pods-page'}); | |
134 }, | |
135 | |
136 /** | |
137 * Handles profile create/import warning message pushed by ProfileApi. | |
138 */ | |
139 handleWarning_: function(warningHTML) { | |
140 this.createInProgress_ = false; | |
141 this.errorMessage_ = warningHTML; | |
142 }, | |
143 | |
144 /** | |
145 * Handles profile create/import error message pushed by ProfileApi. | |
146 */ | |
147 handleError_: function(errorHTML) { | |
148 this.createInProgress_ = false; | |
149 this.errorMessage_ = errorHTML; | |
150 }, | |
151 | |
152 /** | |
153 * Observer for |errorMessage_|. Updates the content of |messageBubble|. | |
154 */ | |
155 errorMessageChanged_: function(newValue, oldValue) { | |
156 this.$.messageBubble.innerHTML = newValue; | |
157 }, | |
158 | |
159 /** | |
160 * Computed binding determining which profile icon button is toggled on. | |
161 */ | |
162 isActiveIcon_: function(iconUrl, profileIconUrl) { | |
163 return iconUrl == profileIconUrl; | |
164 }, | |
165 | |
166 /** | |
167 * Computed binding determining whether |Ok| button is disabled. | |
168 */ | |
169 isOkDisabled_: function(createInProgress, profileName, errorMessage) { | |
170 return createInProgress || profileName == '' || | |
171 !this.$.nameInput.validate() || errorMessage != ''; | |
172 }, | |
173 | |
174 /** | |
175 * Computed binding determining whether supervised user checkbox is disabled. | |
176 */ | |
177 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { | |
178 return createInProgress || !signedIn; | |
179 } | |
180 }); | |
OLD | NEW |