Browse files

Patch adds dynamic on demand loading of dialogs. A dialog handler was…

… added to the python server that uses genshi to return the desired dialog from the template. The loading is performed when the dialog is first needed (Achim Hasenmueller).

git-svn-id: http://vboxweb.googlecode.com/svn/trunk@82 729376a8-6c6b-11de-afdd-bb9f892af8c1
  • Loading branch information...
1 parent 954ce3c commit 74b017d163a592ecc570ec76a121f5b9c5c39c0a vboxweb committed Aug 27, 2009
View
8 VBoxWebSrv.py
@@ -441,6 +441,14 @@ def vboxVMAction(self, operation, uuid):
else:
return self.jsonPrinter(arrJSON, default=convertObjToJSON)
+ # return markup for a specific dialog
+ @cherrypy.expose
+ @require()
+ def dialog(self, dialogid):
+ print "Page: dialog, requesting ID " + dialogid
+ tmpl = self.templateLoader.load('dialogs.html')
+ return tmpl.generate(dialogid=dialogid).render('html')
+
# Entry point when browser loads the whole page
@cherrypy.expose
@require()
View
225 www/templates/dialogs.html → templates/dialogs.html
@@ -1,111 +1,114 @@
-<!--
- * Copyright (C) 2009 Sun Microsystems, Inc.
-
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
-
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
--->
-
-<html>
- <head></head>
- <body>
- <!-- 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>
-
- <div id="newvm-dialog" title="Create a new Virtual Machine" style="display: none;">
- <table width="100%">
- <tr align="top">
- <td style="padding-right: 10px; padding-top: 10px;">
- <img src="/images/vbox/vmw_new_welcome.png" alt=""/>
- </td>
- <td valign="top" width="100%">
- <form id="newvm-form" method="post" action="#">
- <div class="step">
- <table width="100%">
- <tr>
- <td class="wizardpagetitle">Welcome to the New Virtual Machine Wizard!</td>
- </tr>
- <tr>
- <td class="wizardform">
- This wizard will guide you through the steps that are necessary to create a new virtual
- machine on your VirtualBox host.<p>
- Use the <b>Next</b> button to go to the next page of the wizard and the <b>Back</b>
- button to return to the previous page.</p>
- </td>
- </tr>
- </table>
- </div>
- <div class="step">
- <table width="100%">
- <tr>
- <td class="wizardpagetitle">VM Name and OS Type</td>
- </tr>
- <tr>
- <td class="wizardform">
- <table>
- <tr><td style="padding-right: 10px">Name:</td><td width="100%"><input disabled="disabled" type="text" value="" /></td></tr>
- <tr><td style="padding-right: 10px">Operating System:</td><td width="100%"><div id="newvmdialog-ostype"class="xapplicationMenu">
- <table class="rootVoices" cellspacing='0' cellpadding='0' border='0'><tr>
- <td id="ostype-selected" class="rootVoice {menu: 'menu_OSType'}">placeholder</td>
- </tr></table>
- </div></td></tr>
- </table>
- </td>
- </tr>
- </table>
- </div>
- <!-- these become to Back Next buttoms -->
- <div style="position: absolute; bottom: 30px;">
- <input type="reset" value="Reset" />
- <input type="submit" value="Submit" />
- </div>
- </form>
- </td>
- </tr>
- </table>
- <div id="menu_OSType" class="menu">
- <a rel="text" >
- <img src="/images/vbox/os_win_other.png" alt="img"/>
- Select the operating system family and version of the guest that you plan to run in this virtual machine.<br/>
- </a>
- <a rel="separator"> </a>
- <!-- this gets populated dynamically with the OS families -->
- <span id="osfamilies-span"></span>
- </div>
- <!-- this gets populated with the individual OS family submenues -->
- <span id="ostype_submenues"></span>
- </div>
- </body>
-</html>
+<!--
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+ <body>
+
+ <div py:if='dialogid == "poweroff-dialog"'
+ 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>
+
+ <div py:if= 'dialogid == "newvm-dialog"'
+ id="newvm-dialog" title="Create a new Virtual Machine" style="display: none;">
+ <table width="100%">
+ <tr align="top">
+ <td style="padding-right: 10px; padding-top: 10px;">
+ <img src="/images/vbox/vmw_new_welcome.png" alt=""/>
+ </td>
+ <td valign="top" width="100%">
+ <form id="newvm-form" method="post" action="#">
+ <div class="step">
+ <table width="100%">
+ <tr>
+ <td class="wizardpagetitle">Welcome to the New Virtual Machine Wizard!</td>
+ </tr>
+ <tr>
+ <td class="wizardform">
+ This wizard will guide you through the steps that are necessary to create a new virtual
+ machine on your VirtualBox host.<p>
+ Use the <b>Next</b> button to go to the next page of the wizard and the <b>Back</b>
+ button to return to the previous page.</p>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="step">
+ <table width="100%">
+ <tr>
+ <td class="wizardpagetitle">VM Name and OS Type</td>
+ </tr>
+ <tr>
+ <td class="wizardform">
+ <table>
+ <tr><td style="padding-right: 10px">Name:</td><td width="100%"><input disabled="disabled" type="text" value="" /></td></tr>
+ <tr><td style="padding-right: 10px">Operating System:</td><td width="100%"><div id="newvmdialog-ostype" class="xapplicationMenu">
+ <table class="rootVoices" cellspacing='0' cellpadding='0' border='0'><tr>
+ <td id="ostype-selected" class="rootVoice {menu: 'menu_OSType'}">placeholder</td>
+ </tr></table>
+ </div></td></tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <!-- these become to Back Next buttoms -->
+ <div style="position: absolute; bottom: 30px;">
+ <input type="reset" value="Reset" />
+ <input type="submit" value="Submit" />
+ </div>
+ </form>
+ </td>
+ </tr>
+ </table>
+ <div id="menu_OSType" class="menu">
+ <a rel="text" >
+ <img src="/images/vbox/os_win_other.png" alt="img"/>
+ Select the operating system family and version of the guest that you plan to run in this virtual machine.<br/>
+ </a>
+ <a rel="separator"> </a>
+ <!-- this gets populated dynamically with the OS families -->
+ <span id="osfamilies-span"></span>
+ </div>
+ <!-- this gets populated with the individual OS family submenues -->
+ <span id="ostype_submenues"></span>
+ </div>
+ </body>
+</html>
View
24 templates/template_login.html
@@ -1,3 +1,27 @@
+<!--
+ * Copyright (C) 2009 Sun Microsystems, Inc.
+
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude"
View
130 www/static/js/vboxDialogs.js
@@ -25,15 +25,16 @@
var vboxDialogs = Class.create(
{
- /*
- * This performs the initial setup work for the dialogs, like
- * loading the HTML file and inserting it into the DOM, configuring
- * the DIVs, etc. Called when the HTML loads.
- */
- initDialogs: function()
+ showPowerOffDialog: function()
{
- /* load the dialogs HTML file with a completion function */
- jQuery.get("/html/dialogs.html", function(data) {
+ /* already loaded? Then show */
+ if (jQuery("#poweroff-dialog").length)
+ {
+ jQuery('#poweroff-dialog').dialog('open');
+ return;
+ }
+ /* load the dialog */
+ jQuery.get("dialog?dialogid=poweroff-dialog", function(data) {
/* append the loaded HTML to the body section */
jQuery("body").append(data);
@@ -65,6 +66,24 @@ var vboxDialogs = Class.create(
}
});
});
+ jQuery('#poweroff-dialog').dialog('open');
+ });
+ },
+
+ showNewVMWizard: function()
+ {
+ /* already loaded? Then show */
+ if (jQuery("#newvm-dialog").length)
+ {
+ selectOSType("WindowsXP");
+ jQuery("#newvm-form").formwizard("reset");
+ jQuery('#newvm-dialog').dialog('open');
+ return;
+ }
+ /* load the dialog */
+ jQuery.get("dialog?dialogid=newvm-dialog", function(data) {
+ /* append the loaded HTML to the body section */
+ jQuery("body").append(data);
jQuery(function(){
jQuery("#newvmdialog-ostype").buildMenu(
@@ -114,59 +133,56 @@ var vboxDialogs = Class.create(
}
});
});
- });
- },
- showNewVMWizard: function()
- {
- /*
- * Create the OS type menu. We're doing this here and not at dialog
- * loading time for several reasons. First of all, the OS type list
- * might not have been loaded from the server yet and also this is a
- * potentially time consuming task. Later, we should load the whole
- * dialog not at startup time but when called for the first time.
- */
- selectOSType = function(osTypeId)
- {
- jQuery("#ostype-selected").html(
- "<img alt=\"\" width=\"20px\" align=\"top\" style=\"padding-right: 20px;\" src=\"" +
- vbGlobal.vmGuestOSTypeIcon(osTypeId, false) + "\"/>" +
- "<span id=\"ostype-selected-id\">" +
- vbGlobal.mVirtualBox.getGuestOSTypeById(osTypeId).getDescription() +
- "</span>"
- );
- }
- var osTypes = vbGlobal.mVirtualBox.mArrGuestOSTypes;
- for (var i = 0; i < osTypes.length; i++)
- {
- /* check if the menu for the family exists */
- var submenu = jQuery("#ostype-submenu-" + osTypes[i].getFamilyId());
- if (submenu.length == 0)
+ /*
+ * Create the OS type menu. We're doing this here and not at dialog
+ * loading time for several reasons. First of all, the OS type list
+ * might not have been loaded from the server yet and also this is a
+ * potentially time consuming task. Later, we should load the whole
+ * dialog not at startup time but when called for the first time.
+ */
+ selectOSType = function(osTypeId)
{
- /* create link to the submenu */
- jQuery("#osfamilies-span").append(
- "<a class=\"{menu: 'ostype-submenu-" + osTypes[i].getFamilyId() + "', " +
- "img: 'vm_start_32px.png'}\">" + osTypes[i].getFamilyId() + "</a>"
- );
- /* create the submenu */
- jQuery("#ostype_submenues").append(
- "<div id=\"ostype-submenu-" + osTypes[i].getFamilyId() + "\" class=\"menu\">" +
- "<span id=\"osfamily-" + osTypes[i].getFamilyId() + "-span\"></span>" +
- "</div>"
+ jQuery("#ostype-selected").html(
+ "<img alt=\"\" width=\"20px\" align=\"top\" style=\"padding-right: 20px;\" src=\"" +
+ vbGlobal.vmGuestOSTypeIcon(osTypeId, false) + "\"/>" +
+ "<span id=\"ostype-selected-id\">" +
+ vbGlobal.mVirtualBox.getGuestOSTypeById(osTypeId).getDescription() +
+ "</span>"
);
}
- /* now add the OS entry to the right submenu, check if present to multiple calls to this method */
- if (jQuery("#ostype-entry-" + osTypes[i].getId()).length == 0)
- jQuery("#osfamily-" + osTypes[i].getFamilyId() + "-span").append(
- "<a id=\"ostype-entry-" + osTypes[i].getId() + "\" class=\"{action: 'selectOSType(\\'" + osTypes[i].getId() + "\\')', img: '" +
- vbGlobal.vmGuestOSTypeIcon(osTypes[i].getId(), true) +
- "'}\">" + osTypes[i].getDescription() + "</a>"
- );
- }
- /* start with Windows XP as the default */
- selectOSType("WindowsXP");
- jQuery("#newvm-form").formwizard("reset");
- jQuery("#newvm-dialog").dialog("open");
+ var osTypes = vbGlobal.mVirtualBox.mArrGuestOSTypes;
+ for (var i = 0; i < osTypes.length; i++)
+ {
+ /* check if the menu for the family exists */
+ var submenu = jQuery("#ostype-submenu-" + osTypes[i].getFamilyId());
+ if (submenu.length == 0)
+ {
+ /* create link to the submenu */
+ jQuery("#osfamilies-span").append(
+ "<a class=\"{menu: 'ostype-submenu-" + osTypes[i].getFamilyId() + "', " +
+ "img: 'vm_start_32px.png'}\">" + osTypes[i].getFamilyId() + "</a>"
+ );
+ /* create the submenu */
+ jQuery("#ostype_submenues").append(
+ "<div id=\"ostype-submenu-" + osTypes[i].getFamilyId() + "\" class=\"menu\">" +
+ "<span id=\"osfamily-" + osTypes[i].getFamilyId() + "-span\"></span>" +
+ "</div>"
+ );
+ }
+ /* now add the OS entry to the right submenu, check if present to multiple calls to this method */
+ if (jQuery("#ostype-entry-" + osTypes[i].getId()).length == 0)
+ jQuery("#osfamily-" + osTypes[i].getFamilyId() + "-span").append(
+ "<a id=\"ostype-entry-" + osTypes[i].getId() + "\" class=\"{action: 'selectOSType(\\'" + osTypes[i].getId() + "\\')', img: '" +
+ vbGlobal.vmGuestOSTypeIcon(osTypes[i].getId(), true) +
+ "'}\">" + osTypes[i].getDescription() + "</a>"
+ );
+ }
+ /* start with Windows XP as the default */
+ selectOSType("WindowsXP");
+ jQuery("#newvm-form").formwizard("reset");
+ jQuery("#newvm-dialog").dialog("open");
+ });
}
});
View
2 www/static/js/vboxVMToolbar.js
@@ -83,7 +83,7 @@ var vboxVMToolbar = Class.create(
if (state == VMState.Running ||
state == VMState.Paused)
{
- jQuery('#poweroff-dialog').dialog('open');
+ vboxDialogs.showPowerOffDialog();
}
else if (state == VMState.Saved)
{
View
1 www/templates/index.html
@@ -191,7 +191,6 @@
vmSelWnd = new vboxSelectorWnd(vmListView, vmTabView, vmToolbar);
vbGlobal.setSelectorWnd(vmSelWnd);
vboxDialogs = new vboxDialogs();
- vboxDialogs.initDialogs();
jQuery('#vmTab').bind('tabsselect', function(event, ui) {
return vmTabView.onTabChange(event, ui);

0 comments on commit 74b017d

Please sign in to comment.