<%@ page contentType="text/html;charset=UTF-8" %>
<script>
	    var $materialTypeTreeTable=null;  
		$(document).ready(function() {
			$materialTypeTreeTable=$('#materialTypeTreeTable').treeTable({  
		    	   theme:'vsStyle',	           
					expandLevel : 2,
					column:0,
					checkbox: false,
		            url:'${ctx}/warehouse/materialtype/materialType/getChildren?parentId=',  
		            callback:function(item) { 
		            	 var treeTableTpl= $("#materialTypeTreeTableTpl").html();
		            	 item.dict = {};
	           	  var result = laytpl(treeTableTpl).render({
								  row: item
							});
		                return result;                   
		            },  
		            beforeClick: function($materialTypeTreeTable, id) { 
		                //异步获取数据 这里模拟替换处理  
		                $materialTypeTreeTable.refreshPoint(id);  
		            },  
		            beforeExpand : function($materialTypeTreeTable, id) {   
		            },  
		            afterExpand : function($materialTypeTreeTable, id) {  
		            },  
		            beforeClose : function($materialTypeTreeTable, id) {    
		            	
		            }  
		        });
		        
		        $materialTypeTreeTable.initParents('${parentIds}', "0");//在保存编辑时定位展开当前节点
		       
		});
		
		function del(con,id){  
			jp.confirm('确认要删除物资类型吗？', function(){
				jp.loading();
	       	  	$.get("${ctx}/warehouse/materialtype/materialType/delete?id="+id, function(data){
	       	  		if(data.success){
	       	  			$materialTypeTreeTable.del(id);
	       	  			jp.success(data.msg);
	       	  		}else{
	       	  			jp.error(data.msg);
	       	  		}
	       	  	})
	       	   
       		});
	
		} 
		
		function add(){//新增
			jp.go('${ctx}/warehouse/materialtype/materialType/form/add');
		}
		function edit(id){//编辑
			jp.go('${ctx}/warehouse/materialtype/materialType/form/edit?id='+id);
		}
		function view(id){//查看
			jp.go('${ctx}/warehouse/materialtype/materialType/form/view?id='+id);
		}
		function addChild(id){//添加下级机构
			jp.go('${ctx}/warehouse/materialtype/materialType/form/add?parent.id='+id);
		}
		function refresh(){//刷新
			var index = jp.loading("正在加载，请稍等...");
			$materialTypeTreeTable.refresh();
			jp.close(index);
		}
</script>
<script type="text/html" id="materialTypeTreeTableTpl">
			<td>
			<c:choose>
			      <c:when test="${fns:hasPermission('warehouse:materialtype:materialType:edit')}">
				    <a  href="${ctx}/warehouse/materialtype/materialType/form/edit?id={{d.row.id}}">

						{{d.row.name === undefined ? "": d.row.name}}
					</a>	
			      </c:when>
			      <c:when test="${fns:hasPermission('warehouse:materialtype:materialType:view')}">
				    <a  href="${ctx}/warehouse/materialtype/materialType/form/view?id={{d.row.id}}">

						{{d.row.name === undefined ? "": d.row.name}}
					</a>	
			      </c:when>
			      <c:otherwise>

					  {{d.row.name === undefined ? "": d.row.name}}
			      </c:otherwise>
			</c:choose>
			</td>
			<td>
				{{d.row.code === undefined ? "": d.row.code}}
			</td>
			<td>
				{{d.row.remarks === undefined ? "": d.row.remarks}}
			</td>
			<td>
				<div class="btn-group">
			 		<button type="button" class="btn  btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
						<i class="fa fa-cog"></i>
						<span class="fa fa-chevron-down"></span>
					</button>
				  <ul class="dropdown-menu" role="menu">
					<shiro:hasPermission name="warehouse:materialtype:materialType:view">
						<li><a href="${ctx}/warehouse/materialtype/materialType/form/view?id={{d.row.id}}"><i class="fa fa-search-plus"></i> 查看</a></li>
					</shiro:hasPermission>
					<shiro:hasPermission name="warehouse:materialtype:materialType:edit">
		   				<li><a href="${ctx}/warehouse/materialtype/materialType/form/edit?id={{d.row.id}}"><i class="fa fa-edit"></i> 修改</a></li>
		   			</shiro:hasPermission>
		   			<shiro:hasPermission name="warehouse:materialtype:materialType:del">
		   				<li><a  onclick="return del(this, '{{d.row.id}}')"><i class="fa fa-trash"></i> 删除</a></li>
					</shiro:hasPermission>
		   			<shiro:hasPermission name="warehouse:materialtype:materialType:add">
						<li><a href="${ctx}/warehouse/materialtype/materialType/form/add?parent.id={{d.row.id}}"><i class="fa fa-plus"></i> 添加下级物资类型</a></li>
					</shiro:hasPermission>
				  </ul>
				</div>
			</td>
	</script>