2011-04-16 14:40:15 +00:00
/ * *
2012-03-14 19:23:51 +00:00
* Global variables
2011-04-16 14:40:15 +00:00
* /
2012-03-14 19:23:51 +00:00
var xcatMonTableId = "xcatMonSettingTable" ;
2011-03-17 03:39:05 +00:00
2011-04-16 14:40:15 +00:00
/ * *
2012-03-14 19:23:51 +00:00
* Load xCAT monitoring
2011-04-16 14:40:15 +00:00
* /
2012-03-14 19:23:51 +00:00
function loadXcatMon ( ) {
// Find xCAT monitoring tab
2010-08-04 08:49:20 +00:00
var xcatMonTab = $ ( '#xcatmon' ) ;
2011-03-17 03:39:05 +00:00
xcatMonTab . append ( "<div id= xcatmonTable></div>" ) ;
2012-03-14 19:23:51 +00:00
// Show content of monsetting table
2011-03-17 03:39:05 +00:00
$ . ajax ( {
2012-03-14 19:23:51 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-03-17 03:39:05 +00:00
cmd : 'tabdump' ,
2012-03-14 19:23:51 +00:00
tgt : '' ,
2011-03-17 03:39:05 +00:00
args : 'monsetting' ,
msg : ''
} ,
2012-03-14 19:23:51 +00:00
success : loadXcatMonSetting
} ) ;
2011-03-17 03:39:05 +00:00
}
2011-04-16 14:40:15 +00:00
2012-03-14 19:23:51 +00:00
function loadXcatMonSetting ( data ) {
var apps = "" ; // Contains the xcatmon config
var rsp = data . rsp ;
var apps _flag = 0 ;
var ping ; // xcatmon ping interval
2011-09-12 16:10:53 +00:00
var ping _flag = 0 ;
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
// Create an info bar
var infoBar = createInfoBar ( 'Click on a cell to edit. Click outside the table to write to the cell. Once you are finished configuring the xCAT monitor, click on Apply.' ) ;
2011-03-17 03:39:05 +00:00
$ ( '#xcatmonTable' ) . append ( infoBar ) ;
2012-03-14 19:23:51 +00:00
// Create xcatmon table
var xcatmonTable = new DataTable ( xcatMonTableId ) ;
// Create datatable
2011-03-17 03:39:05 +00:00
var dTable ;
2010-08-04 08:49:20 +00:00
2012-03-14 19:23:51 +00:00
// Create table header
var header = rsp [ 0 ] . split ( "," ) ;
header . splice ( 3 , 2 ) ;
header . splice ( 0 , 1 ) ;
header [ 0 ] = "App Name" ;
header [ 1 ] = "Configure" ;
header . push ( '<input type="checkbox" onclick="selectAllCheckbox(event,$(this))">' ) ;
2011-03-17 03:39:05 +00:00
header . unshift ( '' ) ;
2012-03-14 19:23:51 +00:00
xcatmonTable . init ( header ) ;
// Create container for original table contents
var origCont = new Array ( ) ;
origCont [ 0 ] = header ; // Table headers
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
// Create container for new contents to use later updating monsetting table
var newCont = new Object ( ) ;
newCont [ 0 ] = rsp [ 0 ] . split ( "," ) ; // Table headers
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
// Create container for other monsetting lines
var otherCont = new Array ( ) ;
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
$ ( '#xcatmonTable' ) . append ( xcatmonTable . object ( ) ) ;
var m = 1 ; // Count for origCont
2011-09-12 16:10:53 +00:00
var n = 0 ;
2012-03-14 19:23:51 +00:00
for ( var i = 1 ; i < rsp . length ; i ++ ) {
var pos = rsp [ i ] . indexOf ( "xcatmon" ) ; // Only check xcatmon setting
2011-09-12 16:10:53 +00:00
if ( pos == 1 ) {
2012-03-14 19:23:51 +00:00
if ( ( rsp [ i ] . indexOf ( "apps" ) == - 1 ) && ( rsp [ i ] . indexOf ( "ping" ) == - 1 ) ) {
var cols = rsp [ i ] . split ( ',' ) ;
for ( var j = 0 ; j < cols . length ; j ++ ) {
if ( cols [ j ] . count ( '"' ) % 2 == 1 ) {
while ( cols [ j ] . count ( '"' ) % 2 == 1 ) {
cols [ j ] = cols [ j ] + "," + cols [ j + 1 ] ;
cols . splice ( j + 1 , 1 ) ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
cols [ j ] = cols [ j ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
cols . splice ( 3 , 2 ) ;
cols . splice ( 0 , 1 ) ;
cols . push ( '<input type="checkbox" name="' + cols [ 0 ] + '" title="Checking this box will add/remove the app from the configured app value"/>' ) ;
cols . unshift ( '<span class="ui-icon ui-icon-close" onclick="deleteXcatMonRow(this)"></span>' ) ;
// Add column to table
xcatmonTable . add ( cols ) ;
2011-09-12 16:10:53 +00:00
origCont [ m ++ ] = cols ;
} else {
2012-03-14 19:23:51 +00:00
if ( ! apps _flag ) { // Check the apps setting
if ( rsp [ i ] . indexOf ( "apps" ) > - 1 ) {
apps = rsp [ i ] . split ( ',' ) ;
for ( var j = 0 ; j < apps . length ; j ++ ) {
if ( apps [ j ] . count ( '"' ) % 2 == 1 ) {
while ( apps [ j ] . count ( '"' ) % 2 == 1 ) {
apps [ j ] = apps [ j ] + "," + apps [ j + 1 ] ;
apps . splice ( j + 1 , 1 ) ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
apps [ j ] = apps [ j ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
apps _flag = 1 ; // Set the flag to 1 to avoid this subroute
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
// Get into the ping settings
2011-09-12 16:10:53 +00:00
if ( ! ping _flag ) {
2012-03-14 19:23:51 +00:00
// Check the ping interval
2011-09-12 16:10:53 +00:00
if ( rsp [ i ] . indexOf ( "ping-interval" ) > - 1 ) {
2012-03-14 19:23:51 +00:00
ping = rsp [ i ] . split ( ',' ) ;
for ( var j = 0 ; j < ping . length ; j ++ ) {
if ( ping [ j ] . count ( '"' ) % 2 == 1 ) {
while ( ping [ j ] . count ( '"' ) % 2 == 1 ) {
ping [ j ] = ping [ j ] + "," + ping [ j + 1 ] ;
ping . splice ( j + 1 , 1 ) ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
ping [ j ] = ping [ j ] . replace ( ( new RegExp ( '"' , 'g' ) ) ,
'' ) ;
2011-03-17 03:39:05 +00:00
}
2011-09-12 16:10:53 +00:00
ping _flag = 1 ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
}
2011-09-12 16:10:53 +00:00
} else if ( pos != 1 ) {
2012-03-14 19:23:51 +00:00
// The other monitor in the monsetting table
2011-09-12 16:10:53 +00:00
var otherCols = rsp [ i ] . split ( ',' ) ;
2012-03-14 19:23:51 +00:00
for ( var k = 0 ; k < otherCols . length ; k ++ ) {
if ( otherCols [ k ] . count ( '"' ) % 2 == 1 ) {
while ( otherCols [ k ] . count ( '"' ) % 2 == 1 ) {
otherCols [ k ] = otherCols [ k ] + "," + otherCols [ k + 1 ] ;
otherCols . splice ( k + 1 , 1 ) ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
otherCols [ k ] = otherCols [ k ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
2011-09-12 16:10:53 +00:00
otherCont [ n ++ ] = otherCols ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
// If app is not in the monsetting table, then create default apps row
if ( ! apps _flag ) {
2011-09-12 16:10:53 +00:00
apps = rsp [ 0 ] . split ( ',' ) ;
apps [ 0 ] = "xcatmon" ;
apps [ 1 ] = "apps" ;
apps [ 2 ] = "" ;
apps [ 3 ] = "" ;
apps [ 4 ] = "" ;
2011-04-16 14:40:15 +00:00
}
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
// If the ping interval is not in the monsetting table, then create the
// default ping-interval
if ( ! ping _flag ) {
2011-09-12 16:10:53 +00:00
ping = rsp [ 0 ] . split ( ',' ) ;
ping [ 0 ] = "xcatmon" ;
ping [ 1 ] = "ping-interval" ;
2012-03-14 19:23:51 +00:00
// Set default ping-interval setting to 5
2011-09-12 16:10:53 +00:00
ping [ 2 ] = "5" ;
ping [ 3 ] = "" ;
ping [ 4 ] = "" ;
2010-08-04 08:49:20 +00:00
}
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
// Set checkbox to be true
2011-09-12 16:10:53 +00:00
var checked = apps [ 2 ] . split ( ',' ) ;
2012-03-14 19:23:51 +00:00
for ( var i = 0 ; i < checked . length ; i ++ ) {
$ ( "input:checkbox[name=" + checked [ i ] + "]" ) . attr ( 'checked' , true ) ;
for ( var j = 0 ; j < origCont . length ; j ++ ) {
2011-09-12 16:10:53 +00:00
if ( origCont [ j ] [ 1 ] == checked [ i ] ) {
2012-03-14 19:23:51 +00:00
origCont [ j ] . splice ( 3 , 1 ) ;
origCont [ j ] . push ( '<input type="checkbox" name="' + origCont [ j ] [ 1 ] + '" title="Check this checkbox to add/remove the app from the configured app value." checked=true/>' ) ;
2011-03-17 03:39:05 +00:00
}
}
2010-08-04 08:49:20 +00:00
2011-03-17 03:39:05 +00:00
}
$ ( ":checkbox" ) . tooltip ( ) ;
2011-09-12 16:10:53 +00:00
2012-03-14 19:23:51 +00:00
// Make the table editable
$ ( '#' + xcatMonTableId + ' td:not(td:nth-child(1),td:last-child)' ) . editable ( function ( value , settings ) {
var colPos = this . cellIndex ;
var rowPos = dTable . fnGetPosition ( this . parentNode ) ;
dTable . fnUpdate ( value , rowPos , colPos ) ;
return ( value ) ;
} , {
onblur : 'submit' ,
type : 'textarea' ,
placeholder : ' ' ,
height : '30px'
} ) ;
// Save datatable
dTable = $ ( '#' + xcatMonTableId ) . dataTable ( {
'iDisplayLength' : 50 ,
'bLengthChange' : false ,
"sScrollX" : "100%" ,
"bAutoWidth" : true
2011-09-12 16:10:53 +00:00
} ) ;
2010-08-04 08:49:20 +00:00
2012-03-14 19:23:51 +00:00
// Create action bar
2011-09-12 16:10:53 +00:00
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
var addRowLnk = $ ( '<a>Add row</a>' ) ;
addRowLnk . bind ( 'click' , function ( event ) {
2012-03-14 19:23:51 +00:00
// Create container for new row
2011-03-17 03:39:05 +00:00
var row = new Array ( ) ;
2012-03-14 19:23:51 +00:00
// Add delete button to row
row . push ( '<span class="ui-icon ui-icon-close" onclick="deleteXcatMonRow(this)"></span>' ) ;
for ( var i = 0 ; i < header . length - 2 ; i ++ )
2011-03-17 03:39:05 +00:00
row . push ( '' ) ;
2012-03-14 19:23:51 +00:00
// Add checkbox
row . push ( '<input type="checkbox" name="' + row [ 2 ] + '" title="Checking this checkbox will add/remove the app from the configured apps value"/>' ) ;
// Get the datatable of the table
var dTable = $ ( '#' + xcatMonTableId ) . dataTable ( ) ;
// Add the new row to the datatable
2011-03-17 03:39:05 +00:00
dTable . fnAddData ( row ) ;
2012-03-14 19:23:51 +00:00
// make the datatable editable
2011-03-17 03:39:05 +00:00
$ ( ":checkbox[title]" ) . tooltip ( ) ;
2012-03-14 19:23:51 +00:00
$ ( '#' + xcatMonTableId + ' td:not(td:nth-child(1),td:last-child)' ) . editable ( function ( value , settings ) {
var colPos = this . cellIndex ;
var rowPos = dTable
. fnGetPosition ( this . parentNode ) ;
dTable . fnUpdate ( value , rowPos ,
colPos ) ;
return ( value ) ;
} , {
onblur : 'submit' ,
type : 'textarea' ,
placeholder : ' ' ,
height : '30px'
} ) ;
2010-08-04 08:49:20 +00:00
} ) ;
2012-03-14 19:23:51 +00:00
// Create apply button to store the contents of the table to the monsetting table
2011-09-12 16:10:53 +00:00
var applyLnk = $ ( '<a>Apply</a>' ) ;
2012-03-14 19:23:51 +00:00
applyLnk . bind ( 'click' , function ( event ) {
// Get the datatable
var dTable = $ ( '#' + xcatMonTableId ) . dataTable ( ) ;
// Get datatable rows
var dRows = dTable . fnGetNodes ( ) ;
2011-09-12 16:10:53 +00:00
var count = 0 ;
2012-03-14 19:23:51 +00:00
// Create a new container for the apps value
2011-09-12 16:10:53 +00:00
var appValue = '' ;
var tableName = 'monsetting' ;
var closeBtn = createButton ( 'close' ) ;
2012-03-14 19:23:51 +00:00
// Get the row contents
for ( var i = 0 ; i < dRows . length ; i ++ ) {
2011-09-12 16:10:53 +00:00
if ( dRows [ i ] ) {
2012-03-14 19:23:51 +00:00
// Get the row columns
2011-09-12 16:10:53 +00:00
var cols = dRows [ i ] . childNodes ;
2012-03-14 19:23:51 +00:00
// Create a container for the new columns
2011-03-17 03:39:05 +00:00
var vals = new Array ( ) ;
2012-03-14 19:23:51 +00:00
for ( var j = 1 ; j < cols . length - 1 ; j ++ ) {
var val = cols . item ( j ) . firstChild . nodeValue ;
if ( val == ' ' )
vals [ j - 1 ] = '' ;
else
vals [ j - 1 ] = val ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
2011-09-12 16:10:53 +00:00
var vals _orig = new Array ( ) ;
2012-03-14 19:23:51 +00:00
// Copy data from vals to vals_orig
for ( var p = 0 ; p < 2 ; p ++ ) {
2011-09-12 16:10:53 +00:00
var val = vals [ p ] ;
2012-03-14 19:23:51 +00:00
vals _orig [ p ] = val ;
2011-04-16 14:40:15 +00:00
}
2011-03-17 03:39:05 +00:00
2011-09-12 16:10:53 +00:00
vals . push ( '' ) ;
vals . push ( '' ) ;
vals . unshift ( 'xcatmon' ) ;
2012-03-14 19:23:51 +00:00
// Stored new column to newCont
newCont [ i + 1 ] = vals ;
2011-03-17 03:39:05 +00:00
2012-03-14 19:23:51 +00:00
if ( cols . item ( cols . length - 1 ) . firstChild . checked ) {
vals _orig . push ( '<input type="checkbox" name="' + vals _orig [ 0 ] + '" title="Checking this checkbox will add/remove the app from the configured apps value" checked=true/>' ) ;
2011-09-12 16:10:53 +00:00
} else {
2012-03-14 19:23:51 +00:00
vals _orig . push ( '<input type="checkbox" name="' + vals _orig [ 0 ] + '" title="Checking this checkbox will add/remove the app from the configured apps value"/>' ) ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
// Add delete button to row
vals _orig . unshift ( '<span class="ui-icon ui-icon-close" onclick="deleteXcatMonRow(this)"></span>' ) ;
// Add row to origCont
origCont [ i + 1 ] = vals _orig ;
count = i + 1 ;
// Check checkbox for every row when merging the app name with the apps values
if ( cols . item ( cols . length - 1 ) . firstChild . checked )
appValue = appValue . concat ( cols . item ( 2 ) . firstChild . nodeValue + "," ) ;
2011-03-17 03:39:05 +00:00
}
}
2012-03-14 19:23:51 +00:00
2011-03-17 03:39:05 +00:00
count ++ ;
2012-03-14 19:23:51 +00:00
// Delete the last comma of the apps value
appValue = appValue . substring ( 0 , ( appValue . length - 1 ) ) ;
apps [ 2 ] = appValue ;
2011-09-12 16:10:53 +00:00
newCont [ count ++ ] = apps ;
newCont [ count ++ ] = ping ;
2012-03-14 19:23:51 +00:00
// Add to other monitor settings
for ( var j = 0 ; j < otherCont . length ; j ++ ) {
2011-09-12 16:10:53 +00:00
newCont [ count ++ ] = otherCont [ j ] ;
2011-03-17 03:39:05 +00:00
}
2012-03-14 19:23:51 +00:00
// Create save dialog
var dialogSave = $ ( '<div id="saveDialog" align="center">Saving configuration</div>' ) ;
2011-03-22 11:49:27 +00:00
dialogSave . append ( createLoader ( ) ) ;
2012-03-14 19:23:51 +00:00
2011-09-12 16:10:53 +00:00
$ ( '#xcatmon' ) . append ( dialogSave ) ;
2012-03-14 19:23:51 +00:00
$ ( "#saveDialog" ) . dialog ( {
modal : true
} ) ;
2011-03-22 11:49:27 +00:00
$ ( '.ui-dialog-titlebar-close' ) . hide ( ) ;
2010-08-04 08:49:20 +00:00
$ . ajax ( {
2011-03-17 03:39:05 +00:00
type : 'POST' ,
url : 'lib/tabRestore.php' ,
2010-08-04 08:49:20 +00:00
dataType : 'json' ,
data : {
2011-03-17 03:39:05 +00:00
table : tableName ,
cont : newCont
2010-08-04 08:49:20 +00:00
} ,
2012-03-14 19:23:51 +00:00
success : function ( data ) {
// empty the dialog.add the close button
$ ( "#saveDialog" ) . empty ( ) . append ( '<p>Configuration saved!</p>' ) ;
2011-03-22 11:49:27 +00:00
$ ( "#saveDialog" ) . append ( closeBtn ) ;
2010-08-04 08:49:20 +00:00
}
} ) ;
2012-03-14 19:23:51 +00:00
// Close button
closeBtn . bind ( 'click' , function ( event ) {
$ ( "#saveDialog" ) . dialog ( "destroy" ) ;
2011-04-16 14:40:15 +00:00
$ ( "#saveDialog" ) . remove ( ) ;
} ) ;
2010-08-04 08:49:20 +00:00
2012-03-14 19:23:51 +00:00
// Clear the newCont
2011-09-12 16:10:53 +00:00
newCont = null ;
newCont = new Object ( ) ;
newCont [ 0 ] = rsp [ 0 ] . split ( "," ) ;
2011-04-16 14:40:15 +00:00
} ) ;
2012-03-14 19:23:51 +00:00
2011-09-12 16:10:53 +00:00
var cancelLnk = $ ( '<a>Cancel</a>' ) ;
2012-03-14 19:23:51 +00:00
cancelLnk . bind ( 'click' , function ( event ) {
// Get the datatable for the page
var dTable = $ ( '#' + xcatMonTableId ) . dataTable ( ) ;
// Clear the datatable
2011-03-17 03:39:05 +00:00
dTable . fnClearTable ( ) ;
2012-03-14 19:23:51 +00:00
// Add the contents of origCont to the datatable
for ( var i = 1 ; i < origCont . length ; i ++ )
dTable . fnAddData ( origCont [ i ] , true ) ;
2011-03-17 03:39:05 +00:00
$ ( ":checkbox[title]" ) . tooltip ( ) ;
2012-03-14 19:23:51 +00:00
$ ( '#' + xcatMonTableId + ' td:not(td:nth-child(1),td:last-child)' ) . editable ( function ( value , settings ) {
2011-09-12 16:10:53 +00:00
var colPos = this . cellIndex ;
var rowPos = dTable . fnGetPosition ( this . parentNode ) ;
2012-03-14 19:23:51 +00:00
dTable . fnUpdate ( value , rowPos , colPos ) ;
2011-04-16 14:40:15 +00:00
return ( value ) ;
2012-03-14 19:23:51 +00:00
} , {
2011-04-16 14:40:15 +00:00
onblur : 'submit' ,
type : 'textarea' ,
2012-03-14 19:23:51 +00:00
placeholder : ' ' ,
2011-04-16 14:40:15 +00:00
height : '30px'
2012-03-14 19:23:51 +00:00
} ) ;
2011-04-16 14:40:15 +00:00
} ) ;
2011-09-12 16:10:53 +00:00
2012-03-14 19:23:51 +00:00
// Create actions menu
var actionsLnk = '<a>Actions</a>' ;
var actsMenu = createMenu ( [ addRowLnk , applyLnk , cancelLnk ] ) ;
2011-09-12 16:10:53 +00:00
var actionsMenu = createMenu ( [ [ actionsLnk , actsMenu ] ] ) ;
actionsMenu . superfish ( ) ;
actionsMenu . css ( 'display' , 'inline-block' ) ;
actionBar . append ( actionsMenu ) ;
2012-03-14 19:23:51 +00:00
// Create a division to hold actions menu
var menuDiv = $ ( '<div id="' + xcatMonTableId + '_menuDiv" class="menuDiv"></div>' ) ;
$ ( '#' + xcatMonTableId + '_wrapper' ) . prepend ( menuDiv ) ;
menuDiv . append ( actionBar ) ;
$ ( '#' + xcatMonTableId + '_filter' ) . appendTo ( menuDiv ) ;
2010-08-04 08:49:20 +00:00
}
2011-04-16 14:40:15 +00:00
/ * *
2012-03-14 19:23:51 +00:00
* Delete a row from the table
2011-04-16 14:40:15 +00:00
* /
2012-03-14 19:23:51 +00:00
function deleteXcatMonRow ( obj ) {
var dTable = $ ( '#' + xcatMonTableId ) . dataTable ( ) ;
2011-09-12 16:10:53 +00:00
var rows = dTable . fnGetNodes ( ) ;
var tgtRow = $ ( obj ) . parent ( ) . parent ( ) . get ( 0 ) ;
2012-03-14 19:23:51 +00:00
for ( var i in rows ) {
2011-09-12 16:10:53 +00:00
if ( rows [ i ] == tgtRow ) {
2012-03-14 19:23:51 +00:00
dTable . fnDeleteRow ( i , null , true ) ;
2011-03-17 03:39:05 +00:00
break ;
}
2010-08-04 08:49:20 +00:00
}
}