]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
remove unneeded applyEmptyText
[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 PVE.Utils.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 = PVE.Utils.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 PVE.Utils.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 = PVE.Utils.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 PVE.Utils.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("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" +
72 gettext("Minimum characters") + ": 2" + "<br />" +
73 gettext("Maximum characters") + ": 21" + "<br />" +
74 gettext("Must start with") + ": 'a-z'",
75
76 QemuStartDate: function(v) {
77 return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v);
78 },
79 QemuStartDateText: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
80
81 StorageId: function(v) {
82 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v);
83 },
84 StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" +
85 gettext("Minimum characters") + ": 2" + "<br />" +
86 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
87 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
88
89 ConfigId: function(v) {
90 return (/^[a-z][a-z0-9\_]+$/i).test(v);
91 },
92 ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" +
93 gettext("Minimum characters") + ": 2" + "<br />" +
94 gettext("Must start with") + ": " + gettext("letter"),
95
96 HttpProxy: function(v) {
97 return (/^http:\/\/.*$/).test(v);
98 },
99 HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
100
101 DnsName: function(v) {
102 return PVE.Utils.DnsName_match.test(v);
103 },
104 DnsNameText: gettext('This is not a valid DNS name'),
105
106 // workaround for https://www.sencha.com/forum/showthread.php?302150
107 pveMail: function(v) {
108 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v);
109 },
110 pveMailText: gettext('Example') + ": user@example.com",
111
112 HostList: function(v) {
113 var list = v.split(/[\ \,\;]+/);
114 var i;
115 for (i = 0; i < list.length; i++) {
116 if (list[i] == "") {
117 continue;
118 }
119
120 if (!PVE.Utils.HostPort_match.test(list[i]) &&
121 !PVE.Utils.HostPortBrackets_match.test(list[i]) &&
122 !PVE.Utils.IP6_dotnotation_match.test(list[i])) {
123 return false;
124 }
125 }
126
127 return true;
128 },
129 HostListText: gettext('Not a valid list of hosts')
130 });
131
132 // ExtJs 5-6 has an issue with caching
133 // see https://www.sencha.com/forum/showthread.php?308989
134 Ext.define('PVE.UnderlayPool', {
135 override: 'Ext.dom.UnderlayPool',
136
137 checkOut: function () {
138 var cache = this.cache,
139 len = cache.length,
140 el;
141
142 // do cleanup because some of the objects might have been destroyed
143 while (len--) {
144 if (cache[len].destroyed) {
145 cache.splice(len, 1);
146 }
147 }
148 // end do cleanup
149
150 el = cache.shift();
151
152 if (!el) {
153 el = Ext.Element.create(this.elementConfig);
154 el.setVisibilityMode(2);
155 //<debug>
156 // tell the spec runner to ignore this element when checking if the dom is clean
157 el.dom.setAttribute('data-sticky', true);
158 //</debug>
159 }
160
161 return el;
162 }
163 });
164
165 // if the order of the values are not the same in originalValue and value
166 // extjs will not overwrite value, but marks the field dirty and thus
167 // the reset button will be enabled (but clicking it changes nothing)
168 // so if the arrays are not the same after resetting, we
169 // clear and set it
170 Ext.define('PVE.form.ComboBox', {
171 override: 'Ext.form.field.ComboBox',
172
173 reset: function() {
174 // copied from combobox
175 var me = this;
176 me.callParent();
177
178 // clear and set when not the same
179 var value = me.getValue();
180 if (Ext.isArray(me.originalValue) && Ext.isArray(value) && !Ext.Array.equals(value, me.originalValue)) {
181 me.clearValue();
182 me.setValue(me.originalValue);
183 }
184 }
185 });
186
187 // should be fixed with ExtJS 6.0.2, see:
188 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
189 Ext.define('PVE.Datepicker', {
190 override: 'Ext.picker.Date',
191 hideMode: 'visibility'
192 });
193
194 // force alert boxes to be rendered with an Error Icon
195 // since Ext.Msg is an object and not a prototype, we need to override it
196 // after the framework has been initiated
197 Ext.onReady(function() {
198 /*jslint confusion: true */
199 Ext.override(Ext.Msg, {
200 alert: function(title, message, fn, scope) {
201 if (Ext.isString(title)) {
202 var config = {
203 title: title,
204 message: message,
205 icon: this.ERROR,
206 buttons: this.OK,
207 fn: fn,
208 scope : scope,
209 minWidth: this.minWidth
210 };
211 return this.show(config);
212 }
213 }
214 });
215 /*jslint confusion: false */
216 });
217 Ext.define('Ext.ux.IFrame', {
218 extend: 'Ext.Component',
219
220 alias: 'widget.uxiframe',
221
222 loadMask: 'Loading...',
223
224 src: 'about:blank',
225
226 renderTpl: [
227 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
228 ],
229 childEls: ['iframeEl'],
230
231 initComponent: function () {
232 this.callParent();
233
234 this.frameName = this.frameName || this.id + '-frame';
235 },
236
237 initEvents : function() {
238 var me = this;
239 me.callParent();
240 me.iframeEl.on('load', me.onLoad, me);
241 },
242
243 initRenderData: function() {
244 return Ext.apply(this.callParent(), {
245 src: this.src,
246 frameName: this.frameName
247 });
248 },
249
250 getBody: function() {
251 var doc = this.getDoc();
252 return doc.body || doc.documentElement;
253 },
254
255 getDoc: function() {
256 try {
257 return this.getWin().document;
258 } catch (ex) {
259 return null;
260 }
261 },
262
263 getWin: function() {
264 var me = this,
265 name = me.frameName,
266 win = Ext.isIE
267 ? me.iframeEl.dom.contentWindow
268 : window.frames[name];
269 return win;
270 },
271
272 getFrame: function() {
273 var me = this;
274 return me.iframeEl.dom;
275 },
276
277 beforeDestroy: function () {
278 this.cleanupListeners(true);
279 this.callParent();
280 },
281
282 cleanupListeners: function(destroying){
283 var doc, prop;
284
285 if (this.rendered) {
286 try {
287 doc = this.getDoc();
288 if (doc) {
289 /*jslint nomen: true*/
290 Ext.get(doc).un(this._docListeners);
291 /*jslint nomen: false*/
292 if (destroying && doc.hasOwnProperty) {
293 for (prop in doc) {
294 if (doc.hasOwnProperty(prop)) {
295 delete doc[prop];
296 }
297 }
298 }
299 }
300 } catch(e) { }
301 }
302 },
303
304 onLoad: function() {
305 var me = this,
306 doc = me.getDoc(),
307 fn = me.onRelayedEvent;
308
309 if (doc) {
310 try {
311 // These events need to be relayed from the inner document (where they stop
312 // bubbling) up to the outer document. This has to be done at the DOM level so
313 // the event reaches listeners on elements like the document body. The effected
314 // mechanisms that depend on this bubbling behavior are listed to the right
315 // of the event.
316 /*jslint nomen: true*/
317 Ext.get(doc).on(
318 me._docListeners = {
319 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
320 mousemove: fn, // window resize drag detection
321 mouseup: fn, // window resize termination
322 click: fn, // not sure, but just to be safe
323 dblclick: fn, // not sure again
324 scope: me
325 }
326 );
327 /*jslint nomen: false*/
328 } catch(e) {
329 // cannot do this xss
330 }
331
332 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
333 Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
334
335 this.el.unmask();
336 this.fireEvent('load', this);
337
338 } else if (me.src) {
339
340 this.el.unmask();
341 this.fireEvent('error', this);
342 }
343
344
345 },
346
347 onRelayedEvent: function (event) {
348 // relay event from the iframe's document to the document that owns the iframe...
349
350 var iframeEl = this.iframeEl,
351
352 // Get the left-based iframe position
353 iframeXY = iframeEl.getTrueXY(),
354 originalEventXY = event.getXY(),
355
356 // Get the left-based XY position.
357 // This is because the consumer of the injected event will
358 // perform its own RTL normalization.
359 eventXY = event.getTrueXY();
360
361 // the event from the inner document has XY relative to that document's origin,
362 // so adjust it to use the origin of the iframe in the outer document:
363 event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
364
365 event.injectEvent(iframeEl); // blame the iframe for the event...
366
367 event.xy = originalEventXY; // restore the original XY (just for safety)
368 },
369
370 load: function (src) {
371 var me = this,
372 text = me.loadMask,
373 frame = me.getFrame();
374
375 if (me.fireEvent('beforeload', me, src) !== false) {
376 if (text && me.el) {
377 me.el.mask(text);
378 }
379
380 frame.src = me.src = (src || me.src);
381 }
382 }
383 });