]>
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, DnsName_match, DnsName_REGEXP, IPV4_REGEXP, IPV6_REGEXP*/
2 /*global HostPort_match, HostPortBrackets_match, IP6_dotnotation_match*/
3 // ExtJS related things
5 PVE
.Utils
.toolkit
= 'extjs';
7 // do not send '_dc' parameter
8 Ext
.Ajax
.disableCaching
= false;
11 Ext
.apply(Ext
.form
.field
.VTypes
, {
12 IPAddress: function(v
) {
13 return IP4_match
.test(v
);
15 IPAddressText
: gettext('Example') + ': 192.168.1.1',
16 IPAddressMask
: /[\d\.]/i,
18 IPCIDRAddress: function(v
) {
19 var result
= IP4_cidr_match
.exec(v
);
20 // limits according to JSON Schema see
21 // pve-common/src/PVE/JSONSchema.pm
22 return (result
!== null && result
[1] >= 8 && result
[1] <= 32);
24 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
25 IPCIDRAddressMask
: /[\d\.\/]/i,
27 IP6Address: function(v
) {
28 return IP6_match
.test(v
);
30 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
31 IP6AddressMask
: /[A-Fa-f0-9:]/,
33 IP6CIDRAddress: function(v
) {
34 var result
= IP6_cidr_match
.exec(v
);
35 // limits according to JSON Schema see
36 // pve-common/src/PVE/JSONSchema.pm
37 return (result
!== null && result
[1] >= 8 && result
[1] <= 120);
39 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
40 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
42 IP6PrefixLength: function(v
) {
43 return v
>= 0 && v
<= 128;
45 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
46 IP6PrefixLengthMask
: /[0-9]/,
48 IP64Address: function(v
) {
49 return IP64_match
.test(v
);
51 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
52 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
54 MacAddress: function(v
) {
55 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
57 MacAddressMask
: /[a-fA-F0-9:]/,
58 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
60 BridgeName: function(v
) {
61 return (/^vmbr\d{1,4}$/).test(v
);
63 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
65 BondName: function(v
) {
66 return (/^bond\d{1,4}$/).test(v
);
68 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
70 InterfaceName: function(v
) {
71 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
73 InterfaceNameText
: gettext('Format') + ': [a-z][a-z0-9_]{1,20}',
76 QemuStartDate: function(v
) {
77 return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v
);
79 QemuStartDateText
: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
81 StorageId: function(v
) {
82 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
84 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'",
86 ConfigId: function(v
) {
87 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
89 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'",
91 HttpProxy: function(v
) {
92 return (/^http:\/\/.*$/).test(v
);
94 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
96 DnsName: function(v
) {
97 return DnsName_match
.test(v
);
99 DnsNameText
: gettext('This is not a valid DNS name'),
101 // workaround for https://www.sencha.com/forum/showthread.php?302150
102 pveMail: function(v
) {
103 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
105 pveMailText
: gettext('Example') + ": user@example.com",
107 HostList: function(v
) {
108 var list
= v
.split(/[\ \,\;]+/);
110 for (i
= 0; i
< list
.length
; i
++) {
115 if (!HostPort_match
.test(list
[i
]) &&
116 !HostPortBrackets_match
.test(list
[i
]) &&
117 !IP6_dotnotation_match
.test(list
[i
])) {
124 HostListText
: gettext('Not a valid list of hosts')
127 // ExtJs 5-6 has an issue with caching
128 // see https://www.sencha.com/forum/showthread.php?308989
129 Ext
.define('PVE.UnderlayPool', {
130 override
: 'Ext.dom.UnderlayPool',
132 checkOut: function () {
133 var cache
= this.cache
,
137 // do cleanup because some of the objects might have been destroyed
139 if (cache
[len
].destroyed
) {
140 cache
.splice(len
, 1);
148 el
= Ext
.Element
.create(this.elementConfig
);
149 el
.setVisibilityMode(2);
151 // tell the spec runner to ignore this element when checking if the dom is clean
152 el
.dom
.setAttribute('data-sticky', true);
160 // if the order of the values are not the same in originalValue and value
161 // extjs will not overwrite value, but marks the field dirty and thus
162 // the reset button will be enabled (but clicking it changes nothing)
163 // so if the arrays are not the same after resetting, we
165 Ext
.define('PVE.form.ComboBox', {
166 override
: 'Ext.form.field.ComboBox',
169 // copied from combobox
174 // clear and set when not the same
175 var value
= me
.getValue();
176 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
178 me
.setValue(me
.originalValue
);
183 // should be fixed with ExtJS 6.0.2, see:
184 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
185 Ext
.define('PVE.Datepicker', {
186 override
: 'Ext.picker.Date',
187 hideMode
: 'visibility'
190 // force alert boxes to be rendered with an Error Icon
191 // since Ext.Msg is an object and not a prototype, we need to override it
192 // after the framework has been initiated
193 Ext
.onReady(function() {
194 /*jslint confusion: true */
195 Ext
.override(Ext
.Msg
, {
196 alert: function(title
, message
, fn
, scope
) {
197 if (Ext
.isString(title
)) {
205 minWidth
: this.minWidth
207 return this.show(config
);
211 /*jslint confusion: false */
213 Ext
.define('Ext.ux.IFrame', {
214 extend
: 'Ext.Component',
216 alias
: 'widget.uxiframe',
218 loadMask
: 'Loading...',
223 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
225 childEls
: ['iframeEl'],
227 initComponent: function () {
230 this.frameName
= this.frameName
|| this.id
+ '-frame';
233 initEvents : function() {
236 me
.iframeEl
.on('load', me
.onLoad
, me
);
239 initRenderData: function() {
240 return Ext
.apply(this.callParent(), {
242 frameName
: this.frameName
246 getBody: function() {
247 var doc
= this.getDoc();
248 return doc
.body
|| doc
.documentElement
;
253 return this.getWin().document
;
263 ? me
.iframeEl
.dom
.contentWindow
264 : window
.frames
[name
];
268 getFrame: function() {
270 return me
.iframeEl
.dom
;
273 beforeDestroy: function () {
274 this.cleanupListeners(true);
278 cleanupListeners: function(destroying
){
285 /*jslint nomen: true*/
286 Ext
.get(doc
).un(this._docListeners
);
287 /*jslint nomen: false*/
288 if (destroying
&& doc
.hasOwnProperty
) {
290 if (doc
.hasOwnProperty(prop
)) {
303 fn
= me
.onRelayedEvent
;
307 // These events need to be relayed from the inner document (where they stop
308 // bubbling) up to the outer document. This has to be done at the DOM level so
309 // the event reaches listeners on elements like the document body. The effected
310 // mechanisms that depend on this bubbling behavior are listed to the right
312 /*jslint nomen: true*/
315 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
316 mousemove
: fn
, // window resize drag detection
317 mouseup
: fn
, // window resize termination
318 click
: fn
, // not sure, but just to be safe
319 dblclick
: fn
, // not sure again
323 /*jslint nomen: false*/
325 // cannot do this xss
328 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
329 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
332 this.fireEvent('load', this);
337 this.fireEvent('error', this);
343 onRelayedEvent: function (event
) {
344 // relay event from the iframe's document to the document that owns the iframe...
346 var iframeEl
= this.iframeEl
,
348 // Get the left-based iframe position
349 iframeXY
= iframeEl
.getTrueXY(),
350 originalEventXY
= event
.getXY(),
352 // Get the left-based XY position.
353 // This is because the consumer of the injected event will
354 // perform its own RTL normalization.
355 eventXY
= event
.getTrueXY();
357 // the event from the inner document has XY relative to that document's origin,
358 // so adjust it to use the origin of the iframe in the outer document:
359 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
361 event
.injectEvent(iframeEl
); // blame the iframe for the event...
363 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
366 load: function (src
) {
369 frame
= me
.getFrame();
371 if (me
.fireEvent('beforeload', me
, src
) !== false) {
376 frame
.src
= me
.src
= (src
|| me
.src
);