]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
rename manager5 to manager6
[pve-manager.git] / www / manager6 / Toolkit.js
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]/,
39
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 },
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', '_'",
82
83 HttpProxy: function(v) {
84 return (/^http:\/\/.*$/).test(v);
85 },
86 HttpProxyText: gettext('Example') + ": http://username:password&#64;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 },
91 DnsNameText: gettext('This is not a valid DNS name')
92 });
93
94 // we dont want that a displayfield set the form dirty flag!
95 Ext.override(Ext.form.field.Display, {
96 isDirty: function() { return false; }
97 });
98
99 // hack: ExtJS does not display the correct value if we
100 // call setValue while the store is loading, so we need
101 // to call it again after loading
102 Ext.override(Ext.form.field.ComboBox, {
103 onLoad: function() {
104 this.setValue(this.value, false);
105 this.callOverridden(arguments);
106 }
107 });
108
109 Ext.define('Ext.ux.IFrame', {
110 extend: 'Ext.Component',
111
112 alias: 'widget.uxiframe',
113
114 loadMask: 'Loading...',
115
116 src: 'about:blank',
117
118 renderTpl: [
119 '<iframe src="{src}" name="{frameName}" width="100%" height="100%" frameborder="0"></iframe>'
120 ],
121
122 initComponent: function () {
123 this.callParent();
124
125 this.frameName = this.frameName || this.id + '-frame';
126
127 this.addEvents(
128 'beforeload',
129 'load'
130 );
131
132 Ext.apply(this.renderSelectors, {
133 iframeEl: 'iframe'
134 });
135 },
136
137 initEvents : function() {
138 var me = this;
139 me.callParent();
140 me.iframeEl.on('load', me.onLoad, me);
141 },
142
143 initRenderData: function() {
144 return Ext.apply(this.callParent(), {
145 src: this.src,
146 frameName: this.frameName
147 });
148 },
149
150 getBody: function() {
151 var doc = this.getDoc();
152 return doc.body || doc.documentElement;
153 },
154
155 getDoc: function() {
156 try {
157 return this.getWin().document;
158 } catch (ex) {
159 return null;
160 }
161 },
162
163 getWin: function() {
164 var me = this,
165 name = me.frameName,
166 win = Ext.isIE
167 ? me.iframeEl.dom.contentWindow
168 : window.frames[name];
169 return win;
170 },
171
172 getFrame: function() {
173 var me = this;
174 return me.iframeEl.dom;
175 },
176
177 beforeDestroy: function () {
178 this.cleanupListeners(true);
179 this.callParent();
180 },
181
182 cleanupListeners: function(destroying){
183 var doc, prop;
184
185 if (this.rendered) {
186 try {
187 doc = this.getDoc();
188 if (doc) {
189 Ext.EventManager.removeAll(doc);
190 if (destroying) {
191 for (prop in doc) {
192 if (doc.hasOwnProperty && doc.hasOwnProperty(prop)) {
193 delete doc[prop];
194 }
195 }
196 }
197 }
198 } catch(e) { }
199 }
200 },
201
202 onLoad: function() {
203 var me = this,
204 doc = me.getDoc(),
205 fn = me.onRelayedEvent;
206
207 if (doc) {
208 try {
209 Ext.EventManager.removeAll(doc);
210
211 // These events need to be relayed from the inner document (where they stop
212 // bubbling) up to the outer document. This has to be done at the DOM level so
213 // the event reaches listeners on elements like the document body. The effected
214 // mechanisms that depend on this bubbling behavior are listed to the right
215 // of the event.
216 Ext.EventManager.on(doc, {
217 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
218 mousemove: fn, // window resize drag detection
219 mouseup: fn, // window resize termination
220 click: fn, // not sure, but just to be safe
221 dblclick: fn, // not sure again
222 scope: me
223 });
224 } catch(e) {
225 // cannot do this xss
226 }
227
228 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
229 Ext.EventManager.on(this.getWin(), 'beforeunload', me.cleanupListeners, me);
230
231 this.el.unmask();
232 this.fireEvent('load', this);
233
234 } else if(me.src && me.src != '') {
235
236 this.el.unmask();
237 this.fireEvent('error', this);
238 }
239
240
241 },
242
243 load: function (src) {
244 var me = this,
245 text = me.loadMask,
246 frame = me.getFrame();
247
248 if (me.fireEvent('beforeload', me, src) !== false) {
249 if (text && me.el) {
250 me.el.mask(text);
251 }
252
253 frame.src = me.src = (src || me.src);
254 }
255 }
256 });