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 * @fileoverview | |
7 * Polymer element for displaying a list of fingerprints. | |
8 * | |
9 * Example: | |
10 * <settings-fingerprint-list></settings-fingerprint-list> | |
Dan Beam
2016/12/13 19:53:23
can you drop this @fileoverview? we decided these
sammiequon
2016/12/13 23:33:34
Done.
| |
11 */ | |
12 | |
Dan Beam
2016/12/13 19:53:24
if we stick with the object wrapper with a name ke
sammiequon
2016/12/13 23:33:33
Changed to array of string.
| |
13 (function() { | |
14 'use strict'; | |
15 | |
16 /** | |
17 * The max number of fingerprints this list can hold. | |
18 * @type {number} | |
19 * @const | |
Dan Beam
2016/12/13 19:53:24
nit: @const {number} or just @const
sammiequon
2016/12/13 23:33:34
Done.
| |
20 */ | |
21 var MAX_NUMBER_FINGERPRINTS_ALLOWED = 5; | |
22 | |
23 Polymer({ | |
24 is: 'settings-fingerprint-list', | |
25 | |
26 behaviors: [ | |
27 I18nBehavior, | |
28 ], | |
29 | |
30 properties: { | |
31 /** | |
32 * The list of fingerprint objects. | |
33 * @private {Array<Object>} | |
Dan Beam
2016/12/13 19:53:24
!Array<!Fingerprint>
sammiequon
2016/12/13 23:33:34
Done.
| |
34 */ | |
35 fingerprints_: { | |
36 type: Array, | |
37 value: function() { | |
38 return []; | |
39 }, | |
40 notify: true | |
Dan Beam
2016/12/13 19:53:24
why do you need this notify true? it seems like y
sammiequon
2016/12/13 23:33:34
Done.
| |
41 } | |
42 }, | |
43 | |
44 /** | |
45 * Check if |fingerprints_| has a fingerprint with name |name|. | |
46 * @param {string} name The name we are looking for. | |
47 * @return {boolean} | |
48 * @private | |
49 */ | |
50 isNameUsed_: function(name) { | |
51 return !!this.fingerprints_.find(function(e) { | |
52 return e.name == name; | |
53 }); | |
54 }, | |
55 | |
56 /** | |
57 * Adds a fingerprint with a default name. | |
58 * @private | |
59 */ | |
60 onAddFingerprint_: function() { | |
61 // Determines what the newly added fingerprint's name should be. | |
62 // TODO(sammiequon): Add fingerprint using private API once it is ready. | |
63 | |
64 var fingerprintName; | |
65 for (var i = 1; i <= MAX_NUMBER_FINGERPRINTS_ALLOWED; ++i) { | |
66 fingerprintName = this.i18n('lockScreenFingerprintNewName', i); | |
67 if (this.isNameUsed_(fingerprintName)) | |
68 continue; | |
69 break; | |
70 } | |
71 this.push('fingerprints_', { 'name': fingerprintName }); | |
Dan Beam
2016/12/13 19:53:23
this.push('fingerprints_', {'name': fingerprintNam
Dan Beam
2016/12/13 19:53:24
wait, why are you using {name: <string>} as the it
sammiequon
2016/12/13 23:33:34
Done.
sammiequon
2016/12/13 23:33:34
Done.
| |
72 this.$.fingerprintsList.fire('iron-resize'); | |
Dan Beam
2016/12/13 19:53:24
nit: notifyResize() instead of fire('iron-resize')
sammiequon
2016/12/13 23:33:34
Done.
| |
73 }, | |
74 | |
75 /** | |
76 * Deletes a fingerprint from |fingerprints_|. | |
77 * @private | |
78 */ | |
79 onFingerprintDelete_: function(e) { | |
80 // TODO(sammiequon): Remove fingerprint using private API once it is ready. | |
81 this.splice('fingerprints_', e.model.index, 1); | |
82 this.$.fingerprintsList.fire('iron-resize'); | |
83 }, | |
84 | |
85 /** | |
86 * Returns the text to be displayed for the add fingerprint button. | |
Dan Beam
2016/12/13 19:53:24
@param
sammiequon
2016/12/13 23:33:34
Done.
| |
87 * @return {string} | |
88 * @private | |
89 */ | |
90 getFingerprintButtonText_: function(length) { | |
Dan Beam
2016/12/13 19:53:24
can you name this argument something other than "l
sammiequon
2016/12/13 23:33:34
Done.
| |
91 if (this.canAddNewFingerprint_(length)) | |
92 return this.i18n('lockScreenAddFingerprint'); | |
93 | |
94 return this.i18n('lockScreenCannotAddFingerprint', | |
95 MAX_NUMBER_FINGERPRINTS_ALLOWED); | |
96 }, | |
97 | |
98 /** | |
99 * Checks whether another fingerprint can be added. | |
Dan Beam
2016/12/13 19:53:24
@param
sammiequon
2016/12/13 23:33:34
Done.
| |
100 * @return {boolean} | |
101 * @private | |
102 */ | |
103 canAddNewFingerprint_: function(length) { | |
104 return length < MAX_NUMBER_FINGERPRINTS_ALLOWED; | |
105 } | |
106 }); | |
107 })(); | |
OLD | NEW |