2020-11-06 12:01:56 +00:00
|
|
|
Ext.define('pbs-authids', {
|
|
|
|
extend: 'Ext.data.Model',
|
|
|
|
fields: [
|
|
|
|
'authid', 'comment', 'type',
|
|
|
|
],
|
|
|
|
idProperty: 'authid',
|
|
|
|
});
|
|
|
|
|
|
|
|
Ext.define('PBS.form.AuthidSelector', {
|
|
|
|
extend: 'Proxmox.form.ComboGrid',
|
|
|
|
alias: 'widget.pbsAuthidSelector',
|
|
|
|
|
|
|
|
allowBlank: false,
|
|
|
|
autoSelect: false,
|
|
|
|
valueField: 'authid',
|
|
|
|
displayField: 'authid',
|
|
|
|
|
|
|
|
editable: true,
|
|
|
|
anyMatch: true,
|
|
|
|
forceSelection: true,
|
|
|
|
|
|
|
|
store: {
|
|
|
|
model: 'pbs-authids',
|
|
|
|
params: {
|
|
|
|
enabled: 1,
|
|
|
|
},
|
|
|
|
sorters: 'authid',
|
|
|
|
},
|
|
|
|
|
|
|
|
initComponent: function() {
|
|
|
|
let me = this;
|
|
|
|
me.userStore = Ext.create('Ext.data.Store', {
|
|
|
|
model: 'pbs-users-with-tokens',
|
|
|
|
});
|
|
|
|
me.userStore.on('load', this.onLoad, this);
|
|
|
|
me.userStore.load();
|
|
|
|
|
|
|
|
me.callParent();
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function(store, data, success) {
|
2020-11-06 18:46:08 +00:00
|
|
|
let me = this;
|
2020-11-06 12:01:56 +00:00
|
|
|
if (!success) return;
|
|
|
|
|
|
|
|
let records = [];
|
2020-11-06 18:46:08 +00:00
|
|
|
for (const rec of data) {
|
|
|
|
records.push({
|
|
|
|
authid: rec.data.userid,
|
|
|
|
comment: rec.data.comment,
|
|
|
|
type: 'u',
|
|
|
|
});
|
|
|
|
let tokens = rec.data.tokens || [];
|
|
|
|
for (const token of tokens) {
|
|
|
|
records.push({
|
|
|
|
authid: token.tokenid,
|
|
|
|
comment: token.comment,
|
|
|
|
type: 't',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 12:01:56 +00:00
|
|
|
|
2020-11-06 18:46:08 +00:00
|
|
|
me.store.loadData(records);
|
2020-11-09 11:21:02 +00:00
|
|
|
// we need to re-set the value, ExtJS doesn't knows that we injected data into the store
|
|
|
|
me.setValue(me.value);
|
2020-11-06 18:46:08 +00:00
|
|
|
me.validate();
|
2020-11-06 12:01:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
listConfig: {
|
2020-11-06 18:46:08 +00:00
|
|
|
width: 500,
|
2020-11-06 12:01:56 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
header: gettext('Type'),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'type',
|
|
|
|
renderer: function(value) {
|
|
|
|
switch (value) {
|
|
|
|
case 'u': return gettext('User');
|
|
|
|
case 't': return gettext('API Token');
|
|
|
|
default: return Proxmox.Utils.unknownText;
|
|
|
|
}
|
|
|
|
},
|
2020-11-06 18:46:08 +00:00
|
|
|
width: 80,
|
2020-11-06 12:01:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
header: gettext('Auth ID'),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'authid',
|
|
|
|
renderer: Ext.String.htmlEncode,
|
2020-11-06 18:46:08 +00:00
|
|
|
flex: 2,
|
2020-11-06 12:01:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
header: gettext('Comment'),
|
|
|
|
sortable: false,
|
|
|
|
dataIndex: 'comment',
|
|
|
|
renderer: Ext.String.htmlEncode,
|
2020-11-06 18:46:08 +00:00
|
|
|
flex: 3,
|
2020-11-06 12:01:56 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|