]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
improve gui cidr matching
[pve-manager.git] / www / manager6 / Toolkit.js
1 // ExtJS related things
2
3 PVE.Utils.toolkit = 'extjs',
4
5 // do not send '_dc' parameter
6 Ext.Ajax.disableCaching = false;
7
8 // custom Vtypes
9 Ext.apply(Ext.form.field.VTypes, {
10 IPAddress: function(v) {
11 return IP4_match.test(v);
12 },
13 IPAddressText: gettext('Example') + ': 192.168.1.1',
14 IPAddressMask: /[\d\.]/i,
15
16 IPCIDRAddress: function(v) {
17 var result = IP4_cidr_match.exec(v);
18 // limits according to JSON Schema see
19 // pve-common/src/PVE/JSONSchema.pm
20 return (result !== null && result[1] >= 8 && result[1] <= 32);
21 },
22 IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
23 IPCIDRAddressMask: /[\d\.\/]/i,
24
25 IP6Address: function(v) {
26 return IP6_match.test(v);
27 },
28 IP6AddressText: gettext('Example') + ': 2001:DB8::42',
29 IP6AddressMask: /[A-Fa-f0-9:]/,
30
31 IP6CIDRAddress: function(v) {
32 var result = IP6_cidr_match.exec(v);
33 // limits according to JSON Schema see
34 // pve-common/src/PVE/JSONSchema.pm
35 return (result !== null && result[1] >= 8 && result[1] <= 120);
36 },
37 IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
38 IP6CIDRAddressMask: /[A-Fa-f0-9:\/]/,
39
40 IP6PrefixLength: function(v) {
41 return v >= 0 && v <= 128;
42 },
43 IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128',
44 IP6PrefixLengthMask: /[0-9]/,
45
46 IP64Address: function(v) {
47 return IP64_match.test(v);
48 },
49 IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
50 IP64AddressMask: /[A-Fa-f0-9\.:]/,
51
52 MacAddress: function(v) {
53 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
54 },
55 MacAddressMask: /[a-fA-F0-9:]/,
56 MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab',
57
58 BridgeName: function(v) {
59 return (/^vmbr\d{1,4}$/).test(v);
60 },
61 BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
62
63 BondName: function(v) {
64 return (/^bond\d{1,4}$/).test(v);
65 },
66 BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
67
68 InterfaceName: function(v) {
69 return (/^[a-z][a-z0-9_]{1,20}$/).test(v);
70 },
71 InterfaceNameText: gettext('Format') + ': [a-z][a-z0-9_]{1,20}',
72
73
74 QemuStartDate: function(v) {
75 return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v);
76 },
77 QemuStartDateText: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
78
79 StorageId: function(v) {
80 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v);
81 },
82 StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'",
83
84 ConfigId: function(v) {
85 return (/^[a-z][a-z0-9\_]+$/i).test(v);
86 },
87 ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'",
88
89 HttpProxy: function(v) {
90 return (/^http:\/\/.*$/).test(v);
91 },
92 HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
93
94 DnsName: function(v) {
95 return (/^(([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)\.)*([A-Za-z0-9]([A-Za-z0-9\-]*[A-Za-z0-9])?)$/).test(v);
96 },
97 DnsNameText: gettext('This is not a valid DNS name'),
98
99 // workaround for https://www.sencha.com/forum/showthread.php?302150
100 pveMail: function(v) {
101 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v);
102 },
103 pveMailText: gettext('Example') + ": user@example.com",
104 });
105
106 // ExtJs 5-6 has an issue with caching
107 // see https://www.sencha.com/forum/showthread.php?308989
108 Ext.define('PVE.UnderlayPool', {
109 override: 'Ext.dom.UnderlayPool',
110
111 checkOut: function () {
112 var cache = this.cache,
113 len = cache.length,
114 el;
115
116 // do cleanup because some of the objects might have been destroyed
117 while (len--) {
118 if (cache[len].destroyed) {
119 cache.splice(len, 1);
120 }
121 }
122 // end do cleanup
123
124 el = cache.shift();
125
126 if (!el) {
127 el = Ext.Element.create(this.elementConfig);
128 el.setVisibilityMode(2);
129 //<debug>
130 // tell the spec runner to ignore this element when checking if the dom is clean
131 el.dom.setAttribute('data-sticky', true);
132 //</debug>
133 }
134
135 return el;
136 }
137 });
138
139 // should be fixed with ExtJS 6.0.2, see:
140 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
141 Ext.define('PVE.Datepicker', {
142 override: 'Ext.picker.Date',
143 hideMode: 'visibility'
144 });
145
146 // force alert boxes to be rendered with an Error Icon
147 // since Ext.Msg is an object and not a prototype, we need to override it
148 // after the framework has been initiated
149 Ext.onReady(function() {
150 Ext.override(Ext.Msg, {
151 alert: function(title, message, fn, scope) {
152 if (Ext.isString(title)) {
153 var config = {
154 title: title,
155 message: message,
156 icon: this.ERROR,
157 buttons: this.OK,
158 fn: fn,
159 scope : scope,
160 minWidth: this.minWidth
161 };
162 return this.show(config);
163 }
164 }
165 });
166 });
167
168 Ext.define('Ext.ux.IFrame', {
169 extend: 'Ext.Component',
170
171 alias: 'widget.uxiframe',
172
173 loadMask: 'Loading...',
174
175 src: 'about:blank',
176
177 renderTpl: [
178 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
179 ],
180 childEls: ['iframeEl'],
181
182 initComponent: function () {
183 this.callParent();
184
185 this.frameName = this.frameName || this.id + '-frame';
186 },
187
188 initEvents : function() {
189 var me = this;
190 me.callParent();
191 me.iframeEl.on('load', me.onLoad, me);
192 },
193
194 initRenderData: function() {
195 return Ext.apply(this.callParent(), {
196 src: this.src,
197 frameName: this.frameName
198 });
199 },
200
201 getBody: function() {
202 var doc = this.getDoc();
203 return doc.body || doc.documentElement;
204 },
205
206 getDoc: function() {
207 try {
208 return this.getWin().document;
209 } catch (ex) {
210 return null;
211 }
212 },
213
214 getWin: function() {
215 var me = this,
216 name = me.frameName,
217 win = Ext.isIE
218 ? me.iframeEl.dom.contentWindow
219 : window.frames[name];
220 return win;
221 },
222
223 getFrame: function() {
224 var me = this;
225 return me.iframeEl.dom;
226 },
227
228 beforeDestroy: function () {
229 this.cleanupListeners(true);
230 this.callParent();
231 },
232
233 cleanupListeners: function(destroying){
234 var doc, prop;
235
236 if (this.rendered) {
237 try {
238 doc = this.getDoc();
239 if (doc) {
240 Ext.get(doc).un(this._docListeners);
241 if (destroying) {
242 for (prop in doc) {
243 if (doc.hasOwnProperty && doc.hasOwnProperty(prop)) {
244 delete doc[prop];
245 }
246 }
247 }
248 }
249 } catch(e) { }
250 }
251 },
252
253 onLoad: function() {
254 var me = this,
255 doc = me.getDoc(),
256 fn = me.onRelayedEvent;
257
258 if (doc) {
259 try {
260 // These events need to be relayed from the inner document (where they stop
261 // bubbling) up to the outer document. This has to be done at the DOM level so
262 // the event reaches listeners on elements like the document body. The effected
263 // mechanisms that depend on this bubbling behavior are listed to the right
264 // of the event.
265 Ext.get(doc).on(
266 me._docListeners = {
267 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
268 mousemove: fn, // window resize drag detection
269 mouseup: fn, // window resize termination
270 click: fn, // not sure, but just to be safe
271 dblclick: fn, // not sure again
272 scope: me
273 }
274 );
275 } catch(e) {
276 // cannot do this xss
277 }
278
279 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
280 Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
281
282 this.el.unmask();
283 this.fireEvent('load', this);
284
285 } else if (me.src) {
286
287 this.el.unmask();
288 this.fireEvent('error', this);
289 }
290
291
292 },
293
294 onRelayedEvent: function (event) {
295 // relay event from the iframe's document to the document that owns the iframe...
296
297 var iframeEl = this.iframeEl,
298
299 // Get the left-based iframe position
300 iframeXY = iframeEl.getTrueXY(),
301 originalEventXY = event.getXY(),
302
303 // Get the left-based XY position.
304 // This is because the consumer of the injected event will
305 // perform its own RTL normalization.
306 eventXY = event.getTrueXY();
307
308 // the event from the inner document has XY relative to that document's origin,
309 // so adjust it to use the origin of the iframe in the outer document:
310 event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
311
312 event.injectEvent(iframeEl); // blame the iframe for the event...
313
314 event.xy = originalEventXY; // restore the original XY (just for safety)
315 },
316
317 load: function (src) {
318 var me = this,
319 text = me.loadMask,
320 frame = me.getFrame();
321
322 if (me.fireEvent('beforeload', me, src) !== false) {
323 if (text && me.el) {
324 me.el.mask(text);
325 }
326
327 frame.src = me.src = (src || me.src);
328 }
329 }
330 });