<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="cm" uri="/commons-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>部门管理</title>
<link href="../resources/style/base.css" rel="stylesheet" type="text/css"/>
<s:include value="../common/head.jsp" />
<link type="text/css" href="../resources/js/jquery/css/redmond/jquery-ui-1.8.10.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="../resources/js/jquery/jquery-ui-1.8.10.custom.min.js"></script>
<script language="javascript" src="../code/vm/ExtCodeJs.htm"></script>
<script type="text/javascript">
function showEditTable(){
	$("#editInfoDiv").hide();
	$("#editTable").show();	
}
function selectEmplOrg(id){
	showEditTable();
	switchTab(0);
	var json=getHttpData("<s:url action='emplOrgDetail'/>?emplOrg.id="+id);
	var eo=eval('(' + json + ')');  
	gi("editName").value=strVal(eo.name);
	gi("editId").value=strVal(eo.id);
	gi("editPid").value=strVal(eo.pid);
	gi("editPname").value=strVal(eo.pname);
	gi("editMname").value=strVal(eo.mname);
	gi("editMid").value=strVal(eo.mid);
	gi("editDescr").value=strVal(eo.descr);
	gi("editOrderBy").value=strVal(eo.orderBy);
	rootCheck();	
}

function strVal(obj){
	return obj==null?"":obj;
}

function rootCheck(){
	if(gi("editId").value=="0000"){
		gi("editPid").disabled=true;
		gi("editPname").disabled=true;
		gi("delBnt").disabled=true;
		$("#parentOrgId").hide();
	}else{
		gi("editPid").disabled=false;
		gi("editPname").disabled=false;
		gi("delBnt").disabled=false;
		$("#parentOrgId").show();
	}
}

function deleteEmplOrg(){
	if(gi("editId").value==""){
		msgAlert("请点击左边的 “部门架构” 树，选择您要删除的部门。");
	}else{
		msgConfirm("您确定要删除 “"+gi("editName").value+"” 吗？",function(){
			goto("<s:url action='emplOrgDelete'/>?emplOrg.id="+gi("editId").value);
		});
	}
}
</script>
<script type="text/javascript">

$(function(){
	tableResize();
	initTabs();
	rootCheck();
});

$(window).resize(function(){
	tableResize();
});

function tableResize(){
	var $bd=$("#body_div");
	$bd.outerHeight($(window).height()-30);
	var of=$bd.offset();
	of.top=15;
	$bd.offset(of);
	
	$("#td_frame").height($bd.height()-2);
}

var $tab;
function switchTab(ix){
	$tab.tabs('select', ix);
}


function initTabs(){
	$tab=$('#tabs').tabs();
	var turl=location+"";
	var isEdit=turl.indexOf("emplOrgEdit")!=-1;
	var isAdd=turl.indexOf("emplOrgAdd")!=-1;
	if(isEdit){
		showEditTable();
		switchTab(0);
	}
	if(isAdd){
		switchTab(1);	
	}	
}


</script>
</head>

<body>
<div id="body_div">
<table width="780" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="40%" valign="top" class="table_line" id="td_frame">
    	<iframe id="treeFrame" style="height:100%; width:100%;" src="<s:url action='emplOrgTree'/>" frameborder="0" scrolling="auto"></iframe>
    </td>
	<td width="3%">&nbsp;</td>
    <td width="57%" valign="top">
		<s:include value="../common/body.jsp" />
    	<div id="tabs">
			<ul>
				<li><a href="#tabs-1" style="font-size:13px; margin:0; padding:0.2em 1em;">修 改</a></li>
				<li><a href="#tabs-2" style="font-size:13px; margin:0; padding:0.2em 1em;">添 加</a></li>
			</ul>
			<div id="tabs-1" style="height:250px;">
            	<s:form action="emplOrgEdit" id="editForm" namespace="/employe"  onsubmit="return checkForm(this)">
                <div id="editInfoDiv" style="font-size:14px; padding-top:50px; text-align:center;">
                	请点击左边的 “部门架构” 树，选择您要修改的部门。
                </div>
                <table id="editTable" style="display:none;" width="100%" border="0" align="right" cellpadding="0" cellspacing="0">
                  <tr class="form_tab_tr">
                     <td width="146" align="right"><span class="required">•</span>部门名称：</td>
                    <td width="299">
                    	<s:textfield name="emplOrg.name" id="editName" maxlength="50" title="部门名称为必填项"  cssStyle="width:200px;"/>
                    	<s:hidden id="editId" name="emplOrg.id" />
                    </td>
                  </tr>
                  <tbody id="parentOrgId">
                  <tr class="form_tab_tr">
                    <td align="right"><span class="required">•</span>上级部门：</td>
                    <td><s:textfield name="emplOrg.parent.name" title="上级部门为必填项" id="editPname" readonly="true" cssClass="find_input" 
                    	onClick="codeTree('emplOrgTree',gi('editPid'),this,'yes','cid='+gi('editId').value)" cssStyle="width:200px;"/>
                        <s:hidden name="emplOrg.parent.id" id="editPid" /></td>
                  </tr>
                  </tbody>
                   <tr class="form_tab_tr">
                    <td align="right">负责人：</td>
                    <td><s:textfield name="emplOrg.manager.name" id="editMname"  readonly="true"  cssClass="find_input"
                    	onClick="codeTable('emplInfoTable',gi('editMid'),this)" cssStyle="width:200px;"/>
                        <s:hidden name="emplOrg.manager.id" id="editMid" /></td>
                  </tr>                 
                  <tr class="form_tab_tr">
                    <td align="right">排序编号：</td>
                    <td><s:textfield id="editOrderBy" name="emplOrg.orderBy" cssStyle="width:80px;"/>
                    （小编号的排在前面）</td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right">描述信息：</td>
                    <td>
                    <s:textarea  name="emplOrg.descr" id="editDescr" cssStyle="width:200px;height:80px;"/></td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right">&nbsp;</td>
                    <td>
                        <input type="submit" name="button" id="button" value="修 改" />
                        &nbsp;
                        <input type="button" name="button" onclick="deleteEmplOrg()" id="delBnt" value="删 除" />
                    </td>
                  </tr>                    
                </table>
                </s:form>
            </div>
			<div id="tabs-2" style="height:250px;">
            	<s:form action="emplOrgAdd" id="addForm" namespace="/employe" onsubmit="return checkForm(this)">
                <table id="addTable" width="100%" border="0" align="right" cellpadding="0" cellspacing="0">
                  <tr class="form_tab_tr">
                    <td width="146" align="right"><span class="required">•</span>部门名称：</td>
                    <td width="299">
                    	<s:textfield name="emplOrg.name" value="" maxlength="50" title="部门名称为必填项" cssStyle="width:200px;"/>
                    	<s:hidden value="" name="emplOrg.id" />
                    </td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right"><span class="required">•</span>上级部门：</td>
                    <td><s:textfield name="emplOrg.parent.name" value="" title="上级部门为必填项" readonly="true" id="addOname" 
                    	onClick="codeTree('emplOrgTree',gi('addOid'),this)" cssStyle="width:200px;" cssClass="find_input"/>
                        <s:hidden value="" name="emplOrg.parent.id" id="addOid" /></td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right">负责人：</td>
                    <td><s:textfield name="emplOrg.manager.name" value="" readonly="true" 
                    		onClick="codeTable('emplInfoTable',gi('addMid'),this)" id="addMname" cssClass="find_input" cssStyle="width:200px;"/>
                            <s:hidden value="" name="emplOrg.manager.id" id="addMid" /></td>
                  </tr>                 
                  <tr class="form_tab_tr">
                    <td align="right">排序编号：</td>
                    <td><s:textfield name="emplOrg.orderBy" value="" cssStyle="width:80px;"/>
                    （小编号的排在前面）</td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right">描述信息：</td>
                    <td>
                    <s:textarea name="emplOrg.descr" value="" cssStyle="width:200px;height:80px;"/></td>
                  </tr>
                  <tr class="form_tab_tr">
                    <td align="right">&nbsp;</td>
                    <td>
                        <input type="submit" name="button" id="button" value="添 加" />
                    </td>
                  </tr>                          
                </table>
                </s:form>            
            </div>
		</div>
		
    </td>
  </tr>
</table>
</div>
</body>
</html>