Cleaned up code

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6797 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
phamt 2010-07-19 18:28:31 +00:00
parent 9f4125089d
commit 5f7bca49f8
8 changed files with 616 additions and 628 deletions

View File

@ -2,7 +2,7 @@
* Global variables
*/
var configTabs; // Config tabs
var configDataTables = new Object(); // Datatables on the config page
var configDatatables = new Object(); // Datatables on the config page
/**
* Set the datatable
@ -14,7 +14,7 @@ var configDataTables = new Object(); // Datatables on the config page
* @return Nothing
*/
function setConfigDatatable(id, obj) {
configDataTables[id] = obj;
configDatatables[id] = obj;
}
/**
@ -25,7 +25,7 @@ function setConfigDatatable(id, obj) {
* @return Datatable object
*/
function getConfigDatatable(id) {
return configDataTables[id];
return configDatatables[id];
}
/**
@ -71,7 +71,7 @@ function loadConfigPage() {
var loader = createLoader();
loader = $('<center></center>').append(loader);
// Configure xCAT tables
// Configure xCAT datable tables
tab.add('configTablesTab', 'Tables', loader);
// Get list of tables and their descriptions
@ -90,7 +90,7 @@ function loadConfigPage() {
}
/**
* Load xCAT table names and their descriptions
* Load xCAT database table names and their descriptions
*
* @param data
* Data returned from HTTP request
@ -105,7 +105,7 @@ function loadTableNames(data) {
$('#' + tabId).find('img').hide();
// Create a groups division
var tablesDIV = $('<div id="configure_table"></div>');
var tablesDIV = $('<div id="configTable"></div>');
$('#' + tabId).append(tablesDIV);
// Create info bar
@ -167,7 +167,7 @@ function loadTableNames(data) {
}
/**
* Load a given table
* Load a given database table
*
* @param data
* Data returned from HTTP request
@ -209,10 +209,10 @@ function loadTable(data) {
newCont[0] = tmp;
// Create a new datatable
var tableId = id + 'DataTable';
var tableId = id + 'Datatable';
var table = new DataTable(tableId);
// Add column for the remove button
// Add column for the remove row button
headers.unshift('');
table.init(headers);
headers.shift();
@ -248,8 +248,7 @@ function loadTable(data) {
}
// Add remove button
cols
.unshift('<span class="ui-icon ui-icon-close" onclick="deleteRow(this)"></span>');
cols.unshift('<span class="ui-icon ui-icon-close" onclick="deleteRow(this)"></span>');
// Add row
table.add(cols);
@ -274,15 +273,14 @@ function loadTable(data) {
return (value);
}, {
onblur : 'submit', // Clicking outside editable area submits
// changes
onblur : 'submit', // Clicking outside editable area submits changes
type : 'textarea',
height : '30px' // The height of the text area
});
// Turn table into datatable
dTable = $('#' + id + 'DataTable').dataTable();
setConfigDatatable(id + 'DataTable', dTable);
dTable = $('#' + id + 'Datatable').dataTable();
setConfigDatatable(id + 'Datatable', dTable);
// Create add row button
var addBar = $('<div></div>');
@ -299,54 +297,50 @@ function loadTable(data) {
/**
* Add row
*/
addRowBtn
.bind(
'click',
function(event) {
// Create an empty row
var row = new Array();
addRowBtn.bind('click', function(event) {
// Create an empty row
var row = new Array();
/**
* Remove button
*/
row
.push('<span class="ui-icon ui-icon-close" onclick="deleteRow(this)"></span>');
for ( var i = 0; i < headers.length; i++) {
row.push('');
}
/**
* Remove button
*/
row.push('<span class="ui-icon ui-icon-close" onclick="deleteRow(this)"></span>');
for ( var i = 0; i < headers.length; i++) {
row.push('');
}
// Get tab ID
var tabId = $(this).parent().parent().attr('id');
// Get table name
var tableName = tabId.replace('Tab', '');
// Get table ID
var tableId = tableName + 'DataTable';
// Get tab ID
var tabId = $(this).parent().parent().attr('id');
// Get table name
var tableName = tabId.replace('Tab', '');
// Get table ID
var tableId = tableName + 'Datatable';
// Get datatable
var dTable = getConfigDatatable(tableId);
// Add the row to the data table
dTable.fnAddData(row);
// Get datatable
var dTable = getConfigDatatable(tableId);
// Add the row to the data table
dTable.fnAddData(row);
// Enable editable columns (again)
// Do not make 1st column editable
$('#' + tabId + ' td:not(td:nth-child(1))').editable(
function(value, settings) {
// Get column index
var colPos = this.cellIndex;
// Get row index
var rowPos = dTable.fnGetPosition(this.parentNode);
// Enable editable columns (again)
// Do not make 1st column editable
$('#' + tabId + ' td:not(td:nth-child(1))').editable(
function(value, settings) {
// Get column index
var colPos = this.cellIndex;
// Get row index
var rowPos = dTable.fnGetPosition(this.parentNode);
// Update datatable
dTable.fnUpdate(value, rowPos, colPos);
// Update datatable
dTable.fnUpdate(value, rowPos, colPos);
return (value);
}, {
onblur : 'submit', // Clicking outside editable area
// submits changes
type : 'textarea',
height : '30px' // The height of the text area
});
return (value);
}, {
onblur : 'submit', // Clicking outside editable area
// submits changes
type : 'textarea',
height : '30px' // The height of the text area
});
});
/**
* Save changes
@ -357,7 +351,7 @@ function loadTable(data) {
// Get table name
var tableName = tabId.replace('Tab', '');
// Get table ID
var tableId = tableName + 'DataTable';
var tableId = tableName + 'Datatable';
// Get datatable
var dTable = getConfigDatatable(tableId);
@ -415,7 +409,7 @@ function loadTable(data) {
// Get table name
var tableName = tabId.replace('Tab', '');
// Get table ID
var tableId = tableName + 'DataTable';
var tableId = tableName + 'Datatable';
// Get datatable
var dTable = getConfigDatatable(tableId);
@ -489,6 +483,5 @@ function deleteRow(obj) {
* @return The number of occurrences
*/
String.prototype.count = function(char) {
return (this.length - this.replace(new RegExp(char, "g"), '').length)
/ char.length;
return (this.length - this.replace(new RegExp(char, "g"), '').length)/char.length;
};

View File

@ -1,5 +1,5 @@
$(document).ready(function(){
// Include utility script
// Include utility scripts
});
/**
@ -14,10 +14,10 @@ function loadInventory(data) {
}
/**
* Load the clone page
* Load clone page
*
* @param node
* Source node
* Source node to clone
* @return Nothing
*/
function loadClonePage(node) {
@ -25,7 +25,7 @@ function loadClonePage(node) {
}
/**
* Load zVM provision page
* Load provision page
*
* @param tabId
* The provision tab ID
@ -33,4 +33,13 @@ function loadClonePage(node) {
*/
function loadProvisionPage(tabId) {
}
/**
* Load resources
*
* @return Nothing
*/
function loadResources() {
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/**
* Global variables
*/
var diskDataTable; // zVM datatable containing disks
var networkDataTable; // zVM datatable containing networks
var diskDatatable; // zVM datatable containing disks
var networkDatatable; // zVM datatable containing networks
/**
* Get the disk datatable
@ -11,7 +11,7 @@ var networkDataTable; // zVM datatable containing networks
* @return Data table object
*/
function getDiskDataTable() {
return diskDataTable;
return diskDatatable;
}
/**
@ -22,7 +22,7 @@ function getDiskDataTable() {
* @return Nothing
*/
function setDiskDataTable(table) {
diskDataTable = table;
diskDatatable = table;
}
/**
@ -32,7 +32,7 @@ function setDiskDataTable(table) {
* @return Data table object
*/
function getNetworkDataTable() {
return networkDataTable;
return networkDatatable;
}
/**
@ -43,7 +43,7 @@ function getNetworkDataTable() {
* @return Nothing
*/
function setNetworkDataTable(table) {
networkDataTable = table;
networkDatatable = table;
}
/**
@ -115,7 +115,9 @@ function loadUserEntry(data) {
cancelBtn.show();
});
// Save button
/**
* Save
*/
var saveBtn = createButton('Save');
saveBtn.hide();
saveBtn.bind('click', function(event) {
@ -144,7 +146,7 @@ function loadUserEntry(data) {
});
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
txtArea.attr('readonly', 'readonly');
txtArea.css( {
@ -158,7 +160,9 @@ function loadUserEntry(data) {
cancelBtn.hide();
});
// Cancel button
/**
* Cancel
*/
var cancelBtn = createButton('Cancel');
cancelBtn.hide();
cancelBtn.bind('click', function(event) {
@ -188,20 +192,20 @@ function loadUserEntry(data) {
* Node to set cookie for
* @return Nothing
*/
function incrementZNodeProcess(node) {
function incrementNodeProcess(node) {
// Set cookie for number actions performed against node
var actions = $.cookie(node + 'Processes');
if (actions) {
var procs = $.cookie(node + 'Processes');
if (procs) {
// One more process
actions = parseInt(actions) + 1;
$.cookie(node + 'Processes', actions);
procs = parseInt(procs) + 1;
$.cookie(node + 'Processes', procs);
} else {
$.cookie(node + 'Processes', 1);
}
}
/**
* Update the provision status bar
* Update the provision status
*
* @param data
* Data returned from HTTP request
@ -235,10 +239,9 @@ function updateProvisionStatus(data) {
var osImage = $('#' + tabId + ' input[name=os]').val();
/**
* 2. Update /etc/hosts
* (2) Update /etc/hosts
*/
if (cmd == 'nodeadd') {
// If no output, no errors occurred
if (rsp.length) {
$('#' + statBarId).append(
@ -264,7 +267,7 @@ function updateProvisionStatus(data) {
}
/**
* 3. Update DNS
* (3) Update DNS
*/
else if (cmd == 'makehosts') {
// If no output, no errors occurred
@ -291,7 +294,7 @@ function updateProvisionStatus(data) {
}
/**
* 4. Create user entry
* (4) Create user entry
*/
else if (cmd == 'makedns') {
// Reset the number of tries
@ -325,7 +328,7 @@ function updateProvisionStatus(data) {
}
/**
* 5. Add disk and format disk
* (5) Add disk
*/
else if (cmd == 'mkvm') {
var failed = false;
@ -383,14 +386,12 @@ function updateProvisionStatus(data) {
}
// If there were no errors
else {
// Reset the number of tries
$.cookie('tries4' + tabId, 0);
// Set cookie for number of disks
var diskRows = $('#' + tabId + ' table tr');
$.cookie('zProvisionDisks2Add' + out2Id, diskRows.length);
if (diskRows.length > 0) {
for ( var i = 0; i < diskRows.length; i++) {
var diskArgs = diskRows.eq(i).find('td');
@ -431,7 +432,7 @@ function updateProvisionStatus(data) {
}
/**
* 6. Set the operating system for given node
* (6) Set the operating system for given node
*/
else if (cmd == 'chvm') {
var failed = false;
@ -550,7 +551,7 @@ function updateProvisionStatus(data) {
}
/**
* 7. Update DHCP
* (7) Update DHCP
*/
else if (cmd == 'noderes') {
// If no output, no errors occurred
@ -578,7 +579,7 @@ function updateProvisionStatus(data) {
}
/**
* 8. Prepare node for boot
* (8) Prepare node for boot
*/
else if (cmd == 'makedhcp') {
var failed = false;
@ -619,7 +620,7 @@ function updateProvisionStatus(data) {
}
/**
* 9. Boot node from network
* (9) Boot node to network
*/
else if (cmd == 'nodeset') {
var failed = false;
@ -667,7 +668,7 @@ function updateProvisionStatus(data) {
}
/**
* 10. Done
* (10) Done
*/
else if (cmd == 'rnetboot') {
var failed = false;
@ -705,7 +706,7 @@ function updateProvisionStatus(data) {
}
/**
* Update node status bar
* Update zVM node status
*
* @param data
* Data returned from HTTP request
@ -720,13 +721,14 @@ function updateZNodeStatus(data) {
// One less process
actions = actions - 1;
$.cookie(node + 'Processes', actions);
if (actions < 1) {
// Hide loader when there are no more processes
var statusBarLoaderId = node + 'StatusBarLoader';
$('#' + statusBarLoaderId).hide();
}
var statusId = node + 'StatusBar';
var statBarId = node + 'StatusBar';
var failed = false;
// Separate output into lines
@ -746,11 +748,11 @@ function updateZNodeStatus(data) {
}
}
$('#' + statusId).append(p);
$('#' + statBarId).append(p);
}
/**
* Update the clone status bar
* Update the clone status
*
* @param data
* Data returned from HTTP request
@ -766,7 +768,7 @@ function updateCloneStatus(data) {
var out2Id = args[2].replace('out=', '');
/**
* 2. Update /etc/hosts
* (2) Update /etc/hosts
*/
if (cmd == 'nodeadd') {
var node = args[3].replace('node=', '');
@ -800,7 +802,7 @@ function updateCloneStatus(data) {
}
/**
* 3. Update DNS
* (3) Update DNS
*/
else if (cmd == 'makehosts') {
// If no output, no errors occurred
@ -827,7 +829,7 @@ function updateCloneStatus(data) {
}
/**
* 4. Clone
* (4) Clone
*/
else if (cmd == 'makedns') {
// Separate output into lines
@ -841,6 +843,8 @@ function updateCloneStatus(data) {
$('#' + out2Id).append(p);
// The tab must be opened for this to work
// Get clone tab
var tabId = out2Id.replace('CloneStatusBar', 'CloneTab');
@ -849,6 +853,7 @@ function updateCloneStatus(data) {
var tgtNodes = '';
if (tgtNodeRange.indexOf('-') > -1) {
var tmp = tgtNodeRange.split('-');
// Get node base name
var nodeBase = tmp[0].match(/[a-zA-Z]+/);
// Get the starting index
@ -867,9 +872,7 @@ function updateCloneStatus(data) {
} else {
tgtNodes = tgtNodeRange;
}
// The tab must be opened for this to work
// Get other inputs
var srcNode = $('#' + tabId + ' input[name=srcNode]').val();
hcp = $('#' + tabId + ' input[name=newHcp]').val();
@ -896,7 +899,7 @@ function updateCloneStatus(data) {
}
/**
* 5. Done
* (5) Done
*/
else if (cmd == 'mkvm') {
var failed = false;
@ -924,14 +927,14 @@ function updateCloneStatus(data) {
}
/**
* Get the resources
* Get zVM resources
*
* @param data
* Data from HTTP request
* @return Nothing
*/
function getZResources(data) {
// Do not set cookie if there is no output
// Do not continue if there is no output
if (data.rsp) {
// Loop through each line
var node, hcp;
@ -1007,7 +1010,6 @@ function getNodeAttrs(keys, propNames, data) {
// Loop through property keys
// Does this line contains one of the properties?
for ( var j = 0; j < keys.length; j++) {
// Find property name
if (data[i].indexOf(propNames[keys[j]]) > -1) {
attrs[keys[j]] = new Array();
@ -1073,7 +1075,7 @@ function addProcessor(v, m, f) {
});
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';
@ -1122,7 +1124,7 @@ function addDisk(v, m, f) {
});
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';
@ -1200,7 +1202,7 @@ function addNic(v, m, f) {
}
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';
@ -1235,7 +1237,7 @@ function removeProcessor(node, address) {
});
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';
@ -1269,7 +1271,7 @@ function removeDisk(node, address) {
});
// Increment node process and save it in a cookie
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';
@ -1306,7 +1308,7 @@ function removeNic(node, nic) {
});
// Set cookie for number actions performed against node
incrementZNodeProcess(node);
incrementNodeProcess(node);
// Show loader
var statusId = node + 'StatusBar';

View File

@ -203,7 +203,7 @@ function loadNodes(data) {
// Load the plugin code
// Plugin code should be located under js/custom/
// Plugin names should be valid values of mgt
// Plugin names should be valid values of nodehm.mgt
for ( var p in plugins) {
resetJs();
includeJs("js/custom/" + p + ".js");
@ -858,14 +858,14 @@ function loadNodesetPage(trgtNodes) {
var nodesetForm = $('<div class="form"></div>');
// Create status bar
var barId = 'nodesetStatusBar' + inst;
var statusBar = createStatusBar(barId);
statusBar.hide();
nodesetForm.append(statusBar);
var statBarId = 'nodesetStatusBar' + inst;
var statBar = createStatusBar(statBarId);
statBar.hide();
nodesetForm.append(statBar);
// Create loader
var loader = createLoader('nodesetLoader');
statusBar.append(loader);
statBar.append(loader);
// Create info bar
var infoBar = createInfoBar('Set the boot state for a node range');
@ -997,7 +997,7 @@ function loadNodesetPage(trgtNodes) {
});
/**
* 1. Set the OS, arch, and profile
* (1) Set the OS, arch, and profile
*/
$.ajax( {
url : 'lib/cmd.php',
@ -1015,7 +1015,7 @@ function loadNodesetPage(trgtNodes) {
});
// Show status bar
statusBar.show();
statBar.show();
} else {
alert('You are missing some values');
}
@ -1174,7 +1174,7 @@ function loadNetbootPage(tgtNodes) {
});
/**
* 1. Boot to network
* (1) Boot to network
*/
$.ajax( {
url : 'lib/cmd.php',
@ -1431,7 +1431,7 @@ function loadUpdatenodePage(tgtNodes) {
});
/**
* 1. Boot to network
* (1) Boot to network
*/
$.ajax( {
url : 'lib/cmd.php',
@ -1455,7 +1455,7 @@ function loadUpdatenodePage(tgtNodes) {
updatenodeForm.append(okBtn);
// Append to discover tab
tab.add(newTabId, 'updatenode', updatenodeForm);
tab.add(newTabId, 'Updatenode', updatenodeForm);
// Select new tab
tab.select(newTabId);
@ -1625,7 +1625,7 @@ function updateNodesetStatus(data) {
var method = $('#' + tabId + ' select[id=bootMethod]').val();
/**
* 2. Update /etc/hosts
* (2) Update /etc/hosts
*/
if (cmd == 'nodeadd') {
// If no output, no errors occurred
@ -1682,7 +1682,7 @@ function updateNodesetStatus(data) {
}
/**
* 4. Update DNS
* (4) Update DNS
*/
else if (cmd == 'makehosts') {
// If no output, no errors occurred
@ -1709,7 +1709,7 @@ function updateNodesetStatus(data) {
}
/**
* 5. Update DHCP
* (5) Update DHCP
*/
else if (cmd == 'makedns') {
// Separate output into lines
@ -1739,7 +1739,7 @@ function updateNodesetStatus(data) {
}
/**
* 6. Prepare node for boot
* (6) Prepare node for boot
*/
else if (cmd == 'makedhcp') {
var failed = false;
@ -1780,7 +1780,7 @@ function updateNodesetStatus(data) {
}
/**
* 7. Boot node from network
* (7) Boot node from network
*/
else if (cmd == 'nodeset') {
var tgtsArray = tgts.split(',');
@ -1808,7 +1808,7 @@ function updateNodesetStatus(data) {
}
/**
* Update the status bar
* Update the status bar of a given tab
*
* @param data
* Data returned from HTTP request
@ -1848,8 +1848,7 @@ function updateStatusBar(data) {
for ( var i = 0; i < rsp.length; i++) {
if (rsp[i]) {
// Determine if the command failed
if (rsp[i].indexOf("Error") > -1
|| rsp[i].indexOf("Failed") > -1) {
if (rsp[i].indexOf("Error") > -1 || rsp[i].indexOf("Failed") > -1) {
failed = true;
}
@ -1886,8 +1885,7 @@ function updateStatusBar(data) {
if (rsp[i]) {
// Find the node name and insert a break before it
for ( var j = 0; j < tgts.length; j++) {
rsp[i] = rsp[i].replace(new RegExp(tgts[j], 'g'),
'<br>' + tgts[j]);
rsp[i] = rsp[i].replace(new RegExp(tgts[j], 'g'), '<br>' + tgts[j]);
}
p.append(rsp[i]);
@ -1900,7 +1898,7 @@ function updateStatusBar(data) {
}
/**
* Check the completeness of the form
* Check if the form is complete
*
* @param tabId
* Tab ID containing form
@ -1915,6 +1913,7 @@ function formComplete(tabId) {
// If there is no value given in the input
if (!inputs.eq(i).val()) {
inputs.eq(i).css('border', 'solid #FF0000 1px');
// It is not complete
ready = false;
} else {
@ -1926,7 +1925,7 @@ function formComplete(tabId) {
}
/**
* Update the power status of the node
* Update the power status of a node in the datatable
*
* @param data
* Data from HTTP request

View File

@ -99,6 +99,7 @@ function loadProvisionPage() {
tab.add(newTabId, hw, '');
// Load plugin code
resetJs();
includeJs("js/custom/" + hw + ".js");
// Select tab

View File

@ -111,7 +111,7 @@ function submit_request($req, $skipVerify){
* $key
* @return
*/
function xorcrypt($data,$key) {
function xorcrypt($data, $key) {
$datalen = strlen($data);
$keylen = strlen($key);
for ($i=0;$i<$datalen;$i++) {
@ -142,7 +142,7 @@ function getpassword() {
/**
* Get the password splitting knowledge between server
* and client side persistant storage. Caller should regenerate
* session id when contemplating a new user/password, to preclude
* session ID when contemplating a new user/password, to preclude
* session fixation, though fixation is limited without the secret.
*
* @param $password Password
@ -161,7 +161,7 @@ function setpassword($password) {
}
/**
* Get RAND characters.
* Get RAND characters
*
* @param $length Length of characters
* @return RAND characters

View File

@ -95,7 +95,7 @@ if (isset($_GET["cmd"])) {
}
}
// Unlock virtual server
// Run shell script
// This is a typical command used by all platforms. It is put here because
// most of the code needed are already here
else if (strncasecmp($cmd, "xdsh", 4) == 0) {