mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-07-26 04:31:08 +00:00
ui: token selector: refactor to more schematic approach
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
e3372697a0
commit
4dedd333d1
@ -4,77 +4,58 @@ Ext.define('PVE.form.TokenSelector', {
|
|||||||
|
|
||||||
allowBlank: false,
|
allowBlank: false,
|
||||||
autoSelect: false,
|
autoSelect: false,
|
||||||
valueField: 'id',
|
|
||||||
displayField: 'id',
|
displayField: 'id',
|
||||||
|
|
||||||
editable: true,
|
editable: true,
|
||||||
anyMatch: true,
|
anyMatch: true,
|
||||||
forceSelection: true,
|
forceSelection: true,
|
||||||
|
|
||||||
initComponent: function() {
|
store: {
|
||||||
var me = this;
|
model: 'pve-tokens',
|
||||||
|
autoLoad: true,
|
||||||
|
proxy: {
|
||||||
|
type: 'proxmox',
|
||||||
|
url: 'api2/json/access/users',
|
||||||
|
extraParams: { 'full': 1 },
|
||||||
|
},
|
||||||
|
sorters: 'id',
|
||||||
|
listeners: {
|
||||||
|
load: function(store, records, success) {
|
||||||
|
let tokens = [];
|
||||||
|
for (const rec of records) {
|
||||||
|
let user = rec.data;
|
||||||
|
if (!user.tokens || user.tokens.length === 0) continue;
|
||||||
|
|
||||||
var store = new Ext.data.Store({
|
for (token of user.tokens) {
|
||||||
model: 'pve-tokens',
|
tokens.push({
|
||||||
sorters: [{
|
id: `${user.userid}!${token.tokenid}`,
|
||||||
property: 'userid'
|
comment: token.comment,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
store.loadData(tokens);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
listConfig: {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
header: gettext('API Token'),
|
||||||
|
sortable: true,
|
||||||
|
dataIndex: 'id',
|
||||||
|
flex: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
property: 'tokenid'
|
header: gettext('Comment'),
|
||||||
}]
|
sortable: false,
|
||||||
});
|
dataIndex: 'comment',
|
||||||
|
renderer: Ext.String.htmlEncode,
|
||||||
Ext.apply(me, {
|
flex: 1
|
||||||
store: store,
|
|
||||||
listConfig: {
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
header: gettext('API Token'),
|
|
||||||
sortable: true,
|
|
||||||
dataIndex: 'id',
|
|
||||||
flex: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: gettext('Comment'),
|
|
||||||
sortable: false,
|
|
||||||
dataIndex: 'comment',
|
|
||||||
renderer: Ext.String.htmlEncode,
|
|
||||||
flex: 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
});
|
]
|
||||||
|
},
|
||||||
me.callParent();
|
|
||||||
|
|
||||||
Proxmox.Utils.API2Request({
|
|
||||||
url: '/access/users/?full=1',
|
|
||||||
method: 'GET',
|
|
||||||
failure: function(response, opts) {
|
|
||||||
Proxmox.Utils.setErrorMask(me, response.htmlStatus);
|
|
||||||
me.load_task.delay(me.load_delay);
|
|
||||||
},
|
|
||||||
success: function(response, opts) {
|
|
||||||
Proxmox.Utils.setErrorMask(me, false);
|
|
||||||
var result = Ext.decode(response.responseText);
|
|
||||||
var data = result.data || [];
|
|
||||||
var records = [];
|
|
||||||
Ext.Array.each(data, function(user) {
|
|
||||||
tokens = user.tokens || [];
|
|
||||||
Ext.Array.each(tokens, function(token) {
|
|
||||||
var r = {};
|
|
||||||
r.id = user.userid + '!' + token.tokenid;
|
|
||||||
r.comment = token.comment;
|
|
||||||
records.push(r);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
store.loadData(records);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
||||||
Ext.define('pve-tokens', {
|
Ext.define('pve-tokens', {
|
||||||
extend: 'Ext.data.Model',
|
extend: 'Ext.data.Model',
|
||||||
fields: [
|
fields: [
|
||||||
@ -84,8 +65,4 @@ Ext.define('PVE.form.TokenSelector', {
|
|||||||
],
|
],
|
||||||
idProperty: 'id'
|
idProperty: 'id'
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user