<!-- include 'header' -->
<body>
	<div class="mainLayout">
		<div class="mainMenu">
			<div class="menuItem">
				<a href="#" class="mLogo">CLD</a>
				<ul>
					<!-- include 'menu' -->
				</ul>
			</div>
		</div>
		<div class="warpContent">
			<div class="subMenu fL">
				<div class="menuItem">
					<ul>
						<!-- include 'admin_menu' -->
					</ul>
				</div>
			</div>
			<div class="adminContent autoHeight">
				<div class="subNav">
					<ul class="navTabs">
						<li class="active"><a href="/holidaygroup">审批组</a></li>
						<li><a href="/hcsgroup">抄送人</a></li>
						<li><a href="/holidayadmin">假期管理</a></li>
					</ul>
				</div>
					<legend>添加审批组</legend>
						<form method="post" action="/addholidayapprover" name="group" onsubmit="return checkgroup();">
							<div class="control-group">
								<label class="control-label">组描述</label>
								<div class="controls">
									<input type="text" name="title">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">成员</label>
								<div class="controls">
									<style>
										.controls > .checkbox{margin-left: 10px}
									</style>
									<!-- loop staffList -->
									<label class="checkbox inline">
										<input type="checkbox" id="holiday_{{staffList' value.sid}}" data="{{staffList' value.username}}" value="{{staffList' value.sid}}:{{staffList' value.username}}:{{staffList' value.wxid}}">{{staffList' value.username}}
									</label>
									<!-- endloop -->
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">已选审批人</label>
								<div class="controls colRed" id="approverlist"></div>
								<input type="hidden" name="staff" id="approverstaff" value="">
							</div>
							<div class="control-group">
								<div class="controls">
									<button class="button" type="submit">添加新审查组</button>
								</div>
							</div>
			    		</form>
						<table class="table table-striped">
              <thead>
                <tr>
                  <th>组描述</th>
                  <th>成员</th>
				  <th>可见</th>
                  <th>审批组操作</th>
                </tr>
              </thead>
              <tbody>
			  <!-- if isset({{acmanlist}}) && !empty({{acmanlist}}) -->
			  <!-- loop acmanlist -->
                <tr>
                  <td>{{acmanlist' value.typename}}</td>
                  <td>{{acmanlist' value.name}}</td>
				  <td>{{acmanlist' value.categoryname}} <a href="#view" data-toggle="modal" onclick="setgroupsee('{{acmanlist' value.id}}', '{{acmanlist' value.category}}');">编辑</a></td>
                  <td><a href="#del" data-toggle="modal" onclick='delapprovalid("{{acmanlist' value.id}}")'>删除审批组</a></td>
                </tr>
			  <!-- endloop -->
			  <!-- endif -->
              </tbody>
          	</table>
			</div>
		</div>
	</div>

	<!--弹出（编辑可见）-->
	<div class="modal hide fade" id="view">

		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h3>设置审批组可见</h3>
				</div>
				<form method="post" action="/setholidaysee" >
				<input id="holidaygroupid" type="hidden" name="groupid" value="">
				<div class="modal-body">
					<div class="control-group">
						<div class="controls">
							<style>
								.controls > .checkbox{margin-left: 10px}
							</style>
							<!-- loop category -->
							<label class="checkbox inline"><input type="checkbox" value="{{category' value.cid}}" name="category[]" >{{category' value.title}}</label>
							<!-- endloop -->
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a>
					<button class="button" type="submit">确定</button>
				</div>
				</form>
			</div>
		</div>
	</div>
<!--弹出（删除组）-->
<div class="modal hide fade" id="del">

  <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <h3>确认删除</h3>
    </div>
    <div class="modal-body">
    	<p>删除后，正在使用该审批组的费用审批将不受影响，可继续审批。</p>
    </div>
		<form method="post" action="/delholidaygroup">
			<input type="hidden" id="delapporval" name="approvalid" value="">
	<div class="modal-footer">
	    <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a>
	    <button class="button" type="submit">确定</button>
	</div>
		</form>
</div>
</div>
</div>
<!--弹出-->
<script type="text/javascript">autoFlashHeight();</script>
<script>
	function checkgroup(){
		if($('input[name="title"]').val() == ''){
			alert('请输入组名');
			return false;
		}
		if(!$('input').is(":checked")){
			alert('请选择成员');
			return false;
		}
	}

	function delapprovalid(id){
		$('#delapporval').val(id);
	}

	function setgroupsee(id,cate){
		$('#holidaygroupid').val(id);
		var category = cate.split(',');
		$("[name=category[]]:checkbox").attr("checked", false);
		$.each(category,function(k,v){
			var num = document.getElementsByName("category[]");
			for(var i=0;i<num.length;i++){
				if(num[i].value == v){
					num[i].checked = true;
				}
			}
		})
	}

	$(function(){
		$('.controls label').live('click',function(e){
			if($(e.target).is('label')){
				return;
			}
			if($(this).children('input').is(":checked")){
				if($('#approverlist').text() != ''){
					$('#approverlist').append(' > '+$(this).children('input').attr('data'));
					$('#approverstaff').val($('#approverstaff').val()+','+$(this).children('input').val());
				}else{
					$('#approverlist').append($(this).children('input').attr('data'));
					$('#approverstaff').val($(this).children('input').val());
				}
			}else{
				var arr = $('#approverlist').text().split(' > ');
				var arr2 = $('#approverstaff').val().split(',');
				for(var i = 0; i<arr.length; i++){
					if(arr[i] == $(this).children('input').attr('data')) {
						arr.splice(i, 1);
						arr2.splice(i, 1);
						break;
					}
				}
				$('#approverlist').text(arr.join(' > '));
				$('#approverstaff').val(arr2.join(','));
			}
		})
	})
</script>
</body>
