]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
1 /*global IP4_match, IP4_cidr_match, IP6_match, IP6_cidr_match, IP64_match*/
2 // ExtJS related things
4 PVE
.Utils
.toolkit
= 'extjs';
6 // do not send '_dc' parameter
7 Ext
.Ajax
.disableCaching
= false;
10 Ext
.apply(Ext
.form
.field
.VTypes
, {
11 IPAddress: function(v
) {
12 return IP4_match
.test(v
);
14 IPAddressText
: gettext('Example') + ': 192.168.1.1',
15 IPAddressMask
: /[\d\.]/i,
17 IPCIDRAddress: function(v
) {
18 var result
= IP4_cidr_match
.exec(v
);
19 // limits according to JSON Schema see
20 // pve-common/src/PVE/JSONSchema.pm
21 return (result
!== null && result
[1] >= 8 && result
[1] <= 32);
23 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
24 IPCIDRAddressMask
: /[\d\.\/]/i,
26 IP6Address: function(v
) {
27 return IP6_match
.test(v
);
29 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
30 IP6AddressMask
: /[A-Fa-f0-9:]/,
32 IP6CIDRAddress: function(v
) {
33 var result
= IP6_cidr_match
.exec(v
);
34 // limits according to JSON Schema see
35 // pve-common/src/PVE/JSONSchema.pm
36 return (result
!== null && result
[1] >= 8 && result
[1] <= 120);
38 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
39 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
41 IP6PrefixLength: function(v
) {
42 return v
>= 0 && v
<= 128;
44 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
45 IP6PrefixLengthMask
: /[0-9]/,
47 IP64Address: function(v
) {
48 return IP64_match
.test(v
);
50 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
51 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
53 MacAddress: function(v
) {
54 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
56 MacAddressMask
: /[a-fA-F0-9:]/,
57 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
59 BridgeName: function(v
) {
60 return (/^vmbr\d{1,4}$/).test(v
);
62 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
64 BondName: function(v
) {
65 return (/^bond\d{1,4}$/).test(v
);
67 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
69 InterfaceName: function(v
) {
70 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
72 InterfaceNameText
: gettext('Format') + ': [a-z][a-z0-9_]{1,20}',
75 QemuStartDate: function(v
) {
76 return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v
);
78 QemuStartDateText
: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
80 StorageId: function(v
) {
81 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
83 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'",
85 ConfigId: function(v
) {
86 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
88 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'",
90 HttpProxy: function(v
) {
91 return (/^http:\/\/.*$/).test(v
);
93 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
95 DnsName: function(v
) {
96 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
);
98 DnsNameText
: gettext('This is not a valid DNS name'),
100 // workaround for https://www.sencha.com/forum/showthread.php?302150
101 pveMail: function(v
) {
102 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
104 pveMailText
: gettext('Example') + ": user@example.com"
107 // ExtJs 5-6 has an issue with caching
108 // see https://www.sencha.com/forum/showthread.php?308989
109 Ext
.define('PVE.UnderlayPool', {
110 override
: 'Ext.dom.UnderlayPool',
112 checkOut: function () {
113 var cache
= this.cache
,
117 // do cleanup because some of the objects might have been destroyed
119 if (cache
[len
].destroyed
) {
120 cache
.splice(len
, 1);
128 el
= Ext
.Element
.create(this.elementConfig
);
129 el
.setVisibilityMode(2);
131 // tell the spec runner to ignore this element when checking if the dom is clean
132 el
.dom
.setAttribute('data-sticky', true);
140 // should be fixed with ExtJS 6.0.2, see:
141 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
142 Ext
.define('PVE.Datepicker', {
143 override
: 'Ext.picker.Date',
144 hideMode
: 'visibility'
147 // force alert boxes to be rendered with an Error Icon
148 // since Ext.Msg is an object and not a prototype, we need to override it
149 // after the framework has been initiated
150 Ext
.onReady(function() {
151 /*jslint confusion: true */
152 Ext
.override(Ext
.Msg
, {
153 alert: function(title
, message
, fn
, scope
) {
154 if (Ext
.isString(title
)) {
162 minWidth
: this.minWidth
164 return this.show(config
);
168 /*jslint confusion: false */
170 Ext
.define('Ext.ux.IFrame', {
171 extend
: 'Ext.Component',
173 alias
: 'widget.uxiframe',
175 loadMask
: 'Loading...',
180 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
182 childEls
: ['iframeEl'],
184 initComponent: function () {
187 this.frameName
= this.frameName
|| this.id
+ '-frame';
190 initEvents : function() {
193 me
.iframeEl
.on('load', me
.onLoad
, me
);
196 initRenderData: function() {
197 return Ext
.apply(this.callParent(), {
199 frameName
: this.frameName
203 getBody: function() {
204 var doc
= this.getDoc();
205 return doc
.body
|| doc
.documentElement
;
210 return this.getWin().document
;
220 ? me
.iframeEl
.dom
.contentWindow
221 : window
.frames
[name
];
225 getFrame: function() {
227 return me
.iframeEl
.dom
;
230 beforeDestroy: function () {
231 this.cleanupListeners(true);
235 cleanupListeners: function(destroying
){
242 /*jslint nomen: true*/
243 Ext
.get(doc
).un(this._docListeners
);
244 /*jslint nomen: false*/
245 if (destroying
&& doc
.hasOwnProperty
) {
247 if (doc
.hasOwnProperty(prop
)) {
260 fn
= me
.onRelayedEvent
;
264 // These events need to be relayed from the inner document (where they stop
265 // bubbling) up to the outer document. This has to be done at the DOM level so
266 // the event reaches listeners on elements like the document body. The effected
267 // mechanisms that depend on this bubbling behavior are listed to the right
269 /*jslint nomen: true*/
272 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
273 mousemove
: fn
, // window resize drag detection
274 mouseup
: fn
, // window resize termination
275 click
: fn
, // not sure, but just to be safe
276 dblclick
: fn
, // not sure again
280 /*jslint nomen: false*/
282 // cannot do this xss
285 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
286 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
289 this.fireEvent('load', this);
294 this.fireEvent('error', this);
300 onRelayedEvent: function (event
) {
301 // relay event from the iframe's document to the document that owns the iframe...
303 var iframeEl
= this.iframeEl
,
305 // Get the left-based iframe position
306 iframeXY
= iframeEl
.getTrueXY(),
307 originalEventXY
= event
.getXY(),
309 // Get the left-based XY position.
310 // This is because the consumer of the injected event will
311 // perform its own RTL normalization.
312 eventXY
= event
.getTrueXY();
314 // the event from the inner document has XY relative to that document's origin,
315 // so adjust it to use the origin of the iframe in the outer document:
316 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
318 event
.injectEvent(iframeEl
); // blame the iframe for the event...
320 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
323 load: function (src
) {
326 frame
= me
.getFrame();
328 if (me
.fireEvent('beforeload', me
, src
) !== false) {
333 frame
.src
= me
.src
= (src
|| me
.src
);