/** * Execute when the DOM is fully loaded */ $(document).ready(function() { // Load utility scripts }); /** * Constructor * * @return Nothing */ var hmcPlugin = function() { }; /** * Load node inventory * * @param data * Data from HTTP request * @return Nothing */ hmcPlugin.prototype.loadInventory = function(data) { // Get arguments var args = data.msg.split(','); // Get tab ID var tabId = args[0].replace('out=', ''); // Get node var node = args[1].replace('node=', ''); // Get node inventory var inv = data.rsp; // Remove loader $('#' + tabId).find('img').remove(); // Create division to hold inventory var invDivId = tabId + 'Inventory'; var invDiv = $('
'); // Loop through each line var fieldSet, legend, oList, item; for (var k = 0; k < inv.length; k++) { // Remove node name in front var str = inv[k].replace(node + ': ', ''); str = jQuery.trim(str); // If string is a header if (str.indexOf('I/O Bus Information') > -1 || str.indexOf('Machine Configuration Info') > -1) { // Create a fieldset fieldSet = $('
'); legend = $('' + str + ''); fieldSet.append(legend); oList = $('
    '); fieldSet.append(oList); invDiv.append(fieldSet); } else { // If no fieldset is defined if (!fieldSet) { // Define general fieldset fieldSet = $('
    '); legend = $('General'); fieldSet.append(legend); oList = $('
      '); fieldSet.append(oList); invDiv.append(fieldSet); } // Append the string to a list item = $('
    1. '); item.append(str); oList.append(item); } } // Append to inventory form $('#' + tabId).append(invDiv); }; /** * Load clone page * * @param node * Source node to clone * @return Nothing */ hmcPlugin.prototype.loadClonePage = function(node) { // Get nodes tab var tab = getNodesTab(); var newTabId = node + 'CloneTab'; // If there is no existing clone tab if (!$('#' + newTabId).length) { // Create status bar and hide it var statBarId = node + 'CloneStatusBar'; var statBar = $('
      ').hide(); // Create info bar var infoBar = createInfoBar('Under construction'); // Create clone form var cloneForm = $('
      '); cloneForm.append(statBar); cloneForm.append(infoBar); // Add clone tab tab.add(newTabId, 'Clone', cloneForm, true); } tab.select(newTabId); }; /** * Load provision page * * @param tabId * The provision tab ID * @return Nothing */ hmcPlugin.prototype.loadProvisionPage = function(tabId) { // Create provision form var provForm = $('
      '); // Create info bar var infoBar = createInfoBar('Provision a node on System p.'); provForm.append(infoBar); // Append to provision tab $('#' + tabId).append(provForm); /** * Create provision new node division */ // You should copy whatever is in this function, put it here, and customize it createProvision('hmc', provForm); }; /** * Load resources * * @return Nothing */ hmcPlugin.prototype.loadResources = function() { // Get resource tab ID var tabId = 'hmcResourceTab'; // Remove loader $('#' + tabId).find('img').remove(); // Create info bar var infoBar = createInfoBar('Under construction'); // Create resource form var resrcForm = $('
      '); resrcForm.append(infoBar); $('#' + tabId).append(resrcForm); }; /** * Add node range * * @return Nothing */ hmcPlugin.prototype.addNode = function() { var diaDiv = $('
      '); diaDiv.append('
      '); diaDiv.append('
      '); // Show the dialog diaDiv.dialog({ modal : true, width : 400, title : 'Add System p Node', close : function(){$('#addpnodeDiv').remove();} }); // Bind the select change event $('#pnodetype').bind('change', function() { $('#pnodeeditarea').empty(); if ('HMC' == $(this).val()) { $('#addpnodeDiv').dialog('option', 'width', '400'); $('#pnodeeditarea').append('

      ' + '
      '); $('#addpnodeDiv').dialog('option', 'buttons', {'Add': function(){addHmcNode();}, 'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); } else { //add loader image and delete buttons $('#pnodeeditarea').append(createLoader()); $('#addpnodeDiv').dialog('option', 'buttons', {'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); $('#addpnodeDiv').dialog('option', 'width', '650'); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodels', tgt : 'all', args : 'ppc.nodetype==hmc', msg : '' }, success : function(data) { $('#pnodeeditarea img').remove(); drawHmcSelector(data.rsp); } }); } }); // Trigger the select change event $('#pnodetype').trigger('change'); }; /** * Add HMCs into the dialog * * @param hmc * HMCs * @return Nothing */ function drawHmcSelector(hmcs){ if (1 > hmcs.length) { $('#pnodeeditarea').append(createWarnBar('Please define HMC node first.')); return; } // Add HMCs into a selector and add a scan button var hmcoption = ''; var scanbutton = createButton('Scan'); for (var i in hmcs) { hmcoption += ''; } $('#pnodeeditarea').append(''); $('#pnodeeditarea').append(scanbutton); scanbutton.bind('click', function() { var hmcname = $('#pnodeeditarea select').val(); $('#pnodeeditarea').append(createLoader()); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rscan', tgt : hmcname, args : '', msg : '' }, success : function(data) { $('#pnodeeditarea img').remove(); // Draw a table with checkbox drawRscanResult(data.rsp[0]); // Add the add button $('#addpnodeDiv').dialog('option', 'buttons', {'Add': function(){addPNode();}, 'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); } }); }); } function drawRscanResult(rscanresult){ var line = ''; var tempreg = /\S+/g; var idpreg = /^\d+$/; var resultDiv = $('
      '); var rscantable = $('
      '); var temprow = ''; var colnum = 0; var fields = 0; $('#pnodeeditarea div').remove(); if (!rscanresult) { return; } var rows = rscanresult.split("\n"); if (rows.length < 2) { return; } // Add the table header fields = rows[0].match(tempreg); colnum = fields.length; temprow = ''; for(var i in fields) { temprow += '' + fields[i] + ''; } rscantable.append(temprow); // Add the tbody for (var i = 1; i < rows.length; i++) { line = rows[i]; if (!line) { continue; } var fields = line.match(tempreg); if ('hmc' == fields[0]) { continue; } // May be the 3rd field(id) is empty, so we should add the new if (!idpreg.test(fields[2])){ fields = [fields[0], fields[1], ''].concat(fields.slice(2)); } temprow = ''; for(var j = 0; j < colnum; j++) { temprow += ''; if (fields[j]) { temprow += fields[j]; } temprow += ''; } temprow += ''; rscantable.append(temprow); } resultDiv.append(rscantable); $('#pnodeeditarea').append(resultDiv); } /** * Add hmc node * * @return Nothing */ function addHmcNode(){ var errorinfo = ''; var args = ''; $('#pnodeeditarea input').each(function(){ if (!$(this).val()){ errorinfo = 'You are missing some inputs!'; } args += $(this).val() + ','; }); if (errorinfo){ // Add warning message alert(errorinfo); return; } // Disabled the button $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); args = args.substr(0, args.length - 1); $('#pnodeeditarea').append(createLoader()); // Send the save HMC request $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'addpnode;hmc;' + args, msg : '' }, success : function(data){ // Refresh the area on the right side $('#addpnodeDiv').dialog('close'); $('.selectgroup').trigger('click'); } }); } /** * Add System p node, contains frame, cec, lpar * * @return Nothing */ function addPNode(){ // Get the HMC name var hmcname = $('#pnodeeditarea select').val(); var nodename = ''; // Get checked nodes $('#pnodeeditarea :checked').each(function() { if ($(this).attr('name')) { nodename += $(this).attr('name') + ','; } }); if (!nodename) { alert('You should select nodes first!'); return; } // Disabled the button $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); nodename = nodename.substr(0, nodename.length - 1); $('#pnodeeditarea').append(createLoader()); // Send the add request $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'addpnode;node;' + hmcname + ',' + nodename, msg : '' }, success : function(data) { // Refresh the area on the right side $('#addpnodeDiv').dialog('close'); $('.selectgroup').trigger('click'); } }); } /** * Select all checkbox in a table * * @return Nothing */ function selectAllRscanNode(obj){ var status = $(obj).attr('checked'); $(obj).parents('table').find(':checkbox').attr('checked', status); }