]>
Commit | Line | Data |
---|---|---|
52e4096b DM |
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) { | |
368df92e DC |
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); | |
52e4096b | 21 | }, |
368df92e | 22 | IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32', |
52e4096b DM |
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) { | |
368df92e DC |
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); | |
52e4096b | 36 | }, |
368df92e | 37 | IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120', |
52e4096b DM |
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]/, | |
3d9bc0a2 | 45 | |
52e4096b DM |
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 | }, | |
24bf5bd4 DM |
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', '_'", | |
52e4096b DM |
88 | |
89 | HttpProxy: function(v) { | |
90 | return (/^http:\/\/.*$/).test(v); | |
91 | }, | |
92 | HttpProxyText: gettext('Example') + ": http://username:password@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 | }, | |
8ca163bd EK |
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 | }, | |
22f2f9d6 | 103 | pveMailText: gettext('Example') + ": user@example.com" |
52e4096b DM |
104 | }); |
105 | ||
ee231e79 DC |
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 | ||
598ee8e6 TL |
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 | ||
026b7601 EK |
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() { | |
ec0bd652 | 150 | /*jslint confusion: true */ |
026b7601 EK |
151 | Ext.override(Ext.Msg, { |
152 | alert: function(title, message, fn, scope) { | |
153 | if (Ext.isString(title)) { | |
154 | var config = { | |
155 | title: title, | |
156 | message: message, | |
157 | icon: this.ERROR, | |
158 | buttons: this.OK, | |
159 | fn: fn, | |
160 | scope : scope, | |
161 | minWidth: this.minWidth | |
162 | }; | |
163 | return this.show(config); | |
164 | } | |
165 | } | |
166 | }); | |
ec0bd652 | 167 | /*jslint confusion: false */ |
026b7601 | 168 | }); |
52e4096b DM |
169 | Ext.define('Ext.ux.IFrame', { |
170 | extend: 'Ext.Component', | |
171 | ||
172 | alias: 'widget.uxiframe', | |
173 | ||
174 | loadMask: 'Loading...', | |
175 | ||
176 | src: 'about:blank', | |
177 | ||
178 | renderTpl: [ | |
8fae05ea | 179 | '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>' |
52e4096b | 180 | ], |
06366d35 | 181 | childEls: ['iframeEl'], |
52e4096b DM |
182 | |
183 | initComponent: function () { | |
184 | this.callParent(); | |
185 | ||
06366d35 | 186 | this.frameName = this.frameName || this.id + '-frame'; |
52e4096b DM |
187 | }, |
188 | ||
189 | initEvents : function() { | |
190 | var me = this; | |
191 | me.callParent(); | |
192 | me.iframeEl.on('load', me.onLoad, me); | |
193 | }, | |
194 | ||
195 | initRenderData: function() { | |
196 | return Ext.apply(this.callParent(), { | |
197 | src: this.src, | |
198 | frameName: this.frameName | |
199 | }); | |
200 | }, | |
201 | ||
202 | getBody: function() { | |
203 | var doc = this.getDoc(); | |
204 | return doc.body || doc.documentElement; | |
205 | }, | |
206 | ||
207 | getDoc: function() { | |
208 | try { | |
209 | return this.getWin().document; | |
210 | } catch (ex) { | |
211 | return null; | |
212 | } | |
213 | }, | |
214 | ||
215 | getWin: function() { | |
216 | var me = this, | |
217 | name = me.frameName, | |
218 | win = Ext.isIE | |
219 | ? me.iframeEl.dom.contentWindow | |
220 | : window.frames[name]; | |
221 | return win; | |
222 | }, | |
223 | ||
224 | getFrame: function() { | |
225 | var me = this; | |
226 | return me.iframeEl.dom; | |
227 | }, | |
228 | ||
229 | beforeDestroy: function () { | |
230 | this.cleanupListeners(true); | |
231 | this.callParent(); | |
232 | }, | |
3d9bc0a2 | 233 | |
52e4096b DM |
234 | cleanupListeners: function(destroying){ |
235 | var doc, prop; | |
236 | ||
237 | if (this.rendered) { | |
238 | try { | |
06366d35 | 239 | doc = this.getDoc(); |
52e4096b | 240 | if (doc) { |
06366d35 | 241 | Ext.get(doc).un(this._docListeners); |
52e4096b DM |
242 | if (destroying) { |
243 | for (prop in doc) { | |
244 | if (doc.hasOwnProperty && doc.hasOwnProperty(prop)) { | |
245 | delete doc[prop]; | |
246 | } | |
247 | } | |
248 | } | |
249 | } | |
250 | } catch(e) { } | |
251 | } | |
252 | }, | |
253 | ||
254 | onLoad: function() { | |
255 | var me = this, | |
256 | doc = me.getDoc(), | |
257 | fn = me.onRelayedEvent; | |
258 | ||
259 | if (doc) { | |
260 | try { | |
52e4096b DM |
261 | // These events need to be relayed from the inner document (where they stop |
262 | // bubbling) up to the outer document. This has to be done at the DOM level so | |
263 | // the event reaches listeners on elements like the document body. The effected | |
264 | // mechanisms that depend on this bubbling behavior are listed to the right | |
265 | // of the event. | |
06366d35 DC |
266 | Ext.get(doc).on( |
267 | me._docListeners = { | |
268 | mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) | |
269 | mousemove: fn, // window resize drag detection | |
270 | mouseup: fn, // window resize termination | |
271 | click: fn, // not sure, but just to be safe | |
272 | dblclick: fn, // not sure again | |
273 | scope: me | |
274 | } | |
275 | ); | |
52e4096b DM |
276 | } catch(e) { |
277 | // cannot do this xss | |
278 | } | |
279 | ||
280 | // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! | |
06366d35 | 281 | Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); |
52e4096b DM |
282 | |
283 | this.el.unmask(); | |
284 | this.fireEvent('load', this); | |
285 | ||
06366d35 | 286 | } else if (me.src) { |
52e4096b DM |
287 | |
288 | this.el.unmask(); | |
289 | this.fireEvent('error', this); | |
290 | } | |
291 | ||
292 | ||
293 | }, | |
294 | ||
06366d35 DC |
295 | onRelayedEvent: function (event) { |
296 | // relay event from the iframe's document to the document that owns the iframe... | |
297 | ||
298 | var iframeEl = this.iframeEl, | |
299 | ||
300 | // Get the left-based iframe position | |
301 | iframeXY = iframeEl.getTrueXY(), | |
302 | originalEventXY = event.getXY(), | |
303 | ||
304 | // Get the left-based XY position. | |
305 | // This is because the consumer of the injected event will | |
306 | // perform its own RTL normalization. | |
307 | eventXY = event.getTrueXY(); | |
308 | ||
309 | // the event from the inner document has XY relative to that document's origin, | |
310 | // so adjust it to use the origin of the iframe in the outer document: | |
311 | event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; | |
312 | ||
313 | event.injectEvent(iframeEl); // blame the iframe for the event... | |
314 | ||
315 | event.xy = originalEventXY; // restore the original XY (just for safety) | |
316 | }, | |
317 | ||
52e4096b DM |
318 | load: function (src) { |
319 | var me = this, | |
320 | text = me.loadMask, | |
321 | frame = me.getFrame(); | |
322 | ||
323 | if (me.fireEvent('beforeload', me, src) !== false) { | |
324 | if (text && me.el) { | |
325 | me.el.mask(text); | |
326 | } | |
327 | ||
328 | frame.src = me.src = (src || me.src); | |
329 | } | |
330 | } | |
331 | }); |