[pve-devel] [PATCH manager 1/2] add 'delete_if_default' helper and use it
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Nov 2 10:31:19 CET 2016
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
www/manager6/Utils.js | 15 +++++++++++++++
www/manager6/ha/ResourceEdit.js | 21 +++------------------
www/manager6/lxc/ResourceEdit.js | 22 ++++------------------
www/manager6/qemu/CPUOptions.js | 23 ++++-------------------
4 files changed, 26 insertions(+), 55 deletions(-)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 463a546..b32b2d0 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1253,6 +1253,21 @@ Ext.define('PVE.Utils', { utilities: {
menu.showAt(event.getXY());
}},
+ // helper for deleting field which are set to there default values
+ delete_if_default: function(values, fieldname, default_val, create) {
+ if (values[fieldname] === '' || values[fieldname] === default_val) {
+ if (!create) {
+ if (values['delete']) {
+ values['delete'] += ',' + fieldname;
+ } else {
+ values['delete'] = fieldname;
+ }
+ }
+
+ delete values[fieldname];
+ }
+ },
+
singleton: true,
constructor: function() {
var me = this;
diff --git a/www/manager6/ha/ResourceEdit.js b/www/manager6/ha/ResourceEdit.js
index 83db647..4ee08a7 100644
--- a/www/manager6/ha/ResourceEdit.js
+++ b/www/manager6/ha/ResourceEdit.js
@@ -10,12 +10,6 @@ Ext.define('PVE.ha.VMResourceInputPanel', {
values.sid = values.vmid;
}
- if (values.group === '') {
- if (!me.create) {
- values['delete'] = 'group';
- }
- delete values.group;
- }
delete values.vmid;
@@ -26,18 +20,9 @@ Ext.define('PVE.ha.VMResourceInputPanel', {
}
delete values.enable;
- if (values.max_restart == '1') {
- if (!me.create) {
- values['delete'] = values['delete'] ? values['delete'] + ',max_restart' : 'max_restart';
- }
- delete values.max_restart;
- }
- if (values.max_relocate == '1') {
- if (!me.create) {
- values['delete'] = values['delete'] ? values['delete'] + ',max_relocate' : 'max_relocate';
- }
- delete values.max_relocate;
- }
+ PVE.Utils.delete_if_default(values, 'group', '', me.create);
+ PVE.Utils.delete_if_default(values, 'max_restart', '1', me.create);
+ PVE.Utils.delete_if_default(values, 'max_relocate', '1', me.create);
return values;
},
diff --git a/www/manager6/lxc/ResourceEdit.js b/www/manager6/lxc/ResourceEdit.js
index 8511f01..c9cd4aa 100644
--- a/www/manager6/lxc/ResourceEdit.js
+++ b/www/manager6/lxc/ResourceEdit.js
@@ -104,24 +104,10 @@ Ext.define('PVE.lxc.CPUInputPanel', {
onGetValues: function(values) {
var me = this;
- var delete_array = [];
-
- if (values.cores === '') {
- delete_array.push('cores');
- delete values.cores;
- }
- if (values.cpulimit === '' || values.cpulimit == '0') {
- delete_array.push('cpulimit');
- delete values.cpulimit;
- }
- if (values.cpuunits === '' || values.cpuunits == '1024') {
- delete_array.push('cpuunits');
- delete values.cpuunits;
- }
-
- if (delete_array.length) {
- values['delete'] = delete_array.join(',');
- }
+ PVE.Utils.delete_if_default(values, 'cores', '', me.insideWizard);
+ // cpu{limit,unit} aren't in the wizard so create is always false
+ PVE.Utils.delete_if_default(values, 'cpulimit', '0', 0);
+ PVE.Utils.delete_if_default(values, 'cpuunits', '1024', 0);
return values;
},
diff --git a/www/manager6/qemu/CPUOptions.js b/www/manager6/qemu/CPUOptions.js
index ae31987..5ee7afb 100644
--- a/www/manager6/qemu/CPUOptions.js
+++ b/www/manager6/qemu/CPUOptions.js
@@ -5,28 +5,13 @@ Ext.define('PVE.qemu.CPUOptionsInputPanel', {
onGetValues: function(values) {
var me = this;
- var delete_array = [];
-
- if (values.vcpus === '') {
- delete_array.push('vcpus');
- delete values.vcpus;
- }
- if (values.cpulimit === '' || values.cpulimit == '0') {
- delete_array.push('cpulimit');
- delete values.cpulimit;
- }
- if (values.cpuunits === '' || values.cpuunits == '1024') {
- delete_array.push('cpuunits');
- delete values.cpuunits;
- }
+ PVE.Utils.delete_if_default(values, 'vcpus', '', 0);
+ PVE.Utils.delete_if_default(values, 'cpulimit', '0', 0);
+ PVE.Utils.delete_if_default(values, 'cpuunits', '1024', 0);
- if (delete_array.length) {
- values['delete'] = delete_array.join(',');
- }
-
return values;
},
-
+
initComponent : function() {
var me = this;
--
2.1.4
More information about the pve-devel
mailing list