Utils.js: add code to make api3 request
This commit is contained in:
parent
083418619e
commit
03862a2eeb
@ -1,4 +1,5 @@
|
||||
JSSRC= \
|
||||
Utils.js \
|
||||
Logo.js \
|
||||
VersionInfo.js \
|
||||
Application.js \
|
||||
|
88
www/Utils.js
Normal file
88
www/Utils.js
Normal file
@ -0,0 +1,88 @@
|
||||
/*global Proxmox */
|
||||
Ext.ns('PBS');
|
||||
|
||||
console.log("Starting Backup Server GUI");
|
||||
|
||||
Ext.define('PBS.Utils', {
|
||||
singleton: true,
|
||||
|
||||
// Ext.Ajax.request
|
||||
API3Request: function(reqOpts) {
|
||||
|
||||
var newopts = Ext.apply({
|
||||
waitMsg: gettext('Please wait...')
|
||||
}, reqOpts);
|
||||
|
||||
if (!newopts.url.match(/^\/api3/)) {
|
||||
newopts.url = '/api3/extjs' + newopts.url;
|
||||
}
|
||||
delete newopts.callback;
|
||||
|
||||
var createWrapper = function(successFn, callbackFn, failureFn) {
|
||||
Ext.apply(newopts, {
|
||||
success: function(response, options) {
|
||||
if (options.waitMsgTarget) {
|
||||
if (Proxmox.Utils.toolkit === 'touch') {
|
||||
options.waitMsgTarget.setMasked(false);
|
||||
} else {
|
||||
options.waitMsgTarget.setLoading(false);
|
||||
}
|
||||
}
|
||||
var result = Ext.decode(response.responseText);
|
||||
response.result = result;
|
||||
if (!result.success) {
|
||||
response.htmlStatus = Proxmox.Utils.extractRequestError(result, true);
|
||||
Ext.callback(callbackFn, options.scope, [options, false, response]);
|
||||
Ext.callback(failureFn, options.scope, [response, options]);
|
||||
return;
|
||||
}
|
||||
Ext.callback(callbackFn, options.scope, [options, true, response]);
|
||||
Ext.callback(successFn, options.scope, [response, options]);
|
||||
},
|
||||
failure: function(response, options) {
|
||||
if (options.waitMsgTarget) {
|
||||
if (Proxmox.Utils.toolkit === 'touch') {
|
||||
options.waitMsgTarget.setMasked(false);
|
||||
} else {
|
||||
options.waitMsgTarget.setLoading(false);
|
||||
}
|
||||
}
|
||||
response.result = {};
|
||||
try {
|
||||
response.result = Ext.decode(response.responseText);
|
||||
} catch(e) {}
|
||||
var msg = gettext('Connection error') + ' - server offline?';
|
||||
if (response.aborted) {
|
||||
msg = gettext('Connection error') + ' - aborted.';
|
||||
} else if (response.timedout) {
|
||||
msg = gettext('Connection error') + ' - Timeout.';
|
||||
} else if (response.status && response.statusText) {
|
||||
msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText;
|
||||
}
|
||||
response.htmlStatus = msg;
|
||||
Ext.callback(callbackFn, options.scope, [options, false, response]);
|
||||
Ext.callback(failureFn, options.scope, [response, options]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure);
|
||||
|
||||
var target = newopts.waitMsgTarget;
|
||||
if (target) {
|
||||
if (Proxmox.Utils.toolkit === 'touch') {
|
||||
target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} );
|
||||
} else {
|
||||
// Note: ExtJS bug - this does not work when component is not rendered
|
||||
target.setLoading(newopts.waitMsg);
|
||||
}
|
||||
}
|
||||
Ext.Ajax.request(newopts);
|
||||
},
|
||||
|
||||
constructor: function() {
|
||||
var me = this;
|
||||
|
||||
// do whatever you want here
|
||||
}
|
||||
});
|
@ -21,7 +21,7 @@ Ext.define('PBS.view.main.VersionInfo',{
|
||||
me.callParent();
|
||||
|
||||
if (me.makeApiCall) {
|
||||
Proxmox.Utils.API2Request({
|
||||
PBS.Utils.API3Request({
|
||||
url: '/version',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
|
Loading…
Reference in New Issue
Block a user