]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
ext6migrate: fix fullscreen for noVNC
[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 // we dont want that a displayfield set the form dirty flag!
101 Ext.override(Ext.form.field.Display, {
102 isDirty: function() { return false; }
103 });
104
105 // hack: ExtJS does not display the correct value if we
106 // call setValue while the store is loading, so we need
107 // to call it again after loading
108 Ext.override(Ext.form.field.ComboBox, {
109 onLoad: function() {
110 this.setValue(this.value, false);
111 this.callOverridden(arguments);
112 }
113 });
114
115 Ext.define('Ext.ux.IFrame', {
116 extend: 'Ext.Component',
117
118 alias: 'widget.uxiframe',
119
120 loadMask: 'Loading...',
121
122 src: 'about:blank',
123
124 renderTpl: [
125 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
126 ],
127 childEls: ['iframeEl'],
128
129 initComponent: function () {
130 this.callParent();
131
132 this.frameName = this.frameName || this.id + '-frame';
133 },
134
135 initEvents : function() {
136 var me = this;
137 me.callParent();
138 me.iframeEl.on('load', me.onLoad, me);
139 },
140
141 initRenderData: function() {
142 return Ext.apply(this.callParent(), {
143 src: this.src,
144 frameName: this.frameName
145 });
146 },
147
148 getBody: function() {
149 var doc = this.getDoc();
150 return doc.body || doc.documentElement;
151 },
152
153 getDoc: function() {
154 try {
155 return this.getWin().document;
156 } catch (ex) {
157 return null;
158 }
159 },
160
161 getWin: function() {
162 var me = this,
163 name = me.frameName,
164 win = Ext.isIE
165 ? me.iframeEl.dom.contentWindow
166 : window.frames[name];
167 return win;
168 },
169
170 getFrame: function() {
171 var me = this;
172 return me.iframeEl.dom;
173 },
174
175 beforeDestroy: function () {
176 this.cleanupListeners(true);
177 this.callParent();
178 },
179
180 cleanupListeners: function(destroying){
181 var doc, prop;
182
183 if (this.rendered) {
184 try {
185 doc = this.getDoc();
186 if (doc) {
187 Ext.get(doc).un(this._docListeners);
188 if (destroying) {
189 for (prop in doc) {
190 if (doc.hasOwnProperty && doc.hasOwnProperty(prop)) {
191 delete doc[prop];
192 }
193 }
194 }
195 }
196 } catch(e) { }
197 }
198 },
199
200 onLoad: function() {
201 var me = this,
202 doc = me.getDoc(),
203 fn = me.onRelayedEvent;
204
205 if (doc) {
206 try {
207 // These events need to be relayed from the inner document (where they stop
208 // bubbling) up to the outer document. This has to be done at the DOM level so
209 // the event reaches listeners on elements like the document body. The effected
210 // mechanisms that depend on this bubbling behavior are listed to the right
211 // of the event.
212 Ext.get(doc).on(
213 me._docListeners = {
214 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
215 mousemove: fn, // window resize drag detection
216 mouseup: fn, // window resize termination
217 click: fn, // not sure, but just to be safe
218 dblclick: fn, // not sure again
219 scope: me
220 }
221 );
222 } catch(e) {
223 // cannot do this xss
224 }
225
226 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
227 Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
228
229 this.el.unmask();
230 this.fireEvent('load', this);
231
232 } else if (me.src) {
233
234 this.el.unmask();
235 this.fireEvent('error', this);
236 }
237
238
239 },
240
241 onRelayedEvent: function (event) {
242 // relay event from the iframe's document to the document that owns the iframe...
243
244 var iframeEl = this.iframeEl,
245
246 // Get the left-based iframe position
247 iframeXY = iframeEl.getTrueXY(),
248 originalEventXY = event.getXY(),
249
250 // Get the left-based XY position.
251 // This is because the consumer of the injected event will
252 // perform its own RTL normalization.
253 eventXY = event.getTrueXY();
254
255 // the event from the inner document has XY relative to that document's origin,
256 // so adjust it to use the origin of the iframe in the outer document:
257 event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
258
259 event.injectEvent(iframeEl); // blame the iframe for the event...
260
261 event.xy = originalEventXY; // restore the original XY (just for safety)
262 },
263
264 load: function (src) {
265 var me = this,
266 text = me.loadMask,
267 frame = me.getFrame();
268
269 if (me.fireEvent('beforeload', me, src) !== false) {
270 if (text && me.el) {
271 me.el.mask(text);
272 }
273
274 frame.src = me.src = (src || me.src);
275 }
276 }
277 });