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></settings-fingerprint-list> | |
jdufault
2016/12/01 17:11:20
Include items binding in your example.
sammiequon
2016/12/01 20:52:29
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 items: { | |
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 * Adds a fingerprint with a default name. Should open up a dialog or move to | |
61 * a new page, then go through a new fingerprint setup phase and probably | |
62 * store the fingerprint somehow. For now just adds a new fingerpint to | |
63 * |items|. | |
64 * @private | |
65 */ | |
66 onAddFingerprint_: function() { | |
67 // Determines what the newly added fingerprint's name should be. The name | |
68 // should be in the format "Finger x" where x should be the lowest unused | |
69 // number. A number is considered used if it matches the pattern "Finger x". | |
70 // Note that finger x or Fingerx are not considered matches. | |
71 var numbersUsed = []; | |
72 var isRtl = document.dir == 'rtl'; | |
jdufault
2016/12/01 17:11:19
There is a lot of complexity here to try to figure
sammiequon
2016/12/01 20:52:29
Done.
| |
73 var defaultName = this.i18n('lockScreenFingerprintNewName'); | |
74 var pattern = isRtl ? '^[0-9] ' + defaultName + '$' : | |
75 '^' + defaultName + ' [0-9]$'; | |
76 var regex = new RegExp(pattern); | |
77 for (var i = 0; i < this.items.length; ++i) { | |
78 var name = this.items[i]['name']; | |
79 if (!!regex.exec(name)) | |
80 numbersUsed.push(parseInt(isRtl ? name[0] : name[name.length - 1])); | |
81 } | |
82 | |
83 var index = this.items.length + 1; | |
84 for (var i = 1; i <= this.items.length; ++i) { | |
85 if (!numbersUsed.includes(i)) { | |
86 index = i; | |
87 break; | |
88 } | |
89 } | |
90 this.push('items', { 'name': isRtl ? index + ' ' + defaultName : | |
jdufault
2016/12/01 17:11:19
Use a string format parameter to handle this logic
sammiequon
2016/12/01 20:52:29
Done.
| |
91 defaultName + ' ' + index }); | |
92 }, | |
93 | |
94 /** | |
95 * Deletes a fingerprint from |items|. Should signal to the fingerprint module | |
jdufault
2016/12/01 17:11:20
What is the "fingerprint module"?
// TODO(sammieq
sammiequon
2016/12/01 20:52:29
Done.
| |
96 * to remove the fingerprint as well. | |
97 * @private | |
98 */ | |
99 onItemDelete_: function(e) { | |
100 this.splice('items', 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 |