[Kimchi-devel] [PATCH] Issue #363: Fix data/information consistence in edit template window

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Tue Apr 8 15:24:54 UTC 2014


This patch changes edit template window to fix consistence:
- Show storagepool + volume name correctly in storagepool field after
  saving
- Show disk size according to storagepool or storagepool/volume selected
- Block disk size input box when disk is type volume (iscsi/scsi volumes
  cannot be changed)

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.template_edit_main.js | 35 ++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js
index 386095b..db9a984 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -30,6 +30,11 @@ kimchi.template_edit_main = function() {
         }
         var disks = template.disks;
         $('input[name="disks"]').val(disks[0].size);
+        if (disks[0].volume) {
+            var spool_value = $('#form-template-edit [name="storagepool"]').val();
+            $('input[name="storagepool"]', templateEditForm).val(spool_value + '/' + disks[0].volume);
+            $('input[name="disks"]', templateEditForm).attr('disabled','disabled');
+        }
 
         var options = [{label: 'VNC', value: 'vnc'}];
         kimchi.getCapabilities(function(result) {
@@ -37,7 +42,7 @@ kimchi.template_edit_main = function() {
                 options.push({label: 'Spice', value: 'spice'})
             }
         }, function() {
-        }, function(){
+        }, function() {
             kimchi.select('template-edit-graphics-list', options);
         });
 
@@ -101,6 +106,31 @@ kimchi.template_edit_main = function() {
         kimchi.window.close();
     });
 
+    $('input[name="storagepool"]', templateEditForm).change(function() {
+        var storagepool = $('#form-template-edit [name="storagepool"]').val();
+        var storageArray = storagepool.split("/");
+        if (storageArray.length > 3) {
+            volumeName = storageArray.pop();
+            storageName = storageArray.pop();
+            kimchi.listStorageVolumes(storageName, function(result) {
+                $.each(result, function(index, storageVolume) {
+                    if (storageVolume.name == volumeName) {
+                        $('input[name="disks"]', templateEditForm).val(storageVolume.allocation / Math.pow(1024,3));
+                        $('input[name="disks"]', templateEditForm).attr('disabled','disabled');
+                        return false;
+                    }
+                });
+            });
+        } else if (origDisks[0].volume) {
+            // Set default value when original disk was a volume
+            $('input[name="disks"]', templateEditForm).val(10);
+            $('input[name="disks"]', templateEditForm).removeAttr('disabled');
+        } else {
+            $('input[name="disks"]', templateEditForm).val(origDisks[0].size);
+            $('input[name="disks"]', templateEditForm).removeAttr('disabled');
+        }
+    });
+
     $('#tmpl-edit-button-save').on('click', function() {
         var editableFields = [ 'name', 'cpus', 'memory', 'storagepool', 'disks', 'graphics'];
         var data = {};
@@ -124,9 +154,10 @@ kimchi.template_edit_main = function() {
         storageArray = storagepool.split("/");
         if (storageArray.length > 3){
             /* Support only 1 disk at this moment */
-            delete data["disks"][0].size;
             data["disks"][0].volume = storageArray.pop();
             data['storagepool'] = storageArray.join("/");
+        } else if (data["disks"][0].volume) {
+            delete data["disks"][0].volume;
         }
         var networks = templateEditForm.serializeObject().networks;
         if (networks instanceof Array) {
-- 
1.8.5.3




More information about the Kimchi-devel mailing list