[Kimchi-devel] [PATCH v2] [Kimchi] Fixed "Add a Storage Device to VM" modal behavior

Socorro Stoppler socorro at linux.vnet.ibm.com
Mon Mar 14 21:27:55 UTC 2016


From: Samuel Guimarães <sguimaraes943 at gmail.com>

v2:
Change default to qcow2 format


Signed-off-by: Socorro Stoppler <socorro at linux.vnet.ibm.com>
Signed-off-by: Samuel Guimarães <sguimaraes943 at gmail.com>
---
 ui/js/src/kimchi.guest_storage_add.main.js | 41 ++++++++++++++++--------------
 ui/pages/guest-storage-add.html.tmpl       |  2 +-
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/ui/js/src/kimchi.guest_storage_add.main.js b/ui/js/src/kimchi.guest_storage_add.main.js
index 3f416e7..fb7fed3 100644
--- a/ui/js/src/kimchi.guest_storage_add.main.js
+++ b/ui/js/src/kimchi.guest_storage_add.main.js
@@ -83,12 +83,13 @@ kimchi.guest_storage_add_main = function() {
         }
         formatTextbox.empty();
         formatTextbox.append(selectFormatHTML);
-        $(formatTextbox).change();
+        formatTextbox.val("qcow2");
+        $(formatTextbox).trigger('change');
         formatTextbox.selectpicker();
         $('.selectpicker').selectpicker('refresh');
     };
 
-    typeTextbox.change(function() {
+    typeTextbox.on('change',function() {
         var pathObject = {'cdrom': ".path-section", 'disk': '.volume-section'};
         selectType = $(this).val();
         $.each(pathObject, function(type, value) {
@@ -105,13 +106,13 @@ kimchi.guest_storage_add_main = function() {
             if ($('#new-disk').checked) {
                 $('#existing-disk-box').addClass('hidden');
                 $(newPoolTextbox).val('default');
-                $(newPoolTextbox).change();
+                $(newPoolTextbox).trigger('change');
                 $(formatTextbox).val('qcow2');
-                $(formatTextbox).change();
+                $(formatTextbox).trigger('change');
             } else if ($('#existing-disk').checked) {
                 $('#new-disk-box').addClass('hidden');
                 $(poolTextbox).val('default');
-                $(poolTextbox).change();
+                $(poolTextbox).trigger('change');
             } else {
                 //Goes here the first time since radiobuttons are undefined
                 if (rbExisting === 'true') {
@@ -119,7 +120,7 @@ kimchi.guest_storage_add_main = function() {
                 } else {
                     $('#existing-disk-box').addClass('hidden');
                     $(formatTextbox).val('qcow2');
-                    $(formatTextbox).change();
+                    $(formatTextbox).trigger('change');
                 }
             }
         } else {
@@ -159,13 +160,13 @@ kimchi.guest_storage_add_main = function() {
                 if (radioButton === 'existing') {
                     poolTextbox.empty();
                     poolTextbox.append(selectStoragePoolHTML);
-                    $(poolTextbox).change();
+                    $(poolTextbox).trigger('change');
 	            poolTextbox.selectpicker();
                     $('.selectpicker').selectpicker('refresh');
                 } else if (radioButton === 'new') { //new disk
                     newPoolTextbox.empty();
                     newPoolTextbox.append(selectStoragePoolHTML);
-                    $(newPoolTextbox).val("qcow2");
+                    $(newPoolTextbox).val("ISO");
                     newPoolTextbox.selectpicker();
                     getFormatList();
                 }
@@ -176,7 +177,7 @@ kimchi.guest_storage_add_main = function() {
     //First time retrieving list of Storage Pools - defaulting to new disk
     getStoragePools('new');
 
-    poolTextbox.change(function() {
+    poolTextbox.on('change',function() {
         var options = [];
         selectStorageVolHTML = '';
         volTextbox.empty();
@@ -198,7 +199,7 @@ kimchi.guest_storage_add_main = function() {
                     }
                     volTextbox.append(selectStorageVolHTML);
                     $(volTextbox).val(options[0].value);
-                    $(volTextbox).change();
+                    $(volTextbox).trigger('change');
                     $(volTextbox).prop('disabled',false);
                 }else {
                     $(volTextbox).prop('disabled',true);
@@ -213,7 +214,7 @@ kimchi.guest_storage_add_main = function() {
         }, null, false);
     });
 
-    typeTextbox.change(function() {
+    typeTextbox.on('change',function() {
         var pathObject = {'cdrom': ".path-section", 'disk': '.volume-section'};
         var selectType = $(this).val();
         $.each(pathObject, function(type, value) {
@@ -226,7 +227,7 @@ kimchi.guest_storage_add_main = function() {
     });
 
     var currentPage = 'new-disk-box';
-    $('#existing-disk').change(function() {
+    $('#existing-disk').on('change',function() {
         if (this.checked) {
             rbExisting = 'true';
             if (currentPage === 'new-disk-box') {
@@ -246,10 +247,10 @@ kimchi.guest_storage_add_main = function() {
         }
     });
 
-    $('#new-disk').change(function() {
+    $('#new-disk').on('change',function() {
         if (this.checked) {
             $(formatTextbox).val("qcow2");
-            $(formatTextbox).change();
+            $(formatTextbox).trigger('change');
             rbExisting = 'false';
             if (currentPage === 'existing-disk-box') {
                 kimchi.switchPage(currentPage, 'new-disk-box', 'right');
@@ -268,19 +269,21 @@ kimchi.guest_storage_add_main = function() {
         }
     });
 
+    var selectType = $(typeTextbox).val();
     if (kimchi.thisVMState === 'running') {
-        types =typesRunning;
-        $(typeTextbox).val('disk');
-        typeTextbox.change();
-        poolTextbox.change();
+        types = typesRunning;
     }
-    var selectType = $(typeTextbox).val();
     for (var i = 0; i < types.length; i++) {
         selectStorageTypeHTML += '<option value="'+ types[i].value + '">' + types[i].label + '</option>';
     }
     typeTextbox.append(selectStorageTypeHTML);
     typeTextbox.find('option:first').attr('selected','selected');
     typeTextbox.selectpicker();
+    if (kimchi.thisVMState === 'running') {
+        $(typeTextbox).val('disk');
+        typeTextbox.trigger('change');
+        poolTextbox.trigger('change');
+    }
 
     var validateCDROM = function(settings) {
         if (/^((https|http|ftp|ftps|tftp|\/).*)+$/.test(settings['path'])){
diff --git a/ui/pages/guest-storage-add.html.tmpl b/ui/pages/guest-storage-add.html.tmpl
index 18da825..afc72c8 100644
--- a/ui/pages/guest-storage-add.html.tmpl
+++ b/ui/pages/guest-storage-add.html.tmpl
@@ -39,7 +39,7 @@
                     <label>$_("Device Type")</label>
                     <select id="guest-storage-type" class="selectpicker col-md-12 col-lg-12">
                     </select>
-                    <p class="help-block"><i class="fa fa-info-circle"></i> $_("The device type. Currently, \"cdrom\" and \"disk\" are supported.")</p>
+                    <p class="help-block"><i class="fa fa-info-circle"></i> $_("The device type. Currently, \"cdrom\" and \"disk\" are supported. If the guest is running, only \"disk\" is supported.")</p>
                 </div>
                 <div class="volume-section hidden form-group">
                     <div class="template-modal-container">
-- 
1.9.1




More information about the Kimchi-devel mailing list