[pve-devel] r6319 - in pve-manager/pve2: . www/manager www/manager/window
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue Jul 19 06:52:40 CEST 2011
Author: dietmar
Date: 2011-07-19 06:52:40 +0200 (Tue, 19 Jul 2011)
New Revision: 6319
Modified:
pve-manager/pve2/ChangeLog
pve-manager/pve2/www/manager/Utils.js
pve-manager/pve2/www/manager/window/Edit.js
Log:
* www/manager/Utils.js (API2Request): use createWrapper function to
avoid js scope problem.
* www/manager/window/Edit.js (load): use createWrapper function to
avoid js scope problem.
Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog 2011-07-19 04:20:59 UTC (rev 6318)
+++ pve-manager/pve2/ChangeLog 2011-07-19 04:52:40 UTC (rev 6319)
@@ -1,3 +1,11 @@
+2011-07-19 Proxmox Support Team <support at proxmox.com>
+
+ * www/manager/Utils.js (API2Request): use createWrapper function to
+ avoid js scope problem.
+
+ * www/manager/window/Edit.js (load): use createWrapper function to
+ avoid js scope problem.
+
2011-07-18 Proxmox Support Team <support at proxmox.com>
* www/manager/qemu/BootOrderEdit.js: impl.
Modified: pve-manager/pve2/www/manager/Utils.js
===================================================================
--- pve-manager/pve2/www/manager/Utils.js 2011-07-19 04:20:59 UTC (rev 6318)
+++ pve-manager/pve2/www/manager/Utils.js 2011-07-19 04:52:40 UTC (rev 6319)
@@ -242,40 +242,44 @@
},
// Ext.Ajax.request
- API2Request: function(options) {
- var callbackFn = options.callback;
- var successFn = options.success;
- var failureFn = options.failure;
+ API2Request: function(reqOpts) {
- if (!options.url.match(/^\/api2/)) {
- options.url = '/api2/extjs' + options.url;
+ var newopts = Ext.apply({}, reqOpts);
+
+ if (!newopts.url.match(/^\/api2/)) {
+ newopts.url = '/api2/extjs' + newopts.url;
}
- delete options.callback;
+ delete newopts.callback;
- options.success = function(response, options) {
- var result = Ext.decode(response.responseText);
- response.result = result;
- if (!result.success) {
- response.htmlStatus = PVE.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]);
+ var createWrapper = function(successFn, callbackFn, failureFn) {
+ Ext.apply(newopts, {
+ success: function(response, options) {
+ var result = Ext.decode(response.responseText);
+ response.result = result;
+ if (!result.success) {
+ response.htmlStatus = PVE.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) {
+ var msg = "Connection error - server offline?";
+ if (response.status && response.statusText) {
+ msg = "Connection error " + response.status + ": " + response.statusText;
+ }
+ response.htmlStatus = msg;
+ Ext.callback(callbackFn, options.scope, [options, false, response]);
+ Ext.callback(failureFn, options.scope, [response, options]);
+ }
+ });
};
- options.failure = function(response, options) {
- var msg = "Connection error - server offline?";
- if (response.status && response.statusText) {
- msg = "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);
- Ext.Ajax.request(options);
+ Ext.Ajax.request(newopts);
},
assemble_field_data: function(values, data) {
Modified: pve-manager/pve2/www/manager/window/Edit.js
===================================================================
--- pve-manager/pve2/www/manager/window/Edit.js 2011-07-19 04:20:59 UTC (rev 6318)
+++ pve-manager/pve2/www/manager/window/Edit.js 2011-07-19 04:52:40 UTC (rev 6319)
@@ -82,30 +82,34 @@
options = options || {};
- var orgSuccessFn = options.success;
+ var newopts = Ext.apply({}, options);
- var newopts = Ext.apply({}, options, {
- url: me.url,
- method: 'GET',
- success: function(response, opts) {
- form.clearInvalid();
- if (orgSuccessFn) {
- orgSuccessFn(response, opts);
- } else {
- me.setValues(response.result.data);
+ var createWrapper = function(successFn) {
+ Ext.apply(newopts, {
+ url: me.url,
+ method: 'GET',
+ success: function(response, opts) {
+ form.clearInvalid();
+ if (successFn) {
+ successFn(response, opts);
+ } else {
+ me.setValues(response.result.data);
+ }
+ // hack: fix ExtJS bug
+ Ext.Array.each(me.query('radiofield'), function(f) {
+ f.resetOriginalValue();
+ });
+ },
+ failure: function(response, opts) {
+ Ext.Msg.alert('Error', response.htmlStatus, function() {
+ me.close();
+ });
}
- // hack: fix ExtJS bug
- Ext.Array.each(me.query('radiofield'), function(f) {
- f.resetOriginalValue();
- });
- },
- failure: function(response, opts) {
- Ext.Msg.alert('Error', response.htmlStatus, function() {
- me.close();
- });
- }
- });
+ });
+ };
+ createWrapper(options.success);
+
PVE.Utils.API2Request(newopts);
},
More information about the pve-devel
mailing list