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