[Kimchi-devel] [PATCH 1/2] Eject cdrom: Change js support for eject cdrom

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Thu Jun 5 08:22:50 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Add new api of eject, and support eject for cdrom which has
media in it.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js                   | 13 +++++++++++
 ui/js/src/kimchi.guest_cdrom_edit_main.js |  1 +
 ui/js/src/kimchi.guest_media_main.js      | 38 ++++++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 7d85fdf..9da04a5 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -816,6 +816,19 @@ var kimchi = {
         });
     },
 
+    ejectVMStorage : function(settings, suc, err) {
+        var vm = encodeURIComponent(settings['vm']);
+        var dev = encodeURIComponent(settings['dev']);
+        kimchi.requestJSON({
+            url : kimchi.url + 'vms/' + vm + '/storages/' + dev + '/eject',
+            type : 'POST',
+            contentType : 'application/json',
+            dataType : 'json',
+            success : suc,
+            error : err
+        });
+    },
+
     deleteVMStorage : function(settings, suc, err) {
         var vm = settings['vm'];
         var dev = settings['dev'];
diff --git a/ui/js/src/kimchi.guest_cdrom_edit_main.js b/ui/js/src/kimchi.guest_cdrom_edit_main.js
index abce9a5..19fbf08 100644
--- a/ui/js/src/kimchi.guest_cdrom_edit_main.js
+++ b/ui/js/src/kimchi.guest_cdrom_edit_main.js
@@ -82,4 +82,5 @@ kimchi.guest_cdrom_edit_main = function() {
             ($(this).val() === '');
         $(submitButton).prop('disabled', invalid);
     });
+    pathTextbox.select();
 };
diff --git a/ui/js/src/kimchi.guest_media_main.js b/ui/js/src/kimchi.guest_media_main.js
index 02009ec..1661b33 100644
--- a/ui/js/src/kimchi.guest_media_main.js
+++ b/ui/js/src/kimchi.guest_media_main.js
@@ -32,14 +32,46 @@ kimchi.guest_media_main = function() {
                 container.append(templated);
             });
 
-            var replaceCDROM = function(event) {
+            var insertCDROM = function(event) {
                 event.preventDefault();
                 kimchi.selectedGuestStorage = $(this).data('dev');
                 kimchi.window.open("guest-cdrom-edit.html");
             };
 
-            $('input[type="text"][name="cdrom"]', container).on('click', replaceCDROM);
-            $('.replace', container).on('click', replaceCDROM);
+
+            cdroms = $('input[type="text"][name="cdrom"]', container);
+            $.each(cdroms, function(index, cdroms) {
+                if($(this).val() == "") {
+                    $('.eject', $(this).parent()).addClass("hidden");
+                    $('.replace', $(this).parent()).addClass("hidden");
+                }
+                else {
+                    $('.insert', $(this).parent()).addClass("hidden");
+                }
+            });
+            var ejectCDROM = function(event) {
+                var settings = {
+                    vm: kimchi.selectedGuest,
+                    dev: $(this).data('dev'),
+                };
+
+                event.preventDefault();
+                kimchi.ejectVMStorage(settings, function(result) {
+                kimchi.topic('kimchi/vmCDROMReplaced').publish({
+                    result: result
+                    });
+                }, function(result) {
+                    var errText = result['reason'] ||
+                        result['responseJSON']['reason'];
+                    kimchi.message.error(errText);
+                });
+            };
+
+
+            $('input[type="text"][name="cdrom"]', container).on('click', insertCDROM);
+            $('.insert', container).on('click', insertCDROM);
+            $('.replace', container).on('click', insertCDROM);
+            $('.eject', container).on('click', ejectCDROM);
         });
     };
 
-- 
1.8.3.2




More information about the Kimchi-devel mailing list