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 * Properties: | |
10 * items: The fingerprints to display. | |
11 * | |
12 * Example: | |
13 * <settings-fingerprint-list items="{{items}}"></settings-fingerprint-list> | |
jdufault
2016/12/05 22:29:36
should this be fingerprints="{{items}}"?
Actually
sammiequon
2016/12/05 22:57:15
Done.
| |
14 */ | |
15 | |
16 (function() { | |
17 'use strict'; | |
18 | |
19 /** | |
20 * The max number of fingerprints this list can hold. | |
21 * @type {number} | |
22 * @const | |
23 */ | |
24 var MAX_NUMBER_FINGERPRINTS_ALLOWED = 5; | |
25 | |
26 Polymer({ | |
27 is: 'settings-fingerprint-list', | |
28 | |
29 behaviors: [ | |
30 I18nBehavior, | |
31 ], | |
32 | |
33 properties: { | |
34 /** | |
35 * The list of fingerprint objects. | |
36 * @type {Array<Object>} | |
37 * @private | |
38 */ | |
39 fingerprints: { | |
jdufault
2016/12/05 22:29:36
Add _ to the end of the name.
sammiequon
2016/12/05 22:57:15
Done.
| |
40 type: Array, | |
41 value: function() { | |
42 return []; | |
43 }, | |
44 notify: true, | |
45 } | |
46 }, | |
47 | |
48 /** | |
49 * Returns the text to be displayed when the user has set up | |
50 * |MAX_NUMBER_FINGERPRINTS_ALLOWED|. | |
51 * @return {string} | |
52 * @private | |
53 */ | |
54 getFingerprintButtonCannotAddText_: function() { | |
55 return this.i18n('lockScreenCannotAddFingerprint', | |
56 MAX_NUMBER_FINGERPRINTS_ALLOWED); | |
57 }, | |
58 | |
59 /** | |
60 * Check if the registered fingerprints has a fingerprint with name |name|. | |
61 * @param {string} name The name we are looking for. | |
62 * @return {boolean} | |
63 * @private | |
64 */ | |
65 isNameUsed_: function(name) { | |
66 for (var i = 0; i < this.fingerprints.length; ++i) { | |
jdufault
2016/12/05 22:29:36
You could also implement this as:
return !!thi
sammiequon
2016/12/05 22:57:15
Done.
| |
67 if (this.fingerprints[i]['name'] == name) | |
jdufault
2016/12/05 22:29:36
Replace ['name'] with .name
sammiequon
2016/12/05 22:57:15
Done.
| |
68 return true; | |
69 } | |
70 return false; | |
71 }, | |
72 | |
73 /** | |
74 * Adds a fingerprint with a default name. | |
75 * @private | |
76 */ | |
77 onAddFingerprint_: function() { | |
78 // Determines what the newly added fingerprint's name should be. The name | |
79 // should be in the format "Finger x" where x should be the lowest unused | |
jdufault
2016/12/05 22:29:36
Update comment (the discussion about the required
sammiequon
2016/12/05 22:57:15
Done.
| |
80 // number. A number is considered used if it matches the pattern "Finger x". | |
81 // Note that finger x or Fingerx are not considered matches. | |
82 // TODO(sammiequon): Add fingerprint using private API once it is ready. | |
83 | |
84 var fingerprintName = this.i18n('lockScreenFingerprintNewName', 1); | |
jdufault
2016/12/05 22:29:36
Do not seed an initial fingerprintName value.
sammiequon
2016/12/05 22:57:15
Done.
| |
85 for (var i = 1; i <= MAX_NUMBER_FINGERPRINTS_ALLOWED; ++i) { | |
86 fingerprintName = this.i18n('lockScreenFingerprintNewName', i); | |
87 if (this.isNameUsed_(fingerprintName)) | |
88 continue; | |
89 break; | |
90 } | |
91 this.push('fingerprints', { 'name': fingerprintName }); | |
92 }, | |
93 | |
94 /** | |
95 * Deletes a fingerprint from |fingerprints|. | |
96 * @private | |
97 */ | |
98 onFingerprintDelete_: function(e) { | |
99 // TODO(sammiequon): Remove fingerprint using private API once it is ready. | |
100 this.splice('fingerprints', e.model.index, 1); | |
101 }, | |
102 | |
103 /** | |
104 * Checks whether another fingerprint can be added. | |
105 * @return {boolean} | |
106 * @private | |
107 */ | |
108 canAddNewFingerprint_: function(length) { | |
109 return length < MAX_NUMBER_FINGERPRINTS_ALLOWED; | |
110 } | |
111 }); | |
112 })(); | |
OLD | NEW |