[Ovirt-devel] [PATCH server] fix incorrect forward vnc url in vm details pane

Mohammed Morsi mmorsi at redhat.com
Mon Apr 20 14:46:46 UTC 2009


use javascript to grab the url from the browser and use that
instead of generating it server side
---
 src/app/views/vm/show.rhtml     |   13 +++++++++----
 src/public/javascripts/ovirt.js |   16 +++++++++++++++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/app/views/vm/show.rhtml b/src/app/views/vm/show.rhtml
index add29b4..dffcb7b 100644
--- a/src/app/views/vm/show.rhtml
+++ b/src/app/views/vm/show.rhtml
@@ -88,7 +88,8 @@
     <div id="vms_selection_id" style="display:none"><%= @vm.id %></div>
     <div class="selection_key">
         Uuid:<br/>
-        <%= @vm.forward_vnc ? "VNC uri:<br/>" : "" %>
+        <%= @vm.forward_vnc && @vm.state == Vm::STATE_RUNNING ?
+              "VNC uri:<br/>" : "" %>
 	Num vcpus allocated:<br/>
 	Num vcpus used:<br/>
 	Memory allocated:<br/>
@@ -101,9 +102,13 @@
     </div>
     <div class="selection_value">
        <%=h @vm.uuid %><br/>
-       <%= url = request.url
-           url = request.url[0..(url.index('/', 8) - 1)] + ":" + @vm.forward_vnc_port.to_s
-           @vm.forward_vnc ? (url + "<br/>") : "" %>
+       <% if @vm.forward_vnc && @vm.state == Vm::STATE_RUNNING %>
+         <div id="vm_forward_vnc"></div>
+         <script type="text/javascript">
+            $("#vm_forward_vnc").html(
+              (get_server_from_url() + ":<%= @vm.forward_vnc_port %><br/>"));
+         </script>
+       <% end %>
        <%=h @vm.num_vcpus_allocated %><br/>
        <%=h @vm.num_vcpus_used %><br/>
        <%=h @vm.memory_allocated_in_mb %> MB<br/>
diff --git a/src/public/javascripts/ovirt.js b/src/public/javascripts/ovirt.js
index c24df16..b06f33e 100644
--- a/src/public/javascripts/ovirt.js
+++ b/src/public/javascripts/ovirt.js
@@ -380,4 +380,18 @@ var VmCreator = {
       VmCreator.recreateTree(storedOptions);
       VmCreator.clickCheckboxes();
   }
-}
\ No newline at end of file
+}
+
+// retreives server from url
+function get_server_from_url()
+{
+   var regexS = "https.*"
+   var regex  = new RegExp(regexS);
+   var results = regex.exec( window.location.href );
+   var start = 8;
+   if(results == null){
+     start = 7;
+   }
+   var end = window.location.href.indexOf('/', 8) - start;
+   return window.location.href.substr(start, end);
+}
-- 
1.6.0.6




More information about the ovirt-devel mailing list