
function init(){

}


function loadData_findAll() {
	DWRUtil.useLoadingMessage("LOADING......");
	service_findAll();
}
function service_findAll() {
	 TaskBoard.findAll(fillTable);
}
function loadData_findByPrimaryKey(id) {
	DWRUtil.useLoadingMessage("LOADING......");
	service_findByPrimaryKey(id);
}
function service_findByPrimaryKey(id) {
	 TaskBoard.findByPrimaryKey(fillTable);
}
function loadData_findByConditions(id,title,author) {
	DWRUtil.useLoadingMessage("LOADING......");
	service_findByConditions(id,title,author);
}
function service_findByConditions(id,title,author) {
	 TaskBoard.findByConditions(fillTable);
}
function loadData_getAuthorHistory(id) {
	DWRUtil.useLoadingMessage("LOADING......");
	service_getAuthorHistory(id);
}
function service_getAuthorHistory(id) {
	 TaskBoard.getAuthorHistory(fillTable);
}
var dataCache = { };
var viewed = -1;
function fillTable(dataList) {
	dwr.util.removeAllRows("dataTableBody", { filter:function(tr) {
		return (tr.id != "pattern");
		}});
	var data, id;
	for (var i = 0; i < dataList.length; i++) { 
		data = dataList[i]; 
		id = data.id;
		dwr.util.setValue("id", id);
		dwr.util.cloneNode("pattern", { idSuffix:data.id });
		var title = data.title;
		dwr.util.setValue("title" + id, title);
		var author = data.author;
		dwr.util.setValue("author" + id, author);
		var status = data.status;
		dwr.util.setValue("status" + id, status);
		if ($("pattern" + id).style.getPropertyValue) {
			$("pattern" + id).style.display = "table-row";
		} else {
			$("pattern" + id).style.setAttribute('display', '');
			$("pattern" + id).style.setAttribute('display', 'table-row');
		}
		dataCache[id] = data;
		clearInputData();
	}
}

function saveData(){
	 var id = DWRUtil.getValue("inputData_id");
	 var title = DWRUtil.getValue("inputData_title");
	 var author = DWRUtil.getValue("inputData_author");
	 var status = DWRUtil.getValue("inputData_status");
	if(id == -1) {
		TaskBoard.add(title,author,status);
	} else {
		TaskBoard.update(id,title,author,status);
	}
	DWRUtil.useLoadingMessage("LOADING......");
	loadData_findAll();
}

function editData(eleid){
 		DWRUtil.useLoadingMessage("LOADING......");
		var data = dataCache[eleid.substring(4)];
	 DWRUtil.setValue("inputData_id",data.id);
	 DWRUtil.setValue("inputData_title",data.title);
	 DWRUtil.setValue("inputData_author",data.author);
	 DWRUtil.setValue("inputData_status",data.status);
}

function deleteData(eleid) {
	alert('DELETE.');
	dwr.engine.beginBatch();
	TaskBoard.remove(eleid.substring(6));
	loadData_findAll();
	dwr.engine.endBatch();
 }

function clearInputData(){
	DWRUtil.setValue("inputData_id",-1);
	DWRUtil.setValue("inputData_title","");
	DWRUtil.setValue("inputData_author","");
	DWRUtil.setValue("inputData_status","");
}

function Button3() {
} 
function Hello_sayHello() {
    // return type is java.lang.string
	Hello.sayHello(loadinfoFromsayHello);
}
function loadinfoFromsayHello(data) {
	dwr.util.setValue("TargetTagId", data);
}
function Hello_sayHelloPlus(name) {
    // return type is java.lang.string
	Hello.sayHelloPlus(loadinfoFromsayHelloPlus);
}
function loadinfoFromsayHelloPlus(data) {
	dwr.util.setValue("TargetTagId", data);
}



