]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/form/TFASelector.js
ui: enable gettext localisation for more user exposed strings
[pve-manager.git] / www / manager6 / form / TFASelector.js
1 Ext.define('PVE.form.TFASelector', {
2 extend: 'Ext.container.Container',
3 xtype: 'pveTFASelector',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 deleteEmpty: true,
7
8 viewModel: {
9 data: {
10 type: '__default__',
11 step: null,
12 digits: null,
13 id: null,
14 key: null,
15 url: null,
16 },
17
18 formulas: {
19 isOath: (get) => get('type') === 'oath',
20 isYubico: (get) => get('type') === 'yubico',
21 tfavalue: {
22 get: function(get) {
23 let val = {
24 type: get('type'),
25 };
26 if (get('isOath')) {
27 let step = get('step');
28 let digits = get('digits');
29 if (step) {
30 val.step = step;
31 }
32 if (digits) {
33 val.digits = digits;
34 }
35 } else if (get('isYubico')) {
36 let id = get('id');
37 let key = get('key');
38 let url = get('url');
39 val.id = id;
40 val.key = key;
41 if (url) {
42 val.url = url;
43 }
44 } else if (val.type === '__default__') {
45 return "";
46 }
47
48 return PVE.Parser.printPropertyString(val);
49 },
50 set: function(value) {
51 let val = PVE.Parser.parseTfaConfig(value);
52 this.set(val);
53 this.notify();
54 // we need to reset the original values, so that
55 // we can reliably track the state of the form
56 let form = this.getView().up('form');
57 if (form.trackResetOnLoad) {
58 let fields = this.getView().query('field[name!="tfa"]');
59 fields.forEach((field) => field.resetOriginalValue());
60 }
61 },
62 },
63 },
64 },
65
66 items: [
67 {
68 xtype: 'proxmoxtextfield',
69 name: 'tfa',
70 hidden: true,
71 submitValue: true,
72 cbind: {
73 deleteEmpty: '{deleteEmpty}',
74 },
75 bind: {
76 value: "{tfavalue}",
77 },
78 },
79 {
80 xtype: 'proxmoxKVComboBox',
81 value: '__default__',
82 deleteEmpty: false,
83 submitValue: false,
84 fieldLabel: gettext('Require TFA'),
85 comboItems: [
86 ['__default__', Proxmox.Utils.noneText],
87 ['oath', 'OATH/TOTP'],
88 ['yubico', 'Yubico'],
89 ],
90 bind: {
91 value: "{type}",
92 },
93 },
94 {
95 xtype: 'proxmoxintegerfield',
96 hidden: true,
97 minValue: 10,
98 submitValue: false,
99 emptyText: Proxmox.Utils.defaultText + ' (30)',
100 fieldLabel: gettext('Time Step'),
101 bind: {
102 value: "{step}",
103 hidden: "{!isOath}",
104 disabled: "{!isOath}",
105 },
106 },
107 {
108 xtype: 'proxmoxintegerfield',
109 hidden: true,
110 submitValue: false,
111 fieldLabel: gettext('Secret Length'),
112 minValue: 6,
113 maxValue: 8,
114 emptyText: Proxmox.Utils.defaultText + ' (6)',
115 bind: {
116 value: "{digits}",
117 hidden: "{!isOath}",
118 disabled: "{!isOath}",
119 },
120 },
121 {
122 xtype: 'textfield',
123 hidden: true,
124 submitValue: false,
125 allowBlank: false,
126 fieldLabel: 'Yubico API Id',
127 bind: {
128 value: "{id}",
129 hidden: "{!isYubico}",
130 disabled: "{!isYubico}",
131 },
132 },
133 {
134 xtype: 'textfield',
135 hidden: true,
136 submitValue: false,
137 allowBlank: false,
138 fieldLabel: 'Yubico API Key',
139 bind: {
140 value: "{key}",
141 hidden: "{!isYubico}",
142 disabled: "{!isYubico}",
143 },
144 },
145 {
146 xtype: 'textfield',
147 hidden: true,
148 submitValue: false,
149 fieldLabel: 'Yubico URL',
150 bind: {
151 value: "{url}",
152 hidden: "{!isYubico}",
153 disabled: "{!isYubico}",
154 },
155 },
156 ],
157 });