Permalink
Browse files

Implemented a simple message area for feedback and status updates. Co…

…nnected it to the toolbar buttons. Message updates can either come from the JS code or the server side Python (Achim Hasenmueller).

git-svn-id: http://vboxweb.googlecode.com/svn/trunk@45 729376a8-6c6b-11de-afdd-bb9f892af8c1
  • Loading branch information...
1 parent 338773c commit a88ce85efeec9a3379e7efe6d9802252cef51d10 vboxweb committed Aug 12, 2009
View
@@ -23,13 +23,10 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
-import cgi
import cherrypy
import os
import socket
import sys
-import time
-import traceback
if sys.version_info < (2, 6):
import simplejson
@@ -58,13 +55,14 @@ def default(self, obj):
return convertObjToJSON(obj)
class jsHeader:
- def __init__(self, ctx, arrMach, type):
+ def __init__(self, ctx, arrMach, type, statusMessage = ""):
self.magic = "jsVBxWb"
self.ver = 1
self.sessionID = cherrypy.session.id
self.numMach = len(arrMach)
self.updateType = type
+ self.statusMessage = statusMessage
#
# @todo write autowrapper for attributes main-like classes below.
@@ -385,6 +383,7 @@ def vboxVMAction(self, operation, uuid):
# todo we shouldn't wait here, perform asynchronously
progress.waitForCompletion(-1)
session.close()
+ statusMessage = "Started VM with ID " + uuid
# Commands requiring an open session
elif (operation == "pausevm" or
@@ -397,8 +396,10 @@ def vboxVMAction(self, operation, uuid):
console = session.console;
if operation == "pausevm":
console.pause()
+ statusMessage = "Paused VM with ID " + uuid
elif operation == "resumevm":
console.resume()
+ statusMessage = "Resumed VM with ID " + uuid
elif operation == "savestatevm":
pass
elif operation == "poweroff":
@@ -411,9 +412,8 @@ def vboxVMAction(self, operation, uuid):
else:
print "vboxVMAction: unknown operation"
- # todo easier way to return "no updates"?
arrJSON = []
- arrJSON.append(jsHeader(self.ctx, [], 1))
+ arrJSON.append(jsHeader(self.ctx, [], 1, statusMessage))
if isSimpleJson:
return self.jsonPrinter(arrJSON, cls=ConvertObjToJSONClass)
else:
@@ -504,7 +504,6 @@ def rdpWebControlDownload(forceUpdate = False, url = None, dest = None, proxies
return
# Get latest version information
- strVersion = ""
print "Looking up latest version of Sun RDP Web Control (from %s) ..." %(url)
fhFileVer = url_open(url + "LATEST.TXT", None, proxies)
@@ -49,6 +49,11 @@ body {
overflow: auto; /* Override layout default 'auto'. */
}
+/* south */
+.outer-layout-south {
+ padding: 0px;
+}
+
/* Layout togglers (gripper bars). */
.ui-layout-toggler {
color: #666;
@@ -163,3 +168,16 @@ body {
margin-left: 0;
}
+/* the message list */
+td.message {
+ border-bottom: 1px #000000 dotted;
+ text-align: left;
+ font-weight: normal;
+ font-size: .7em;
+ color: #404040;
+ background-color: #fafafa;
+ padding-top: 4px;
+ padding-bottom: 4px;
+ padding-left: 8px;
+ padding-right: 0px;
+}
@@ -50,11 +50,11 @@ var vboxVMToolbar = Class.create(
switch (event.target.id)
{
case "toolbar-button-new":
- console.log("New VM not implemented!");
+ vbGlobal.mVirtualBox.addMessage("New VM not implemented yet!");
break;
case "toolbar-button-settings":
- console.log("Change VM settings not implemented!");
+ vbGlobal.mVirtualBox.addMessage("Change VM settings not implemented!");
break;
case "toolbar-button-start-pause":
@@ -66,19 +66,15 @@ var vboxVMToolbar = Class.create(
vbGlobal.mVirtualBox.startVM(id);
break;
- case "toolbar-button-discard":
- console.log("Discard VM state not implemented!");
- break;
-
case "toolbar-button-stop-discard":
if (state == VMState.Running ||
state == VMState.Paused)
{
- console.log("Stop VM: here will be a dialog in da future!");
+ vbGlobal.mVirtualBox.addMessage("Stop VM: here will be a dialog in da future!");
}
else if (state == VMState.Saved)
{
- console.log("Discard VM not implemented!");
+ vbGlobal.mVirtualBox.addMessage("Discard VM not implemented!");
}
break;
@@ -81,12 +81,14 @@ var vboxVirtualBox = Class.create(
checkForUpdates: function()
{
- console.log("vboxVirtualBox::checkForUpdates: Called.");
this.receiveData("/vboxGetUpdates");
},
updateProcess: function(response)
{
+ // don't try to parse empty responses
+ if (response.responseText == "")
+ return;
try
{
var res = response.responseText.evalJSON(true);
@@ -95,6 +97,10 @@ var vboxVirtualBox = Class.create(
if ((res[0].magic != "jsVBxWb") || (res[0].ver != "1"))
throw "Invalid header!";
+ /* did we get a status messsage to display? */
+ if (res[0].statusMessage)
+ vbGlobal.mVirtualBox.addMessage(res[0].statusMessage);
+
var numUpdates = res[0].numMach;
var updateType = res[0].updateType;
switch (res[0].__class__)
@@ -111,15 +117,14 @@ var vboxVirtualBox = Class.create(
this.clearMachines();
/* Add new or update existing machines. */
- for (var i=0; i<numUpdates; i++)
+ for (var i = 0; i < numUpdates; i++)
{
- arrJSON = res[i+1];
+ arrJSON = res[i + 1];
newMach = new vboxIMachineImpl(arrJSON);
curMach = this.getMachineById(newMach.getId());
if (curMach == undefined)
{
- console.log("vboxVirtualBox::updateProcess: Adding new machine: %s", newMach.getName());
this.addMachine(newMach);
}
else
@@ -132,11 +137,9 @@ var vboxVirtualBox = Class.create(
var sel = vbGlobal.selectorWnd();
sel.refreshVMList();
}
- else console.log("vboxVirtualBox::updateProcess: No updates.");
break;
default:
-
throw "Wrong class!"
break;
}
@@ -169,6 +172,28 @@ var vboxVirtualBox = Class.create(
return true;
},
+ addMessage: function(message)
+ {
+ /* this is ugly business but I couldn't find a better method */
+ date = new Date();
+ month = date.getMonth() + 1;
+ if (month < 10) month = '0' + month;
+ day = date.getDate();
+ if (day < 10) day = '0' + day;
+ hours = date.getHours();
+ if (hours < 10) hours = '0' + hours;
+ minutes = date.getMinutes();
+ if (minutes < 10) minutes = '0' + minutes;
+ seconds = date.getSeconds();
+ if (seconds < 10) seconds = '0' + seconds;
+ dateStr = date.getFullYear() + '-' + month + '-' + day + ' ' +
+ hours + ':' + minutes + ':' + seconds;
+
+ jQuery("#vmMessageTable").prepend('<tr><td class="message" nowrap="nowrap" style="width:100px">' +
+ dateStr + '</td><td class="message" width="100%">' + message + '</td></tr>')
+
+ },
+
addMachine: function(vboxMachineImpl)
{
/** @todo Search for machine first before adding. */
@@ -208,7 +233,7 @@ var vboxVirtualBox = Class.create(
{
/** @todo Slow lookup, improve this! */
var l = this.mArrMachines.length;
- for (var i=0; i<l; i++)
+ for (var i = 0; i < l; i++)
{
if (this.mArrMachines[i].getId() == id)
return this.mArrMachines[i];
View
@@ -142,6 +142,10 @@
, west__onresize: function () { jQuery("#vmList").selectable('resize'); }
, center__paneSelector: ".outer-layout-center"
, center__onresize: resizeTabLayout
+ , south__paneSelector: ".outer-layout-south"
+ , south__resizable: true
+ , south__slidable: true
+ , south__size: 100
});
/* Best to create the tabs first, because it's the container
@@ -387,6 +391,11 @@
</div>
+ <div id="vmMessageArea" class="outer-layout-south" style="display: none;">
+ <table id="vmMessageTable" width="100%" cellspacing="0">
+ </table>
+ </div>
+
<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank">
This frame prevents back forward cache in Safari.
</iframe>

0 comments on commit a88ce85

Please sign in to comment.