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