<?xml version="1.0" encoding="utf-8"?>
<template>
	<name>viewList</name>
	<filePath>WebContent/webpage/${lastPackageName}/${moduleName}/${subModuleName}</filePath>
	<fileName>${className}List.jsp</fileName>
	<content><![CDATA[
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>${functionNameSimple}管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/webpage/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			var tpl = $("#treeTableTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			var data = ${"$"}{fns:toJson(list)}, ids = [], rootIds = [];
			for (var i=0; i<data.length; i++){
				ids.push(data[i].id);
			}
			ids = ',' + ids.join(',') + ',';
			for (var i=0; i<data.length; i++){
				if (ids.indexOf(','+data[i].parentId+',') == -1){
					if ((','+rootIds.join(',')+',').indexOf(','+data[i].parentId+',') == -1){
						rootIds.push(data[i].parentId);
					}
				}
			}
			for (var i=0; i<rootIds.length; i++){
				addRow("#treeTableList", tpl, data, rootIds[i], true);
			}
			$("#treeTable").treeTable({expandLevel : 5});
		});
		function addRow(list, tpl, data, pid, root){
			for (var i=0; i<data.length; i++){
				var row = data[i];
				if ((${"$"}{fns:jsGetVal('row.parentId')}) == pid){
					$(list).append(Mustache.render(tpl, {
						dict: {
							<#list table.columnList as c>
								<#if c.isList?? && c.isList == "1" && (c.showType == "select" || c.showType == "checkbox" || c.showType == "radiobox")>
							${c.simpleJavaField}: getDictLabel(${"$"}{fns:toJson(fns:getDictList('${c.dictType}'))}, row.${c.simpleJavaField}),
								</#if>
							</#list>
						blank123:0}, pid: (root?0:pid), row: row
					}));
					addRow(list, tpl, data, row.id);
				}
			}
		}
		
		function refresh(){//刷新
			
			window.location="${r"${ctx}"}/${urlPrefix}/";
		}
	</script>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
	<div class="ibox">
	<div class="ibox-title">
			<h5>${functionNameSimple}列表 </h5>
			<div class="ibox-tools">
				<a class="collapse-link">
					<i class="fa fa-chevron-up"></i>
				</a>
				<a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
					<i class="fa fa-wrench"></i>
				</a>
				<ul class="dropdown-menu dropdown-user">
					<li><a href="#">选项1</a>
					</li>
					<li><a href="#">选项2</a>
					</li>
				</ul>
				<a class="close-link">
					<i class="fa fa-times"></i>
				</a>
			</div>
	</div>
    
    <div class="ibox-content">
	<sys:message content="${r"${message}"}"/>

	<!--查询条件-->
	<div class="row">
	<div class="col-sm-12">
	<form:form id="searchForm" modelAttribute="${className}" action="${r"${ctx}"}/${urlPrefix}/" method="post" class="form-inline">
		<div class="form-group">
		<#list table.columnList as c>
			<#if c.isQuery?? && c.isQuery == "1">
				<label>${c.comments}：</label>
			<#if c.showType == "input" || c.showType == "textarea">
				<form:input path="${c.javaFieldId}" htmlEscape="false"<#if c.dataLength != "0"> maxlength="${c.dataLength}"</#if> class="form-control input-sm"/>
			<#elseif c.showType == "select">
				<form:select path="${c.javaFieldId}" class="form-control m-b">
					<form:option value="" label=""/>
					<form:options items="${"$"}{fns:getDictList('${c.dictType}')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			<#elseif c.showType == "checkbox">
				<form:checkboxes class="i-checks" path="${c.javaFieldId}" items="${"$"}{fns:getDictList('${c.dictType}')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
			<#elseif c.showType == "radiobox">
				<form:radiobuttons class="i-checks" path="${c.javaFieldId}" items="${"$"}{fns:getDictList('${c.dictType}')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
			<#elseif c.showType == "dateselect" && c.queryType == "between">
				<input id="begin${c.simpleJavaField?cap_first}" name="begin${c.simpleJavaField?cap_first}" type="text" maxlength="20" class="laydate-icon form-control layer-date input-sm"
					value="<fmt:formatDate value="${"$"}{${className}.begin${c.simpleJavaField?cap_first}}" pattern="yyyy-MM-dd HH:mm:ss"/>"/> - 
				<input id="end${c.simpleJavaField?cap_first}" name="end${c.simpleJavaField?cap_first}" type="text" maxlength="20" class="laydate-icon form-control layer-date input-sm"
					value="<fmt:formatDate value="${"$"}{${className}.end${c.simpleJavaField?cap_first}}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			<#elseif c.showType == "dateselect">
				<input id="${c.javaFieldId}" name="${c.javaFieldId}" type="text" maxlength="20" class="laydate-icon form-control layer-date input-sm"
					value="<fmt:formatDate value="${"$"}{${className}.${c.javaFieldId}}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			<#elseif c.showType == "userselect">
				<sys:treeselect id="${c.simpleJavaField}" name="${c.javaFieldId}" value="${"$"}{${className}.${c.javaFieldId}}" labelName="${c.javaFieldName}" labelValue="${"$"}{${className}.${c.javaFieldName}}"
					title="用户" url="/sys/office/treeData?type=3" cssClass="form-control input-sm" allowClear="true" notAllowSelectParent="true"/>
			<#elseif c.showType == "officeselect">
				<sys:treeselect id="${c.simpleJavaField}" name="${c.javaFieldId}" value="${"$"}{${className}.${c.javaFieldId}}" labelName="${c.javaFieldName}" labelValue="${"$"}{${className}.${c.javaFieldName}}"
					title="部门" url="/sys/office/treeData?type=2" cssClass="form-control input-sm" allowClear="true" notAllowSelectParent="true"/>
			<#elseif c.showType == "areaselect">
				<sys:treeselect id="${c.simpleJavaField}" name="${c.javaFieldId}" value="${"$"}{${className}.${c.javaFieldId}}" labelName="${c.javaFieldName}" labelValue="${"$"}{${className}.${c.javaFieldName}}"
					title="区域" url="/sys/area/treeData" cssClass="form-control input-sm" allowClear="true" notAllowSelectParent="true"/>
			</#if>
			</#if>
		</#list>
		</div>
	</form:form>
	<br/>
	</div>
	</div>
	
	<!-- 工具栏 -->
	<div class="row">
	<div class="col-sm-12">
		<div class="pull-left">
			<shiro:hasPermission name="${permissionPrefix}:add">
				<table:addRow url="${r"${ctx}"}/${urlPrefix}/form" title="${functionNameSimple}"></table:addRow><!-- 增加按钮 -->
			</shiro:hasPermission>
	       <button class="btn btn-white btn-sm " data-toggle="tooltip" data-placement="left" onclick="refresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i> 刷新</button>
		</div>
		<div class="pull-right">
			<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="search()" ><i class="fa fa-search"></i> 查询</button>
			<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="reset()" ><i class="fa fa-refresh"></i> 重置</button>
		</div>
	</div>
	</div>
	
	<table id="treeTable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable">
		<thead>
			<tr>
				<#list table.columnList as c>
					<#if c.isList?? && c.isList == "1">
				<th>${c.comments}</th>
					</#if>
				</#list>
				<shiro:hasPermission name="${permissionPrefix}:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody id="treeTableList"></tbody>
	</table>
	<script type="text/template" id="treeTableTpl">
		<tr id="{{row.id}}" pId="{{pid}}">
			<#assign firstListField = true>
			<#list table.columnList as c>
				<#if c.isList?? && c.isList == "1">
			<td><#if firstListField><a  href="#" onclick="openDialogView('查看${functionNameSimple}', '${r"${ctx}"}/${urlPrefix}/form?id={{row.id}}','800px', '500px')"></#if>
			<#if c.showType == "select" || c.showType == "checkbox" || c.showType == "radiobox">
				{{dict.${c.simpleJavaField}}}
			<#elseif c.showType == "userselect" || c.showType == "officeselect" || c.showType == "areaselect">
				{{row.${c.javaFieldName}}}
			<#else>
				{{row.${c.javaFieldId}}}
			</#if>
			<#if firstListField></a></#if></td>
					<#assign firstListField = false>
				</#if>
			</#list>
			<td>
			<shiro:hasPermission name="${permissionPrefix}:view">
				<a href="#" onclick="openDialogView('查看${functionNameSimple}', '${r"${ctx}"}/${urlPrefix}/form?id={{row.id}}','800px', '500px')" class="btn btn-info btn-xs" ><i class="fa fa-search-plus"></i>  查看</a>
				</shiro:hasPermission>
			<shiro:hasPermission name="${permissionPrefix}:edit">
   				<a href="#" onclick="openDialog('修改${functionNameSimple}', '${r"${ctx}"}/${urlPrefix}/form?id={{row.id}}','800px', '500px')" class="btn btn-success btn-xs" ><i class="fa fa-edit"></i> 修改</a>
   			</shiro:hasPermission>
   			<shiro:hasPermission name="${permissionPrefix}:del">
				<a href="${r"${ctx}"}/${urlPrefix}/delete?id={{row.id}}" onclick="return confirmx('确认要删除该${functionNameSimple}及所有子${functionNameSimple}吗？', this.href)" class="btn btn-danger btn-xs" ><i class="fa fa-trash"></i> 删除</a>
			</shiro:hasPermission>
   			<shiro:hasPermission name="${permissionPrefix}:add">
				<a href="#" onclick="openDialog('添加下级${functionNameSimple}', '${r"${ctx}"}/${urlPrefix}/form?parent.id={{row.id}}','800px', '500px')" class="btn btn-primary btn-xs" ><i class="fa fa-plus"></i> 添加下级${functionNameSimple}</a>
			</shiro:hasPermission>
			</td>
		</tr>
	</script>
</body>
</html>]]>
	</content>
</template>