189 lines
7.6 KiB
Plaintext
189 lines
7.6 KiB
Plaintext
<%@ page language="java" pageEncoding="UTF-8"%>
|
||
<%@page import="com.sipai.tools.CommUtil"%>
|
||
<%request.setAttribute("nowDate", CommUtil.nowDate().replaceAll("[[\\s-:punct:]]","")); %>
|
||
<style type="text/css">
|
||
.select2-container .select2-selection--single{
|
||
height:34px;
|
||
line-height: 34px;
|
||
}
|
||
.select2-selection__arrow{
|
||
margin-top:3px;
|
||
}
|
||
</style>
|
||
<script type="text/javascript">
|
||
var masterId='${reportTemplate.id}';
|
||
var tbName='TB_Report_TemplateFile'; //数据表
|
||
var nameSpace='ReportTemplateFile';//保存文件夹
|
||
var filelist = new Array();
|
||
var control;
|
||
var dataLength = 0;
|
||
//初始化fileinput控件(第一次初始化)
|
||
function initFileInput(ctrlName, uploadUrl) {
|
||
control = $('#' + ctrlName);
|
||
control.fileinput({
|
||
language: 'zh', //设置语言
|
||
uploadUrl: uploadUrl, //上传的地址
|
||
uploadAsync:true,
|
||
allowedFileExtensions : ['jasper'],//接收的文件后缀
|
||
showUpload: false, //是否显示上传按钮
|
||
showRemove:false,
|
||
dropZoneEnabled: false,//是否显示拖拽区域
|
||
showCaption: false,//是否显示标题
|
||
showClose:false,//右上角关闭按钮
|
||
browseClass: "btn btn-info", //按钮样式
|
||
maxFileCount: 1, //表示允许同时上传的最大文件个数
|
||
enctype: 'multipart/form-data',
|
||
autoReplace:true,
|
||
validateInitialCount:true,
|
||
previewFileIcon: "<i class='fa fa-file'></i>",
|
||
preferIconicPreview: true,//是否强制相关文件展示icon
|
||
initialPreviewAsData: true,
|
||
uploadExtraData:function (previewId, index) { //传参
|
||
var data = {
|
||
"masterId": masterId, //此处自定义传参
|
||
"tbName": tbName,
|
||
"nameSpace": nameSpace
|
||
};
|
||
return data;
|
||
},
|
||
layoutTemplates:{
|
||
actionDelete:''
|
||
},
|
||
});
|
||
//文件上传后的事件
|
||
control.on("filebatchselected", function (event, data, index) {
|
||
//console.info(data.length)
|
||
if(data.length == 0){
|
||
$("#name").val("");
|
||
showAlert('d','上传失败,请检查上传文件的类型!');
|
||
}else if(data.length >0){
|
||
dataLength = data.length;
|
||
//上传文件后生成模板名称
|
||
var tempName = data[0].name;
|
||
var nameArr = tempName.split('.');
|
||
$("#name").val(nameArr[0]+"${nowDate}");
|
||
console.info(dataLength)
|
||
}else{
|
||
showAlert('d','上传失败!');
|
||
}
|
||
//$(this).fileinput("upload");
|
||
});
|
||
//隐藏预览
|
||
$(".file-preview").css("display","none");
|
||
//导入文件上传保存完成之后的事件
|
||
control.on("fileuploaded", function (event, data, previewId, index) {
|
||
if(data.response.suc) {
|
||
//$("#name").val(data.files[0].name);
|
||
}
|
||
});
|
||
}
|
||
|
||
function dosave() {
|
||
console.info(dataLength.toString())
|
||
$('#subForm').data('bootstrapValidator')
|
||
.updateStatus('name', 'NOT_VALIDATED',null)
|
||
.validateField('name');
|
||
$("#subForm").bootstrapValidator('validate');//提交验证
|
||
if ($("#subForm").data('bootstrapValidator').isValid()) {//获取验证结果,如果成功,执行下面代码
|
||
$.post(ext.contextPath + "/report/reportTemplate/update.do?fileLength="+dataLength+"&tbName="+tbName,
|
||
$("#subForm").serialize(), function(data) {
|
||
if (data.res == 1){
|
||
if(dataLength>0){
|
||
control.fileinput("upload");//保存上传的文件
|
||
}
|
||
closeModal('subModal');
|
||
$("#table").bootstrapTable('refresh');
|
||
}else if(data.res == 0){
|
||
showAlert('d','保存失败');
|
||
}else{
|
||
showAlert('d',data.res);
|
||
}
|
||
},'json');
|
||
}
|
||
}
|
||
$(function(){
|
||
initFileInput("filelist",ext.contextPath+ "/base/inputFile.do");
|
||
//输入框验证
|
||
$("#subForm").bootstrapValidator({
|
||
live: 'disabled',//验证时机,enabled是内容有变化就验证(默认),disabled和submitted是提交再验证
|
||
fields: {
|
||
name: {
|
||
validators: {
|
||
notEmpty: {
|
||
message: '模板类型名称不能为空'
|
||
}
|
||
}
|
||
},
|
||
typeId: {
|
||
validators: {
|
||
notEmpty: {
|
||
message: '模板类型不能为空'
|
||
}
|
||
}
|
||
},
|
||
}
|
||
});
|
||
//选择模板类型
|
||
$.post(ext.contextPath + "/report/templateType/getTemplateTypeForSelect.do", function(data) {
|
||
var selelct =$("#typeId").select2({
|
||
data: data,
|
||
placeholder:'请选择',//默认文字提示
|
||
allowClear: false,//允许清空
|
||
escapeMarkup: function (markup) { return markup; }, // 自定义格式化防止xss注入
|
||
language: "zh-CN",
|
||
minimumInputLength: 0,
|
||
minimumResultsForSearch: 10,//数据超过十个启用搜索框
|
||
formatResult: function formatRepo(repo){return repo.text;}, // 函数用来渲染结果
|
||
formatSelection: function formatRepoSelection(repo){return repo.text;} // 函数用于呈现当前的选择
|
||
});
|
||
selelct.val('${reportTemplate.typeId}').trigger("change");
|
||
selelct.on("change",function(){
|
||
//$("#name").val($("#typeId option:selected").text()+"${nowDate}");
|
||
});
|
||
},'json');
|
||
})
|
||
|
||
</script>
|
||
<div class="modal fade" id="subModal">
|
||
<div class="modal-dialog">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||
<span aria-hidden="true">×</span></button>
|
||
<h4 class="modal-title">编辑报表模板</h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- 新增界面formid强制为subForm -->
|
||
<form class="form-horizontal" id="subForm">
|
||
<!-- 界面提醒div强制id为alertDiv -->
|
||
<div id="alertDiv"></div>
|
||
<input type="hidden" id="id" name ="id" value="${reportTemplate.id}">
|
||
<div class="form-group">
|
||
<label class="col-sm-2 control-label">*模板类型</label>
|
||
<div class="col-sm-6">
|
||
<select class="form-control select2" id="typeId" name ="typeId" style="width:270px;"></select>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="col-sm-2 control-label">*模板名称</label>
|
||
<div class="col-sm-6">
|
||
<input type="text" class="form-control" id="name" name ="name" placeholder="名称" autocomplete="off" value="${reportTemplate.name}" readonly>
|
||
</div>
|
||
<div class="col-sm-2">
|
||
<label class="input-group-btn">
|
||
<input name="filelist" id="filelist" class="file" type="file" >
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
|
||
<button type="button" class="btn btn-primary" onclick="dosave()" id="btn_save">保存</button>
|
||
</div>
|
||
</div>
|
||
<!-- /.modal-content -->
|
||
</div>
|
||
<!-- /.modal-dialog -->
|
||
</div>
|