<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.stfoa.domain.Employee"%>
<%@page import="com.stfoa.dao.hibernate.CollaborateConfDAO"%>
<%@page import="com.stfoa.domain.CollaborateConf"%>
<%@page import="com.stfoa.dao.hibernate.EmployeeDAO"%>
<%@include file="/common/include/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/include/meta.jsp"%>
<%@include file="/common/include/jquery.jsp"%>
<%@include file="/common/include/formvalidator.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
  $.formValidator.initConfig({autotip:true,tidymode:true,onerror:function(msg){alert(msg)}});
  $("#trustCause").formValidator({empty:true,onfocus:"原因最长支持40个字符！",defaultvalue:""})
               .inputValidator({min:0,max:40,onerror:"原因长度不允许超过40个字符！"});
});
</script>
<script>
function cancel(){
 if(window.screen){   
    var widths   =   screen.width;        
    if(widths<1000){   
     self.location='${ctx}/jsp/desktop/index_800.jsp';
    }else{
     self.location='${ctx}/jsp/desktop/index.jsp';
    }     
  } 
}
 function save(){
  if(myform.trustEmpId.value==''){
	  alert('请选择授权人！');
	  return; 
  }
  if(!$.formValidator.pageIsValid('1')){
    return;
  }
  if(myform.trustCause.value==''){
	  alert('请填写原因！');
	  return;
  }
  myform.action = '${ctx}/collaborate.do?actionmethod=saveTrustEmp';
  ajaxSubmitForm('myform',saveHandler,'text');
 }
 function saveHandler(responseText){  
  if(responseText=='success'){
   alert('授权成功！'); 
   cancel();
  }else if(responseText=='fail'){
   alert('授权失败！');
  }else{
   alert(responseText);
  }
 }

 function cancelTrustEmp(){
	 ajaxQuery('${ctx}/collaborate.do?actionmethod=cancelTrustEmp',function(responseText){  
		  if(responseText=='success'){
			   alert('取消成功！'); 
			   cancel();
			  }else if(responseText=='fail'){
			   alert('取消失败！');
			  }else{
			   alert(responseText);
			  }
	 },'text');
 }
 function selectEmp(){
	var retValue = window.showModalDialog("${ctx}/common/selectemp/selectoneemp.jsp",parent.toolframe,"dialogHeight: 500px; dialogWidth:580px;dialogTop:150;dialogLeft: 200;center: yes; status=no");
	if(retValue){
		var empId = retValue.split(',')[0];
		myform.trustEmpId.value = empId.substring(1,empId.length);
		myform.trustEmpName.value = retValue.split(',')[1];
	}
 }
</script>
<%
  Employee emp = (Employee)request.getSession().getAttribute("session_employee"); 
  CollaborateConfDAO confdao = new CollaborateConfDAO();
  EmployeeDAO empdao = new EmployeeDAO();
  CollaborateConf conf = confdao.findById(emp.getEmpId());
  try{
 %>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" onload="parent.button.locationtext.innerText='协同处理授权';">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="15%">&nbsp;</td>
    <td width="60%">
      <div align="left"><fieldset> <legend>&nbsp;<img src="${ctx}/common/images/bigedit.gif" width="32" height="32" align="absmiddle"><b><font color="#000000"><span>协同处理授权</span></font></b></legend>
        <p></p>
        <p></p>
        <table border="0" cellpadding="0" cellspacing="0" style="margin-left: 20; margin-right: 20; margin-top: 8; margin-bottom: 6" align="center" width="80%">
          <tr>
            <td>
              <form method="post" id="myform" style="margin-bottom:0;margin-top:0"  enctype="multipart/form-data">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">                  
				  
				  <tr>
                    <td align="left" valign="middle" nowrap>授权人：</td>
                    <td nowrap valign="middle">&nbsp;</td>
					<td nowrap valign="middle">
					 <input type="text" name="trustEmpName" id="trustEmpName" style="cursor:hand;width:200px;" readonly value="<%=conf==null?"":empdao.findById(conf.getTrustEmpId()).getEmpName()%>"  onclick="selectEmp()"/>
					 <img alt="选择授权人" src="${ctx}/common/images/user.gif" style="cursor:hand;vertical-align:bottom;" onclick="selectEmp()">
					 <input type="hidden" name="trustEmpId" id="trustEmpId" value="<%=conf==null?"":conf.getTrustEmpId()%>"/>
					</td>
                  </tr>				  
				  <tr>
                    <td align="left" valign="middle" nowrap>原因：</td>
                    <td nowrap valign="middle">&nbsp;</td>
                    <td nowrap valign="middle"><textarea cols="30" id="trustCause" name="trustCause" rows="5" style="width:300; height: 50"><%=conf==null?"":conf.getTrustCause() %></textarea></td>
                  </tr>
                </table>
             	
              </form>
              
               <br>
 <div align=center>
  <BUTTON class=Btnnormal onmousedown="javascript:this.className='Btnover'" 
  onmouseover="javascript:this.className='Btnover'" title='授权' accessKey=S 
  onmouseout="javascript:this.className='Btnnormal'" onclick="save();">&nbsp;&nbsp;授权&nbsp;&nbsp;</BUTTON>&nbsp;
  <%if(conf!=null){ %>
  <BUTTON class=Btnnormal onmousedown="javascript:this.className='Btnover'" 
  onmouseover="javascript:this.className='Btnover'" title='取消授权' accessKey=S 
  onmouseout="javascript:this.className='Btnnormal'" onclick="cancelTrustEmp();">&nbsp;&nbsp;取消授权&nbsp;&nbsp;</BUTTON>&nbsp;
  <%}%>
  <BUTTON class=Btnnormal onmousedown="javascript:this.className='Btnover'" 
  onmouseover="javascript:this.className='Btnover'" title='取消' accessKey=S 
  onmouseout="javascript:this.className='Btnnormal'" onclick="cancel();">&nbsp;&nbsp;取消&nbsp;&nbsp;</BUTTON>&nbsp;
 </div>
            </td>
          </tr>
        </table>
        </fieldset>        
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      </div>
    </td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>
</BODY>
<%}catch(Exception ex){ex.printStackTrace();} %>
</HTML>