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. | |
jdufault
2016/12/06 17:35:07
Remove properties doc
sammiequon
2016/12/06 17:50:04
Done.
| |
11 * | |
12 * Example: | |
13 * <settings-fingerprint-list></settings-fingerprint-list> | |
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_: { | |
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 return !!this.fingerprints_.find(function(e) { | |
67 return e.name == name; | |
68 }); | |
69 }, | |
70 | |
71 /** | |
72 * Adds a fingerprint with a default name. | |
73 * @private | |
74 */ | |
75 onAddFingerprint_: function() { | |
76 // Determines what the newly added fingerprint's name should be. | |
77 // TODO(sammiequon): Add fingerprint using private API once it is ready. | |
78 | |
79 var fingerprintName; | |
80 for (var i = 1; i <= MAX_NUMBER_FINGERPRINTS_ALLOWED; ++i) { | |
81 fingerprintName = this.i18n('lockScreenFingerprintNewName', i); | |
82 if (this.isNameUsed_(fingerprintName)) | |
83 continue; | |
84 break; | |
85 } | |
86 this.push('fingerprints_', { 'name': fingerprintName }); | |
87 }, | |
88 | |
89 /** | |
90 * Deletes a fingerprint from |fingerprints_|. | |
91 * @private | |
92 */ | |
93 onFingerprintDelete_: function(e) { | |
94 // TODO(sammiequon): Remove fingerprint using private API once it is ready. | |
95 this.splice('fingerprints_', e.model.index, 1); | |
96 }, | |
97 | |
98 /** | |
99 * Checks whether another fingerprint can be added. | |
100 * @return {boolean} | |
101 * @private | |
102 */ | |
103 canAddNewFingerprint_: function(length) { | |
104 return length < MAX_NUMBER_FINGERPRINTS_ALLOWED; | |
105 } | |
106 }); | |
107 })(); | |
OLD | NEW |