<!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="templateName"/>
							</li>

							<li>
								项目：
								<select id="projectId" name="projectId" th:with="type=${projects}">
								    <option value="">所有项目</option>
	                                <option th:each="projects : ${type}" th:text="${projects.projectName}" th:value="${projects.projectId}" th:selected="${projects.projectId == defaultProjectId}"></option>
	                            </select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.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">
				<shiro:hasPermission name="testmanagmt:projectProtocolTemplate:add">
				<a class="btn btn-success" onclick="$.operate.add()">
					<i class="fa fa-plus"></i> 添加
				</a>
				</shiro:hasPermission>
				<shiro:hasPermission name="testmanagmt:projectProtocolTemplate:edit">
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()">
					<i class="fa fa-edit"></i> 修改
				</a>
				</shiro:hasPermission>
				<shiro:hasPermission name="testmanagmt:projectProtocolTemplate:edit">
				<a class="btn btn-info btn-edit disabled" onclick="$.operate.customFull()">
					<i class="fa fa-folder-open-o"></i> 模板参数
				</a>
				</shiro:hasPermission>
				<shiro:hasPermission name="testmanagmt:projectProtocolTemplate:add">
				<a class="btn btn-info btn-edit disabled" onclick="$.operate.copy()">
					<i class="fa fa-copy"></i> 复制模板
				</a>
				</shiro:hasPermission>
				<shiro:hasPermission name="testmanagmt:projectProtocolTemplate:remove">
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()">
					<i class="fa fa-remove"></i> 删除
				</a>
				</shiro:hasPermission>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true" style="table-layout:fixed"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('testmanagmt:projectProtocolTemplate:edit')}]];
        var removeFlag = [[${@permission.hasPermi('testmanagmt:projectProtocolTemplate:remove')}]];
        var prefix = ctx + "testmanagmt/projectProtocolTemplate";
        var paramsPrefix = ctx + "testmanagmt/projectTemplateParams";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                copyUrl: prefix + "/copy/{id}",
                removeUrl: prefix + "/remove",
                customUrl: paramsPrefix + "/editParams/{id}",
                modalName: "协议模板",
                childrenModalName: "协议模板参数编辑",
				search: false,
				queryParams: function(params) {
	            	return {
	        			// 传递参数查询参数
	                    pageSize:       params.limit,
	                    pageNum:        params.offset / params.limit + 1,
	                    searchValue:    params.search,
	                    orderByColumn:  params.sort,
	                    isAsc:          params.order,
	                    projectId:      $('#projectId').val()
	        		};
				},
		        showExport: false,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'templateId', 
					title : '模板ID',
					sortable: true,
					visible: false
				},
				{
					field : 'project.projectName', 
					title : '项目名称',
					width : '10%',
					class : 'myTDLengthHidden'
				},
				{
					field : 'templateName', 
					title : '模板名称',
					width : '20%',
					class : 'myTDLengthHidden',
					editable : {
						type : 'text',
						title : '模板名称',
						emptytext : "【模板名称】为空",
						validate : function(value) {
							if (value.length > 50)
								return '模板名称不能超过50个字符';
							if (value.length == 0)
								return '模板名称不能为空';
						}
					}
				},
				{
					field : 'encoding', 
					title : '编码格式',
					width : '5%',
					class : 'myTDLengthHidden',
					editable : {
						type : 'select',
						title : '编码格式',
						source : [ {
							value : "UTF-8",
							text : "UTF-8"
						}, {
							value : "GBK",
							text : "GBK"
						}]
					}
				},
				{
					field : 'headMsg', 
					title : '消息头域',
					width : '20%',
					class : 'myTDLengthHidden',
					editable : {
						type : 'text',
						title : '消息头域',
						emptytext : "【消息头域】为空",
						validate : function(value) {
							if (value.length > 3000)
								return '消息头域不能超过3000个字符';
						}
					}
				},
				{
					field : 'cerificatePath', 
					title : '客户端中的证书路径',
					visible: false
				},
				{
					field : 'timeout', 
					title : '超时时间',
					width : '5%',
					class : 'myTDLengthHidden',
					editable : {
						type : 'text',
						title : '超时时间',
						emptytext : "【超时时间】为空",
						validate: function (value) {
	                        if (isNaN(value)) return '超时时间必须是数字';
	                        var time = parseInt(value);
	                        if (time < 1) return '超时时间必须大于等于1';
	                        if (time > 300) return '超时时间必须小于300';
	                    }
					}
				},
				{
					field : 'isResponseHead', 
					title : '头域返回',
					visible: false,
		        	formatter: function (value, row, index) {
		    		    if (value == 0) {
		        			return '响应不返回';
		        		} else if(value == 1){
		        			return '响应返回';
		        		} else{
		        			return '未知数据';
		        		}
		        	}
				},
				{
					field : 'isResponseCode', 
					title : '状态码返回',
					visible: false,
		        	formatter: function (value, row, index) {
		    		    if (value == 0) {
		        			return '响应不返回';
		        		} else if(value == 1){
		        			return '响应返回';
		        		} else{
		        			return '未知数据';
		        		}
		        	}
				},
				{
					field : 'createBy', 
					title : '创建者',
					visible: false
				},
				{
					field : 'createTime', 
					title : '创建时间',
					visible: false
				},
				{
					field : 'updateBy', 
					title : '更新者',
					class : 'myTDLengthHidden',
					width : '5%'
				},
				{
					field : 'updateTime', 
					title : '更新时间',
					width : '12%',
					sortable: true,
					class : 'myTDLengthHidden'
				},
				{
					field : 'remark', 
					title : '备注',
					width : '10%',
					class : 'myTDLengthHidden',
					editable : {
						type : 'textarea',
						title : '备注',
						emptytext : "【备注】为空",
						validate : function(value) {
							if (value.length > 200)
								return '备注不能超过200个字符';
						}
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            width : '13%',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.templateId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.templateId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        /* actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.customFull(\'' + row.templateId + '\')"><i class="fa fa-folder-open-o"></i>模板参数</a> '); */
						return actions.join('');
		            }
		        }],
		        //行内编辑
				onEditableSave : function(field, row, oldValue, $el) {	
					$('#bootstrap-table').bootstrapTable("resetView");
					delete row.project;
					
					if(field=='timeout'){
						time = parseInt(row.timeout);
						row.timeout = time;
					}
					
 					$.ajax({
						type : "post",
						url : prefix + "/edit",
						data : row,
						dataType : 'JSON',
						success : function(result) {
			                if (result.code == 0) {
			                	$.modal.msgSuccess(result.msg);
			                } else {
			                    $.modal.alertError(result.msg);
			                }
						},
						error : function() {
							$.modal.alertError("系统错误");
						}

					});
				}
            };
            $.table.init(options);
        });
    </script>
</body>
</html>