

$import('itsm.portal.calendar');

var helpdeskPortal=function(){
	//公共方法
	this.showData=function(tableId,postUrl,param,method){
		
		$.post(postUrl,param,function(data){
			
			if(data!=null && data!="" && data.length>0){
				
				$(tableId).empty();
				
				var count=0;
				$.each(data,function(i,item){
					method(i,item);
					count++;
					
					if(count>7){
						
						return false;
					}
					
				});
			}
				
		})
		
	}
	
	
	//公共方法
	this.showDataBk=function(tableId,postUrl,param,method){
		

		$.post(postUrl,param,function(data){
			
			if(data!=null && data.data!=null && data.data!=""){
				
				$(tableId).empty();
				
				var count=0;
				$.each(data.data,function(i,item){
					
					method(i,item);
					
					count++;
					
					if(count>7){
						
						return false;
					}
				});
			}
		});
	}


	//我的任务
	this.showMyTask=function(){
		
		showDataBk('#myTaskList','tasks!findPagerTask.action',"taskQueryDto.owner="+login_userName+"&sidx=taskId&sord=desc",showMyTaskMethod);
	}
	//我的任务Method
	this.showMyTaskMethod=function(i,item){
		
		$('#myTaskList').append("<tr><td style='width:5px'><img src='../images/numbers/"+(i+1)+".gif' /></td><td style='padding-left:10px;'><a href='javascript:portalShowMyTask()'>"+item.title+"</a></td></tr>");
	}
	
	
	//指派给我的请求
	this.showAssignToMe=function(){
		
		var url="request!findRequestForPortal.action";
		var param="requestQueryDTO.technicianName="+login_userName;
		
		showData('#assignProcessingRequestList',url,param,showAssignToMeMethod);
	}
	
	//指派给我的请求Method
	this.showAssignToMeMethod=function(i,item){
		
		$('#assignProcessingRequestList').append("<tr><td style='width:5px'><img src='../images/numbers/"+(i+1)+".gif' /></td><td style='padding-left:10px;'><a href=javascript:portalShowRequestDetail('"+item.eno+"')>"+item.etitle+"</a></td><td>"+item.createdByName+"</td></tr>");
		
	}
	
	//待指派
	this.showWaitAssign=function(){
		
		var url="request!findRequestForPortal.action";
		var param="requestQueryDTO.queryTag=unAssign";
		showData('#waitAssignRequestList',url,param,showWaitAssignMethod);

	}
	//待指派Method
	this.showWaitAssignMethod=function(i,item){
		
		$('#waitAssignRequestList').append("<tr><td style='width:5px'><img src='../images/numbers/"+(i+1)+".gif' /></td><td style='padding-left:10px;'><a href=javascript:portalShowRequestDetail('"+item.eno+"')>"+item.etitle+"</a></td><td>"+item.createdByName+"</td></tr>");

	}
	
	
	//公告
	this.showAffiche=function(){
		
		var url="affiche!find.action";
		showDataBk('#afficheInfo',url,null,showAfficheMethod);
		
	}
	//公告Method
	this.showAfficheMethod=function(i,item){
		
		$('#afficheInfo').append("<tr><td style='width:5px'><img src='../images/numbers/"+(i+1)+".gif' /></td><td style='padding-left:10px;'><a href='javascript:void(0)' onclick=portalShowAffiche('"+item.aid+"')>"+item.affTitle+"</a></td><td>"+timeFormatter(item.affEnd)+"</td></tr>");
	}
	

	//即时消息
	this.showMyIM=function(){
		
		var url="immanage!findPager.action?manageQueryDTO.receiveUsers="+login_userName+"&sidx=	imId&sord=desc";
		showDataBk('#IMSG',url,null,showMyIMmethod);
	}
	
	//即时消息
	this.showMyIMmethod=function(i,item){
		
		$('#IMSG').append("<tr><td style='width:5px'><img src='../images/numbers/"+(i+1)+".gif' /></td><td style='padding-left:10px;'><a href='javascript:void(0)' onclick=portalShowIm('"+item.imId+"')>"+item.title+"</a></td><td style='width:80px'>"+item.sendUsers+"</td></tr>");
	}
	
	
	
	//打开请求详细
	this.portalShowRequestDetail=function(gr){
		var url="request!requestDetails.action?eno="+gr+"&random="+Math.random()*10+1;
		refreshTab(i18n['title_request_requestDetail'],url);	
	} 
	
	
	//打开知识详情
	this.portalShowKnowledge=function(id){
		
		var url="knowledgeInfo!showKnowledge.action?kid="+id;
		refreshTab(knowledgeDetails,url);	
	}
	
	//打开公告信息
	this.portalShowAffiche=function(id){
		
		var url="../pages/tools/affiche.jsp?id="+id;
		refreshTab(affiche,url);	
	}

	//打开即时消息
	this.portalShowIm=function(id){
		
		var url="../pages/tools/im.jsp?id="+id;
		refreshTab(im,url);	
	}
	
	//
	this.portalShowMyTask=function(){
		
		var url="../pages/tools/task.jsp";
		refreshTab(personTask,url);	
	}
	
	
	
	this.calendarLoad="0";
	/**
	 * @description 为tab点击绑定事件
	 */
	this.helpdeskPortalTabClick=function(){

            $('#helpdeskPortalTab').tabs({
                onSelect:function(title){
                	if(title==calendarTitle && calendarLoad=="0"){
                		itsm.portal.calendar.loadCalendar();
                		calendarLoad="1";
                	}
                	
                }  
            });
	}
	
	
	return{
		init:function(){
			
			showMyTask();
			setTimeout(helpdeskPortalTabClick,0);
			
		}
	}
}();

//载入
$(document).ready(helpdeskPortal.init);