-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
os_powerwash_dialog_esim_item.js
99 lines (89 loc) · 2.5 KB
/
os_powerwash_dialog_esim_item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* 'os-settings-powerwash-dialog-esim-item' is an item showing details of an
* installed eSIM profile shown in a list in the device reset dialog.
*/
import '../../settings_shared_css.js';
import {I18nBehavior} from '//resources/js/i18n_behavior.m.js';
import {html, Polymer} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Polymer({
_template: html`{__html_template__}`,
is: 'os-settings-powerwash-dialog-esim-item',
behaviors: [
I18nBehavior,
],
properties: {
/** @type {?chromeos.cellularSetup.mojom.ESimProfileRemote} */
profile: {
type: Object,
value: null,
observer: 'onProfileChanged_',
},
/**
* @type {?chromeos.cellularSetup.mojom.ESimProfileProperties}
* @private
*/
profileProperties_: {
type: Object,
value: null,
},
},
/** @private */
onProfileChanged_() {
if (!this.profile) {
this.profileProperties_ = null;
return;
}
this.profile.getProperties().then(response => {
this.profileProperties_ = response.properties;
});
},
/**
* @return {string}
* @private
*/
getItemInnerHtml_() {
if (!this.profileProperties_) {
return '';
}
const profileName = this.getProfileName_(this.profileProperties_);
const providerName = this.escapeHtml_(
String.fromCharCode(...this.profileProperties_.serviceProvider.data));
if (!providerName) {
return profileName;
}
return this.i18nAdvanced(
'powerwashDialogESimListItemTitle',
{attrs: ['id'], substitutions: [profileName, providerName]});
},
/**
* @param {chromeos.cellularSetup.mojom.ESimProfileProperties}
* profileProperties
* @return {string}
* @private
*/
getProfileName_(profileProperties) {
if (!profileProperties.nickname.data ||
!profileProperties.nickname.data.length) {
return this.escapeHtml_(
String.fromCharCode(...profileProperties.name.data));
}
return this.escapeHtml_(
String.fromCharCode(...profileProperties.nickname.data));
},
/**
* @param {string} string
* @return {string}
* @private
*/
escapeHtml_(string) {
return string.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
},
});