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