]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - Toolkit.js
1 // ExtJS related things
3 // do not send '_dc' parameter
4 Ext
.Ajax
.disableCaching
= false;
7 Ext
.apply(Ext
.form
.field
.VTypes
, {
8 IPAddress: function(v
) {
9 return Proxmox
.Utils
.IP4_match
.test(v
);
11 IPAddressText
: gettext('Example') + ': 192.168.1.1',
12 IPAddressMask
: /[\d\.]/i,
14 IPCIDRAddress: function(v
) {
15 var result
= Proxmox
.Utils
.IP4_cidr_match
.exec(v
);
16 // limits according to JSON Schema see
17 // pve-common/src/PVE/JSONSchema.pm
18 return (result
!== null && result
[1] >= 8 && result
[1] <= 32);
20 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
21 IPCIDRAddressMask
: /[\d\.\/]/i,
23 IP6Address: function(v
) {
24 return Proxmox
.Utils
.IP6_match
.test(v
);
26 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
27 IP6AddressMask
: /[A-Fa-f0-9:]/,
29 IP6CIDRAddress: function(v
) {
30 var result
= Proxmox
.Utils
.IP6_cidr_match
.exec(v
);
31 // limits according to JSON Schema see
32 // pve-common/src/PVE/JSONSchema.pm
33 return (result
!== null && result
[1] >= 8 && result
[1] <= 120);
35 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
36 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
38 IP6PrefixLength: function(v
) {
39 return v
>= 0 && v
<= 128;
41 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
42 IP6PrefixLengthMask
: /[0-9]/,
44 IP64Address: function(v
) {
45 return Proxmox
.Utils
.IP64_match
.test(v
);
47 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
48 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
50 MacAddress: function(v
) {
51 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
53 MacAddressMask
: /[a-fA-F0-9:]/,
54 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
56 BridgeName: function(v
) {
57 return (/^vmbr\d{1,4}$/).test(v
);
59 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
61 BondName: function(v
) {
62 return (/^bond\d{1,4}$/).test(v
);
64 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
66 InterfaceName: function(v
) {
67 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
69 InterfaceNameText
: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" +
70 gettext("Minimum characters") + ": 2" + "<br />" +
71 gettext("Maximum characters") + ": 21" + "<br />" +
72 gettext("Must start with") + ": 'a-z'",
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', '-', '_', '.'" + "<br />" +
83 gettext("Minimum characters") + ": 2" + "<br />" +
84 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
85 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
87 ConfigId: function(v
) {
88 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
90 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" +
91 gettext("Minimum characters") + ": 2" + "<br />" +
92 gettext("Must start with") + ": " + gettext("letter"),
94 HttpProxy: function(v
) {
95 return (/^http:\/\/.*$/).test(v
);
97 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
99 DnsName: function(v
) {
100 return Proxmox
.Utils
.DnsName_match
.test(v
);
102 DnsNameText
: gettext('This is not a valid DNS name'),
104 // workaround for https://www.sencha.com/forum/showthread.php?302150
105 proxmoxMail: function(v
) {
106 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
108 proxmoxMailText
: gettext('Example') + ": user@example.com",
110 HostList: function(v
) {
111 var list
= v
.split(/[\ \,\;]+/);
113 for (i
= 0; i
< list
.length
; i
++) {
118 if (!Proxmox
.Utils
.HostPort_match
.test(list
[i
]) &&
119 !Proxmox
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
120 !Proxmox
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
127 HostListText
: gettext('Not a valid list of hosts')
130 // ExtJs 5-6 has an issue with caching
131 // see https://www.sencha.com/forum/showthread.php?308989
132 Ext
.define('Proxmox.UnderlayPool', {
133 override
: 'Ext.dom.UnderlayPool',
135 checkOut: function () {
136 var cache
= this.cache
,
140 // do cleanup because some of the objects might have been destroyed
142 if (cache
[len
].destroyed
) {
143 cache
.splice(len
, 1);
151 el
= Ext
.Element
.create(this.elementConfig
);
152 el
.setVisibilityMode(2);
154 // tell the spec runner to ignore this element when checking if the dom is clean
155 el
.dom
.setAttribute('data-sticky', true);
163 // if the order of the values are not the same in originalValue and value
164 // extjs will not overwrite value, but marks the field dirty and thus
165 // the reset button will be enabled (but clicking it changes nothing)
166 // so if the arrays are not the same after resetting, we
168 Ext
.define('Proxmox.form.ComboBox', {
169 override
: 'Ext.form.field.ComboBox',
172 // copied from combobox
177 // clear and set when not the same
178 var value
= me
.getValue();
179 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
181 me
.setValue(me
.originalValue
);
186 // should be fixed with ExtJS 6.0.2, see:
187 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
188 Ext
.define('Proxmox.Datepicker', {
189 override
: 'Ext.picker.Date',
190 hideMode
: 'visibility'
193 // force alert boxes to be rendered with an Error Icon
194 // since Ext.Msg is an object and not a prototype, we need to override it
195 // after the framework has been initiated
196 Ext
.onReady(function() {
197 /*jslint confusion: true */
198 Ext
.override(Ext
.Msg
, {
199 alert: function(title
, message
, fn
, scope
) {
200 if (Ext
.isString(title
)) {
208 minWidth
: this.minWidth
210 return this.show(config
);
214 /*jslint confusion: false */
216 Ext
.define('Ext.ux.IFrame', {
217 extend
: 'Ext.Component',
219 alias
: 'widget.uxiframe',
221 loadMask
: 'Loading...',
226 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
228 childEls
: ['iframeEl'],
230 initComponent: function () {
233 this.frameName
= this.frameName
|| this.id
+ '-frame';
236 initEvents : function() {
239 me
.iframeEl
.on('load', me
.onLoad
, me
);
242 initRenderData: function() {
243 return Ext
.apply(this.callParent(), {
245 frameName
: this.frameName
249 getBody: function() {
250 var doc
= this.getDoc();
251 return doc
.body
|| doc
.documentElement
;
256 return this.getWin().document
;
266 ? me
.iframeEl
.dom
.contentWindow
267 : window
.frames
[name
];
271 getFrame: function() {
273 return me
.iframeEl
.dom
;
276 beforeDestroy: function () {
277 this.cleanupListeners(true);
281 cleanupListeners: function(destroying
){
288 /*jslint nomen: true*/
289 Ext
.get(doc
).un(this._docListeners
);
290 /*jslint nomen: false*/
291 if (destroying
&& doc
.hasOwnProperty
) {
293 if (doc
.hasOwnProperty(prop
)) {
306 fn
= me
.onRelayedEvent
;
310 // These events need to be relayed from the inner document (where they stop
311 // bubbling) up to the outer document. This has to be done at the DOM level so
312 // the event reaches listeners on elements like the document body. The effected
313 // mechanisms that depend on this bubbling behavior are listed to the right
315 /*jslint nomen: true*/
318 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
319 mousemove
: fn
, // window resize drag detection
320 mouseup
: fn
, // window resize termination
321 click
: fn
, // not sure, but just to be safe
322 dblclick
: fn
, // not sure again
326 /*jslint nomen: false*/
328 // cannot do this xss
331 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
332 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
335 this.fireEvent('load', this);
340 this.fireEvent('error', this);
346 onRelayedEvent: function (event
) {
347 // relay event from the iframe's document to the document that owns the iframe...
349 var iframeEl
= this.iframeEl
,
351 // Get the left-based iframe position
352 iframeXY
= iframeEl
.getTrueXY(),
353 originalEventXY
= event
.getXY(),
355 // Get the left-based XY position.
356 // This is because the consumer of the injected event will
357 // perform its own RTL normalization.
358 eventXY
= event
.getTrueXY();
360 // the event from the inner document has XY relative to that document's origin,
361 // so adjust it to use the origin of the iframe in the outer document:
362 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
364 event
.injectEvent(iframeEl
); // blame the iframe for the event...
366 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
369 load: function (src
) {
372 frame
= me
.getFrame();
374 if (me
.fireEvent('beforeload', me
, src
) !== false) {
379 frame
.src
= me
.src
= (src
|| me
.src
);