webhook edit: make items config not static

modifying static elements from the class, like done here with e.g.

 me.items[0][key] = value;

is dangerous, since it directly modifies the class definition of those
arrays/objects.

Instead move the definition in initComponent, which uses a fresh
declaration each time the component is initialized.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2024-11-12 15:41:53 +01:00 committed by Thomas Lamprecht
parent 20002254e6
commit 3052c4dfc8

View File

@ -318,90 +318,93 @@ Ext.define('Proxmox.form.WebhookKeyValueList', {
}, },
}, },
items: [
{
xtype: 'grid',
reference: 'grid',
minHeight: 100,
maxHeight: 100,
scrollable: 'vertical',
viewConfig: {
deferEmptyText: false,
},
store: {
listeners: {
update: function() {
this.commitChanges();
},
},
},
margin: '5 0 5 0',
},
{
xtype: 'button',
text: gettext('Add'),
iconCls: 'fa fa-plus-circle',
handler: 'addLine',
},
],
initComponent: function() { initComponent: function() {
let me = this; let me = this;
for (const [key, value] of Object.entries(me.gridConfig ?? {})) { let items = [
me.items[0][key] = value;
}
me.items[0].columns = [
{ {
header: me.fieldTtitle, xtype: 'grid',
dataIndex: 'headerName', reference: 'grid',
xtype: 'widgetcolumn', minHeight: 100,
widget: { maxHeight: 100,
xtype: 'textfield', scrollable: 'vertical',
isFormField: false,
maskRe: me.maskRe, viewConfig: {
allowBlank: false, deferEmptyText: false,
queryMode: 'local', },
store: {
listeners: { listeners: {
change: 'itemChange', update: function() {
this.commitChanges();
},
}, },
}, },
flex: 1, margin: '5 0 5 0',
columns: [
{
header: me.fieldTtitle,
dataIndex: 'headerName',
xtype: 'widgetcolumn',
widget: {
xtype: 'textfield',
isFormField: false,
maskRe: me.maskRe,
allowBlank: false,
queryMode: 'local',
listeners: {
change: 'itemChange',
},
},
flex: 1,
},
{
header: me.fieldTtitle,
dataIndex: 'headerValue',
xtype: 'widgetcolumn',
widget: {
xtype: 'proxmoxtextfield',
inputType: me.maskValues ? 'password' : 'text',
isFormField: false,
maskRe: me.maskRe,
queryMode: 'local',
listeners: {
change: 'itemChange',
},
allowBlank: !me.isCreate && me.maskValues,
bind: {
emptyText: '{record.emptyText}',
},
},
flex: 1,
},
{
xtype: 'widgetcolumn',
width: 40,
widget: {
xtype: 'button',
iconCls: 'fa fa-trash-o',
},
},
],
}, },
{ {
header: me.fieldTtitle, xtype: 'button',
dataIndex: 'headerValue', text: gettext('Add'),
xtype: 'widgetcolumn', iconCls: 'fa fa-plus-circle',
widget: { handler: 'addLine',
xtype: 'proxmoxtextfield',
inputType: me.maskValues ? 'password' : 'text',
isFormField: false,
maskRe: me.maskRe,
queryMode: 'local',
listeners: {
change: 'itemChange',
},
allowBlank: !me.isCreate && me.maskValues,
bind: {
emptyText: '{record.emptyText}',
},
},
flex: 1,
},
{
xtype: 'widgetcolumn',
width: 40,
widget: {
xtype: 'button',
iconCls: 'fa fa-trash-o',
},
}, },
]; ];
for (const [key, value] of Object.entries(me.gridConfig ?? {})) {
items[0][key] = value;
}
Ext.apply(me, {
items,
});
me.callParent(); me.callParent();
me.initField(); me.initField();
}, },