From e2ff20af187231622348ac39627af5fe5110f6c6 Mon Sep 17 00:00:00 2001 From: phamt Date: Thu, 15 Jul 2010 13:41:29 +0000 Subject: [PATCH] Cleaned up code git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6773 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/nodes/nodes.js | 178 +++++++++++++++----------------------- xCAT-UI/js/ui.js | 64 +++----------- 2 files changed, 82 insertions(+), 160 deletions(-) diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index 1990ad24f..d1d317c20 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -163,6 +163,8 @@ function loadNodes(data) { var attrs = new Object(); // Node attributes var headers = new Object(); + // Plugins hash + var plugins = new Object(); var node; var args; @@ -186,6 +188,18 @@ function loadNodes(data) { // Create a hash table attrs[node][key] = val; headers[key] = 1; + + // Create a plugin hash + if (key == 'mgt') { + plugins[val] = 1; + } + } + + // Load the plugin code + // Plugin code should be located under js/custom/ + // Plugin names should be valid values of mgt + for ( var p in plugins) { + includeJs("js/custom/" + p + ".js"); } // Sort headers @@ -233,7 +247,7 @@ function loadNodes(data) { // Clear the tab before inserting the table $('#nodesTab').children().remove(); - // Create action buttons + // Create action bar var actionBar = $('
'); /** @@ -251,46 +265,22 @@ function loadNodes(data) { */ var powerOnLnk = $('Power on'); powerOnLnk.bind('click', function(event) { - var tgtNodes = ''; - - // Get node that was checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + var tgtNodes = getNodesChecked(); + if (tgtNodes) { + powerNode(tgtNodes, 'on'); } - } - - if (tgtNodes) { - powerNode(tgtNodes, 'on'); - } -} ); + }); /* * Power off */ var powerOffLnk = $('Power off'); powerOffLnk.bind('click', function(event) { - var tgtNodes = ''; - - // Get node that was checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + var tgtNodes = getNodesChecked(); + if (tgtNodes) { + powerNode(tgtNodes, 'off'); } - } - - if (tgtNodes) { - powerNode(tgtNodes, 'off'); - } -} ); + }); /* * Clone @@ -319,48 +309,26 @@ function loadNodes(data) { */ var deleteLnk = $('Delete'); deleteLnk.bind('click', function(event) { - var tgtNodes = ''; + var tgtNodes = getNodesChecked(); - // Get node that was checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + // Load delete page + if (tgtNodes) { + deleteNode(tgtNodes); } - } - - // Load delete page - if (tgtNodes) { - deleteNode(tgtNodes); - } -} ); + }); /* * Unlock */ var unlockLnk = $('Unlock'); unlockLnk.bind('click', function(event) { - var tgtNodes = ''; + var tgtNodes = getNodesChecked(); - // Get node that was checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + // Load unlock page + if (tgtNodes) { + loadUnlockPage(tgtNodes); } - } - - // Load unlock page - if (tgtNodes) { - loadUnlockPage(tgtNodes); - } -} ); + }); /* * Run script @@ -368,22 +336,13 @@ function loadNodes(data) { var scriptLnk = $('Run script'); scriptLnk.bind('click', function(event) { // Get node that was checked - var tgtNodes = ''; - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); + var tgtNodes = getNodesChecked(); - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + // Load script page + if (tgtNodes) { + loadScriptPage(tgtNodes); } - } - - // Load script page - if (tgtNodes) { - loadScriptPage(tgtNodes); - } -} ); + }); /* * Update node @@ -391,22 +350,13 @@ function loadNodes(data) { var updateLnk = $('Update'); updateLnk.bind('click', function(event) { // Get node that was checked - var tgtNodes = ''; - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); + var tgtNodes = getNodesChecked(); + + // TODO: Load update page + if (tgtNodes) { - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; } - } - - // TODO: Load update page - if (tgtNodes) { - - } -} ); + }); /* * Set boot state @@ -414,26 +364,14 @@ function loadNodes(data) { var setBootStateLnk = $('Set boot state'); setBootStateLnk.bind('click', function(event) { // Get node that was checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - // Get node that was checked - var tgtNodes = ''; - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); - for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; - } - } + var tgtNodes = getNodesChecked(); // Load nodeset page if (tgtNodes) { loadNodesetPage(tgtNodes); } - } -} ); + + }); /* * Boot to network @@ -1795,7 +1733,7 @@ function setOSImageCookies(data) { function setGroupsCookies(data) { var rsp = data.rsp; - // Save image names in a cookie + // Save groups names in a cookie $.cookie('Groups', rsp); } @@ -1828,4 +1766,26 @@ function getNodeRow(tgtNode, rows) { } return; +} + +/** + * Get the nodes that were checked in the nodes table + * + * @return Nodes that were checked + */ +function getNodesChecked() { + var tgtNodes = ''; + + // Get nodes that were checked + var nodes = $('#nodesDataTable input[type=checkbox]:checked'); + for ( var i = 0; i < nodes.length; i++) { + tgtNodes += nodes.eq(i).attr('name'); + + // Add a comma in front of each node + if (i < nodes.length - 1) { + tgtNodes += ','; + } + } + + return tgtNodes; } \ No newline at end of file diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index b1f0b15e9..62b44ad63 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -427,64 +427,26 @@ function initPage() { headers.eq(0).css('background-color', '#A9D0F5'); loadNodesPage(); } - - // Bind each link to open the page on click - for ( var i = 0; i < headers.length; i++) { - var title = headers.eq(i).text(); - var link = headers.eq(i); - link.attr('href', '#'); - - if (title == 'Nodes') { - link.bind('click', function(event) { - $("#content").children().remove(); - headers.css('background-color', ''); - $(this).css('background-color', '#A9D0F5'); - - loadNodesPage(); - }); - } else if (title == 'Configure') { - link.bind('click', function(event) { - $("#content").children().remove(); - headers.css('background-color', ''); - $(this).css('background-color', '#A9D0F5'); - - loadConfigPage(); - }); - } else if (title == 'Provision') { - link.bind('click', function(event) { - $("#content").children().remove(); - headers.css('background-color', ''); - $(this).css('background-color', '#A9D0F5'); - - loadProvisionPage(); - }); - } else if (title == 'Monitor') { - link.bind('click', function(event) { - $("#content").children().remove(); - headers.css('background-color', ''); - $(this).css('background-color', '#A9D0F5'); - - loadMonitorPage(); - }); - } - } } /** - * Include javascript file + * Include javascript file in * * @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); + var script = $("head script[src='" + file + "']"); + if (!script.length) { + // Create script + var script = $(''); + script.attr( { + type : 'text/javascript', + src : file + }) + + // Append to + $('head').append(script); + } } \ No newline at end of file