]> git.proxmox.com Git - pmg-gui.git/blob - js/RegexTester.js
spam info grid: use monospace font for score and level names
[pmg-gui.git] / js / RegexTester.js
1 Ext.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
15 items: [
16 {
17 xtype: 'textfield',
18 submitValue: false,
19 name: 'teststring',
20 isDirty: () => false,
21 reset: Ext.emptyFn,
22 flex: 1,
23 },
24 {
25 margin: '0 0 0 5',
26 xtype: 'button',
27 text: 'Test',
28 handler: function(btn) {
29 let view = this.up();
30 let regexField = view.up().child(`field[reference=${view.regexFieldReference}]`);
31
32 let regex = regexField.getValue();
33 if (view.wholeMatch) {
34 regex = `^${regex}$`;
35 }
36
37 Proxmox.Utils.API2Request({
38 url: '/api2/extjs/config/regextest',
39 waitMsgTarget: view.up('window'),
40 params: {
41 regex: regex,
42 text: view.down('textfield[name=teststring]').getValue(),
43 },
44 method: 'POST',
45 success: function(response) {
46 let elapsed = response.result.data;
47 Ext.Msg.show({
48 title: gettext('Success'),
49 message: gettext('OK') + ` (elapsed time: ${elapsed}ms)`,
50 buttons: Ext.Msg.OK,
51 icon: Ext.MessageBox.INFO,
52 });
53 },
54 failure: function(response, opts) {
55 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
56 },
57 });
58 },
59 },
60 ],
61
62 initComponent: function() {
63 let me = this;
64
65 if (!me.regexFieldReference) {
66 throw "No regex field reference given";
67 }
68
69 me.callParent();
70 },
71 });