Permalink
Browse files

Added a VM power off dialog and user logout support (Achim Hasenmuell…

…er).

git-svn-id: http://vboxweb.googlecode.com/svn/trunk@48 729376a8-6c6b-11de-afdd-bb9f892af8c1
  • Loading branch information...
1 parent 1db00e1 commit f1c62f9286dc83c0551c1bb2d576579a172cdfa2 vboxweb committed Aug 13, 2009
Showing with 95 additions and 11 deletions.
  1. +9 −4 VBoxWebSrv.py
  2. +8 −2 www/static/js/vboxVMToolbar.js
  3. +17 −1 www/static/js/vboxVirtualBox.js
  4. +61 −4 www/templates/index.html
View
@@ -79,6 +79,7 @@ def __init__(self, ctx, arrMach, type, statusMessage = ""):
self.magic = "jsVBxWb"
self.ver = 1
+ self.username = cherrypy.request.login
self.sessionID = cherrypy.session.id
self.numMach = len(arrMach)
self.updateType = type
@@ -484,6 +485,7 @@ def vboxGetUpdates(self):
@cherrypy.expose
@require()
def vboxVMAction(self, operation, uuid):
+ statusMessage = ""
print "Page: vboxVMAction called with operation " + operation + " and uuid " + uuid
# Close session if opened
if operation == "startvm":
@@ -498,7 +500,7 @@ def vboxVMAction(self, operation, uuid):
elif (operation == "pausevm" or
operation == "resumevm" or
operation == "savestatevm" or
- operation == "poweroff" or
+ operation == "poweroffvm" or
operation == "acpipoweroffvm"):
session = self.ctx['mgr'].getSessionObject(self.ctx['vb'])
progress = self.ctx['vb'].openExistingSession(session, uuid)
@@ -510,11 +512,14 @@ def vboxVMAction(self, operation, uuid):
console.resume()
statusMessage = "Resumed VM with ID " + uuid
elif operation == "savestatevm":
- pass
- elif operation == "poweroff":
+ console.saveState()
+ statusMessage = "Saving state of VM with ID " + uuid
+ elif operation == "poweroffvm":
console.powerDown()
- elif operation == "acpipoweroff":
+ statusMessage = "Powering off VM with ID " + uuid
+ elif operation == "acpipoweroffvm":
console.powerButton()
+ statusMessage = "Sent ACPI power button signal to VM with ID " + uuid
elif operation == "discardvm":
pass
@@ -27,8 +27,9 @@ var vboxVMToolbar = Class.create(
{
initialize: function()
{
- /* bind the static new VM toolbar button */
+ /* bind the static toolbar buttons */
jQuery("#toolbar-button-new").bind("click", this.buttonClicked);
+ jQuery("#toolbar-button-logout").bind("click", this.buttonClicked);
},
setParent: function(parent)
@@ -38,6 +39,7 @@ var vboxVMToolbar = Class.create(
invalidate: function()
{
+ jQuery("#toolbar-username-span").text(vbGlobal.mVirtualBox.getUserName());
this.selectionChanged();
},
@@ -70,14 +72,18 @@ var vboxVMToolbar = Class.create(
if (state == VMState.Running ||
state == VMState.Paused)
{
- vbGlobal.mVirtualBox.addMessage("Stop VM: here will be a dialog in da future!");
+ jQuery('#poweroff-dialog').dialog('open');
}
else if (state == VMState.Saved)
{
vbGlobal.mVirtualBox.addMessage("Discard VM not implemented!");
}
break;
+ case "toolbar-button-logout":
+ vbGlobal.mVirtualBox.logout();
+ break;
+
default:
console.log("vboxVMToolbar::buttonClicked: unknown source ID: " + event.target.id);
}
@@ -46,6 +46,7 @@ var vboxVirtualBox = Class.create(
{
initialize: function()
{
+ this.userName = "";
this.mArrMachines = new Array();
this.mArrGuestOSTypes = new Array();
this.XMLHttpCatch = new Abstract.XMLHttpCatch();
@@ -109,6 +110,8 @@ var vboxVirtualBox = Class.create(
if ((res[0].magic != "jsVBxWb") || (res[0].ver != "1"))
throw "Invalid header!";
+ this.userName = res[0].username;
+
/* Did we get a status messsage to display? */
if (res[0].statusMessage)
vbGlobal.mVirtualBox.addMessage(res[0].statusMessage);
@@ -211,7 +214,20 @@ var vboxVirtualBox = Class.create(
jQuery("#vmMessageTable").prepend('<tr><td class="message" style="width:120px; white-space: nowrap;">' +
dateStr + '</td><td class="message" width="100%">' + message + '</td></tr>');
- },
+ },
+
+ getUserName: function()
+ {
+ return this.userName;
+ },
+
+ logout: function()
+ {
+ this.receiveData("/logout");
+ /* local the main page, that will show the logon dialog */
+ /* note: this might not be clean in case the site does not live on / */
+ window.location = "/";
+ },
addMachine: function(vboxMachineImpl)
{
View
@@ -125,6 +125,35 @@
}
}
+ jQuery(function() {
+ jQuery("#poweroff-dialog").dialog({
+ bgiframe: true,
+ resizable: false,
+ height:200,
+ modal: true,
+ autoOpen: false,
+ overlay: {
+ backgroundColor: '#000',
+ opacity: 0.5
+ },
+ buttons: {
+ Ok: function() {
+ var poweroffMethod = jQuery("input[@name='poweroff-dialog-selection']:checked").val();
+ if (poweroffMethod == "savestate")
+ vbGlobal.mVirtualBox.savestateVM(vmSelWnd.curItem().id());
+ else if (poweroffMethod == "acpipoweroff")
+ vbGlobal.mVirtualBox.acpipoweroffVM(vmSelWnd.curItem().id());
+ else
+ vbGlobal.mVirtualBox.poweroffVM(vmSelWnd.curItem().id());
+ jQuery(this).dialog('close');
+ },
+ Cancel: function() {
+ jQuery(this).dialog('close');
+ }
+ }
+ });
+ });
+
jQuery(document).ready(onDocumentReady);
function onDocumentReady()
{
@@ -234,10 +263,20 @@
</script>
<div id="vmToolbar" class="outer-layout-north" style="display: none;">
- <img id="toolbar-button-new" src="/images/vbox/vm_new_32px.png" alt="New VM"/>
- <span id="toolbar-button-vm-settings-span"></span>
- <span id="toolbar-button-vm-start-span"></span>
- <span id="toolbar-button-vm-stop-span"></span>
+ <table width="100%"cellspacing="0">
+ <tr>
+ <td align="left">
+ <img id="toolbar-button-new" src="/images/vbox/vm_new_32px.png" alt="New VM"/>
+ <span id="toolbar-button-vm-settings-span"></span>
+ <span id="toolbar-button-vm-start-span"></span>
+ <span id="toolbar-button-vm-stop-span"></span>
+ </td>
+ <td align="right">
+ <span id="toolbar-username-span" style="display:inline-block; vertical-align:top"></span>
+ <img id="toolbar-button-logout" src="/images/vbox/vm_poweroff_32px.png" alt="Logout"/>
+ </td>
+ </tr>
+ </table>
</div>
<ol id="vmList" class="outer-layout-west" style="display: none; list-style-type: none;"><li/></ol>
@@ -395,5 +434,23 @@ <h1>Alternative content</h1>
<table id="vmMessageTable" width="100%" cellspacing="0">
</table>
</div>
+
+ <!-- VM power off dialog, initially hidden, displayed using jQuery -->
+ <div id="poweroff-dialog" title="Close virtual machine" style="display: none;">
+ <table width="100%" cellspacing="0">
+ <tr>
+ <td><img src="/images/vbox/state_saved_16px.png" alt=""/></td>
+ <td><input type="radio" name="poweroff-dialog-selection" value="savestate" checked="checked">Save the machine state</input></td>
+ </tr>
+ <tr>
+ <td><img src="/images/vbox/state_powered_off_16px.png" alt=""/></td>
+ <td><input type="radio" name="poweroff-dialog-selection" value="acpipoweroff">Send the shutdown signal</input></td>
+ </tr>
+ <tr>
+ <td><img src="/images/vbox/poweroff_16px.png" alt=""/></td>
+ <td><input type="radio" name="poweroff-dialog-selection" value="poweroff">Power off the machine</input></td>
+ </tr>
+ </table>
+ </div>
</body>
</html>

0 comments on commit f1c62f9

Please sign in to comment.