mirror of
https://git.proxmox.com/git/pmg-gui
synced 2025-05-29 20:57:20 +00:00

the regular expression field is not necessarily after the regex tester (mostly it is before). In order to be more robust, use the child method of the parent window instead of previousSibling of the button. The child method gets any direct descendant matching the query, the sibling one is always directional and there's no method for "any sibling". Tested with: * mailproxy whitelist * match field * match filename * who object Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
Ext.define('PMG.RegexTester', {
|
|
extend: 'Ext.form.FieldContainer',
|
|
alias: 'widget.pmgRegexTester',
|
|
|
|
// the field reference which holds the regex value
|
|
// has to be a sibling of the RegexTester component
|
|
regexFieldReference: undefined,
|
|
|
|
// if true, wraps the regex with ^ and $
|
|
wholeMatch: false,
|
|
|
|
layout: 'hbox',
|
|
submitValue: false,
|
|
|
|
items: [
|
|
{
|
|
xtype: 'textfield',
|
|
submitValue: false,
|
|
name: 'teststring',
|
|
isDirty: () => false,
|
|
reset: Ext.emptyFn,
|
|
},
|
|
{
|
|
margin: '0 0 0 5',
|
|
xtype: 'button',
|
|
text: 'Test',
|
|
handler: function(btn) {
|
|
let view = this.up();
|
|
let regexField = view.up().child(`field[reference=${view.regexFieldReference}]`);
|
|
|
|
let regex = regexField.getValue();
|
|
if (view.wholeMatch) {
|
|
regex = `^${regex}$`;
|
|
}
|
|
|
|
Proxmox.Utils.API2Request({
|
|
url: '/api2/extjs/config/regextest',
|
|
waitMsgTarget: view.up('window'),
|
|
params: {
|
|
regex: regex,
|
|
text: view.down('textfield[name=teststring]').getValue(),
|
|
},
|
|
method: 'POST',
|
|
success: function(response) {
|
|
let elapsed = response.result.data;
|
|
Ext.Msg.show({
|
|
title: gettext('Success'),
|
|
message: gettext('OK') + ` (elapsed time: ${elapsed}ms)`,
|
|
buttons: Ext.Msg.OK,
|
|
icon: Ext.MessageBox.INFO,
|
|
});
|
|
},
|
|
failure: function(response, opts) {
|
|
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
|
},
|
|
});
|
|
},
|
|
},
|
|
],
|
|
|
|
initComponent: function() {
|
|
let me = this;
|
|
|
|
if (!me.regexFieldReference) {
|
|
throw "No regex field reference given";
|
|
}
|
|
|
|
me.callParent();
|
|
},
|
|
});
|