From 081e69e313518c218be84e335ab8f03b7fd0f541 Mon Sep 17 00:00:00 2001 From: phamt Date: Tue, 27 Jul 2010 22:56:42 +0000 Subject: [PATCH] Added writeRsp() method to ui.js to write ajax response to status bar. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6883 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/custom/zvmUtils.js | 319 +++++++++------------------------- xCAT-UI/js/nodes/nodes.js | 119 +++---------- xCAT-UI/js/ui.js | 12 +- 3 files changed, 111 insertions(+), 339 deletions(-) diff --git a/xCAT-UI/js/custom/zvmUtils.js b/xCAT-UI/js/custom/zvmUtils.js index 096a6f7c4..b242c9792 100644 --- a/xCAT-UI/js/custom/zvmUtils.js +++ b/xCAT-UI/js/custom/zvmUtils.js @@ -212,6 +212,7 @@ function incrementNodeProcess(node) { * @return Nothing */ function updateProvisionNewStatus(data) { + // Get ajax response var rsp = data.rsp; var args = data.msg.split(';'); @@ -219,12 +220,10 @@ function updateProvisionNewStatus(data) { var cmd = args[0].replace('cmd=', ''); // Get output ID var out2Id = args[1].replace('out=', ''); - + // Get status bar and provision tab ID var statBarId = 'zProvisionStatBar' + out2Id; var tabId = 'zvmProvisionTab' + out2Id; - // The tab must be open in order to get these inputs - // Get node name var node = $('#' + tabId + ' input[name=nodeName]').val(); // Get userId @@ -244,11 +243,9 @@ function updateProvisionNewStatus(data) { if (cmd == 'nodeadd') { // If no output, no errors occurred if (rsp.length) { - $('#' + statBarId).append( - '

(Error) Failed to create node definition

'); + $('#' + statBarId).append('

(Error) Failed to create node definition

'); } else { - $('#' + statBarId).append( - '

Node definition created for ' + node + '

'); + $('#' + statBarId).append('

Node definition created for ' + node + '

'); } // Update /etc/hosts @@ -300,16 +297,9 @@ function updateProvisionNewStatus(data) { // Reset the number of tries $.cookie('tries4' + tabId, 0); - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + statBarId).append(p); + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); // Create user entry $.ajax( { @@ -331,30 +321,16 @@ function updateProvisionNewStatus(data) { * (5) Add disk */ else if (cmd == 'mkvm') { - var failed = false; + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); - - // If the call failed - if (failed) { + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { + var loaderId = 'zProvisionLoader' + inst; + $('#' + loaderId).remove(); + // Try again (at least 2 times) var tries = parseInt($.cookie('tries4' + tabId)); if (tries < 2) { @@ -435,30 +411,16 @@ function updateProvisionNewStatus(data) { * (6) Set the operating system for given node */ else if (cmd == 'chvm') { - var failed = false; + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { + var loaderId = 'zProvisionLoader' + inst; + $('#' + loaderId).remove(); - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); - - // If the call failed - if (failed) { // Try again (at least 2 times) var tries = parseInt($.cookie('tries4' + tabId)); if (tries < 2) { @@ -501,7 +463,6 @@ function updateProvisionNewStatus(data) { $('#' + loaderId).hide(); } } else { - // Failed - Do not continue var loaderId = 'zProvisionLoader' + out2Id; $('#' + loaderId).remove(); } @@ -584,26 +545,10 @@ function updateProvisionNewStatus(data) { else if (cmd == 'makedhcp') { var failed = false; - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); - + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); + // Prepare node for boot $.ajax( { url : 'lib/cmd.php', @@ -625,31 +570,16 @@ function updateProvisionNewStatus(data) { else if (cmd == 'nodeset') { var failed = false; - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); - - // If the call failed - if (failed) { - // Failed - Do not continue + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); + + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { var loaderId = 'zProvisionLoader' + out2Id; $('#' + loaderId).remove(); + failed = true; } else { // Boot node from network $.ajax( { @@ -673,31 +603,18 @@ function updateProvisionNewStatus(data) { else if (cmd == 'rnetboot') { var failed = false; - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); - - // If the call was successful - if (!failed) { - $('#' + statBarId) - .append( - '

Open a VNC viewer to see the installation progress. It might take a couple of minutes before you can connect.

'); + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { + var loaderId = 'zProvisionLoader' + out2Id; + $('#' + loaderId).remove(); + failed = true; + } else { + $('#' + statBarId).append('

Open a VNC viewer to see the installation progress. It might take a couple of minutes before you can connect.

'); } // Hide loader @@ -729,7 +646,7 @@ function updateProvisionExistingStatus(data) { /** * (2) Prepare node for boot */ - if (cmd == 'chtab') { + if (cmd == 'nodeadd') { // Get operating system var bootMethod = $('#' + tabId + ' select[name=bootMethod]').val(); @@ -757,7 +674,7 @@ function updateProvisionExistingStatus(data) { */ else if (cmd == 'nodeset') { // Write ajax response to status bar - var prg = writeRsp(rsp); + var prg = writeRsp(rsp, ''); $('#' + statBarId).append(prg); // If there was an error @@ -765,6 +682,7 @@ function updateProvisionExistingStatus(data) { if (prg.html().indexOf('Error') > -1) { var loaderId = 'zProvisionLoader' + inst; $('#' + loaderId).remove(); + return; } // Get nodes that were checked @@ -791,7 +709,7 @@ function updateProvisionExistingStatus(data) { */ else if (cmd == 'rnetboot') { // Write ajax response to status bar - var prg = writeRsp(rsp); + var prg = writeRsp(rsp, ''); $('#' + statBarId).append(prg); var loaderId = 'zProvisionLoader' + inst; @@ -823,26 +741,10 @@ function updateZNodeStatus(data) { } var statBarId = node + 'StatusBar'; - var failed = false; - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); + + // Write ajax response to status bar + var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); + $('#' + statBarId).append(prg); } /** @@ -926,19 +828,10 @@ function updateCloneStatus(data) { * (4) Clone */ else if (cmd == 'makedns') { - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + out2Id).append(p); - - // The tab must be opened for this to work - + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + out2Id).append(prg); + // Get clone tab var tabId = out2Id.replace('CloneStatusBar', 'CloneTab'); @@ -996,25 +889,10 @@ function updateCloneStatus(data) { * (5) Done */ else if (cmd == 'mkvm') { - var failed = false; - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + out2Id).append(p); - + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + out2Id).append(prg); + // Hide loader $('#' + out2Id).find('img').hide(); } @@ -1657,27 +1535,11 @@ function connect2GuestLan(data) { var lanOwner = args[3].replace('owner=', ''); var statusId = node + 'StatusBar'; - var failed = false; - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statusId).append(p); - + + // Write ajax response to status bar + var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); + $('#' + statBarId).append(prg); + // Connect NIC to Guest LAN $.ajax( { url : 'lib/cmd.php', @@ -1708,27 +1570,11 @@ function connect2VSwitch(data) { var address = args[1].replace('addr=', ''); var vswitchName = args[2].replace('vsw=', ''); - var statusId = node + 'StatusBar'; - var failed = false; - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statusId).append(p); + var statBarId = node + 'StatusBar'; + + // Write ajax response to status bar + var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); + $('#' + statBarId).append(prg); // Connect NIC to VSwitch $.ajax( { @@ -1778,11 +1624,7 @@ function createZProvisionExisting(inst) { group.append(groupSelect); // Create node datatable - groupSelect.change(function(){ - // Create loader - var loader = createLoader(''); - $('nodesDatatableDIV' + inst).append(loader); - + groupSelect.change(function(){ // Get group selected var thisGroup = $(this).val(); // If a valid group is selected @@ -1816,10 +1658,7 @@ function createZProvisionExisting(inst) { var attrs = new Object(); // Node attributes var headers = new Object(); - - // Remove loader - $('#' + outId).find('img').remove(); - + // Clear nodes datatable division $('#' + outId).children().remove(); @@ -1901,7 +1740,7 @@ function createZProvisionExisting(inst) { // Create node input var node = $('
'); var nodeLabel = $(''); - var nodeDatatable = $('
'); + var nodeDatatable = $('

Select a group to view its nodes

'); node.append(nodeLabel); node.append(nodeDatatable); provExisting.append(node); @@ -2001,9 +1840,9 @@ function createZProvisionExisting(inst) { dataType : 'json', data : { cmd : 'nodeadd', - tgt : tgts, - args : 'noderes.netboot=zvm;nodetype.os=' + os + ';nodetype.arch=' + arch + ';nodetype.profile=' + profile, - msg : 'cmd=chtab;out=' + inst + tgt : '', + args : tgts + ';noderes.netboot=zvm;nodetype.os=' + os + ';nodetype.arch=' + arch + ';nodetype.profile=' + profile, + msg : 'cmd=nodeadd;out=' + inst }, success : updateProvisionExistingStatus diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index b8029e1f7..88d472087 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -1738,17 +1738,10 @@ function updateNodesetStatus(data) { * (5) Update DHCP */ else if (cmd == 'makedns') { - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + statBarId).append(p); - + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); + // Update DHCP $.ajax( { url : 'lib/cmd.php', @@ -1768,27 +1761,9 @@ function updateNodesetStatus(data) { * (6) Prepare node for boot */ else if (cmd == 'makedhcp') { - var failed = false; - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - rsp[i] = rsp[i].replace(new RegExp(node + ': ', 'g'), '
'); - - p.append(rsp[i]); - p.append('
'); - - // If the call failed - if (rsp[i].indexOf('Failed') > -1 - || rsp[i].indexOf('Error') > -1) { - failed = true; - } - } - } - - $('#' + statBarId).append(p); + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); // Prepare node for boot $.ajax( { @@ -1809,24 +1784,9 @@ function updateNodesetStatus(data) { * (7) Boot node from network */ else if (cmd == 'nodeset') { - var tgtsArray = tgts.split(','); - - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - // Find the node name and insert a break before it - for ( var j = 0; j < tgtsArray.length; j++) { - rsp[i] = rsp[i].replace(new RegExp(tgtsArray[j], 'g'), - '
' + tgtsArray[j]); - } - - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + statBarId).append(p); + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); // Hide loader $('#' + statBarId).find('img').hide(); @@ -1851,16 +1811,9 @@ function updateStatusBar(data) { // Hide loader $('#' + statBarId).find('img').hide(); - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - if (rsp[i]) { - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + statBarId).append(p); + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); } else if (cmd == 'rmvm') { // Get data table var dTable = getNodesDataTable(); @@ -1869,28 +1822,16 @@ function updateStatusBar(data) { // Hide loader $('#' + statBarId).find('img').hide(); - // Separate output into lines - var p = $('

'); - 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) { - failed = true; - } - - // 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'), - '
'); - } - - p.append(rsp[i]); - p.append('
'); - } + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).append(prg); + + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { + failed = true; } - $('#' + statBarId).append(p); - // Update data table var rows = dTable.fnGetNodes(); for ( var i = 0; i < tgts.length; i++) { @@ -1905,21 +1846,9 @@ function updateStatusBar(data) { // Hide loader $('#' + statBarId).find('img').hide(); - // Separate output into lines - var p = $('

'); - for ( var i = 0; i < rsp.length; i++) { - 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'), '
' + tgts[j]); - } - - p.append(rsp[i]); - p.append('
'); - } - } - - $('#' + statBarId).append(p); + // Write ajax response to status bar + var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); + $('#' + statBarId).append(prg); } } diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index 2e91d17ae..552147d9a 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -471,15 +471,19 @@ function includeJs(file) { * * @param rsp * Ajax response - * @param replace - * Boolean to replace the node name in front of each line + * @param pattern + * Pattern to insert a break in between * @return Paragraph containing ajax response */ -function writeRsp(rsp) { +function writeRsp(rsp, pattern) { // Create paragraph to hold ajax response var prg = $('

'); for ( var i in rsp) { - if (rsp[i]) { + if (rsp[i]) { + if (pattern) { + rsp[i] = rsp[i].replace(new RegExp(pattern, 'g'), '
'); + } + prg.append(rsp[i]); prg.append('
'); }