2010-06-16 18:21:58 +00:00
/ * *
* Global variables
* /
2010-11-09 05:05:10 +00:00
var nodesTabs ; // Node tabs
2010-11-12 18:59:25 +00:00
var origAttrs = new Object ( ) ; // Original node attributes
2010-12-03 22:09:36 +00:00
var defAttrs ; // Definable node attributes
2010-06-16 18:21:58 +00:00
/ * *
* 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
groupDIV = $ ( '<div id="groups"></div>' ) ;
nodesDIV = $ ( '<div id="nodes"></div>' ) ;
2010-11-08 07:19:05 +00:00
$ ( '#content' ) . append ( groupDIV ) ;
$ ( '#content' ) . append ( nodesDIV ) ;
2010-06-16 18:21:58 +00:00
2010-07-17 13:09:04 +00:00
// Create loader
var loader = createLoader ( ) ;
groupDIV . append ( loader ) ;
2010-06-16 18:21:58 +00:00
// Create info bar
2010-12-03 22:09:36 +00:00
var info = createInfoBar ( 'Select a group to view its nodes.' ) ;
2010-06-16 18:21:58 +00:00
$ ( '#nodes' ) . append ( info ) ;
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
success : loadGroups
} ) ;
2010-11-04 07:07:53 +00:00
2010-11-09 05:05:10 +00:00
// Get graphical view info
2010-11-04 07:07:53 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodels' ,
tgt : 'all' ,
2010-11-12 07:46:42 +00:00
args : 'nodetype.nodetype;ppc.parent;vpd.mtm;nodelist.status;nodehm.mgt' ,
2010-11-04 07:07:53 +00:00
msg : ''
} ,
2010-11-09 05:05:10 +00:00
success : extractGraphicalData
2010-11-04 07:07:53 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
}
}
/ * *
* Load groups
*
* @ param data
* Data returned from HTTP request
* @ return
* /
function loadGroups ( data ) {
2010-07-17 13:09:04 +00:00
// Remove loader
$ ( '#groups' ) . find ( 'img' ) . remove ( ) ;
2010-06-16 18:21:58 +00:00
var groups = data . rsp ;
setGroupsCookies ( data ) ;
// Create a list of groups
var ul = $ ( '<ul></ul>' ) ;
2010-11-04 19:30:39 +00:00
var item = $ ( '<li id="root"><h3>Groups</h3></li>' ) ;
2010-06-16 18:21:58 +00:00
ul . append ( item ) ;
var subUL = $ ( '<ul></ul>' ) ;
item . append ( subUL ) ;
// Create a link for each group
2010-11-24 18:11:42 +00:00
for ( var i = groups . length ; i -- ; ) {
2010-11-11 21:36:51 +00:00
var subItem = $ ( '<li id="' + groups [ i ] + '"></li>' ) ;
var link = $ ( '<a>' + groups [ i ] + '</a>' ) ;
2010-06-16 18:21:58 +00:00
subItem . append ( link ) ;
subUL . append ( subItem ) ;
}
// Turn groups list into a tree
$ ( '#groups' ) . append ( ul ) ;
2010-11-04 19:30:39 +00:00
$ ( '#groups' ) . jstree ( {
core : { "initially_open" : [ "root" ] } ,
themes : {
"theme" : "default" ,
"dots" : false , // No dots
"icons" : false // No icons
}
} ) ;
2010-11-11 21:36:51 +00:00
// Load nodes onclick
$ ( '#groups' ) . bind ( 'select_node.jstree' , function ( event , data ) {
2010-11-18 00:09:17 +00:00
// If there are subgroups, remove them
data . rslt . obj . children ( 'ul' ) . remove ( ) ;
2010-11-11 21:36:51 +00:00
var thisGroup = jQuery . trim ( data . rslt . obj . text ( ) ) ;
if ( thisGroup ) {
// Clear nodes division
$ ( '#nodes' ) . children ( ) . remove ( ) ;
// Create loader
var loader = $ ( '<center></center>' ) . append ( createLoader ( ) ) ;
var loader2 = $ ( '<center></center>' ) . 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
} ,
2010-11-04 19:30:39 +00:00
2010-11-11 21:36:51 +00:00
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
} ) ;
}
2010-11-17 18:53:40 +00:00
// Get physical layout
2010-11-11 21:36:51 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : thisGroup + ';-s' ,
msg : ''
} ,
success : createPhysicalLayout
} ) ;
} // End of if (thisGroup)
} ) ;
2010-09-20 18:57:08 +00:00
// Create link to add nodes
2010-11-01 14:06:53 +00:00
var addNodeLink = $ ( '<a title="Add a node or a node range to xCAT">Add node</a>' ) ;
2010-09-20 18:57:08 +00:00
addNodeLink . bind ( 'click' , function ( event ) {
2010-09-23 20:43:10 +00:00
var info = createInfoBar ( 'Select the hardware management for the new node range' ) ;
var addNodeForm = $ ( '<div class="form"></div>' ) ;
addNodeForm . append ( info ) ;
addNodeForm . append ( '<div><label for="mgt">Hardware management:</label>'
+ '<select id="mgt" name="mgt">'
+ '<option>ipmi</option>'
+ '<option>blade</option>'
+ '<option>hmc</option>'
+ '<option>ivm</option>'
+ '<option>fsp</option>'
+ '<option>zvm</option>'
+ '</select>'
+ '</div>' ) ;
2010-12-02 21:28:24 +00:00
// Create advanced link to set advanced node properties
var advanced = $ ( '<div></div>' ) ;
var advancedLnk = $ ( '<a>Advanced</a>' ) . 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 : ''
} ,
2010-12-03 22:09:36 +00:00
/ * *
* Set definable node attributes and open dialog
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-12-02 21:28:24 +00:00
success : function ( data ) {
setDefAttrs ( data ) ;
openSetPropsDialog ( ) ;
}
} ) ;
// Close dialog
addNodeForm . dialog ( "close" ) ;
} ) ;
advanced . append ( advancedLnk ) ;
addNodeForm . append ( advanced ) ;
2010-09-23 20:43:10 +00:00
2010-09-24 02:27:04 +00:00
// Open dialog to add node
2010-09-23 20:43:10 +00:00
addNodeForm . dialog ( {
modal : true ,
width : 400 ,
buttons : {
2010-10-07 21:01:14 +00:00
"Ok" : function ( ) {
2010-09-24 02:27:04 +00:00
// Get hardware management
2010-09-23 20:43:10 +00:00
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" ) ;
2010-10-07 21:01:14 +00:00
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
2010-09-21 01:35:08 +00:00
}
2010-09-23 20:43:10 +00:00
} ) ;
2010-09-21 01:35:08 +00:00
2010-09-20 18:57:08 +00:00
} ) ;
2010-11-01 14:06:53 +00:00
// Generate tooltips
addNodeLink . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.7
2010-11-01 14:06:53 +00:00
} ) ;
2010-09-20 18:57:08 +00:00
$ ( '#groups' ) . append ( addNodeLink ) ;
2010-06-16 18:21:58 +00:00
}
2010-11-11 21:36:51 +00:00
/ * *
* 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
2010-11-24 18:11:42 +00:00
for ( var i in rsp ) {
2010-11-11 21:36:51 +00:00
// 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
}
2010-06-16 18:21:58 +00:00
/ * *
* Load nodes belonging to a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-11-11 15:07:40 +00:00
function loadNodes ( data ) {
2010-06-16 18:21:58 +00:00
// 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 ( ) ;
2010-11-09 05:05:10 +00:00
2010-11-17 18:53:40 +00:00
// Clear cookie containing list of nodes where
2010-11-09 05:05:10 +00:00
// their attributes need to be updated
2010-11-22 16:18:55 +00:00
$ . cookie ( 'nodes2update' , '' ) ;
2010-11-12 18:59:25 +00:00
// Clear hash table containing node attributes
origAttrs = '' ;
2010-12-02 21:28:24 +00:00
2010-06-16 18:21:58 +00:00
var node ;
var args ;
2010-11-24 18:11:42 +00:00
for ( var i in rsp ) {
2010-06-16 18:21:58 +00:00
// 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 ( '=' ) ;
var key = jQuery . trim ( args [ 0 ] ) ;
var val = jQuery . trim ( args [ 1 ] ) ;
// Create a hash table
attrs [ node ] [ key ] = val ;
headers [ key ] = 1 ;
}
2010-11-12 18:59:25 +00:00
// Save attributes in hash table
origAttrs = attrs ;
2010-06-16 18:21:58 +00:00
// Sort headers
var sorted = new Array ( ) ;
2010-11-24 18:11:42 +00:00
for ( var key in headers ) {
2010-11-11 03:45:47 +00:00
// Do not put in comments twice
if ( key != 'usercomment' ) {
sorted . push ( key ) ;
}
2010-06-16 18:21:58 +00:00
}
sorted . sort ( ) ;
2010-11-09 21:22:43 +00:00
// Add column for check box, node, ping, power, and comments
sorted . unshift ( '<input type="checkbox" onclick="selectAllCheckbox(event, $(this))">' ,
'node' ,
2010-09-28 20:24:31 +00:00
'<a>ping</a><img src="images/loader.gif"></img>' ,
2010-11-09 21:22:43 +00:00
'<a>power</a><img src="images/loader.gif"></img>' ,
'comments' ) ;
2010-06-16 18:21:58 +00:00
// Create a datatable
var dTable = new DataTable ( 'nodesDataTable' ) ;
dTable . init ( sorted ) ;
// Go through each node
2010-11-24 18:11:42 +00:00
for ( var node in attrs ) {
2010-06-16 18:21:58 +00:00
// Create a row
var row = new Array ( ) ;
// Create a check box
var checkBx = '<input type="checkbox" name="' + node + '"/>' ;
// Open node onclick
2010-09-28 20:24:31 +00:00
var nodeLink = $ ( '<a class="node" id="' + node + '">' + node + '</a>' ) . bind ( 'click' , loadNode ) ;
2010-11-11 03:45:47 +00:00
// Push in checkbox, node link, ping, and power
row . push ( checkBx , nodeLink , '' , '' ) ;
2010-06-16 18:21:58 +00:00
2010-11-11 03:45:47 +00:00
// Put in comments
2010-11-11 15:07:40 +00:00
var comment = attrs [ node ] [ 'usercomment' ] ;
2010-11-11 03:45:47 +00:00
var iconSrc ;
// If no comments exists, show 'No comments' and set icon image source
2010-11-11 15:07:40 +00:00
if ( ! comment ) {
comment = 'No comments' ;
2010-11-11 03:45:47 +00:00
iconSrc = 'images/ui-icon-no-comment.png' ;
} else {
iconSrc = 'images/ui-icon-comment.png' ;
}
// Create comments icon
var tipID = node + 'Tip' ;
var icon = $ ( '<img id="' + tipID + '" src="' + iconSrc + '"></img>' ) . css ( {
'width' : '18px' ,
'height' : '18px'
} ) ;
// Create tooltip
2010-11-11 15:07:40 +00:00
var tip = createCommentsToolTip ( comment ) ;
// Create container to put icon and comment in
2010-11-11 03:45:47 +00:00
var col = $ ( '<span></span>' ) . append ( icon ) ;
col . append ( tip ) ;
row . push ( col ) ;
// Generate tooltips
icon . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
2010-11-11 03:45:47 +00:00
relative : true ,
2010-12-03 22:09:36 +00:00
delay : 500
2010-11-11 03:45:47 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
// Go through each header
2010-11-24 18:11:42 +00:00
for ( var i = 5 ; i < sorted . length ; i ++ ) {
2010-06-16 18:21:58 +00:00
// Add the node attributes to the row
var key = sorted [ i ] ;
2010-11-11 15:07:40 +00:00
2010-11-11 03:45:47 +00:00
// Do not put in comments twice
if ( key != 'usercomment' ) {
var val = attrs [ node ] [ key ] ;
if ( val ) {
row . push ( val ) ;
} else {
row . push ( '' ) ;
}
} // End of if
2010-06-16 18:21:58 +00:00
}
// Add the row to the table
dTable . add ( row ) ;
}
// Clear the tab before inserting the table
$ ( '#nodesTab' ) . children ( ) . remove ( ) ;
2010-11-09 05:05:10 +00:00
// 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 ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 13:41:29 +00:00
// Create action bar
2010-06-16 18:21:58 +00:00
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
/ * *
* The following actions are available to perform against a given node :
* power , clone , delete , unlock , and advanced
* /
2010-09-28 20:24:31 +00:00
var powerLnk = $ ( '<a>Power</a>' ) ;
2010-11-09 05:05:10 +00:00
2010-12-03 22:09:36 +00:00
// Power on
2010-09-28 20:24:31 +00:00
var powerOnLnk = $ ( '<a>Power on</a>' ) ;
2010-06-16 18:21:58 +00:00
powerOnLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'on' ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-11-09 05:05:10 +00:00
2010-12-03 22:09:36 +00:00
// Power off
2010-09-28 20:24:31 +00:00
var powerOffLnk = $ ( '<a>Power off</a>' ) ;
2010-06-16 18:21:58 +00:00
powerOffLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'off' ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-11-09 05:05:10 +00:00
// Clone
2010-09-28 20:24:31 +00:00
var cloneLnk = $ ( '<a>Clone</a>' ) ;
2010-06-16 18:21:58 +00:00
cloneLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) . split ( ',' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in tgtNodes ) {
2010-08-03 20:44:26 +00:00
var mgt = getNodeAttr ( tgtNodes [ i ] , 'mgt' ) ;
2010-07-22 19:56:09 +00:00
// Create an instance of the plugin
var plugin ;
switch ( mgt ) {
case "blade" :
2010-07-23 18:47:54 +00:00
plugin = new bladePlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "fsp" :
2010-07-23 18:47:54 +00:00
plugin = new fspPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "hmc" :
2010-07-23 18:47:54 +00:00
plugin = new hmcPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ipmi" :
2010-07-23 18:47:54 +00:00
plugin = new ipmiPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ivm" :
2010-07-23 18:47:54 +00:00
plugin = new ivmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "zvm" :
2010-07-23 18:47:54 +00:00
plugin = new zvmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
}
plugin . loadClonePage ( tgtNodes [ i ] ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Delete
2010-09-28 20:24:31 +00:00
var deleteLnk = $ ( '<a>Delete</a>' ) ;
2010-06-16 18:21:58 +00:00
deleteLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
2010-11-24 18:11:42 +00:00
loadDeletePage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-11-09 05:05:10 +00:00
// Unlock
2010-09-28 20:24:31 +00:00
var unlockLnk = $ ( '<a>Unlock</a>' ) ;
2010-06-16 18:21:58 +00:00
unlockLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
loadUnlockPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Run script
2010-09-28 20:24:31 +00:00
var scriptLnk = $ ( '<a>Run script</a>' ) ;
2010-06-16 18:21:58 +00:00
scriptLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
loadScriptPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Update
2010-09-28 20:24:31 +00:00
var updateLnk = $ ( '<a>Update</a>' ) ;
2010-06-16 18:21:58 +00:00
updateLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
2010-07-17 13:09:04 +00:00
loadUpdatenodePage ( tgtNodes ) ;
2010-07-15 13:41:29 +00:00
}
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Set boot state
2010-09-28 20:24:31 +00:00
var setBootStateLnk = $ ( '<a>Set boot state</a>' ) ;
2010-06-16 18:21:58 +00:00
setBootStateLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-06-16 18:21:58 +00:00
if ( tgtNodes ) {
loadNodesetPage ( tgtNodes ) ;
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Boot to network
2010-09-28 20:24:31 +00:00
var boot2NetworkLnk = $ ( '<a>Boot to network</a>' ) ;
2010-06-16 18:21:58 +00:00
boot2NetworkLnk . bind ( 'click' , function ( event ) {
2010-07-27 19:50:01 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
2010-06-16 18:21:58 +00:00
if ( tgtNodes ) {
2010-07-15 22:57:48 +00:00
loadNetbootPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Remote console
2010-11-09 05:05:10 +00:00
var rcons = $ ( '<a>Open console</a>' ) ;
2010-09-20 07:41:43 +00:00
rcons . bind ( 'click' , function ( event ) {
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) ;
if ( tgtNodes ) {
2010-09-20 18:57:08 +00:00
loadRconsPage ( tgtNodes ) ;
2010-09-20 07:41:43 +00:00
}
} ) ;
2010-11-24 18:11:42 +00:00
2010-12-03 22:09:36 +00:00
// Edit properties
var editProps = $ ( '<a>Edit properties</a>' ) ;
editProps . bind ( 'click' , function ( event ) {
2010-11-24 18:11:42 +00:00
var tgtNodes = getNodesChecked ( 'nodesDataTable' ) . split ( ',' ) ;
for ( var i in tgtNodes ) {
2010-12-03 22:09:36 +00:00
loadEditPropsPage ( tgtNodes [ i ] ) ;
2010-11-24 18:11:42 +00:00
}
} ) ;
2010-09-28 20:24:31 +00:00
var advancedLnk = $ ( '<a>Advanced</a>' ) ;
2010-06-16 18:21:58 +00:00
// Power actions
var powerActions = [ powerOnLnk , powerOffLnk ] ;
var powerActionMenu = createMenu ( powerActions ) ;
// Advanced actions
2010-09-20 07:41:43 +00:00
var advancedActions ;
2010-09-24 02:27:04 +00:00
if ( 'compute' == group ) {
2010-12-03 22:09:36 +00:00
advancedActions = [ boot2NetworkLnk , scriptLnk , setBootStateLnk , updateLnk , rcons , editProps ] ;
2010-09-24 02:27:04 +00:00
} else {
2010-12-03 22:09:36 +00:00
advancedActions = [ boot2NetworkLnk , scriptLnk , setBootStateLnk , updateLnk , editProps ] ;
2010-09-20 07:41:43 +00:00
}
2010-06-16 18:21:58 +00:00
var advancedActionMenu = createMenu ( advancedActions ) ;
/ * *
* Create an action menu
* /
var actionsDIV = $ ( '<div></div>' ) ;
2010-07-15 22:57:48 +00:00
var actions = [ [ powerLnk , powerActionMenu ] , cloneLnk , deleteLnk , unlockLnk , [ advancedLnk , advancedActionMenu ] ] ;
2010-06-16 18:21:58 +00:00
var actionMenu = createMenu ( actions ) ;
actionMenu . superfish ( ) ;
actionsDIV . append ( actionMenu ) ;
actionBar . append ( actionsDIV ) ;
$ ( '#nodesTab' ) . append ( actionBar ) ;
2010-11-09 05:05:10 +00:00
2010-06-16 18:21:58 +00:00
// Insert table
$ ( '#nodesTab' ) . append ( dTable . object ( ) ) ;
2010-11-09 05:05:10 +00:00
// Save changes
var saveLnk = $ ( '<a>Save</a>' ) ;
saveLnk . bind ( 'click' , function ( event ) {
updateNodeAttrs ( group ) ;
} ) ;
// Undo changes
var undoLnk = $ ( '<a>Undo</a>' ) ;
undoLnk . bind ( 'click' , function ( event ) {
2010-11-12 18:59:25 +00:00
restoreNodeAttrs ( ) ;
2010-11-09 05:05:10 +00:00
} ) ;
/ * *
* Create menu to save and undo table changes
* /
// It will be hidden until a change is made
var tableActionsMenu = createMenu ( [ saveLnk , undoLnk ] ) . hide ( ) ;
tableActionsMenu . css ( 'margin-left' , '100px' ) ;
actionsDIV . append ( tableActionsMenu ) ;
2010-06-16 18:21:58 +00:00
// Turn table into a datatable
2010-11-16 20:28:20 +00:00
var myDataTable = $ ( '#nodesDataTable' ) . dataTable ( {
'iDisplayLength' : 50
} ) ;
2010-09-21 23:58:17 +00:00
2010-11-11 15:07:40 +00:00
// Do not sort ping, power, and comment column
2010-09-21 23:58:17 +00:00
var pingCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 2 ) ;
var powerCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 3 ) ;
2010-11-11 15:07:40 +00:00
var commentCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 4 ) ;
2010-09-21 23:58:17 +00:00
pingCol . unbind ( 'click' ) ;
powerCol . unbind ( 'click' ) ;
2010-11-11 15:07:40 +00:00
commentCol . unbind ( 'click' ) ;
2010-09-21 23:58:17 +00:00
2010-09-22 21:08:15 +00:00
// 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' ) ;
2010-12-01 01:54:05 +00:00
// 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' ) ;
2010-09-21 23:58:17 +00:00
// Instead refresh the ping status and power status
pingCol . bind ( 'click' , function ( event ) {
refreshPingStatus ( group ) ;
} ) ;
powerCol . bind ( 'click' , function ( event ) {
refreshPowerStatus ( group ) ;
} ) ;
2010-12-01 01:54:05 +00:00
2010-11-09 05:05:10 +00:00
/ * *
* Enable editable columns
* /
2010-11-09 21:22:43 +00:00
// 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 (
2010-11-09 05:05:10 +00:00
function ( value , settings ) {
// Change text color to red
$ ( this ) . css ( 'color' , 'red' ) ;
// Get column index
var colPos = this . cellIndex ;
// Get row index
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-11-09 05:05:10 +00:00
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 ) ;
} , {
2010-11-17 18:53:40 +00:00
onblur : 'submit' , // Clicking outside editable area submits
// changes
2010-11-09 21:22:43 +00:00
type : 'textarea' ,
2010-11-09 05:05:10 +00:00
placeholder : ' ' ,
2010-11-09 21:22:43 +00:00
height : '30px' // The height of the text area
2010-11-09 05:05:10 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
/ * *
2010-11-11 15:07:40 +00:00
* Get power and ping for each node
2010-06-16 18:21:58 +00:00
* /
2010-11-09 05:05:10 +00:00
// Get power status
2010-06-16 18:21:58 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
tgt : group ,
args : 'stat' ,
msg : ''
} ,
success : loadPowerStatus
} ) ;
2010-11-09 05:05:10 +00:00
// Get ping status
2010-06-16 18:21:58 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'pping ' + group ,
msg : ''
} ,
success : loadPingStatus
} ) ;
2010-11-09 21:22:43 +00:00
2010-12-03 22:09:36 +00:00
// Get definable node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : '-t;node;-h' ,
msg : ''
} ,
success : setDefAttrs
} ) ;
2010-11-24 18:11:42 +00:00
2010-06-16 18:21:58 +00:00
/ * *
2010-07-29 17:32:24 +00:00
* Additional ajax requests need to be made for zVM
2010-06-16 18:21:58 +00:00
* /
2010-11-09 05:05:10 +00:00
// Get index of HCP column
2010-06-16 18:21:58 +00:00
var i = $ . inArray ( 'hcp' , sorted ) ;
if ( i ) {
2010-07-29 17:32:24 +00:00
// Get hardware control point
2010-06-16 18:21:58 +00:00
var rows = dTable . object ( ) . find ( 'tbody tr' ) ;
var hcps = new Object ( ) ;
2010-11-24 18:11:42 +00:00
for ( var j in rows ) {
2010-06-16 18:21:58 +00:00
var val = rows . eq ( j ) . find ( 'td' ) . eq ( i ) . html ( ) ;
hcps [ val ] = 1 ;
}
var args ;
2010-11-24 18:11:42 +00:00
for ( var h in hcps ) {
2010-06-16 18:21:58 +00:00
// Get node without domain name
args = h . split ( '.' ) ;
2010-11-03 16:23:54 +00:00
// Check if SMAPI is online
2010-06-16 18:21:58 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsvm' ,
tgt : args [ 0 ] ,
2010-11-03 16:23:54 +00:00
args : '' ,
msg : 'group=' + group + ';hcp=' + args [ 0 ]
2010-06-16 18:21:58 +00:00
} ,
2010-11-03 16:23:54 +00:00
// Load hardware control point (HCP) specific info
// Get disk pools and network names
success : loadHcpInfo
2010-12-03 22:09:36 +00:00
} ) ;
2010-11-03 16:23:54 +00:00
} // End of for
} // End of if
2010-06-16 18:21:58 +00:00
}
/ * *
2010-07-29 17:32:24 +00:00
* Load power status for each node
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadPowerStatus ( data ) {
// Get datatable
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
var power = data . rsp ;
2010-12-03 22:09:36 +00:00
var rowPos , node , status , args ;
2010-06-16 18:21:58 +00:00
2010-11-24 18:11:42 +00:00
for ( var i in power ) {
2010-09-24 02:27:04 +00:00
// power[0] = nodeName and power[1] = state
2010-06-16 18:21:58 +00:00
args = power [ i ] . split ( ':' ) ;
node = jQuery . trim ( args [ 0 ] ) ;
status = jQuery . trim ( args [ 1 ] ) ;
// Get the row containing the node
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( node , '#nodesDataTable' , 1 ) ;
2010-07-26 08:23:47 +00:00
2010-09-24 02:27:04 +00:00
// Update the power status column
2010-12-03 22:09:36 +00:00
dTable . fnUpdate ( status , rowPos , 3 ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-22 04:04:59 +00:00
2010-09-22 04:10:59 +00:00
// Hide power loader
2010-09-22 04:04:59 +00:00
var powerCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 3 ) ;
powerCol . find ( 'img' ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-21 23:58:17 +00:00
/ * *
* Refresh power status for each node
*
* @ param group
* Group name
* @ return Nothing
* /
function refreshPowerStatus ( group ) {
2010-09-22 04:04:59 +00:00
// Show power loader
var powerCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 3 ) ;
powerCol . find ( 'img' ) . show ( ) ;
2010-09-21 23:58:17 +00:00
// Get the power status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
tgt : group ,
args : 'stat' ,
msg : ''
} ,
success : loadPowerStatus
} ) ;
}
2010-06-16 18:21:58 +00:00
/ * *
2010-07-29 17:32:24 +00:00
* Load ping status for each node
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadPingStatus ( data ) {
// Get data table
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
var ping = data . rsp ;
2010-07-26 08:23:47 +00:00
var rowPos , node , status ;
2010-06-16 18:21:58 +00:00
// Get all nodes within the datatable
2010-11-24 18:11:42 +00:00
for ( var i in ping ) {
2010-09-24 02:27:04 +00:00
// ping[0] = nodeName and ping[1] = state
2010-06-16 18:21:58 +00:00
node = jQuery . trim ( ping [ i ] [ 0 ] ) ;
status = jQuery . trim ( ping [ i ] [ 1 ] ) ;
// Get the row containing the node
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( node , '#nodesDataTable' , 1 ) ;
2010-06-16 18:21:58 +00:00
2010-09-24 02:27:04 +00:00
// Update the ping status column
2010-06-16 18:21:58 +00:00
dTable . fnUpdate ( status , rowPos , 2 ) ;
}
2010-09-22 04:04:59 +00:00
2010-09-22 04:10:59 +00:00
// Hide ping loader
2010-09-22 04:04:59 +00:00
var pingCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 2 ) ;
pingCol . find ( 'img' ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-21 23:58:17 +00:00
/ * *
* Refresh ping status for each node
*
* @ param group
* Group name
* @ return Nothing
* /
function refreshPingStatus ( group ) {
2010-09-22 04:04:59 +00:00
// Show ping loader
var pingCol = $ ( '#nodesDataTable thead tr th' ) . eq ( 2 ) ;
pingCol . find ( 'img' ) . show ( ) ;
2010-09-21 23:58:17 +00:00
// Get the ping status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'pping ' + group ,
msg : ''
} ,
success : loadPingStatus
} ) ;
}
2010-06-16 18:21:58 +00:00
/ * *
* Load inventory for given node
*
* @ param e
* Windows event
* @ return Nothing
* /
function loadNode ( e ) {
if ( ! e ) {
e = window . event ;
}
2010-08-03 21:22:46 +00:00
2010-06-16 18:21:58 +00:00
// Get node that was clicked
var node = ( e . target ) ? e . target . id : e . srcElement . id ;
2010-08-03 20:44:26 +00:00
var mgt = getNodeAttr ( node , 'mgt' ) ;
2010-08-03 21:22:46 +00:00
2010-07-22 19:56:09 +00:00
// Create an instance of the plugin
var plugin ;
switch ( mgt ) {
case "blade" :
2010-07-23 18:47:54 +00:00
plugin = new bladePlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "fsp" :
2010-07-23 18:47:54 +00:00
plugin = new fspPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "hmc" :
2010-07-23 18:47:54 +00:00
plugin = new hmcPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ipmi" :
2010-07-23 18:47:54 +00:00
plugin = new ipmiPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ivm" :
2010-07-23 18:47:54 +00:00
plugin = new ivmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "zvm" :
2010-07-23 18:47:54 +00:00
plugin = new zvmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
}
2010-06-16 18:21:58 +00:00
// Get tab area where a new tab will be inserted
var myTab = getNodesTab ( ) ;
2010-07-26 07:25:27 +00:00
var inst = 0 ;
2010-07-26 18:34:29 +00:00
var newTabId = 'nodeTab' + inst ;
2010-07-26 07:25:27 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-07-26 18:34:29 +00:00
newTabId = 'nodeTab' + inst ;
2010-07-26 07:25:27 +00:00
}
2010-07-15 22:57:48 +00:00
// Reset node process
$ . cookie ( node + 'Processes' , 0 ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Add new tab, only if one does not exist
2010-07-26 07:25:27 +00:00
var loader = createLoader ( newTabId + 'TabLoader' ) ;
2010-07-15 22:57:48 +00:00
loader = $ ( '<center></center>' ) . append ( loader ) ;
2010-08-03 14:58:08 +00:00
myTab . add ( newTabId , node , loader , true ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// 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
} ,
2010-07-22 19:56:09 +00:00
success : plugin . loadInventory
2010-07-15 22:57:48 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
// Select new tab
myTab . select ( newTabId ) ;
}
/ * *
2010-07-15 22:57:48 +00:00
* Unlock a node by setting the SSH keys
2010-06-16 18:21:58 +00:00
*
* @ param tgtNodes
* Nodes to unlock
* @ return Nothing
* /
function loadUnlockPage ( tgtNodes ) {
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var instance = 0 ;
2010-12-03 22:09:36 +00:00
var newTabId = 'unlockTab' + instance ;
2010-06-16 18:21:58 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
instance = instance + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'unlockTab' + instance ;
2010-06-16 18:21:58 +00:00
}
var unlockForm = $ ( '<div class="form"></div>' ) ;
// 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
2010-12-03 22:09:36 +00:00
var infoBar = createInfoBar ( 'Give the root password for this node range to setup its SSH keys.' ) ;
2010-06-16 18:21:58 +00:00
unlockForm . append ( infoBar ) ;
2010-11-01 14:06:53 +00:00
unlockForm . append ( '<div><label>Target node range:</label><input type="text" id="node" name="node" readonly="readonly" value="' + tgtNodes + '" title="The node or node range to unlock"/></div>' ) ;
unlockForm . append ( '<div><label>Password:</label><input type="password" id="password" name="password" title="The root password to unlock this node"/></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-11-01 14:06:53 +00:00
// Generate tooltips
unlockForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.7
2010-11-01 14:06:53 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
/ * *
* Ok
* /
var okBtn = createButton ( 'Ok' ) ;
okBtn . bind ( 'click' , function ( event ) {
2010-09-24 02:27:04 +00:00
// Remove any warning messages
$ ( this ) . parent ( ) . parent ( ) . find ( '.ui-state-error' ) . remove ( ) ;
2010-07-29 17:32:24 +00:00
// If form is complete
2010-06-16 18:21:58 +00:00
var ready = formComplete ( newTabId ) ;
if ( ready ) {
var password = $ ( '#' + newTabId + ' input[name=password]' ) . val ( ) ;
2010-07-15 22:57:48 +00:00
// Setup SSH keys
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'unlock;' + tgtNodes + ';' + password ,
msg : 'out=' + statBarId + ';cmd=unlock;tgt=' + tgtNodes
} ,
success : updateStatusBar
} ) ;
// Show status bar
statusBar . show ( ) ;
2010-07-29 17:32:24 +00:00
// Disable Ok button
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-09-24 02:27:04 +00:00
} else {
// Show warning message
2010-12-03 22:09:36 +00:00
var warn = createWarnBar ( 'You are missing some values!' ) ;
2010-09-24 02:27:04 +00:00
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
2010-07-15 22:57:48 +00:00
}
} ) ;
2010-06-16 18:21:58 +00:00
unlockForm . append ( okBtn ) ;
2010-08-03 14:58:08 +00:00
tab . add ( newTabId , 'Unlock' , unlockForm , true ) ;
2010-06-16 18:21:58 +00:00
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 = $ ( '<div class="form"></div>' ) ;
// Create status bar
var barId = 'scriptStatusBar' + inst ;
var statBar = createStatusBar ( barId ) ;
statBar . hide ( ) ;
scriptForm . append ( statBar ) ;
// Create loader
2010-09-22 19:32:09 +00:00
var loader = createLoader ( 'scriptLoader' + inst ) ;
2010-06-16 18:21:58 +00:00
statBar . append ( loader ) ;
// Create info bar
2010-12-03 22:09:36 +00:00
var infoBar = createInfoBar ( 'Load a script to run against this node range.' ) ;
2010-06-16 18:21:58 +00:00
scriptForm . append ( infoBar ) ;
// Target node or group
2010-11-01 14:06:53 +00:00
var tgt = $ ( '<div><label for="target">Target node range:</label><input type="text" name="target" value="' + tgtNodes + '" title="The node or node range to run a given script against"/></div>' ) ;
2010-06-16 18:21:58 +00:00
scriptForm . append ( tgt ) ;
// Upload file
var upload = $ ( '<form action="lib/upload.php" method="post" enctype="multipart/form-data"></form>' ) ;
var label = $ ( '<label for="file">Remote file:</label>' ) ;
var file = $ ( '<input type="file" name="file" id="file"/>' ) ;
var subBtn = createButton ( 'Load' ) ;
upload . append ( label ) ;
upload . append ( file ) ;
upload . append ( subBtn ) ;
scriptForm . append ( upload ) ;
2010-11-01 14:06:53 +00:00
// Generate tooltips
scriptForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.7
2010-11-01 14:06:53 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
// Script
var script = $ ( '<div><label>Script:</label><textarea/>' ) ;
scriptForm . append ( script ) ;
// Ajax form options
var options = {
// Output to text area
target : '#' + newTabId + ' textarea'
} ;
upload . ajaxForm ( options ) ;
/ * *
* Run
* /
var runBtn = createButton ( 'Run' ) ;
runBtn . bind ( 'click' , function ( event ) {
2010-09-24 02:27:04 +00:00
// Remove any warning messages
$ ( this ) . parent ( ) . parent ( ) . find ( '.ui-state-error' ) . remove ( ) ;
2010-06-16 18:21:58 +00:00
var ready = true ;
// Check script
var textarea = $ ( '#' + newTabId + ' textarea' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in textarea ) {
2010-06-16 18:21:58 +00:00
if ( ! textarea . eq ( i ) . val ( ) ) {
textarea . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
ready = false ;
} else {
textarea . eq ( i ) . css ( 'border' , 'solid #424242 1px' ) ;
}
}
// If no inputs are empty
if ( ready ) {
// Run script
runScript ( inst ) ;
} else {
2010-09-24 02:27:04 +00:00
// Show warning message
var warn = createWarnBar ( 'You are missing some values' ) ;
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
2010-06-16 18:21:58 +00:00
}
} ) ;
scriptForm . append ( runBtn ) ;
// Append to discover tab
2010-08-03 14:58:08 +00:00
tab . add ( newTabId , 'Script' , scriptForm , true ) ;
2010-06-16 18:21:58 +00:00
// Select new tab
tab . select ( newTabId ) ;
}
/ * *
* Sort a list
*
* @ return Sorted list
* /
jQuery . fn . sort = function ( ) {
return this . pushStack ( [ ] . sort . apply ( this , arguments ) , [ ] ) ;
} ;
function sortAlpha ( a , b ) {
return a . innerHTML > b . innerHTML ? 1 : - 1 ;
} ;
/ * *
* Power on a given node
*
* @ param node
* Node to power on or off
* @ param power2
* Power node to given state
* @ return Nothing
* /
function powerNode ( node , power2 ) {
node = node . replace ( 'Power' , '' ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
tgt : node ,
args : power2 ,
msg : node
} ,
success : updatePowerStatus
} ) ;
}
/ * *
2010-11-24 18:11:42 +00:00
* Load delete node page
2010-06-16 18:21:58 +00:00
*
* @ param tgtNodes
* Nodes to delete
* @ return Nothing
* /
2010-11-24 18:11:42 +00:00
function loadDeletePage ( tgtNodes ) {
2010-12-01 01:54:05 +00:00
// Get nodes tab
2010-06-16 18:21:58 +00:00
var myTab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
2010-12-03 22:09:36 +00:00
newTabId = 'deleteTab' + inst ;
2010-06-16 18:21:58 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'deleteTab' + inst ;
2010-06-16 18:21:58 +00:00
}
// Create status bar, hide on load
var statBarId = 'DeleteStatusBar' + inst ;
2010-07-29 20:22:09 +00:00
var statBar = $ ( '<div class="statusBar" id="' + statBarId + '"></div>' ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
// Create loader
var loader = createLoader ( '' ) ;
statBar . append ( loader ) ;
statBar . hide ( ) ;
// Create target nodes string
var tgtNodesStr = '' ;
var nodes = tgtNodes . split ( ',' ) ;
// Loop through each node
2010-11-24 18:11:42 +00:00
for ( var i in nodes ) {
2010-06-16 18:21:58 +00:00
// If it is the 1st and only node
if ( i == 0 && i == nodes . length - 1 ) {
tgtNodesStr += nodes [ i ] ;
}
// If it is the 1st node of many nodes
else if ( i == 0 && i != nodes . length - 1 ) {
// Append a comma to the string
tgtNodesStr += nodes [ i ] + ', ' ;
} else {
// If it is the last node
if ( i == nodes . length - 1 ) {
// Append nothing to the string
tgtNodesStr += nodes [ i ] ;
} else {
2010-07-25 23:53:27 +00:00
// Append a comma to the string
tgtNodesStr += nodes [ i ] + ', ' ;
2010-06-16 18:21:58 +00:00
}
}
}
var deleteForm = $ ( '<div class="form"></div>' ) ;
deleteForm . append ( statBar ) ;
2010-07-25 23:53:27 +00:00
deleteForm . append ( statBar ) ;
// Word wrap
2010-12-03 22:09:36 +00:00
var instr = $ ( '<p>Are you sure you want to delete ' + tgtNodesStr + '?</p>' ) . css ( 'word-wrap' , 'break-word' ) ;
2010-07-25 23:53:27 +00:00
deleteForm . append ( instr ) ;
2010-06-16 18:21:58 +00:00
/ * *
* Delete
* /
var deleteBtn = createButton ( 'Delete' ) ;
deleteBtn . bind ( 'click' , function ( event ) {
// Delete the virtual server
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rmvm' ,
tgt : tgtNodes ,
args : '' ,
msg : 'out=' + statBarId + ';cmd=rmvm;tgt=' + tgtNodes
} ,
success : updateStatusBar
} ) ;
// Show status bar loader
statBar . show ( ) ;
2010-07-29 20:22:09 +00:00
// Disable delete button
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-06-16 18:21:58 +00:00
} ) ;
2010-07-25 07:41:49 +00:00
var cancelBtn = createButton ( 'Cancel' ) ;
cancelBtn . bind ( 'click' , function ( ) {
myTab . remove ( $ ( this ) . parent ( ) . parent ( ) . attr ( 'id' ) ) ;
} ) ;
2010-06-16 18:21:58 +00:00
deleteForm . append ( deleteBtn ) ;
2010-07-25 07:41:49 +00:00
deleteForm . append ( cancelBtn ) ;
2010-08-03 14:58:08 +00:00
myTab . add ( newTabId , 'Delete' , deleteForm , true ) ;
2010-06-16 18:21:58 +00:00
myTab . select ( newTabId ) ;
}
/ * *
2010-07-29 17:32:24 +00:00
* Update status bar of a given tab
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function updateStatusBar ( data ) {
2010-07-29 17:32:24 +00:00
// Get ajax response
2010-06-16 18:21:58 +00:00
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
var statBarId = args [ 0 ] . replace ( 'out=' , '' ) ;
var cmd = args [ 1 ] . replace ( 'cmd=' , '' ) ;
var tgts = args [ 2 ] . replace ( 'tgt=' , '' ) . split ( ',' ) ;
2010-08-04 20:06:12 +00:00
if ( cmd == 'unlock' || cmd == 'updatenode' ) {
2010-06-16 18:21:58 +00:00
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
2010-06-16 18:21:58 +00:00
} else if ( cmd == 'rmvm' ) {
// Get data table
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
var failed = false ;
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
2010-09-24 02:27:04 +00:00
// If there was an error, do not continue
2010-07-27 22:56:42 +00:00
if ( prg . html ( ) . indexOf ( 'Error' ) > - 1 ) {
failed = true ;
2010-06-16 18:21:58 +00:00
}
// Update data table
2010-12-03 22:09:36 +00:00
var rowPos ;
2010-11-24 18:11:42 +00:00
for ( var i in tgts ) {
2010-06-16 18:21:58 +00:00
if ( ! failed ) {
// Get the row containing the node link and delete it
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( tgts [ i ] , '#nodesDataTable' , 1 ) ;
2010-06-16 18:21:58 +00:00
dTable . fnDeleteRow ( rowPos ) ;
}
}
2010-09-22 19:32:09 +00:00
} else if ( cmd == 'xdsh' ) {
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
// Write ajax response to status bar
2010-10-08 03:56:24 +00:00
var prg = $ ( '<p></p>' ) ;
for ( var i in rsp ) {
for ( var j in tgts ) {
rsp [ i ] = rsp [ i ] . replace ( new RegExp ( tgts [ j ] + ':' , 'g' ) , '<br>' ) ;
}
prg . append ( rsp [ i ] ) ;
prg . append ( '<br>' ) ;
}
2010-09-22 19:32:09 +00:00
$ ( '#' + statBarId ) . append ( prg ) ;
// Enable fields
$ ( '#' + statBarId ) . parent ( ) . find ( 'input' ) . removeAttr ( 'disabled' ) ;
$ ( '#' + statBarId ) . parent ( ) . find ( 'textarea' ) . removeAttr ( 'disabled' ) ;
// Enable buttons
$ ( '#' + statBarId ) . parent ( ) . find ( 'button' ) . removeAttr ( 'disabled' ) ;
2010-07-15 22:57:48 +00:00
} else {
2010-06-16 18:21:58 +00:00
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-09-22 19:32:09 +00:00
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '[A-Za-z0-9._-]+:' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
2010-06-16 18:21:58 +00:00
}
}
/ * *
2010-07-19 18:28:31 +00:00
* Check if the form is complete
2010-06-16 18:21:58 +00:00
*
* @ param tabId
* Tab ID containing form
* @ return True : If the form is complete , False : Otherwise
* /
function formComplete ( tabId ) {
var ready = true ;
// Check all inputs within the form
var inputs = $ ( '#' + tabId + ' input' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in inputs ) {
2010-06-16 18:21:58 +00:00
// If there is no value given in the input
if ( ! inputs . eq ( i ) . val ( ) ) {
inputs . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
2010-07-19 18:28:31 +00:00
2010-06-16 18:21:58 +00:00
// It is not complete
ready = false ;
} else {
inputs . eq ( i ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
}
}
return ready ;
}
/ * *
2010-07-29 17:32:24 +00:00
* Update power status of a node in the datatable
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function updatePowerStatus ( data ) {
// Get datatable
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
// Get xCAT response
var rsp = data . rsp ;
// Loop through each line
2010-12-03 22:09:36 +00:00
var node , status , rowPos , strPos ;
2010-11-24 18:11:42 +00:00
for ( var i in rsp ) {
2010-06-16 18:21:58 +00:00
// Get the node
2010-12-03 22:09:36 +00:00
node = rsp [ i ] . split ( ":" ) [ 0 ] ;
2010-06-16 18:21:58 +00:00
// If there is no error
if ( rsp [ i ] . indexOf ( "Error" ) < 0 || rsp [ i ] . indexOf ( "Failed" ) < 0 ) {
// Get the row containing the node link
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( node , '#nodesDataTable' , 1 ) ;
2010-06-16 18:21:58 +00:00
// If it was power on, then the data return would contain "Starting"
2010-12-03 22:09:36 +00:00
strPos = rsp [ i ] . indexOf ( "Starting" ) ;
2010-06-16 18:21:58 +00:00
if ( strPos > - 1 ) {
status = 'on' ;
} else {
status = 'off' ;
}
// Update the power status column
dTable . fnUpdate ( status , rowPos , 3 ) ;
} else {
// Power on/off failed
alert ( rsp [ i ] ) ;
}
}
}
/ * *
* Run a script
*
* @ param inst
* Remote script tab instance
* @ return Nothing
* /
function runScript ( inst ) {
var tabId = 'scriptTab' + inst ;
2010-09-22 19:32:09 +00:00
2010-06-16 18:21:58 +00:00
// Get node name
var tgts = $ ( '#' + tabId + ' input[name=target]' ) . val ( ) ;
// Get script
var script = $ ( '#' + tabId + ' textarea' ) . val ( ) ;
2010-09-22 19:32:09 +00:00
var statBarId = 'scriptStatusBar' + inst ;
$ ( '#' + statBarId ) . show ( ) ; // Show status bar
$ ( '#' + statBarId + ' img' ) . show ( ) ; // Show loader
2010-11-09 05:05:10 +00:00
$ ( '#' + statBarId + ' p' ) . remove ( ) ; // Clear status bar
2010-06-16 18:21:58 +00:00
// Disable all fields
2010-09-22 19:32:09 +00:00
$ ( '#' + tabId + ' input' ) . attr ( 'disabled' , 'true' ) ;
$ ( '#' + tabId + ' textarea' ) . attr ( 'disabled' , 'true' ) ;
// Disable buttons
$ ( '#' + tabId + ' button' ) . attr ( 'disabled' , 'true' ) ;
2010-06-16 18:21:58 +00:00
// Run script
$ . ajax ( {
url : 'lib/zCmd.php' ,
dataType : 'json' ,
data : {
cmd : 'xdsh' ,
tgt : tgts ,
args : '-e' ,
att : script ,
msg : 'out=scriptStatusBar' + inst + ';cmd=xdsh;tgt=' + tgts
} ,
success : updateStatusBar
} ) ;
}
/ * *
2010-08-03 20:44:26 +00:00
* Get an attribute of a given node
2010-06-16 18:21:58 +00:00
*
* @ param node
* The node
2010-08-03 20:44:26 +00:00
* @ param attrName
2010-11-17 18:53:40 +00:00
* The attribute
2010-08-03 20:44:26 +00:00
* @ return The attribute of the node
2010-06-16 18:21:58 +00:00
* /
2010-08-03 20:44:26 +00:00
function getNodeAttr ( node , attrName ) {
// Get the row
2010-07-26 08:23:47 +00:00
var row = $ ( '[id=' + node + ']' ) . parent ( ) . parent ( ) ;
2010-06-16 18:21:58 +00:00
2010-08-03 20:44:26 +00:00
// Search for the column containing the attribute
2010-08-03 21:22:46 +00:00
var attrCol ;
var cols = row . parent ( ) . parent ( ) . find ( 'th:contains("' + attrName + '")' ) ;
// Loop through each column
for ( var i in cols ) {
// Find column that matches the attribute
if ( cols . eq ( i ) . html ( ) == attrName ) {
attrCol = cols . eq ( i ) ;
break ;
}
}
2010-11-17 18:53:40 +00:00
// If the column containing the attribute is found
2010-08-03 21:22:46 +00:00
if ( attrCol ) {
// Get the attribute column index
var attrIndex = attrCol . index ( ) ;
2010-06-16 18:21:58 +00:00
2010-08-03 21:22:46 +00:00
// Get the attribute for the given node
var attr = row . find ( 'td:eq(' + attrIndex + ')' ) ;
2010-06-16 18:21:58 +00:00
2010-08-03 21:22:46 +00:00
return attr . text ( ) ;
} else {
return '' ;
}
2010-06-16 18:21:58 +00:00
}
/ * *
* Set a cookie for the OS images
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function setOSImageCookies ( data ) {
var rsp = data . rsp ;
var imageNames = new Array ;
var profilesHash = new Object ( ) ;
var osVersHash = new Object ( ) ;
var osArchsHash = new Object ( ) ;
2010-11-24 18:11:42 +00:00
for ( var i = 1 ; i < rsp . length ; i ++ ) {
2010-06-16 18:21:58 +00:00
// Get the image name
var cols = rsp [ i ] . split ( ',' ) ;
var osImage = cols [ 0 ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var profile = cols [ 1 ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var osVer = cols [ 5 ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var osArch = cols [ 7 ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
imageNames . push ( osImage ) ;
profilesHash [ profile ] = 1 ;
osVersHash [ osVer ] = 1 ;
osArchsHash [ osArch ] = 1 ;
}
// Save image names in a cookie
2010-11-22 16:18:55 +00:00
$ . cookie ( 'imagenames' , imageNames ) ;
2010-06-16 18:21:58 +00:00
// Save profiles in a cookie
var tmp = new Array ;
2010-11-24 18:11:42 +00:00
for ( var key in profilesHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'profiles' , tmp ) ;
2010-06-16 18:21:58 +00:00
// Save OS versions in a cookie
tmp = [ ] ;
2010-11-24 18:11:42 +00:00
for ( var key in osVersHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'osvers' , tmp ) ;
2010-06-16 18:21:58 +00:00
// Save OS architectures in a cookie
tmp = [ ] ;
2010-11-24 18:11:42 +00:00
for ( var key in osArchsHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'osarchs' , tmp ) ;
2010-06-16 18:21:58 +00:00
}
/ * *
* Set a cookie for the groups
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function setGroupsCookies ( data ) {
var rsp = data . rsp ;
2010-11-22 16:18:55 +00:00
$ . cookie ( 'groups' , rsp ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
/ * *
2010-07-29 17:32:24 +00:00
* Get nodes that are checked in a given datatable
2010-07-15 13:41:29 +00:00
*
2010-07-27 19:50:01 +00:00
* @ param datatableId
2010-11-17 18:53:40 +00:00
* The datatable ID
2010-07-15 13:41:29 +00:00
* @ return Nodes that were checked
* /
2010-07-27 19:50:01 +00:00
function getNodesChecked ( datatableId ) {
var tgts = '' ;
2010-07-15 13:41:29 +00:00
// Get nodes that were checked
2010-07-27 19:50:01 +00:00
var nodes = $ ( '#' + datatableId + ' input[type=checkbox]:checked' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in nodes ) {
2010-07-27 19:50:01 +00:00
var tgtNode = nodes . eq ( i ) . attr ( 'name' ) ;
2010-07-25 07:41:49 +00:00
2010-07-27 19:50:01 +00:00
if ( tgtNode ) {
tgts += tgtNode ;
// Add a comma at the end
if ( i < nodes . length - 1 ) {
tgts += ',' ;
}
2010-07-15 13:41:29 +00:00
}
}
2010-07-27 19:50:01 +00:00
return tgts ;
2010-07-25 07:41:49 +00:00
}
2010-09-20 18:57:08 +00:00
/ * *
2010-12-03 22:09:36 +00:00
* Find the row index using a column search value
2010-09-20 18:57:08 +00:00
*
2010-12-03 22:09:36 +00:00
* @ param searchStr
* String to search for
* @ param table
* Table to check
* @ param col
* Column to find string under
* @ return The row index containing the search string
2010-09-20 18:57:08 +00:00
* /
2010-12-03 22:09:36 +00:00
function findRowIndexUsingCol ( searchStr , table , col ) {
var dTable , rows , cols ;
2010-07-26 08:23:47 +00:00
// Get datatable
2010-12-03 22:09:36 +00:00
dTable = $ ( table ) . dataTable ( ) ;
rows = dTable . fnGetData ( ) ;
// Loop through each row
for ( var i = 0 ; i < rows . length ; i ++ ) {
// Get columns in row
cols = dTable . fnGetData ( i ) ;
// If column contains string
if ( cols [ col ] . indexOf ( searchStr ) > - 1 ) {
// Return index
return i ;
2010-07-26 08:23:47 +00:00
}
}
2010-12-03 22:09:36 +00:00
2010-07-26 08:23:47 +00:00
return - 1 ;
}
2010-07-26 18:34:29 +00:00
2010-07-28 20:24:29 +00:00
/ * *
* Select all checkboxes in a given datatable
*
* @ param event
* Event on element
* @ param obj
* Object triggering event
* @ return Nothing
* /
function selectAllCheckbox ( event , obj ) {
// Get datatable ID
// This will ascend from <input> <td> <tr> <thead> <table>
var datatableId = obj . parent ( ) . parent ( ) . parent ( ) . parent ( ) . attr ( 'id' ) ;
2010-07-25 07:41:49 +00:00
var status = obj . attr ( 'checked' ) ;
2010-07-28 20:24:29 +00:00
$ ( '#' + datatableId + ' :checkbox' ) . attr ( 'checked' , status ) ;
2010-07-25 07:41:49 +00:00
event . stopPropagation ( ) ;
2010-09-20 07:41:43 +00:00
}
2010-09-20 18:57:08 +00:00
/ * *
* Load rcons page
*
* @ param tgtNodes
* Targets to run rcons against
* @ return Nothing
* /
function loadRconsPage ( tgtNodes ) {
2010-09-20 07:41:43 +00:00
var hostName = window . location . host ;
var urlPath = window . location . pathname ;
var redirectUrl = 'https://' ;
var pos = 0 ;
2010-12-03 22:09:36 +00:00
2010-11-09 05:05:10 +00:00
// We only support one node
2010-09-20 07:41:43 +00:00
if ( - 1 != tgtNodes . indexOf ( ',' ) ) {
2010-12-03 22:09:36 +00:00
alert ( "You can only open one console at a time!" ) ;
2010-09-20 07:41:43 +00:00
return ;
}
redirectUrl += hostName ;
pos = urlPath . lastIndexOf ( '/' ) ;
redirectUrl += urlPath . substring ( 0 , pos + 1 ) ;
redirectUrl += 'rconsShow.php' ;
2010-11-09 05:05:10 +00:00
// Open the rcons page
2010-09-20 07:41:43 +00:00
window . open ( redirectUrl + "?rconsnd=" + tgtNodes , '' , "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=670,height=436" ) ;
2010-11-09 05:05:10 +00:00
}
/ * *
* Flag the node in the group table to update
*
* @ param node
* The node name
* @ return Nothing
* /
function flagNode2Update ( node ) {
// Get list containing current nodes to update
2010-11-22 16:18:55 +00:00
var nodes = $ . cookie ( 'nodes2update' ) ;
2010-11-09 05:05:10 +00:00
// If the node is not in the list
if ( nodes . indexOf ( node ) == - 1 ) {
// Add the new node to list
nodes += node + ';' ;
2010-11-22 16:18:55 +00:00
$ . cookie ( 'nodes2update' , nodes ) ;
2010-11-09 05:05:10 +00:00
}
}
/ * *
* Update the node attributes
*
* @ param group
* The node group name
* @ return Nothing
* /
function updateNodeAttrs ( group ) {
2010-11-18 16:35:59 +00:00
// Get the nodes datatable
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
// Get all nodes within the datatable
var rows = dTable . fnGetNodes ( ) ;
// Get table headers
var headers = $ ( '#nodesDataTable thead tr th' ) ;
// Get list of nodes to update
2010-11-22 16:18:55 +00:00
var nodesList = $ . cookie ( 'nodes2update' ) ;
2010-11-18 16:35:59 +00:00
var nodes = nodesList . split ( ';' ) ;
// Create the arguments
var args ;
2010-12-03 22:09:36 +00:00
var rowPos , colPos , value ;
2010-11-18 16:35:59 +00:00
var attrName ;
// Go through each node where an attribute was changed
2010-11-24 18:11:42 +00:00
for ( var i in nodes ) {
2010-11-18 16:35:59 +00:00
if ( nodes [ i ] ) {
args = '' ;
2010-11-09 13:28:55 +00:00
2010-11-18 16:35:59 +00:00
// Get the row containing the node link
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( nodes [ i ] , '#nodesDataTable' , 1 ) ;
$ ( rows [ rowPos ] ) . find ( 'td' ) . each ( function ( ) {
2010-11-18 16:35:59 +00:00
if ( $ ( this ) . css ( 'color' ) == 'red' ) {
// Change color back to normal
$ ( this ) . css ( 'color' , '' ) ;
// Get column position
colPos = $ ( this ) . parent ( ) . children ( ) . index ( $ ( this ) ) ;
// Get column value
value = $ ( this ) . text ( ) ;
// Get attribute name
attrName = jQuery . trim ( headers . eq ( colPos ) . text ( ) ) ;
// Build argument string
if ( args ) {
// Handle subsequent arguments
args += ';' + attrName + '=' + value ;
} else {
// Handle the 1st argument
args += attrName + '=' + value ;
}
}
} ) ;
// Send command to change node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : '-t;node;-o;' + nodes [ i ] + ';' + args ,
2010-12-03 22:09:36 +00:00
msg : 'out=nodesTab;tgt=' + nodes [ i ]
2010-11-18 16:35:59 +00:00
} ,
success : showChdefOutput
} ) ;
} // End of if
} // End of for
// Clear cookie containing list of nodes where
// their attributes need to be updated
2010-11-22 16:18:55 +00:00
$ . cookie ( 'nodes2update' , '' ) ;
2010-11-09 21:22:43 +00:00
}
2010-11-12 18:59:25 +00:00
/ * *
* Restore node attributes to their original content
*
* @ return Nothing
* /
function restoreNodeAttrs ( ) {
// Get list of nodes to update
2010-11-22 16:18:55 +00:00
var nodesList = $ . cookie ( 'nodes2update' ) ;
2010-11-12 18:59:25 +00:00
var nodes = nodesList . split ( ';' ) ;
// Get the nodes datatable
2010-11-17 18:53:40 +00:00
var dTable = $ ( '#nodesDataTable' ) . dataTable ( ) ;
2010-11-12 18:59:25 +00:00
// Get table headers
var headers = $ ( '#nodesDataTable thead tr th' ) ;
// Get all nodes within the datatable
var rows = dTable . fnGetNodes ( ) ;
// Go through each node where an attribute was changed
2010-12-03 22:09:36 +00:00
var rowPos , colPos ;
2010-11-12 18:59:25 +00:00
var attrName , origVal ;
2010-11-24 18:11:42 +00:00
for ( var i in nodes ) {
2010-11-12 18:59:25 +00:00
if ( nodes [ i ] ) {
// Get the row containing the node link
2010-12-03 22:09:36 +00:00
rowPos = findRowIndexUsingCol ( tgts [ i ] , '#nodesDataTable' , 1 ) ;
$ ( rows [ rowPos ] ) . find ( 'td' ) . each ( function ( ) {
2010-11-12 18:59:25 +00:00
if ( $ ( this ) . css ( 'color' ) == 'red' ) {
// Change color back to normal
$ ( this ) . css ( 'color' , '' ) ;
// Get column position
colPos = $ ( this ) . parent ( ) . children ( ) . index ( $ ( this ) ) ;
// Get attribute name
attrName = jQuery . trim ( headers . eq ( colPos ) . text ( ) ) ;
// Get original content
origVal = origAttrs [ nodes [ i ] ] [ attrName ] ;
// Update column
dTable . fnUpdate ( origVal , rowPos , colPos ) ;
}
} ) ;
} // End of if
} // End of for
2010-11-17 18:53:40 +00:00
// Clear cookie containing list of nodes where
2010-11-12 18:59:25 +00:00
// their attributes need to be updated
2010-11-22 16:18:55 +00:00
$ . cookie ( 'nodes2update' , '' ) ;
2010-11-12 18:59:25 +00:00
}
2010-11-09 21:22:43 +00:00
/ * *
2010-11-11 15:07:40 +00:00
* Create a tool tip for comment
2010-11-09 21:22:43 +00:00
*
2010-11-11 15:07:40 +00:00
* @ param comment
2010-11-09 21:22:43 +00:00
* The comments to be placed in the tool tip
* @ return Tool tip
* /
2010-11-11 15:07:40 +00:00
function createCommentsToolTip ( comment ) {
2010-11-09 21:22:43 +00:00
// Create tooltip container
var toolTip = $ ( '<div class="tooltip"></div>' ) ;
2010-11-11 15:07:40 +00:00
// Create textarea to hold comment
var txtArea = $ ( '<textarea>' + comment + '</textarea>' ) . css ( {
2010-11-10 17:14:08 +00:00
'font-size' : '10px' ,
2010-11-09 21:22:43 +00:00
'height' : '50px' ,
'width' : '200px' ,
'background-color' : '#000' ,
'color' : '#fff' ,
2010-11-10 19:11:37 +00:00
'border' : '0px' ,
'display' : 'block'
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-10 17:14:08 +00:00
// Create links to save and cancel changes
2010-11-10 19:11:37 +00:00
var lnkStyle = {
2010-11-10 17:14:08 +00:00
'color' : '#58ACFA' ,
'font-size' : '10px' ,
2010-11-10 19:11:37 +00:00
'display' : 'inline-block' ,
'padding' : '5px' ,
'float' : 'right'
} ;
2010-11-10 21:18:35 +00:00
var saveLnk = $ ( '<a>Save</a>' ) . css ( lnkStyle ) . hide ( ) ;
var cancelLnk = $ ( '<a>Cancel</a>' ) . css ( lnkStyle ) . hide ( ) ;
2010-11-18 16:44:01 +00:00
var infoSpan = $ ( '<span>Click to edit</span>' ) . css ( lnkStyle ) ;
2010-11-10 17:14:08 +00:00
// Save changes onclick
2010-11-09 21:22:43 +00:00
saveLnk . bind ( 'click' , function ( ) {
2010-11-11 15:07:40 +00:00
// Get node and comment
2010-11-10 17:21:39 +00:00
var node = $ ( this ) . parent ( ) . parent ( ) . find ( 'img' ) . attr ( 'id' ) . replace ( 'Tip' , '' ) ;
2010-11-09 21:22:43 +00:00
var comments = $ ( this ) . parent ( ) . find ( 'textarea' ) . val ( ) ;
2010-11-11 15:07:40 +00:00
// Save comment
2010-11-09 21:22:43 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2010-11-18 16:35:59 +00:00
cmd : 'chdef' ,
2010-11-09 21:22:43 +00:00
tgt : '' ,
2010-11-18 16:35:59 +00:00
args : '-t;node;-o;' + node + ';usercomment=' + comments ,
2010-12-03 22:09:36 +00:00
msg : 'out=nodesTab;tgt=' + node
2010-11-09 21:22:43 +00:00
} ,
2010-11-18 16:35:59 +00:00
success : showChdefOutput
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-10 17:14:08 +00:00
// Hide cancel and save links
$ ( this ) . hide ( ) ;
cancelLnk . hide ( ) ;
} ) ;
// Cancel changes onclick
cancelLnk . bind ( 'click' , function ( ) {
2010-11-11 15:07:40 +00:00
// Get original comment and put it back
2010-11-10 17:14:08 +00:00
var orignComments = $ ( this ) . parent ( ) . find ( 'textarea' ) . text ( ) ;
$ ( this ) . parent ( ) . find ( 'textarea' ) . val ( orignComments ) ;
// Hide cancel and save links
$ ( this ) . hide ( ) ;
saveLnk . hide ( ) ;
2010-11-18 16:44:01 +00:00
infoSpan . show ( ) ;
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-11 15:07:40 +00:00
// Show save link when comment is edited
2010-11-09 21:22:43 +00:00
txtArea . bind ( 'click' , function ( ) {
saveLnk . show ( ) ;
2010-11-10 17:14:08 +00:00
cancelLnk . show ( ) ;
2010-11-18 16:44:01 +00:00
infoSpan . hide ( ) ;
2010-11-09 21:22:43 +00:00
} ) ;
toolTip . append ( txtArea ) ;
2010-11-10 17:14:08 +00:00
toolTip . append ( cancelLnk ) ;
2010-11-10 19:11:37 +00:00
toolTip . append ( saveLnk ) ;
2010-11-18 16:44:01 +00:00
toolTip . append ( infoSpan ) ;
2010-11-09 21:22:43 +00:00
return toolTip ;
}
/ * *
2010-11-18 16:35:59 +00:00
* Show chdef output
2010-11-09 21:22:43 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-11-18 16:35:59 +00:00
function showChdefOutput ( data ) {
2010-11-10 21:18:35 +00:00
// Get output
var out = data . rsp ;
2010-11-24 18:11:42 +00:00
var args = data . msg . split ( ';' ) ;
var tabID = args [ 0 ] . replace ( 'out=' , '' ) ;
2010-12-03 22:09:36 +00:00
var tgt = args [ 1 ] . replace ( 'tgt=' , '' ) ;
2010-11-09 21:22:43 +00:00
// Find info bar on nodes tab, if any
2010-11-24 18:11:42 +00:00
var info = $ ( '#' + tabID ) . find ( '.ui-state-highlight' ) ;
2010-11-09 21:22:43 +00:00
if ( ! info . length ) {
// Create info bar if one does not exist
info = createInfoBar ( '' ) ;
2010-12-01 01:54:05 +00:00
$ ( '#' + tabID ) . append ( info ) ;
2010-11-09 21:22:43 +00:00
}
2010-11-10 21:18:35 +00:00
// Go through output and append to paragraph
2010-12-03 22:09:36 +00:00
var prg = $ ( '<p></p>' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in out ) {
2010-12-03 22:09:36 +00:00
prg . append ( tgt + ': ' + out [ i ] + '<br>' ) ;
2010-11-09 21:22:43 +00:00
}
2010-12-03 22:09:36 +00:00
info . append ( prg ) ;
2010-11-24 18:11:42 +00:00
}
/ * *
* Set definable node attributes
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function setDefAttrs ( data ) {
2010-12-02 21:28:24 +00:00
// Clear hash table containing definable node attributes
defAttrs = new Array ( ) ;
2010-11-24 18:11:42 +00:00
// 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 ) ) ;
// Set hash table where key = attribute name and value = description
defAttrs [ key ] = descr ;
} else {
// 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
* /
2010-12-03 22:09:36 +00:00
function loadEditPropsPage ( tgtNode ) {
2010-11-24 18:11:42 +00:00
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
2010-12-03 22:09:36 +00:00
var newTabId = 'editPropsTab' + inst ;
2010-11-24 18:11:42 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'editPropsTab' + inst ;
2010-11-24 18:11:42 +00:00
}
// Open new tab
// Create set properties form
2010-12-03 22:09:36 +00:00
var editPropsForm = $ ( '<div class="form"></div>' ) ;
2010-11-24 18:11:42 +00:00
// Create info bar
var infoBar = createInfoBar ( 'Choose the properties you wish to change on the node. When you are finished, click Save.' ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( infoBar ) ;
2010-11-24 18:11:42 +00:00
// 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 = $ ( '<div></div>' ) . css ( 'display' , 'inline' ) ;
label = $ ( '<label>' + key + ':</label>' ) . css ( 'vertical-align' , 'middle' ) ;
input = $ ( '<input type="text" value="' + value + '" title="' + defAttrs [ key ] + '"/>' ) . 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 ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( div ) ;
2010-11-24 18:11:42 +00:00
}
2010-12-03 22:09:36 +00:00
2010-11-24 18:11:42 +00:00
// Change style for last division
div . css ( {
'display' : 'block' ,
'margin' : '0px 0px 10px 0px'
} ) ;
// Generate tooltips
2010-12-03 22:09:36 +00:00
editPropsForm . find ( 'div input[title]' ) . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
2010-12-02 21:28:24 +00:00
delay : 0 ,
predelay : 800 ,
events : {
def : "mouseover,mouseout" ,
input : "mouseover,mouseout" ,
widget : "focus mouseover,blur mouseout" ,
tooltip : "mouseover,mouseout"
}
2010-11-24 18:11:42 +00:00
} ) ;
/ * *
* 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 ,
2010-12-03 22:09:36 +00:00
msg : 'out=' + newTabId + ';tgt=' + tgtNode
2010-11-24 18:11:42 +00:00
} ,
success : showChdefOutput
} ) ;
} ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( saveBtn ) ;
2010-11-24 18:11:42 +00:00
/ * *
* Cancel
* /
var cancelBtn = createButton ( 'Cancel' ) ;
cancelBtn . bind ( 'click' , function ( event ) {
// Close the tab
tab . remove ( $ ( this ) . parent ( ) . parent ( ) . attr ( 'id' ) ) ;
} ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( cancelBtn ) ;
2010-11-24 18:11:42 +00:00
// Append to discover tab
2010-12-03 22:09:36 +00:00
tab . add ( newTabId , 'Edit' , editPropsForm , true ) ;
2010-11-24 18:11:42 +00:00
// Select new tab
tab . select ( newTabId ) ;
2010-12-02 21:28:24 +00:00
}
/ * *
* Open set node properties dialog
*
* @ return Nothing
* /
function openSetPropsDialog ( ) {
// Open new tab
// Create set properties form
var setPropsForm = $ ( '<div class="form"></div>' ) ;
// 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 = $ ( '<div></div>' ) . css ( 'display' , 'inline' ) ;
label = $ ( '<label>' + key + ':</label>' ) . css ( 'vertical-align' , 'middle' ) ;
input = $ ( '<input type="text" value="' + value + '" title="' + defAttrs [ key ] + '"/>' ) . 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 ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
2010-12-02 21:28:24 +00:00
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 : 650 ,
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
* /
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 += '<br>' + node + ': ' + out [ i ] ;
}
}
openDialog ( 'info' , msg ) ;
}
} ) ;
// Close dialog
$ ( this ) . dialog ( "close" ) ;
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
}
} ) ;
2010-06-16 18:21:58 +00:00
}