]> git.proxmox.com Git - pmg-gui.git/blob - js/RegexTester.js
486c1972538b86d8fc02efb247d1bda6e47ec65a
[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 },
23 {
24 margin: '0 0 0 5',
25 xtype: 'button',
26 text: 'Test',
27 handler: function(btn) {
28 let view = this.up();
29 let regexField = view.up().child(`field[reference=${view.regexFieldReference}]`);
30
31 let regex = regexField.getValue();
32 if (view.wholeMatch) {
33 regex = `^${regex}$`;
34 }
35
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 },
58 },
59 ],
60
61 initComponent: function() {
62 let me = this;
63
64 if (!me.regexFieldReference) {
65 throw "No regex field reference given";
66 }
67
68 me.callParent();
69 },
70 });