]>
git.proxmox.com Git - proxmox-backup.git/blob - www/Utils.js
8841b0cb207a5ee13c4f11ccc68df6e61a8667bc
4 console
.log("Starting Backup Server GUI");
6 Ext
.define('PBS.Utils', {
10 API3Request: function(reqOpts
) {
12 var newopts
= Ext
.apply({
13 waitMsg
: gettext('Please wait...')
16 if (!newopts
.url
.match(/^\/api3/)) {
17 newopts
.url
= '/api3/extjs' + newopts
.url
;
19 delete newopts
.callback
;
21 var createWrapper = function(successFn
, callbackFn
, failureFn
) {
23 success: function(response
, options
) {
24 if (options
.waitMsgTarget
) {
25 if (Proxmox
.Utils
.toolkit
=== 'touch') {
26 options
.waitMsgTarget
.setMasked(false);
28 options
.waitMsgTarget
.setLoading(false);
31 var result
= Ext
.decode(response
.responseText
);
32 response
.result
= result
;
33 if (!result
.success
) {
34 response
.htmlStatus
= Proxmox
.Utils
.extractRequestError(result
, true);
35 Ext
.callback(callbackFn
, options
.scope
, [options
, false, response
]);
36 Ext
.callback(failureFn
, options
.scope
, [response
, options
]);
39 Ext
.callback(callbackFn
, options
.scope
, [options
, true, response
]);
40 Ext
.callback(successFn
, options
.scope
, [response
, options
]);
42 failure: function(response
, options
) {
43 if (options
.waitMsgTarget
) {
44 if (Proxmox
.Utils
.toolkit
=== 'touch') {
45 options
.waitMsgTarget
.setMasked(false);
47 options
.waitMsgTarget
.setLoading(false);
52 response
.result
= Ext
.decode(response
.responseText
);
54 var msg
= gettext('Connection error') + ' - server offline?';
55 if (response
.aborted
) {
56 msg
= gettext('Connection error') + ' - aborted.';
57 } else if (response
.timedout
) {
58 msg
= gettext('Connection error') + ' - Timeout.';
59 } else if (response
.status
&& response
.statusText
) {
60 msg
= gettext('Connection error') + ' ' + response
.status
+ ': ' + response
.statusText
;
62 response
.htmlStatus
= msg
;
63 Ext
.callback(callbackFn
, options
.scope
, [options
, false, response
]);
64 Ext
.callback(failureFn
, options
.scope
, [response
, options
]);
69 createWrapper(reqOpts
.success
, reqOpts
.callback
, reqOpts
.failure
);
71 var target
= newopts
.waitMsgTarget
;
73 if (Proxmox
.Utils
.toolkit
=== 'touch') {
74 target
.setMasked({ xtype
: 'loadmask', message
: newopts
.waitMsg
} );
76 // Note: ExtJS bug - this does not work when component is not rendered
77 target
.setLoading(newopts
.waitMsg
);
80 Ext
.Ajax
.request(newopts
);
83 constructor: function() {
86 // do whatever you want here