update agent manage

This commit is contained in:
fanfuxiaoran 2014-07-04 14:02:42 +08:00
parent 5770422d98
commit e8528765ae
1 changed files with 40 additions and 24 deletions

View File

@ -18,21 +18,36 @@ $(document).ready(function() {
});
function loadAgents(table) {
table.dataTable().fnClearTable();
$.post("loadAgents", {}, function(data) {
if(data.success){
if (data.agents != null) {
for ( var i = 0; i < data.agents.length; i++)
addAgentTableRow(table, data.agents[i]);
}
}
else
alert(data.failedMessage);
$('.delete').click(function(e) {
e.preventDefault();
deleteAgent(this);
});
}, "json");
$
.post(
"loadAgents",
{},
function(data) {
if (data.success) {
if (data.agents != null) {
for ( var i = 0; i < data.agents.length; i++) {
var agent = data.agents[i];
var addRow = table.dataTable().fnAddData(
[ agent.hostName, agent.port,
agent.currentEnumStatus,
agent.maxLoad,
agent.remainLoad,
deleteButton ]);
var tr = table.dataTable().fnSettings().aoData[addRow[0]].nTr;
$(tr).attr("id", agent.id);
$(tr).attr("hostName", agent.hostName);
}
}
} else {
alert(data.failedMessage);
}
$('.delete').click(function(e) {
e.preventDefault();
deleteAgent(this);
});
}, "json");
}
@ -43,20 +58,22 @@ function addAgentTableRow(table, data) {
}
function deleteAgent(obj) {
var table = getTable(obj);
var row = getRow(obj);
var row = $(obj).closest("tr");
var agentId = $(obj).closest("tr").attr("id");
var hostName = row.attr("hostName");
var table=$(obj).closest("table");
$.post("deleteAgent", {
agentId : getColumn(obj, agentColumnIndex.id),
hostName : getColumn(obj, agentColumnIndex.hostName)
agentId : agentId,
hostName : hostName
}, function(data) {
if (data.success)
$(table).dataTable().fnDeleteRow(row.rowIndex - 1);
$(table).dataTable().fnDeleteRow(row.index);
else {
alert(data.failedMessage);
}
},
"json");
}, "json");
}
function addAgentToDB() {
@ -72,8 +89,7 @@ function addAgentToDB() {
} else {
alert(data.failedMessage);
}
},
"json");
}, "json");
}
$('#agentList').click(function(e) {
e.preventDefault();