function loadTestPlans(table) {
	var downLoadButton = "<a class='btn btn-success download'  >"
			+ $.i18n.prop('report') + "</a>";
	var deleteButton = "<a class='btn btn-info delete'>"
			+ $.i18n.prop('delete') + "</a>";
	var viewResult = "<a class='btn btn-info result'><i class='icon-zoom-in icon-white'></i>"
			+ $.i18n.prop('view') + "  " + "</a>";
	table.clear();
	$.get("loadTestPlans", {}, function(data) {
		if (data.success) {
			var testPlans = data.testPlans;
			for ( var i = 0; i < testPlans.length; i++) {

				var tr = table.row.add(
						[ i, testPlans[i].name,
								testStatusMap(testPlans[i].currentStatus),
								new Date(testPlans[i].createDateTime),
								viewResult, deleteButton + downLoadButton ])
						.draw().node();
				$(tr).attr("testPlanRunId", testPlans[i].testPlanRunId);
				$(tr).attr("id", testPlans[i].id);
			}

		} else {
			information($.i18n.prop('fail'));

		}

	

	}, "json");
}
function addEvent(table){
	var tbody = table.table().body();
	$(tbody).on("click", "td a.download", function(e) {
		e.preventDefault();
		var tr = $(this).closest("tr");
		var testPlanId = $(tr).attr("testPlanRunId");
		downloadResult(testPlanId);
	});
	$(tbody).on("click", "td a.delete", function(e) {
		e.preventDefault();
		var tr = $(this).closest("tr");
		var testPlanId = $(tr).attr("id");
		var row = table.row(tr);
		deleteTest(testPlanId, row);
	});
	$(tbody).on("click", "td a.result", function(e) {

		e.preventDefault();
		var tr = $(this).closest("tr");
		var testPlanId = $(tr).attr("testPlanRunId");
		window.open("result.jsp?testPlanId=" + testPlanId);
	});
}

function downloadResult(testPlanId) {
	var form = $("<form>");// 定义一个form表单
	form.attr("style", "display:none");
	form.attr("method", "post");
	form.attr("action", "downloadReport");
	var input1 = $("<input>");
	input1.attr("type", "hidden");
	input1.attr("name", "testPlanId");
	input1.attr("value", testPlanId);
	$("body").append(form);
	form.append(input1);
	form.submit();
}
function deleteTest(testPlanId, row) {
	$.post("deleteTest", {
		testPlanId : testPlanId
	}, function(data) {
		if (data.success) {
			row.remove().draw();
		} else {
			information($.i18n.prop('fail'));
		}
	});

}