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 (function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * The max number of fingerprints this list can hold. |
| 10 * @const {number} |
| 11 */ |
| 12 var MAX_NUMBER_FINGERPRINTS_ALLOWED = 5; |
| 13 |
| 14 Polymer({ |
| 15 is: 'settings-fingerprint-list', |
| 16 |
| 17 behaviors: [ |
| 18 I18nBehavior, |
| 19 ], |
| 20 |
| 21 properties: { |
| 22 /** |
| 23 * The list of fingerprint objects. |
| 24 * @private {!Array<string>} |
| 25 */ |
| 26 fingerprints_: { |
| 27 type: Array, |
| 28 value: function() { |
| 29 return []; |
| 30 } |
| 31 } |
| 32 }, |
| 33 |
| 34 /** |
| 35 * Adds a fingerprint with a default name. |
| 36 * @private |
| 37 */ |
| 38 onAddFingerprint_: function() { |
| 39 // Determines what the newly added fingerprint's name should be. |
| 40 // TODO(sammiequon): Add fingerprint using private API once it is ready. |
| 41 |
| 42 for (var i = 1; i <= MAX_NUMBER_FINGERPRINTS_ALLOWED; ++i) { |
| 43 var fingerprintName = this.i18n('lockScreenFingerprintNewName', i); |
| 44 if (!this.fingerprints_.includes(fingerprintName)) { |
| 45 this.push('fingerprints_', fingerprintName); |
| 46 break; |
| 47 } |
| 48 } |
| 49 }, |
| 50 |
| 51 /** |
| 52 * Deletes a fingerprint from |fingerprints_|. |
| 53 * @private |
| 54 */ |
| 55 onFingerprintDelete_: function(e) { |
| 56 // TODO(sammiequon): Remove fingerprint using private API once it is ready. |
| 57 this.splice('fingerprints_', e.model.index, 1); |
| 58 }, |
| 59 |
| 60 /** |
| 61 * Returns the text to be displayed for the add fingerprint button. |
| 62 * @return {string} |
| 63 * @private |
| 64 */ |
| 65 getFingerprintButtonText_: function() { |
| 66 if (this.canAddNewFingerprint_()) |
| 67 return this.i18n('lockScreenAddFingerprint'); |
| 68 |
| 69 return this.i18n('lockScreenCannotAddFingerprint', |
| 70 MAX_NUMBER_FINGERPRINTS_ALLOWED); |
| 71 }, |
| 72 |
| 73 /** |
| 74 * Checks whether another fingerprint can be added. |
| 75 * @return {boolean} |
| 76 * @private |
| 77 */ |
| 78 canAddNewFingerprint_: function() { |
| 79 return this.fingerprints_.length < MAX_NUMBER_FINGERPRINTS_ALLOWED; |
| 80 } |
| 81 }); |
| 82 })(); |
OLD | NEW |