[pve-devel] [PATCH manager] extjs: add parseBoolean for drive backup and iothreads

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jan 29 10:26:23 CET 2016


The backup and iothread options are now boolean types
internally instead of strings and need to be treated as
such.

Added a parseBoolean() function to deal with this with an
optional default value to use for undefined values.

The default for an undefined backup value is true.
---
 www/manager/Parser.js      | 10 ++++++++++
 www/manager/qemu/HDEdit.js |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/www/manager/Parser.js b/www/manager/Parser.js
index 90c98c7..5a5e47f 100644
--- a/www/manager/Parser.js
+++ b/www/manager/Parser.js
@@ -5,6 +5,16 @@ Ext.define('PVE.Parser', { statics: {
 
     // this class only contains static functions
 
+    parseBoolean: function(value, default_value) {
+	if (!Ext.isDefined(value))
+	    return default_value;
+	value = value.toLowerCase();
+	return value === 1 || value === '1' ||
+	       value === 'on' ||
+	       value === 'yes' ||
+	       value === 'true';
+    },
+
     parseQemuNetwork: function(key, value) {
 	if (!(key && value)) {
 	    return;
diff --git a/www/manager/qemu/HDEdit.js b/www/manager/qemu/HDEdit.js
index ffca0b0..a985876 100644
--- a/www/manager/qemu/HDEdit.js
+++ b/www/manager/qemu/HDEdit.js
@@ -90,11 +90,11 @@ Ext.define('PVE.qemu.HDInputPanel', {
 	}
 
 	values.hdimage = drive.file;
-	values.nobackup = (drive.backup === 'no');
+	values.nobackup = !PVE.Parser.parseBoolean(drive.backup, 1);
 	values.diskformat = drive.format || 'raw';
 	values.cache = drive.cache || '';
 	values.discard = (drive.discard === 'on');
-	values.iothread = (drive.iothread === 'on');
+	values.iothread = PVE.Parser.parseBoolean(drive.iothread);
 
 	me.setValues(values);
     },
-- 
2.1.4





More information about the pve-devel mailing list