]> git.proxmox.com Git - pmg-gui.git/blame - js/RegexTester.js
RegexTester: fix getting reference to regex field
[pmg-gui.git] / js / RegexTester.js
CommitLineData
f3aa84dd
DC
1Ext.define('PMG.RegexTester', {
2 extend: 'Ext.form.FieldContainer',
3 alias: 'widget.pmgRegexTester',
4
5 // the field reference which holds the regex value
6 // has to be a sibling of the RegexTester component
7 regexFieldReference: undefined,
8
9 // if true, wraps the regex with ^ and $
10 wholeMatch: false,
11
12 layout: 'hbox',
13 submitValue: false,
14
28eb60c0
TL
15 items: [
16 {
17 xtype: 'textfield',
18 submitValue: false,
19 name: 'teststring',
20 isDirty: () => false,
21 reset: Ext.emptyFn,
22 },
23 {
24 margin: '0 0 0 5',
25 xtype: 'button',
26 text: 'Test',
27 handler: function(btn) {
28 let view = this.up();
4eaa2d36 29 let regexField = view.up().child(`field[reference=${view.regexFieldReference}]`);
f3aa84dd 30
28eb60c0
TL
31 let regex = regexField.getValue();
32 if (view.wholeMatch) {
33 regex = `^${regex}$`;
34 }
f3aa84dd 35
28eb60c0
TL
36 Proxmox.Utils.API2Request({
37 url: '/api2/extjs/config/regextest',
38 waitMsgTarget: view.up('window'),
39 params: {
40 regex: regex,
41 text: view.down('textfield[name=teststring]').getValue(),
42 },
43 method: 'POST',
44 success: function(response) {
45 let elapsed = response.result.data;
46 Ext.Msg.show({
47 title: gettext('Success'),
48 message: gettext('OK') + ` (elapsed time: ${elapsed}ms)`,
49 buttons: Ext.Msg.OK,
50 icon: Ext.MessageBox.INFO,
51 });
52 },
53 failure: function(response, opts) {
54 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
55 },
56 });
57 },
c87d46fb 58 },
28eb60c0 59 ],
f3aa84dd
DC
60
61 initComponent: function() {
28eb60c0 62 let me = this;
f3aa84dd
DC
63
64 if (!me.regexFieldReference) {
65 throw "No regex field reference given";
66 }
67
68 me.callParent();
c87d46fb 69 },
f3aa84dd 70});