<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								模块名称：<input type="text" name="moduleName"/>
							</li>

							<li>
								项目名称：
								<select name="projectId">
									<option value="">所有</option>
									<option th:each="project:${projects}" th:text="${project.projectName}" th:value="${project.projectId}"></option>
								</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
				<shiro:hasPermission name="testmanagmt:projectCaseModule:import">
				<a class="btn btn-info" onclick="$.table.importExcel2()">
					<i class="fa fa-upload"></i> 导入
				</a>
				</shiro:hasPermission>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('testmanagmt:projectCaseModule:add')}]];
        var editFlag = [[${@permission.hasPermi('testmanagmt:projectCaseModule:edit')}]];
        var removeFlag = [[${@permission.hasPermi('testmanagmt:projectCaseModule:remove')}]];
        var prefix = ctx + "testmanagmt/projectCaseModule";
		
		$(function() {
		    var options = {
		        code: "moduleId",
		        parentCode: "parentId",
		        uniqueId: "moduleId",
		        url: prefix + "/list",
		        createUrl: prefix + "/add/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove/{id}",
                importUrl: prefix + "/import",
                importTemplateUrl: prefix + "/importTemplate",
		        modalName: "用例模块",
		        columns: [{
                    field: 'selectItem', 
                    radio: true
                 },
                 {
 					field : 'moduleName', 
					title : '模块名字',
					align: "left"
		        },
				{
					field : 'projectName', 
					title : '项目名称',
					align: "left"
				},
				{
					field : 'orderNum', 
					title : '显示顺序',
					align: "left"
				},
		        {
		            field: 'updateTime',
		            title: '更新时间',
		            align: "left"
		        },
		        {
		            title: '操作',
		            align: 'left',
		            formatter: function(value, row, index) {
	                    var actions = [];
	                    actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="#" onclick="$.operate.add(\'' + row.moduleId + '\')"><i class="fa fa-plus">新增</i></a> ');
		                if (row.parentId != 0) {
		                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.moduleId + '\')"><i class="fa fa-edit">编辑</i></a> ');
		                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.moduleId + '\')"><i class="fa fa-remove">删除</i></a>');
		                    
		                }
		                return actions.join('');
		            }
		        }]
		    };
		    $.treeTable.init(options);
		});
        
		function remove(id) {
			$.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function() {
				$.ajax({
					type : 'post',
					url: prefix + "/remove/" + id,
					success : function(result) {
						if (result.code == web_status.SUCCESS) {
		                	$.modal.msgSuccess(result.msg);
		                	$.treeTable.refresh();
		                } else {
		                	$.modal.msgError(result.msg);
		                }
					}
				});
			});
		}
    </script>
</body>
<form id="importForm" enctype="multipart/form-data" class="mt20 mb10" style="display: none;">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>

		<div class="mt10 pt5">
			<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
		</div>
		<font color="red" class="pull-left mt10">
			提示：仅允许导入“xls”或“xlsx”格式文件！
		</font>
	</div>
</form>
</html>