function showRootPage() {
	showRootTitle();
	showRootSearch();
	showRootBody();
}

function showRootTitle() {
	$("#title")
			.html(
					"<h2>Project 管理</h2> <a onclick=\"projectPop(newProject,'新增mock项目','insert')\" href='#'>新增</> ");
}

function showRootSearch() {
	$("#search").html("<hr>");
}

function showRootBody() {
	var bodyTalbe = "<table width='100%' border=1 class='Datatable'>" //
			+ "<thead>" //
			+ "<tr>"//
			+ "<th>序号</th>" //
			+ "<th>项目名称</th>" //
			+ "<th>操作</th>" //
			+ "</tr>"//
			+ "</thead>" //
			+ "<tbody id='queryDataTable'>" //
			+ "</tbody>"//
			+ "<table>";
	$("#body").html(bodyTalbe);

	
}

function projectPop(project, title, saveOrUpdate) {

	var proTable = ""
	proTable += "<table class='tableInput'>";
	proTable += "<tr>";
	proTable += "<td >";
	proTable += "名称：";
	proTable += "</td >";
	proTable += "<td >";
	proTable += "<input type='hidden' id='pro_id' value='" + project.id
			+ "'  >"
	proTable += "<input type='text' id='pro_Name' value='"
			+ project.mockProjectName + "'  >";
	proTable += "</td>";
	proTable += "</tr>";
	proTable += "</table>";
	new pop.ui.alert({
		title : title,
		content : proTable,
		width : 300,
		beforeCallback : function() {

		},
		callback : function() {
			saveOrUpdateProject(saveOrUpdate);
		}
	}).init();
}

function saveOrUpdateProject(SaveOrUpdate) {
	reqType = SaveOrUpdate == "insert" ? "POST" : "PUT";
	var URL = "/mock/project";
	var proSU = {};
	if (reqType == "PUT") {
		proSU.id = $('#pro_id').val();
	}

	proSU.mockProjectName = $('#pro_Name').val();

	// versionO.detail = $('#VersionDetail').htmlarea('html');
	data = JSON.stringify(proSU);
	$.ajax({
		type : reqType,
		url : URL,
		contentType:'application/json; charset=UTF-8',
		data : data,
		error : Error,
		success : function(data) {
			var obj = eval(data).entity;
			var status = obj.status;
			if (status == "201" || status == "200") {
				showRootBody();
				alert("操作成功！");

			}else {
				alert(obj.message)
			}
		}
	});
}

function deleteProject(id){
	var a=confirm("确认删除？");
	 if(a==false){
		 return;
	 }
	var URL = "/mock/project";
	var proSU = {id:id};
	data = JSON.stringify(proSU);
	$.ajax({
		type : "DELETE",
		url : URL,	
		contentType:'application/json; charset=UTF-8',
		data : data,
		error : Error,
		success : function(data) {
			var obj = eval(data).entity;
			var status = obj.status;
			if (status == "201" || status == "200") {
				showRootBody();
				alert("删除成功！");

			} else {
				alert(obj.message)
			}
		}
	});	
	
}

var projects = new Array()

var newProject = {
	id : "",
	mockProjectName : ""
}
