$package('itsm.config.eav')
/**  
 * @fileOverview 扩展属性主函数
 * @author tan
 * @version 1.0  
 */  
 /**  
 * @author tan  
 * @constructor 扩展属性主函数
 * @description 扩展属性主函数
 * @date 2011-05-24
 * @since version 1.0 
 */ 
itsm.config.eav.attributes=function(){
	var attr;
	
	return {
		showAttributes:function(entityType,showAttrId){
			$('#'+showAttrId+' table').html('');
			$.post('attrs!findAttributesByEntityType.action','entityType='+entityType,function(data){
				if(data!=null && data.length>0){
					for(var i=0;i<data.length;i++){
			
						attr="<tr><td>"+data[i].attrAsName+"</td><td><input style=width:85% name=requestDTO.attrVals['"+data[i].attrName+"'] class='easyui-datebox' "
						
						if(data[i].attrType=="String")	
							attr+=""
						else if(data[i].attrType=="Date")	
							attr+=""
						else if(data[i].attrType=="Integer")
							attr+="min='0' maxlength='9'"
						else if(data[i].attrType=="Double")	
							attr+="precision='3'"
						
						attr+=" /></td></tr>"
							
						$('#'+showAttrId+' table').append(attr);
								
								
						if(data[i].attrType=="Lob")
							$('#'+showAttrId+' table').append("<tr><td>"+data[i].attrAsName+"</td><td><textarea  style=width:85% name=requestDTO.attrVals['"+data[i].attrName+"'] ></textarea></td></tr>")
						
					}
				}else{
					$('#'+showAttrId+' table').append("<tr><td style=color:red >"+i18n['noData']+"</td></tr>")
				}
			})
		},
		findAttributeByEno:function(eno,entityType,showAttrId){
			$('#'+showAttrId+' table').html('');
			$.post('eventEav!findEventEav.action','eventEavDTO.entityType='+entityType+'&eventEavDTO.eno='+eno,function(eventEavVals){
				
				$.post('attrs!findAttributesByEntityType.action','entityType='+entityType.replace('itsm.',''),function(data){
					if(data!=null && data.length>0){
						for(var i=0;i<data.length;i++){
							var vals=data[i].attrName
							attr="<tr><td>"+data[i].attrAsName+"</td><td><input style=width:85% name=requestDTO.attrVals['"+data[i].attrName+"'] class='easyui-datebox' "
							
							if(eventEavVals!=null){
								if(eval('eventEavVals.'+vals)!=undefined && eval('eventEavVals.'+vals)!=''){
									attr+=" value="+eval('eventEavVals.'+vals)
								}else{
									attr+=" value=''"
								}
							}
							if(data[i].attrType=="String")	
								attr+=""
							else if(data[i].attrType=="Date")	
								attr+=""
							else if(data[i].attrType=="Integer")
								attr+="min='0' maxlength='9'"
							else if(data[i].attrType=="Double")	
								attr+="precision='3'"
							
							attr+=" /></td></tr>"
								
							$('#'+showAttrId+' table').append(attr);
									
									
							if(data[i].attrType=="Lob"){
								if(eval('eventEavVals.'+vals)!=undefined){
									$('#'+showAttrId+' table').append("<tr><td>"+data[i].attrAsName+"</td><td><textarea  style=width:85% name=requestDTO.attrVals['"+data[i].attrName+"'] >'"+eval('eventEavVals.'+vals)+"'</textarea></td></tr>")
								}else
									$('#'+showAttrId+' table').append("<tr><td>"+data[i].attrAsName+"</td><td><textarea  style=width:85% name=requestDTO.attrVals['"+data[i].attrName+"'] ></textarea></td></tr>")
							}
						}

					}
				})
			})
		},
		
		showAttributeInfoByEno:function(eno,entityType,showAttrId){
			$('#'+showAttrId+' table').html('');
			$.post('eventEav!findEventEav.action','eventEavDTO.entityType='+entityType+'&eventEavDTO.eno='+eno,function(eventEavVals){
				$.post('attrs!findAttributesByEntityType.action','entityType='+entityType.replace('itsm.',''),function(data){
					if(data!=null && data.length>0){
						for(var i=0;i<data.length;i++){
							var eventEavHtml="<tr>"+
							"<td width='30%' style='text-align:left'>{0}</td>"+
							"<td style='text-align:left'>{1}</td>"+
							"</tr>"
							var vals=data[i].attrName
							if(eventEavVals!=null){
								eventEavHtml=eventEavHtml.replace('{0}',data[i].attrAsName)
								.replace('{1}',eval('eventEavVals.'+vals))
								.replace('undefined','')
							}else{
								eventEavHtml=eventEavHtml.replace('{0}',data[i].attrAsName)
								.replace('{1}','')
								.replace('undefined','')
							}
							

							$('#'+showAttrId+' table').append(eventEavHtml);
							
						}

					}
				})
			})
		},
	}
	
}();