Chromium Code Reviews| 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> | |
| 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. | |
| 61 * @private | |
| 62 */ | |
| 63 onAddFingerprint_: function() { | |
|
jdufault
2016/12/02 23:02:12
If you invert the first for loop this function can
sammiequon
2016/12/03 21:40:51
Done.
| |
| 64 // Determines what the newly added fingerprint's name should be. The name | |
| 65 // should be in the format "Finger x" where x should be the lowest unused | |
| 66 // number. A number is considered used if it matches the pattern "Finger x". | |
| 67 // Note that finger x or Fingerx are not considered matches. | |
| 68 // TODO(sammiequon): Add fingerprint using private API once it is ready. | |
| 69 | |
| 70 // Find which numbers have the pattern finger x. | |
| 71 var numbersUsed = []; | |
| 72 for (var i = 0; i < this.items.length; ++i) { | |
| 73 var name = this.items[i]['name']; | |
| 74 for (var j = 1; j < MAX_NUMBER_FINGERPRINTS_ALLOWED; ++j) { | |
| 75 if (name == this.i18n('lockScreenFingerprintNewName', j.toString())) { | |
| 76 numbersUsed.push(j); | |
| 77 break; | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 // Find the lowest unused number. | |
| 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 | |
| 91 this.push('items', { 'name': this.i18n('lockScreenFingerprintNewName', | |
| 92 index.toString())}); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * Deletes a fingerprint from |items|. | |
| 97 * @private | |
| 98 */ | |
| 99 onItemDelete_: function(e) { | |
| 100 // TODO(sammiequon): Remove fingerprint using private API once it is ready. | |
| 101 this.splice('items', e.model.index, 1); | |
| 102 }, | |
| 103 | |
| 104 /** | |
| 105 * Checks whether another fingerprint can be added. | |
| 106 * @return {boolean} | |
| 107 * @private | |
| 108 */ | |
| 109 canAddNewFingerprint_: function(length) { | |
|
jdufault
2016/12/02 23:02:12
It seems like passing only the items length makes
sammiequon
2016/12/03 21:40:51
It seems like pop & slice do not notify the |items
jdufault
2016/12/05 22:29:36
There is also items.splices that you could listen
| |
| 110 return length < MAX_NUMBER_FINGERPRINTS_ALLOWED; | |
| 111 } | |
| 112 }); | |
| 113 })(); | |
| OLD | NEW |