Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: chrome/browser/resources/settings/people_page/change_picture.js

Issue 1575543003: Settings People Revamp: Implement parts of ChromeOS Change Picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix camera presence observer Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'settings-change-picture' is the settings subpage containing controls to
8 * edit a ChromeOS user's picture.
9 *
10 * @group Chrome Settings Elements
11 * @element settings-change-picture
12 */
13 Polymer({
14 is: 'settings-change-picture',
15
16 behaviors: [
17 I18nBehavior,
18 ],
19
20 properties: {
21 /**
22 * The currently selected profile image URL. May be a data URL.
23 * @private {string}
24 */
25 selectedImageUrl_: String,
26
27 /**
28 * The url of the 'old' image, which is the existing image sourced from
29 * the camera, a file, or a deprecated default image.
30 * @private {string}
31 */
32 oldImageUrl_: String,
33
34 /**
35 * The url of the profile image.
36 * @private {string}
37 */
38 profileImageUrl_: {
39 type: String,
40 value: settings.ChangePicturePrivateApi.ButtonImages.PROFILE_PICTURE,
41 },
42
43 /**
44 * The default user image images. Populated by ChangePicturePrivateApi.
dpapad 2016/01/11 19:25:50 Maybe change to "The default user images"?
tommycli 2016/01/13 18:29:11 Done.
45 * @private {!Array<!settings.DefaultImage>}
46 */
47 defaultImages_: {
48 type: Array,
49 value: function() { return []; },
50 },
51 },
52
53 /** @override */
54 created: function() {
55 settings.ChangePicturePrivateApi.initialize(
56 this.handleDefaultImages_.bind(this),
57 this.handleSelectedImageUrl_.bind(this),
58 this.handleOldImageUrl_.bind(this),
59 this.handleProfileImageUrl_.bind(this));
60 },
61
62 /**
63 * Handler for when the default images are pushed from
64 * ChangePicturePrivateApi.
65 * @private
66 * @param {!Array<!settings.DefaultImage>} images
67 */
68 handleDefaultImages_: function(images) {
69 this.defaultImages_ = images;
70 },
71
72 /**
73 * Handler for when the selected image URL is pushed from
74 * ChangePicturePrivateApi.
75 * @private
76 * @param {string} imageUrl
77 */
78 handleSelectedImageUrl_: function(imageUrl) {
79 this.selectedImageUrl_ = imageUrl;
80 },
81
82 /**
83 * Handler for when there is an 'old' image is pushed from
84 * ChangePicturePrivateApi. When an 'old' image is pushed, it implies that
85 * it's the selected one.
86 * @private
87 * @param {string} imageUrl
88 */
89 handleOldImageUrl_: function(imageUrl) {
90 this.oldImageUrl_ = imageUrl;
91 this.selectedImageUrl_ = imageUrl;
92 },
93
94 /**
95 * Handler for when there the profile image is pushed from
96 * ChangePicturePrivateApi.
97 * @private
98 * @param {string} imageUrl
99 * @param {boolean} selected
100 */
101 handleProfileImageUrl_: function(imageUrl, selected) {
102 this.profileImageUrl_ = imageUrl;
103 if (selected)
104 this.selectedImageUrl_ = imageUrl;
105 },
106
107 /**
108 * Handler for when the user clicks a new profile image.
109 * @private
110 * @param {!Event} event
111 */
112 onDefaultImageTap_: function(event) {
113 var element = Polymer.dom(event).rootTarget;
114
115 var imageUrl;
dpapad 2016/01/11 19:25:50 Nit: Avoid implicit boolean conversions when possi
tommycli 2016/01/13 18:29:11 Done.
116 if (element.nodeName == 'IMG')
dpapad 2016/01/11 19:25:50 Should we change this to if (element.nodeName.toUp
michaelpg 2016/01/11 20:38:05 element.nodeName is always element.tagName for Ele
117 imageUrl = element.src;
118 else if (element.dataset && element.dataset.imageUrl)
119 imageUrl = element.dataset.imageUrl;
120
121 if (imageUrl) {
122 settings.ChangePicturePrivateApi.selectDefaultImage(imageUrl);
123 // Button toggle state is instead controlled by the selected image URL.
124 event.preventDefault();
125 }
126 },
127
128 /**
129 * Handler for when the user clicks the 'old' image.
130 * @private
131 * @param {!Event} event
132 */
133 onOldImageTap_: function(event) {
134 settings.ChangePicturePrivateApi.selectOldImage();
135 // Button toggle state is instead controlled by the selected image URL.
136 event.preventDefault();
137 },
138
139 /**
140 * Handler for when the user clicks the 'profile' image.
141 * @private
142 * @param {!Event} event
143 */
144 onProfileImageTap_: function(event) {
145 settings.ChangePicturePrivateApi.selectProfileImage();
146 // Button toggle state is instead controlled by the selected image URL.
147 event.preventDefault();
148 },
149
150 /**
151 * Computed binding determining which profile image button is toggled on.
152 * @private
153 * @param {!string} imageUrl
dpapad 2016/01/11 19:25:50 No need to put "!" before "string". It is implied,
tommycli 2016/01/13 18:29:11 Done.
154 * @param {!string} selectedImageUrl
155 * @return {boolean}
156 */
157 isActiveImage_: function(imageUrl, selectedImageUrl) {
158 return imageUrl == selectedImageUrl;
159 },
160 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698