]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
1 // ExtJS related things
3 PVE
.Utils
.toolkit
= 'extjs';
5 // do not send '_dc' parameter
6 Ext
.Ajax
.disableCaching
= false;
9 Ext
.apply(Ext
.form
.field
.VTypes
, {
10 IPAddress: function(v
) {
11 return PVE
.Utils
.IP4_match
.test(v
);
13 IPAddressText
: gettext('Example') + ': 192.168.1.1',
14 IPAddressMask
: /[\d\.]/i,
16 IPCIDRAddress: function(v
) {
17 var result
= PVE
.Utils
.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);
22 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
23 IPCIDRAddressMask
: /[\d\.\/]/i,
25 IP6Address: function(v
) {
26 return PVE
.Utils
.IP6_match
.test(v
);
28 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
29 IP6AddressMask
: /[A-Fa-f0-9:]/,
31 IP6CIDRAddress: function(v
) {
32 var result
= PVE
.Utils
.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);
37 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
38 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
40 IP6PrefixLength: function(v
) {
41 return v
>= 0 && v
<= 128;
43 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
44 IP6PrefixLengthMask
: /[0-9]/,
46 IP64Address: function(v
) {
47 return PVE
.Utils
.IP64_match
.test(v
);
49 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
50 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
52 MacAddress: function(v
) {
53 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
55 MacAddressMask
: /[a-fA-F0-9:]/,
56 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
58 BridgeName: function(v
) {
59 return (/^vmbr\d{1,4}$/).test(v
);
61 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
63 BondName: function(v
) {
64 return (/^bond\d{1,4}$/).test(v
);
66 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
68 InterfaceName: function(v
) {
69 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
71 InterfaceNameText
: gettext('Format') + ': [a-z][a-z0-9_]{1,20}',
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
);
77 QemuStartDateText
: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
79 StorageId: function(v
) {
80 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
82 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'",
84 ConfigId: function(v
) {
85 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
87 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'",
89 HttpProxy: function(v
) {
90 return (/^http:\/\/.*$/).test(v
);
92 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
94 DnsName: function(v
) {
95 return PVE
.Utils
.DnsName_match
.test(v
);
97 DnsNameText
: gettext('This is not a valid DNS name'),
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
);
103 pveMailText
: gettext('Example') + ": user@example.com",
105 HostList: function(v
) {
106 var list
= v
.split(/[\ \,\;]+/);
108 for (i
= 0; i
< list
.length
; i
++) {
113 if (!PVE
.Utils
.HostPort_match
.test(list
[i
]) &&
114 !PVE
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
115 !PVE
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
122 HostListText
: gettext('Not a valid list of hosts')
125 // ExtJs 5-6 has an issue with caching
126 // see https://www.sencha.com/forum/showthread.php?308989
127 Ext
.define('PVE.UnderlayPool', {
128 override
: 'Ext.dom.UnderlayPool',
130 checkOut: function () {
131 var cache
= this.cache
,
135 // do cleanup because some of the objects might have been destroyed
137 if (cache
[len
].destroyed
) {
138 cache
.splice(len
, 1);
146 el
= Ext
.Element
.create(this.elementConfig
);
147 el
.setVisibilityMode(2);
149 // tell the spec runner to ignore this element when checking if the dom is clean
150 el
.dom
.setAttribute('data-sticky', true);
158 // if the order of the values are not the same in originalValue and value
159 // extjs will not overwrite value, but marks the field dirty and thus
160 // the reset button will be enabled (but clicking it changes nothing)
161 // so if the arrays are not the same after resetting, we
163 Ext
.define('PVE.form.ComboBox', {
164 override
: 'Ext.form.field.ComboBox',
167 // copied from combobox
172 // clear and set when not the same
173 var value
= me
.getValue();
174 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
176 me
.setValue(me
.originalValue
);
181 // should be fixed with ExtJS 6.0.2, see:
182 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
183 Ext
.define('PVE.Datepicker', {
184 override
: 'Ext.picker.Date',
185 hideMode
: 'visibility'
188 // force alert boxes to be rendered with an Error Icon
189 // since Ext.Msg is an object and not a prototype, we need to override it
190 // after the framework has been initiated
191 Ext
.onReady(function() {
192 /*jslint confusion: true */
193 Ext
.override(Ext
.Msg
, {
194 alert: function(title
, message
, fn
, scope
) {
195 if (Ext
.isString(title
)) {
203 minWidth
: this.minWidth
205 return this.show(config
);
209 /*jslint confusion: false */
211 Ext
.define('Ext.ux.IFrame', {
212 extend
: 'Ext.Component',
214 alias
: 'widget.uxiframe',
216 loadMask
: 'Loading...',
221 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
223 childEls
: ['iframeEl'],
225 initComponent: function () {
228 this.frameName
= this.frameName
|| this.id
+ '-frame';
231 initEvents : function() {
234 me
.iframeEl
.on('load', me
.onLoad
, me
);
237 initRenderData: function() {
238 return Ext
.apply(this.callParent(), {
240 frameName
: this.frameName
244 getBody: function() {
245 var doc
= this.getDoc();
246 return doc
.body
|| doc
.documentElement
;
251 return this.getWin().document
;
261 ? me
.iframeEl
.dom
.contentWindow
262 : window
.frames
[name
];
266 getFrame: function() {
268 return me
.iframeEl
.dom
;
271 beforeDestroy: function () {
272 this.cleanupListeners(true);
276 cleanupListeners: function(destroying
){
283 /*jslint nomen: true*/
284 Ext
.get(doc
).un(this._docListeners
);
285 /*jslint nomen: false*/
286 if (destroying
&& doc
.hasOwnProperty
) {
288 if (doc
.hasOwnProperty(prop
)) {
301 fn
= me
.onRelayedEvent
;
305 // These events need to be relayed from the inner document (where they stop
306 // bubbling) up to the outer document. This has to be done at the DOM level so
307 // the event reaches listeners on elements like the document body. The effected
308 // mechanisms that depend on this bubbling behavior are listed to the right
310 /*jslint nomen: true*/
313 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
314 mousemove
: fn
, // window resize drag detection
315 mouseup
: fn
, // window resize termination
316 click
: fn
, // not sure, but just to be safe
317 dblclick
: fn
, // not sure again
321 /*jslint nomen: false*/
323 // cannot do this xss
326 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
327 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
330 this.fireEvent('load', this);
335 this.fireEvent('error', this);
341 onRelayedEvent: function (event
) {
342 // relay event from the iframe's document to the document that owns the iframe...
344 var iframeEl
= this.iframeEl
,
346 // Get the left-based iframe position
347 iframeXY
= iframeEl
.getTrueXY(),
348 originalEventXY
= event
.getXY(),
350 // Get the left-based XY position.
351 // This is because the consumer of the injected event will
352 // perform its own RTL normalization.
353 eventXY
= event
.getTrueXY();
355 // the event from the inner document has XY relative to that document's origin,
356 // so adjust it to use the origin of the iframe in the outer document:
357 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
359 event
.injectEvent(iframeEl
); // blame the iframe for the event...
361 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
364 load: function (src
) {
367 frame
= me
.getFrame();
369 if (me
.fireEvent('beforeload', me
, src
) !== false) {
374 frame
.src
= me
.src
= (src
|| me
.src
);