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