From 87cdcc6df6581672789d22cb0e23d106d70a6c4b Mon Sep 17 00:00:00 2001 From: phamt Date: Wed, 14 Jul 2010 20:11:07 +0000 Subject: [PATCH] Refactored code so that Javascripts are loaded on demand git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6766 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/configure/configure.js | 4 +- xCAT-UI/js/monitor/monitor.js | 4 +- xCAT-UI/js/nodes/nodes.js | 4 +- xCAT-UI/js/provision/provision.js | 6 +-- xCAT-UI/js/ui.js | 61 ++++++++++++++++++++++--------- xCAT-UI/lib/ui.php | 25 +------------ 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/xCAT-UI/js/configure/configure.js b/xCAT-UI/js/configure/configure.js index 583a75676..a16e2c2d7 100644 --- a/xCAT-UI/js/configure/configure.js +++ b/xCAT-UI/js/configure/configure.js @@ -56,7 +56,7 @@ function getConfigTab() { */ function loadConfigPage() { // If the configure page has already been loaded - if ($('#configure_page').children().length) { + if ($('#content').children().length) { // Do not reload configure page return; } @@ -65,7 +65,7 @@ function loadConfigPage() { var tab = new Tab(); setConfigTab(tab); tab.init(); - $('#configure_page').append(tab.object()); + $('#content').append(tab.object()); // Create loader var loader = createLoader(); diff --git a/xCAT-UI/js/monitor/monitor.js b/xCAT-UI/js/monitor/monitor.js index 493d0a9c3..94e147912 100644 --- a/xCAT-UI/js/monitor/monitor.js +++ b/xCAT-UI/js/monitor/monitor.js @@ -40,13 +40,13 @@ function loadMonitorPage() { var tab = new Tab(); setConfigTab(tab); tab.init(); - $('#monitor_page').append(tab.object()); + $('#content').append(tab.object()); // Create provision tab var tab = new Tab(); setMonitorTab(tab); tab.init(); - $('#monitor_page').append(tab.object()); + $('#content').append(tab.object()); /** * Monitor nodes diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index d978ea451..1990ad24f 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -57,8 +57,8 @@ function loadNodesPage() { // Create a groups division groupDIV = $('
'); nodesDIV = $('
'); - $('#nodes_page').append(groupDIV); - $('#nodes_page').append(nodesDIV); + $('#content').append(groupDIV); + $('#content').append(nodesDIV); // Create info bar var info = createInfoBar('Select a group to view its nodes'); diff --git a/xCAT-UI/js/provision/provision.js b/xCAT-UI/js/provision/provision.js index 86ec984b6..bdc0b97a3 100644 --- a/xCAT-UI/js/provision/provision.js +++ b/xCAT-UI/js/provision/provision.js @@ -31,7 +31,7 @@ function getProvisionTab() { */ function loadProvisionPage() { // If the page is loaded - if ($('#provision_page').children().length) { + if ($('#content').children().length) { // Do not load again return; } @@ -43,7 +43,7 @@ function loadProvisionPage() { // Create info bar var infoBar = createInfoBar('Provision a node'); - $('#provision_page').append(infoBar); + $('#content').append(infoBar); // Create provision form provForm = $('
'); @@ -54,7 +54,7 @@ function loadProvisionPage() { var tab = new Tab(); setProvisionTab(tab); tab.init(); - $('#provision_page').append(tab.object()); + $('#content').append(tab.object()); // Create drop-down menu // Hardware available to provision - ipmi, blade, hmc, ivm, fsp, and zvm diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index 12a658055..0ba639840 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -29,7 +29,7 @@ Tab.prototype.init = function() { this.tab.append(tabList); // Create a template - var $tabs = this.tab + var tabs = this.tab .tabs( { tabTemplate : "
  • #{label}
  • " }); @@ -42,11 +42,11 @@ Tab.prototype.init = function() { // Append close button to tabs $("#" + this.tabId + " span.tab-close").live("click", function() { - var index = $('li', $tabs).index($(this).parent()); + var index = $('li', tabs).index($(this).parent()); // Do not remove first tab if (index != 0) { - $tabs.tabs('remove', index); + tabs.tabs('remove', index); } }); }; @@ -386,6 +386,23 @@ function createMenu(items) { * @return Nothing */ function initPage() { + // Load javascripts + includeJs("js/jquery/jquery.dataTables.min.js"); + includeJs("js/jquery/jquery.form.js"); + includeJs("js/jquery/jquery.jeditable.js"); + includeJs("js/jquery/jquery.autocomplete.js"); + includeJs("js/jquery/jquery.contextmenu.js"); + includeJs("js/jquery/jquery.cookie.js"); + includeJs("js/jquery/jquery-impromptu.3.0.min.js"); + includeJs("js/jquery/superfish.js"); + includeJs("js/jquery/hoverIntent.js"); + includeJs("js/jquery/jquery.tree.js"); + includeJs("js/configure/configure.js"); + includeJs("js/monitor/monitor.js"); + includeJs("js/nodes/nodes.js"); + includeJs("js/provision/provision.js"); + includeJs("js/custom/zUtils.js"); + // Get the page being loaded var url = window.location.pathname; var page = url.replace('/xcat/', ''); @@ -393,25 +410,20 @@ function initPage() { var headers = $('#header ul li a'); // Show the page - $('div.content').hide(); + $("#content").children().remove(); if (page == 'index.php') { - $("#nodes_page").show(); headers.eq(0).css('background-color', '#A9D0F5'); loadNodesPage(); } else if (page == 'configure.php') { - $('#configure_page').show(); headers.eq(1).css('background-color', '#A9D0F5'); loadConfigPage(); } else if (page == 'provision.php') { - $('#provision_page').show(); headers.eq(2).css('background-color', '#A9D0F5'); loadProvisionPage(); } else if (page == 'monitor.php') { - $('#monitor_page').show(); headers.eq(3).css('background-color', '#A9D0F5'); loadMonitorPage(); } else { - $("#nodes_page").show(); headers.eq(0).css('background-color', '#A9D0F5'); loadNodesPage(); } @@ -424,8 +436,7 @@ function initPage() { if (title == 'Nodes') { link.bind('click', function(event) { - $('div.content').hide(); - $('#nodes_page').show(); + $("#content").children().remove(); headers.css('background-color', ''); $(this).css('background-color', '#A9D0F5'); @@ -433,8 +444,7 @@ function initPage() { }); } else if (title == 'Configure') { link.bind('click', function(event) { - $('div.content').hide(); - $('#configure_page').show(); + $("#content").children().remove(); headers.css('background-color', ''); $(this).css('background-color', '#A9D0F5'); @@ -442,8 +452,7 @@ function initPage() { }); } else if (title == 'Provision') { link.bind('click', function(event) { - $('div.content').hide(); - $('#provision_page').show(); + $("#content").children().remove(); headers.css('background-color', ''); $(this).css('background-color', '#A9D0F5'); @@ -451,8 +460,7 @@ function initPage() { }); } else if (title == 'Monitor') { link.bind('click', function(event) { - $('div.content').hide(); - $('#monitor_page').show(); + $("#content").children().remove(); headers.css('background-color', ''); $(this).css('background-color', '#A9D0F5'); @@ -460,4 +468,23 @@ function initPage() { }); } } +} + +/** + * Include javascript file + * + * @param file + * File to include + * @return Nothing + */ +function includeJs(file) { + // Create script + var script = $(''); + script.attr({ + type : 'text/javascript', + src : file + }) + + // Append to head + $('head').append(script); } \ No newline at end of file diff --git a/xCAT-UI/lib/ui.php b/xCAT-UI/lib/ui.php index 00933da98..06a94adc7 100644 --- a/xCAT-UI/lib/ui.php +++ b/xCAT-UI/lib/ui.php @@ -19,22 +19,7 @@ function loadPage(){ - - - - - - - - - - - - - - - '; // Header menu @@ -50,14 +35,8 @@ function loadPage(){ '; - // Nodes section - echo '
    '; - // Configure section - echo '
    '; - // Provision section - echo '
    '; - // Monitor section - echo '
    '; + // Content + echo '
    '; // End of page echo