]>
Commit | Line | Data |
---|---|---|
f3aa84dd DC |
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 | ||
28eb60c0 TL |
15 | items: [ |
16 | { | |
17 | xtype: 'textfield', | |
18 | submitValue: false, | |
19 | name: 'teststring', | |
20 | isDirty: () => false, | |
21 | reset: Ext.emptyFn, | |
8db2abc2 | 22 | flex: 1, |
28eb60c0 TL |
23 | }, |
24 | { | |
25 | margin: '0 0 0 5', | |
26 | xtype: 'button', | |
27 | text: 'Test', | |
28 | handler: function(btn) { | |
29 | let view = this.up(); | |
4eaa2d36 | 30 | let regexField = view.up().child(`field[reference=${view.regexFieldReference}]`); |
f3aa84dd | 31 | |
28eb60c0 TL |
32 | let regex = regexField.getValue(); |
33 | if (view.wholeMatch) { | |
34 | regex = `^${regex}$`; | |
35 | } | |
f3aa84dd | 36 | |
28eb60c0 TL |
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 | }, | |
c87d46fb | 59 | }, |
28eb60c0 | 60 | ], |
f3aa84dd DC |
61 | |
62 | initComponent: function() { | |
28eb60c0 | 63 | let me = this; |
f3aa84dd DC |
64 | |
65 | if (!me.regexFieldReference) { | |
66 | throw "No regex field reference given"; | |
67 | } | |
68 | ||
69 | me.callParent(); | |
c87d46fb | 70 | }, |
f3aa84dd | 71 | }); |