$(document).ready(function() {

	//检查是否修改密码
	bindEvent();

	//首页任务事件绑定 TasksExecute.js
	bindTaskEvent();
	bindOtherTaskEvent();
	//快捷功能选择 
	AddFunction.initAddFunction();
	
	Public.ajax(web_app.name + "/homePage/queryTasksByViewKind.ajax", {viewTaskKind:'2,8'}, function (data) {
		parseTaskHtml('#taskDoneContent',data['tasks2']);
		parseTaskHtml('#procdoneContent',data['tasks8']);
		$('span.taskCenterDoneCount').html(data['taskCount2']);
		$('span.taskProcdoneCount').html(data['taskCount8']);
    });
	var systemId = $("#systemId").val();
	var roleCode = $("#roleCode").val();
	var roleIdList = $("#roleIdList").val();
	/*if (roleCode == "001"){
		$('#fileList').fileList({bizId: systemId});
		$("#rateSendBtn").show();
	}else {
		$('#fileList').fileList({bizId: systemId,readOnly:true});
		$("#rateSendBtn").hide();
	}*/
	/*if (roleIds.indexOf("298")!=-1 || roleIds.indexOf("91145744473B6F5FE050007F010034D0")!=-1){
		$('#fileList').fileList({bizId: systemId});
		$("#rateSendBtn").show();
	}else {
		$('#fileList').fileList({bizId: systemId,readOnly:true});
		$("#rateSendBtn").hide();
	}*/
	$('#fileList > .ui-attachment-title').css({'color': '#990000'});
});


function bindEvent(){
	// Public.ajax(web_app.name + '/check/checkPassword.ajax',{},
	// 	function(data) {
	// 	if (data.count <= 1) {
	// 		var url=DataUtil.composeURLByParam('/personOwn/forwardUsercontrol.do?codeId=setUserPassword',{});
	// 		UICtrl.addTabItem({tabid:'personOwn', text:$.i18nProp('index.user.own.info'),url:url});
	// 		Public.tip("登录后请修改初始密码!");
	// 		return false;
	// 	}
	// });

}

function reloadGrid(){
	//TasksExecute.js
	
	//initWorkTask();
	//initCaution();
	
	reloadExecuteTasks();
}

function reloadGridDone(){
	reloadExecuteDoneTasks();
}

function reloadGridProcdone(){
	reloadExecuteProcdoneTasks();
}

function reloadSpecialTaskGrid(){
	Public.ajax(web_app.name + "/homePage/queryAllTasks.ajax", {}, function (data) {
		parseSpecialTaskHtml('#trackTaskContent',data['trackingTasks']);
		$('span.trackingTaskCount').html(data['trackingTaskCount']);
	});
}

function reloadAllGrid(){
	Public.ajax(web_app.name + "/homePage/queryTasksByViewKind.ajax", {viewTaskKind:'1,2,7,8'}, function (data) {
		parseTaskHtml('#waitTaskContent',data['tasks1']);
		parseTaskHtml('#trackTaskContent',data['tasks7']);
		parseTaskHtml('#taskDoneContent',data['tasks2']);
		parseTaskHtml('#procdoneContent',data['tasks8']);
		$('span.taskCount').html(data['taskCount1']);
		$('span.trackingTaskCount').html(data['taskCount7']);
		$('span.taskCenterDoneCount').html(data['taskCount2']);
		$('span.taskProcdoneCount').html(data['taskCount8']);
    });
}

function updateTaskExtensionStatusToExecuting(taskId, fn){
	 Public.ajax(web_app.name + '/workflow/updateTaskExtensionStatusToExecuting.ajax', {taskId: taskId}, function () {
	     if ($.isFunction(fn)) {
	    	 fn.call(window);
	     } 
	 });
}


function bindOtherTaskEvent() {
	$("#taskDoneContent").on('click', function (e) {
		var $clicked = $(e.target || e.srcElement);
		if ($clicked.is('a.aLink')) {
			var taskId=$clicked.attr('taskId');
        	$clicked=$('#task_'+taskId);
            showTrackingTask($clicked.attr('taskId'),$clicked.attr('bizId'),$clicked.attr('name'),$clicked.attr('url'));
		}
		return false;
	});
	$("#procdoneContent").on('click', function (e) {
        var $clicked = $(e.target || e.srcElement);
        if ($clicked.is('a.aLink')) {
        	var taskId=$clicked.attr('taskId');
        	$clicked=$('#task_'+taskId);
            showTrackingTask($clicked.attr('taskId'),$clicked.attr('bizId'),$clicked.attr('name'),$clicked.attr('url'));
        }
        return false;
    });
}

