/** * Global variables */ var nodesTabs; // Node tabs var origAttrs = new Object(); // Original node attributes var defAttrs; // Definable node attributes /** * Set the nodes tab * * @param obj * Tab object * @return Nothing */ function setNodesTab(obj) { nodesTabs = obj; } /** * Get the nodes tab * * @param Nothing * @return Tab object */ function getNodesTab() { return nodesTabs; } /** * Load nodes page * * @return Nothing */ function loadNodesPage() { // If groups are not already loaded if (!$('#groups').length) { // Create a groups division var groups = $('
'); var nodes = $('
'); $('#content').append(groups); $('#content').append(nodes); // Create loader var loader = createLoader(); groups.append(loader); // Create info bar var info = createInfoBar('Select a group to view its nodes.'); $('#nodes').append(info); // Get groups $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'extnoderange', tgt : '/.*', args : 'subgroups', msg : '' }, success : loadGroups }); // Get graphical view info $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodels', tgt : 'all', args : 'nodetype.nodetype;ppc.parent;vpd.mtm;nodelist.status;nodehm.mgt', msg : '' }, success : extractGraphicalData }); } } /** * Load groups * * @param data * Data returned from HTTP request * @return */ function loadGroups(data) { // Remove loader $('#groups').find('img').remove(); // Save group in cookie var groups = data.rsp; setGroupsCookies(data); // Create a list of groups var ul = $(''); var item = $('
  • Groups

  • '); var subUL = $(''); ul.append(item); item.append(subUL); // Create a link for each group for (var i = groups.length; i--;) { var subItem = $('
  • '); var link = $('' + groups[i] + ''); subItem.append(link); subUL.append(subItem); } // Turn groups list into a tree $('#groups').append(ul); $('#groups').jstree( { core : { "initially_open" : [ "root" ] }, themes : { "theme" : "default", "dots" : false, // No dots "icons" : false // No icons } }); // Load nodes onclick $('#groups').bind('select_node.jstree', function(event, data) { // If there are subgroups, remove them data.rslt.obj.children('ul').remove(); var thisGroup = jQuery.trim(data.rslt.obj.text()); if (thisGroup) { // Clear nodes division $('#nodes').children().remove(); // Create loader var loader = $('
    ').append(createLoader()); var loader2 = $('
    ').append(createLoader()); // Create a tab for this group var tab = new Tab(); setNodesTab(tab); tab.init(); $('#nodes').append(tab.object()); tab.add('nodesTab', 'Nodes', loader, false); tab.add('graphTab', 'Graphical', loader2, false); // Get nodes within selected group $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : thisGroup, msg : thisGroup }, success : loadNodes }); // Get subgroups within selected group // only when this is the parent group and not a subgroup if (data.rslt.obj.attr('id').indexOf('Subgroup') < 0) { $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'extnoderange', tgt : thisGroup, args : 'subgroups', msg : thisGroup }, success : loadSubgroups }); } // Get physical layout $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : thisGroup + ';-s', msg : '' }, success : createPhysicalLayout }); } // End of if (thisGroup) }); // Create link to add nodes var addNodeLink = $('Add node'); addNodeLink.bind('click', function(event) { var info = createInfoBar('Select the hardware management for the new node range'); var addNodeForm = $('
    '); addNodeForm.append(info); addNodeForm.append('
    ' + '' + '
    ' ); // Create advanced link to set advanced node properties var advanced = $('
    '); var advancedLnk = $('Advanced').css('cursor', 'pointer'); advancedLnk.bind('click', function(event) { // Get definable node attributes $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : '-t;node;-h', msg : '' }, /** * Set definable node attributes and open dialog * * @param data * Data returned from HTTP request * @return Nothing */ success : function(data) { setDefAttrs(data); openSetPropsDialog(); } }); // Close dialog addNodeForm.dialog( "close" ); }); advanced.append(advancedLnk); addNodeForm.append(advanced); // Open dialog to add node addNodeForm.dialog({ modal: true, width: 400, buttons: { "Ok": function(){ // Get hardware management var mgt = $(this).find('select[name=mgt]').val(); var plugin; switch(mgt) { case "blade": plugin = new bladePlugin(); break; case "fsp": plugin = new fspPlugin(); break; case "hmc": plugin = new hmcPlugin(); break; case "ipmi": plugin = new ipmiPlugin(); break; case "ivm": plugin = new ivmPlugin(); break; case "zvm": plugin = new zvmPlugin(); break; } plugin.addNode(); $(this).dialog( "close" ); }, "Cancel": function(){ $(this).dialog( "close" ); } } }); }); // Generate tooltips addNodeLink.tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.7, predelay: 800 }); $('#groups').append(addNodeLink); } /** * Load subgroups belonging to a given group * * @param data * Data returned from HTTP request * @return Nothing */ function loadSubgroups(data) { // Data returned var rsp = data.rsp; // Group name var group = data.msg; // Go through each subgroup for (var i in rsp) { // Do not put the same group in the subgroup if (rsp[i] != group && $('#' + group).length) { // Add subgroup inside group $('#groups').jstree('create', $('#' + group), 'inside', { 'attr': {'id': rsp[i] + 'Subgroup'}, 'data': rsp[i]}, '', true); } } // End of for } /** * Load nodes belonging to a given group * * @param data * Data returned from HTTP request * @return Nothing */ function loadNodes(data) { // Data returned var rsp = data.rsp; // Group name var group = data.msg; // Node attributes hash var attrs = new Object(); // Node attributes var headers = new Object(); // Variable to send command and request node status var getNodeStatus = true; // Clear cookie containing list of nodes where their attributes need to be updated $.cookie('nodes2update', ''); // Clear hash table containing node attributes origAttrs = ''; var node; var args; for (var i in rsp) { // Get the node var pos = rsp[i].indexOf('Object name:'); if (pos > -1) { var temp = rsp[i].split(': '); node = jQuery.trim(temp[1]); // Create a hash for the node attributes attrs[node] = new Object(); i++; } // Get key and value args = rsp[i].split('=', 2); var key = jQuery.trim(args[0]); var val = jQuery.trim(rsp[i].substring(rsp[i].indexOf('=') + 1, rsp[i].length)); // Create a hash table attrs[node][key] = val; headers[key] = 1; // If the node status is available if (key == 'status') { // Do not send command to request node status getNodeStatus = false; } } // Save attributes in hash table origAttrs = attrs; // Sort headers var sorted = new Array(); for (var key in headers) { // Do not put comments and status in twice if (key != 'usercomment' && key != 'status' && key.indexOf('statustime') < 0) { sorted.push(key); } } sorted.sort(); // Add column for check box, node, ping, power, and comments sorted.unshift('', 'node', 'status', 'power', 'comments'); // Create a datatable var dTable = new DataTable('nodesDatatable'); dTable.init(sorted); // Go through each node for (var node in attrs) { // Create a row var row = new Array(); // Create a check box, node link, and get node status var checkBx = ''; var nodeLink = $('' + node + '').bind('click', loadNode); var status = ''; if (attrs[node]['status']){ status = attrs[node]['status'].replace('sshd', 'ping'); } // Push in checkbox, node link, status, and power row.push(checkBx, nodeLink, status, ''); // Put in comments var comment = attrs[node]['usercomment']; var iconSrc; // If no comments exists, show 'No comments' and set icon image source if (!comment) { comment = 'No comments'; iconSrc = 'images/ui-icon-no-comment.png'; } else { iconSrc = 'images/ui-icon-comment.png'; } // Create comments icon var tipID = node + 'Tip'; var icon = $('').css({ 'width': '18px', 'height': '18px' }); // Create tooltip var tip = createCommentsToolTip(comment); var col = $('').append(icon); col.append(tip); row.push(col); // Generate tooltips icon.tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.8, relative: true, delay: 500 }); // Go through each header for (var i = 5; i < sorted.length; i++) { // Add the node attributes to the row var key = sorted[i]; // Do not put comments and status in twice if (key != 'usercomment' && key != 'status' && key.indexOf('statustime') < 0) { var val = attrs[node][key]; if (val) { row.push(val); } else { row.push(''); } } } // Add the row to the table dTable.add(row); } // Clear the tab before inserting the table $('#nodesTab').children().remove(); // Create info bar for nodes tab var info = createInfoBar('Click on a cell to edit. Click outside the table to write to the cell. Hit the Escape key to ignore changes. Once you are satisfied with how the table looks, click on Save.'); $('#nodesTab').append(info); // Create action bar var actionBar = $('
    '); /** * The following actions are available to perform against a given node: * power, clone, delete, unlock, and advanced */ var powerLnk = $('Power'); // Power on var powerOnLnk = $('Power on'); powerOnLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { powerNode(tgtNodes, 'on'); } }); // Power off var powerOffLnk = $('Power off'); powerOffLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { powerNode(tgtNodes, 'off'); } }); // Clone var cloneLnk = $('Clone'); cloneLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable').split(','); for (var i in tgtNodes) { var mgt = getNodeAttr(tgtNodes[i], 'mgt'); // Create an instance of the plugin var plugin; switch(mgt) { case "blade": plugin = new bladePlugin(); break; case "fsp": plugin = new fspPlugin(); break; case "hmc": plugin = new hmcPlugin(); break; case "ipmi": plugin = new ipmiPlugin(); break; case "ivm": plugin = new ivmPlugin(); break; case "zvm": plugin = new zvmPlugin(); break; } plugin.loadClonePage(tgtNodes[i]); } }); // Delete var deleteLnk = $('Delete'); deleteLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadDeletePage(tgtNodes); } }); // Unlock var unlockLnk = $('Unlock'); unlockLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadUnlockPage(tgtNodes); } }); // Run script var scriptLnk = $('Run script'); scriptLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadScriptPage(tgtNodes); } }); // Update var updateLnk = $('Update'); updateLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadUpdatenodePage(tgtNodes); } }); // Set boot state var setBootStateLnk = $('Set boot state'); setBootStateLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadNodesetPage(tgtNodes); } }); // Boot to network var boot2NetworkLnk = $('Boot to network'); boot2NetworkLnk.bind('click', function(event) { var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadNetbootPage(tgtNodes); } }); // Remote console var rcons = $('Open console'); rcons.bind('click', function(event){ var tgtNodes = getNodesChecked('nodesDatatable'); if (tgtNodes) { loadRconsPage(tgtNodes); } }); // Edit properties var editProps = $('Edit properties'); editProps.bind('click', function(event){ var tgtNodes = getNodesChecked('nodesDatatable').split(','); for (var i in tgtNodes) { loadEditPropsPage(tgtNodes[i]); } }); // Power actions var powerActions = [ powerOnLnk, powerOffLnk ]; var powerActionMenu = createMenu(powerActions); // Advanced actions var advancedLnk = $('Advanced'); var advancedActions; if ('compute' == group) { advancedActions = [ boot2NetworkLnk, scriptLnk, setBootStateLnk, updateLnk, rcons, editProps ]; } else { advancedActions = [ boot2NetworkLnk, scriptLnk, setBootStateLnk, updateLnk, editProps ]; } var advancedActionMenu = createMenu(advancedActions); /** * Create an action menu */ var actionsDIV = $('
    '); var actions = [ [ powerLnk, powerActionMenu ], cloneLnk, deleteLnk, unlockLnk, [ advancedLnk, advancedActionMenu ] ]; var actionMenu = createMenu(actions); actionMenu.superfish(); actionsDIV.append(actionMenu); actionBar.append(actionsDIV); // Insert action bar and nodes datatable $('#nodesTab').append(actionBar); $('#nodesTab').append(dTable.object()); /** * Create menu to save and undo table changes */ // Save changes var saveLnk = $('Save'); saveLnk.bind('click', function(event){ updateNodeAttrs(group); }); // Undo changes var undoLnk = $('Undo'); undoLnk.bind('click', function(event){ restoreNodeAttrs(); }); // It will be hidden until a change is made var tableActionsMenu = createMenu([saveLnk, undoLnk]).hide(); tableActionsMenu.css('margin-left', '100px'); actionsDIV.append(tableActionsMenu); // Turn table into a datatable var myDataTable = $('#nodesDatatable').dataTable({ 'iDisplayLength': 50 }); /** * Change how datatable behaves */ // Do not sort ping, power, and comment column var pingCol = $('#nodesDatatable thead tr th').eq(2); var powerCol = $('#nodesDatatable thead tr th').eq(3); var commentCol = $('#nodesDatatable thead tr th').eq(4); pingCol.unbind('click'); powerCol.unbind('click'); commentCol.unbind('click'); // Create enough space for loader to be displayed $('#nodesDatatable tbody tr td:nth-child(3)').css('min-width', '60px'); $('#nodesDatatable tbody tr td:nth-child(4)').css('min-width', '60px'); // Center align power, ping, and comments $('#nodesDatatable tbody tr td:nth-child(3)').css('text-align', 'center'); $('#nodesDatatable tbody tr td:nth-child(4)').css('text-align', 'center'); $('#nodesDatatable tbody tr td:nth-child(5)').css('text-align', 'center'); // Instead refresh the node status and power status pingCol.find('span a').bind('click', function(event) { refreshNodeStatus(group); }); powerCol.find('span a').bind('click', function(event) { refreshPowerStatus(group); }); // Create tooltip for status var pingTip = createStatusToolTip(); pingCol.find('span').append(pingTip); pingCol.find('span a').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.8, relative: true, predelay: 800 }); // Create tooltip for power var powerTip = createPowerToolTip(); powerCol.find('span').append(powerTip); powerCol.find('span a').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.8, relative: true, predelay: 800 }); /** * Enable editable columns */ // Do not make 1st, 2nd, 3rd, 4th, or 5th column editable $('#nodesDatatable td:not(td:nth-child(1),td:nth-child(2),td:nth-child(3),td:nth-child(4),td:nth-child(5))').editable( function(value, settings) { // Change text color to red $(this).css('color', 'red'); // Get column index var colPos = this.cellIndex; // Get row index var dTable = $('#nodesDatatable').dataTable(); var rowPos = dTable.fnGetPosition(this.parentNode); // Update datatable dTable.fnUpdate(value, rowPos, colPos); // Get node name var node = $(this).parent().find('td a.node').text(); // Flag node to update flagNode2Update(node); // Show table menu actions tableActionsMenu.show(); return (value); }, { onblur : 'submit', // Clicking outside editable area submits changes type : 'textarea', placeholder: ' ', height : '30px' // The height of the text area }); /** * Get the node status and definable node attributes */ // If request to get node status is made if (getNodeStatus) { // Get node status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodestat', tgt : group, args : '-u', msg : '' }, success : loadNodeStatus }); } else { // Hide status loader var statCol = $('#nodesDatatable thead tr th').eq(2); statCol.find('img').hide(); } // Get definable node attributes $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : '-t;node;-h', msg : '' }, success : setDefAttrs }); /** * Additional ajax requests need to be made for zVM */ // Get index of HCP column var i = $.inArray('hcp', sorted); if (i) { // Get hardware control point var rows = dTable.object().find('tbody tr'); var hcps = new Object(); for (var j in rows) { var val = rows.eq(j).find('td').eq(i).html(); hcps[val] = 1; } var args; for (var h in hcps) { // Get node without domain name args = h.split('.'); // If there is no disk pool or network names cookie for this zHCP if (!$.cookie(args[0] + 'diskpools') || !$.cookie(args[0] + 'networks')) { // Check if SMAPI is online $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsvm', tgt : args[0], args : '', msg : 'group=' + group + ';hcp=' + args[0] }, // Load hardware control point (HCP) specific info // Get disk pools and network names success : loadHcpInfo }); } } // End of for } // End of if } /** * Load power status for each node * * @param data * Data returned from HTTP request * @return Nothing */ function loadPowerStatus(data) { // Get datatable var dTable = $('#nodesDatatable').dataTable(); var power = data.rsp; var rowPos, node, status, args; for (var i in power) { // power[0] = nodeName and power[1] = state args = power[i].split(':'); node = jQuery.trim(args[0]); status = jQuery.trim(args[1]); // Get the row containing the node rowPos = findRowIndexUsingCol(node, '#nodesDatatable', 1); // Update the power status column dTable.fnUpdate(status, rowPos, 3); } // Hide power loader var powerCol = $('#nodesDatatable thead tr th').eq(3); powerCol.find('img').hide(); } /** * Refresh power status for each node * * @param group * Group name * @return Nothing */ function refreshPowerStatus(group) { // Show power loader var powerCol = $('#nodesDatatable thead tr th').eq(3); powerCol.find('img').show(); // Get the power status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rpower', tgt : group, args : 'stat', msg : '' }, success : loadPowerStatus }); } /** * Load node status for each node * * @param data * Data returned from HTTP request * @return Nothing */ function loadNodeStatus(data) { // Get data table var dTable = $('#nodesDatatable').dataTable(); var rsp = data.rsp; var args, rowPos, node, status; // Get all nodes within the datatable for (var i in rsp) { args = rsp[i].split(':'); // args[0] = node and args[1] = status node = jQuery.trim(args[0]); status = jQuery.trim(args[1]).replace('sshd', 'ping'); // Get the row containing the node rowPos = findRowIndexUsingCol(node, '#nodesDatatable', 1); // Update the ping status column dTable.fnUpdate(status, rowPos, 2); } // Hide status loader var statCol = $('#nodesDatatable thead tr th').eq(2); statCol.find('img').hide(); } /** * Refresh ping status for each node * * @param group * Group name * @return Nothing */ function refreshNodeStatus(group) { // Show ping loader var pingCol = $('#nodesDatatable thead tr th').eq(2); pingCol.find('img').show(); // Get the node status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodestat', tgt : group, args : '-u', msg : '' }, success : loadNodeStatus }); } /** * Load inventory for given node * * @param e * Windows event * @return Nothing */ function loadNode(e) { if (!e) { e = window.event; } // Get node that was clicked var node = (e.target) ? e.target.id : e.srcElement.id; var mgt = getNodeAttr(node, 'mgt'); // Create an instance of the plugin var plugin; switch(mgt) { case "blade": plugin = new bladePlugin(); break; case "fsp": plugin = new fspPlugin(); break; case "hmc": plugin = new hmcPlugin(); break; case "ipmi": plugin = new ipmiPlugin(); break; case "ivm": plugin = new ivmPlugin(); break; case "zvm": plugin = new zvmPlugin(); break; } // Get tab area where a new tab will be inserted var myTab = getNodesTab(); var inst = 0; var newTabId = 'nodeTab' + inst; while ($('#' + newTabId).length) { // If one already exists, generate another one inst = inst + 1; newTabId = 'nodeTab' + inst; } // Reset node process $.cookie(node + 'Processes', 0); // Add new tab, only if one does not exist var loader = createLoader(newTabId + 'TabLoader'); loader = $('
    ').append(loader); myTab.add(newTabId, node, loader, true); // Get node inventory var msg = 'out=' + newTabId + ',node=' + node; $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rinv', tgt : node, args : 'all', msg : msg }, success : plugin.loadInventory }); // Select new tab myTab.select(newTabId); } /** * Unlock a node by setting the SSH keys * * @param tgtNodes * Nodes to unlock * @return Nothing */ function loadUnlockPage(tgtNodes) { // Get nodes tab var tab = getNodesTab(); // Generate new tab ID var instance = 0; var newTabId = 'unlockTab' + instance; while ($('#' + newTabId).length) { // If one already exists, generate another one instance = instance + 1; newTabId = 'unlockTab' + instance; } var unlockForm = $('
    '); // Create status bar, hide on load var statBarId = 'unlockStatusBar' + instance; var statusBar = createStatusBar(statBarId).hide(); unlockForm.append(statusBar); // Create loader var loader = createLoader(''); statusBar.append(loader); // Create info bar var infoBar = createInfoBar('Give the root password for this node range to setup its SSH keys.'); unlockForm.append(infoBar); unlockForm.append('
    '); unlockForm.append('
    '); // Generate tooltips unlockForm.find('div input[title]').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.7, predelay: 800, events : { def : "mouseover,mouseout", input : "mouseover,mouseout", widget : "focus mouseover,blur mouseout", tooltip : "mouseover,mouseout" } }); /** * Ok */ var okBtn = createButton('Ok'); okBtn.bind('click', function(event) { // Remove any warning messages $(this).parent().parent().find('.ui-state-error').remove(); // If a password is given var password = $('#' + newTabId + ' input[name=password]').css('border', 'solid #BDBDBD 1px'); if (password.val()) { // Setup SSH keys $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'unlock;' + tgtNodes + ';' + password.val(), msg : 'out=' + statBarId + ';cmd=unlock;tgt=' + tgtNodes }, success : updateStatusBar }); // Show status bar statusBar.show(); // Disable all inputs and Ok button $('#' + newTabId + ' input').attr('disabled', 'disabled'); $(this).attr('disabled', 'true'); } else { // Show warning message var warn = createWarnBar('You are missing some values!'); warn.prependTo($(this).parent().parent()); password.css('border', 'solid #FF0000 1px'); } }); unlockForm.append(okBtn); tab.add(newTabId, 'Unlock', unlockForm, true); tab.select(newTabId); } /** * Load script page * * @param tgtNodes * Targets to run script against * @return Nothing */ function loadScriptPage(tgtNodes) { // Get nodes tab var tab = getNodesTab(); // Generate new tab ID var inst = 0; var newTabId = 'scriptTab' + inst; while ($('#' + newTabId).length) { // If one already exists, generate another one inst = inst + 1; newTabId = 'scriptTab' + inst; } // Open new tab // Create remote script form var scriptForm = $('
    '); // Create status bar var barId = 'scriptStatusBar' + inst; var statBar = createStatusBar(barId); statBar.hide(); scriptForm.append(statBar); // Create loader var loader = createLoader('scriptLoader' + inst); statBar.append(loader); // Create info bar var infoBar = createInfoBar('Load a script to run against this node range.'); scriptForm.append(infoBar); // Target node or group var tgt = $('
    '); scriptForm.append(tgt); // Upload file var upload = $('
    '); var label = $(''); var file = $(''); var subBtn = createButton('Load'); upload.append(label); upload.append(file); upload.append(subBtn); scriptForm.append(upload); // Generate tooltips scriptForm.find('div input[title]').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.7, predelay: 800, events : { def : "mouseover,mouseout", input : "mouseover,mouseout", widget : "focus mouseover,blur mouseout", tooltip : "mouseover,mouseout" } }); // Script var script = $('
    ').css({ 'font-size': '10px', 'height': '50px', 'width': '200px', 'background-color': '#000', 'color': '#fff', 'border': '0px', 'display': 'block' }); // Create links to save and cancel changes var lnkStyle = { 'color': '#58ACFA', 'font-size': '10px', 'display': 'inline-block', 'padding': '5px', 'float': 'right' }; var saveLnk = $('Save').css(lnkStyle).hide(); var cancelLnk = $('Cancel').css(lnkStyle).hide(); var infoSpan = $('Click to edit').css(lnkStyle); // Save changes onclick saveLnk.bind('click', function(){ // Get node and comment var node = $(this).parent().parent().find('img').attr('id').replace('Tip', ''); var comments = $(this).parent().find('textarea').val(); // Save comment $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'chdef', tgt : '', args : '-t;node;-o;' + node + ';usercomment=' + comments, msg : 'out=nodesTab;tgt=' + node }, success: showChdefOutput }); // Hide cancel and save links $(this).hide(); cancelLnk.hide(); }); // Cancel changes onclick cancelLnk.bind('click', function(){ // Get original comment and put it back var orignComments = $(this).parent().find('textarea').text(); $(this).parent().find('textarea').val(orignComments); // Hide cancel and save links $(this).hide(); saveLnk.hide(); infoSpan.show(); }); // Show save link when comment is edited txtArea.bind('click', function(){ saveLnk.show(); cancelLnk.show(); infoSpan.hide(); }); toolTip.append(txtArea); toolTip.append(cancelLnk); toolTip.append(saveLnk); toolTip.append(infoSpan); return toolTip; } /** * Create a tool tip for node status * * @return Tool tip */ function createStatusToolTip() { // Create tooltip container var toolTip = $('
    ').css({ 'width': '150px' }); // Create info text var info = $('

    '); info.append('Click here to refresh the node status. To configure the xCAT monitor, '); // Create link to turn on xCAT monitoring var monitorLnk = $('click here').css({ 'color': '#58ACFA', 'font-size': '10px' }); // Open dialog to configure xCAT monitor monitorLnk.bind('click', function(){ // Check if xCAT monitor is enabled $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'monls', tgt : '', args : 'xcatmon', msg : '' }, success : openConfXcatMon }); }); info.append(monitorLnk); toolTip.append(info); return toolTip; } /** * Create a tool tip for power status * * @return Tool tip */ function createPowerToolTip() { // Create tooltip container var toolTip = $('
    Click here to refresh the power status
    ').css({ 'width': '150px' }); return toolTip; } /** * Open dialog to configure xCAT monitor * * @param data * Data returned from HTTP request * @return Nothing */ function openConfXcatMon(data) { // Create info bar var info = createInfoBar('Configure the xCAT monitor. Select to enable or disable the monitor below.'); var dialog = $('
    '); dialog.append(info); // Create status area var statusArea = $('
    ').css('padding-top', '10px'); var label = $(''); statusArea.append(label); // Get xCAT monitor status var status = data.rsp[0]; var buttons; // If xCAT monitor is disabled if (status.indexOf('not-monitored') > -1) { status = $('Disabled').css('padding', '0px 5px'); statusArea.append(status); // Create enable and cancel buttons buttons = { "Enable": function(){ // Enable xCAT monitor $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'monstart', tgt : '', args : 'xcatmon', msg : '' }, success : function(data){ openDialog('info', data.rsp[0]); } }); $(this).dialog("close"); }, "Cancel": function(){ $(this).dialog("close"); } }; } else { status = $('Enabled').css('padding', '0px 5px'); statusArea.append(status); // Create disable and cancel buttons buttons = { "Disable": function(){ // Disable xCAT monitor $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'monstop', tgt : '', args : 'xcatmon', msg : '' }, success : function(data){ openDialog('info', data.rsp[0]); } }); $(this).dialog("close"); }, "Cancel": function(){ $(this).dialog("close"); } }; } dialog.append(statusArea); // Open dialog dialog.dialog({ modal: true, width: 500, buttons: buttons }); } /** * Show chdef output * * @param data * Data returned from HTTP request * @return Nothing */ function showChdefOutput(data) { // Get output var out = data.rsp; var args = data.msg.split(';'); var tabID = args[0].replace('out=', ''); var tgt = args[1].replace('tgt=', ''); // Find info bar on nodes tab, if any var info = $('#' + tabID).find('.ui-state-highlight'); if (!info.length) { // Create info bar if one does not exist info = createInfoBar(''); $('#' + tabID).append(info); } // Go through output and append to paragraph var prg = $('

    '); for (var i in out) { prg.append(tgt + ': ' + out[i] + '
    '); } info.append(prg); } /** * Set definable node attributes * * @param data * Data returned from HTTP request * @return Nothing */ function setDefAttrs(data) { // Clear hash table containing definable node attributes defAttrs = new Array(); // Get definable attributes var attrs = data.rsp[2].split(/\n/); // Go through each line var attr, key, descr; for (var i in attrs) { attr = attrs[i]; // If the line is not empty if (attr) { // If the line has the attribute name if (attr.indexOf(':') && attr.indexOf(' ')) { // Get attribute name and description key = jQuery.trim(attr.substring(0, attr.indexOf(':'))); descr = jQuery.trim(attr.substring(attr.indexOf(':') + 1)); // Remove arrow brackets descr = descr.replace(new RegExp('<|>', 'g'), ''); // Set hash table where key = attribute name and value = description defAttrs[key] = descr; } else { // Remove arrow brackets attr = attr.replace(new RegExp('<|>', 'g'), ''); // Append description to hash table defAttrs[key] = defAttrs[key] + '\n' + attr; } } // End of if } // End of for } /** * Load set node properties page * * @param tgtNode * Target node to set properties * @return Nothing */ function loadEditPropsPage(tgtNode) { // Get nodes tab var tab = getNodesTab(); // Generate new tab ID var inst = 0; var newTabId = 'editPropsTab' + inst; while ($('#' + newTabId).length) { // If one already exists, generate another one inst = inst + 1; newTabId = 'editPropsTab' + inst; } // Open new tab // Create set properties form var editPropsForm = $('
    '); // Create info bar var infoBar = createInfoBar('Choose the properties you wish to change on the node. When you are finished, click Save.'); editPropsForm.append(infoBar); // Create an input for each definable attribute var div, label, input, descr, value; // Set node attribute origAttrs[tgtNode]['node'] = tgtNode; for (var key in defAttrs) { // If an attribute value exists if (origAttrs[tgtNode][key]) { // Set the value value = origAttrs[tgtNode][key]; } else { value = ''; } // Create label and input for attribute div = $('
    ').css('display', 'inline'); label = $('').css('vertical-align', 'middle'); input = $('').css('margin-top', '5px'); // Change border to blue onchange input.bind('change', function(event) { $(this).css('border-color', 'blue'); }); div.append(label); div.append(input); editPropsForm.append(div); } // Change style for last division div.css({ 'display': 'block', 'margin': '0px 0px 10px 0px' }); // Generate tooltips editPropsForm.find('div input[title]').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.8, delay: 0, predelay: 800, events: { def: "mouseover,mouseout", input: "mouseover,mouseout", widget: "focus mouseover,blur mouseout", tooltip: "mouseover,mouseout" } }); /** * Save */ var saveBtn = createButton('Save'); saveBtn.bind('click', function(event) { // Get all inputs var inputs = $('#' + newTabId + ' input'); // Go through each input var args = ''; var attrName, attrVal; inputs.each(function(){ // If the border color is blue if ($(this).css('border-left-color') == 'rgb(0, 0, 255)') { // Change border color back to normal $(this).css('border-color', ''); // Get attribute name and value attrName = $(this).parent().find('label').text().replace(':', ''); attrVal = $(this).val(); // Build argument string if (args) { // Handle subsequent arguments args += ';' + attrName + '=' + attrVal; } else { // Handle the 1st argument args += attrName + '=' + attrVal; } } }); // Send command to change node attributes $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'chdef', tgt : '', args : '-t;node;-o;' + tgtNode + ';' + args, msg : 'out=' + newTabId + ';tgt=' + tgtNode }, success: showChdefOutput }); }); editPropsForm.append(saveBtn); /** * Cancel */ var cancelBtn = createButton('Cancel'); cancelBtn.bind('click', function(event) { // Close the tab tab.remove($(this).parent().parent().attr('id')); }); editPropsForm.append(cancelBtn); // Append to discover tab tab.add(newTabId, 'Edit', editPropsForm, true); // Select new tab tab.select(newTabId); } /** * Open set node properties dialog * * @return Nothing */ function openSetPropsDialog() { // Open new tab // Create set properties form var setPropsForm = $('
    '); // Create info bar var infoBar = createInfoBar('Choose the properties you wish to change on the node. When you are finished, click Save.'); setPropsForm.append(infoBar); // Create an input for each definable attribute var div, label, input, descr, value; for (var key in defAttrs) { value = ''; // Create label and input for attribute div = $('
    ').css('display', 'inline'); label = $('').css('vertical-align', 'middle'); input = $('').css('margin-top', '5px'); // Change border to blue onchange input.bind('change', function(event) { $(this).css('border-color', 'blue'); }); div.append(label); div.append(input); setPropsForm.append(div); } // Change style for last division div.css({ 'display': 'block', 'margin': '0px 0px 10px 0px' }); // Generate tooltips setPropsForm.find('div input[title]').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.8, delay: 0, predelay: 800, events: { def: "mouseover,mouseout", input: "mouseover,mouseout", widget: "focus mouseover,blur mouseout", tooltip: "mouseover,mouseout" }, // Change z index to show tooltip in front onBeforeShow: function() { this.getTip().css('z-index', $.topZIndex()); } }); // Enable vertical scroll setPropsForm.css('overflow', 'auto'); // Open form as a dialog setPropsForm.dialog({ modal: true, height: 400, width: 700, buttons: { "Save": function() { // Remove any warning messages $(this).find('.ui-state-error').remove(); // Get all inputs var inputs = $(this).find('input'); // Go through each input var args = ''; var tgtNode, attrName, attrVal; inputs.each(function(){ // If the border color is blue if ($(this).css('border-left-color') == 'rgb(0, 0, 255)') { // Change border color back to normal $(this).css('border-color', ''); // Get attribute name and value attrName = $(this).parent().find('label').text().replace(':', ''); attrVal = $(this).val(); // Get node name if (attrName == 'node') { tgtNode = attrVal; } else { // Build argument string if (args) { // Handle subsequent arguments args += ';' + attrName + '=' + attrVal; } else { // Handle the 1st argument args += attrName + '=' + attrVal; } } } }); // Send command to change node attributes $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'chdef', tgt : '', args : '-t;node;-o;' + tgtNode + ';' + args, msg : 'node=' + tgtNode }, /** * Show results * * @param data * Data returned from HTTP request * @return Nothing */ success: function(data) { // Get output var out = data.rsp; var node = data.msg.replace('node=', ''); // Go through output and append to paragraph var msg = ''; for (var i in out) { if (!msg) { msg = node + ': ' + out[i]; } else { msg += '
    ' + node + ': ' + out[i]; } } openDialog('info', msg); } }); // Close dialog $(this).dialog( "close" ); }, "Cancel": function(){ $(this).dialog( "close" ); } } }); }