[Kimchi-devel] [PATCH v2] VM Edit: CPU and memory

Adam King rak at linux.vnet.ibm.com
Wed Apr 23 03:35:36 UTC 2014


Update the edit VM form to use the new form extensions.
Enable the cpu and memory fields to be edited.

Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
 ui/css/theme-default/guest-edit.css |  2 +-
 ui/js/src/kimchi.guest_edit_main.js | 18 ++++++++++--------
 ui/pages/guest-edit.html.tmpl       | 14 ++++++--------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/ui/css/theme-default/guest-edit.css b/ui/css/theme-default/guest-edit.css
index 0b7ba21..bf5ae5f 100644
--- a/ui/css/theme-default/guest-edit.css
+++ b/ui/css/theme-default/guest-edit.css
@@ -46,7 +46,7 @@
     line-height: 38px;
     margin-top: 5px;
     vertical-align: top;
-    width: 80px;
+    width: 90px;
 }
 
 #form-guest-edit-storage .guest-edit-wrapper-label {
diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index 9375c51..ded8c07 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -80,9 +80,7 @@ kimchi.guest_edit_main = function() {
 
     var initContent = function(guest) {
         guest['icon'] = guest['icon'] || 'images/icon-vm.png';
-        for ( var prop in guest) {
-            $('input[name="' + prop + '"]', guestEditForm).val(guest[prop]);
-        }
+        $('#form-guest-edit-general').fillWithObject(guest);
 
         refreshCDROMs();
 
@@ -116,16 +114,20 @@ kimchi.guest_edit_main = function() {
 
     var submitForm = function(event) {
         $(saveButton).prop('disabled', true);
-        var editableFields = [ 'name' ];
-        var data = {};
-        $.each(editableFields, function(i, field) {
-            data[field] = $('#form-guest-edit [name="' + field + '"]').val();
-        });
+        var data=$('#form-guest-edit-general').serializeObject();
+        if(data['memory']!=undefined) {
+            data['memory'] = Number(data['memory']);
+        }
+        if(data['cpus']!=undefined) {
+            data['cpus']   = Number(data['cpus']);
+        }
+
         kimchi.updateVM(kimchi.selectedGuest, data, function() {
             kimchi.listVmsAuto();
             kimchi.window.close();
         }, function(err) {
             kimchi.message.error(err.responseJSON.reason);
+            $(saveButton).prop('disabled', false); 
         });
 
         event.preventDefault();
diff --git a/ui/pages/guest-edit.html.tmpl b/ui/pages/guest-edit.html.tmpl
index 804fc39..aae9694 100644
--- a/ui/pages/guest-edit.html.tmpl
+++ b/ui/pages/guest-edit.html.tmpl
@@ -59,21 +59,19 @@
                             <input
                                 id="guest-edit-cores-textbox"
                                 name="cpus"
-                                type="text"
-                                disabled="disabled" />
+                                type="text" />
                         </div>
                     </div>
                     <div>
                         <div class="guest-edit-wrapper-label">
                             <label for="guest-edit-memory-textbox">
-                                $_("Memory")
+                                $_("Memory (MB)")
                             </label>
                         </div>
                         <div class="guest-edit-wrapper-controls">
                             <input id="guest-edit-memory-textbox"
                                 name="memory"
-                                type="text"
-                                disabled="disabled" />
+                                type="text" />
                         </div>
                     </div>
                     <div>
@@ -98,7 +96,7 @@
                     <div>
                         <button id="guest-edit-attach-cdrom-button"
                             class="guest-edit-cdrom-button attach"
-                            title="$_("Attach")">
+                            title='$_("Attach")'>
                         </button>
                     </div>
                 </fieldset>
@@ -124,11 +122,11 @@
                 value="{path}" readonly="readonly" />
             <button class="guest-edit-cdrom-button replace"
                 data-vm="{vm}" data-dev="{dev}"
-                title="$_("Replace")">
+                title='$_("Replace")'>
             </button>
             <button class="guest-edit-cdrom-button detach"
                 data-vm="{vm}" data-dev="{dev}"
-                title="$_("Detach")">
+                title='$_("Detach")'>
             </button>
         </div>
     </div>
-- 
1.9.0




More information about the Kimchi-devel mailing list