safesite/safesite/templates/checklist_new.html

419 lines
15 KiB
HTML

<div class="easyui-layout" style="width:100%;height:100%;">
<div data-options="region:'west',split:true,border:false" style="width:30%;height:100%;" title="检查表">
<div id="checklistbar" style="height:auto">
<div>
{% load myfilter %}
<a onclick="addchecklist()" class="easyui-linkbutton"
data-options="iconCls:'fa-plus',plain:true">新增</a>
<a onclick="editchecklist()" class="easyui-linkbutton"
data-options="iconCls:'fa-pencil',plain:true">编辑</a>
<a onclick="delchecklist()" class="easyui-linkbutton"
data-options="iconCls:'fa-trash',plain:true">删除</a>
</div>
</div>
<table id="checklisttable" style="height:100%;"></table>
</div>
<div data-options="region:'center',split:true,border:false" style="width:70%;height:100%;">
<div class="easyui-layout" style="width:100%;height:100%;">
<div data-options="region:'center',split:true,border:false" title='检查条目' style="height: 50%;">
<div id="checkitembar" style="padding:5px;height:auto">
<a onclick="addcheckitem()" class="easyui-linkbutton"
data-options="iconCls:'fa-plus',plain:true">新增</a>
<a onclick="editcheckitem()" class="easyui-linkbutton"
data-options="iconCls:'fa-pencil',plain:true">编辑</a>
<a onclick="delcheckitem()" class="easyui-linkbutton"
data-options="iconCls:'fa-trash',plain:true">删除</a>
</div>
<table id="checkitemtable" style="height:100%;"></table>
</div>
<div data-options="region:'south',split:true,border:false" title='任务配置' style="height: 50%;">
<div id="checklisttasksetbar" style="padding:5px;height:auto">
<a onclick="addchecklisttaskset()" class="easyui-linkbutton"
data-options="iconCls:'fa-plus',plain:true">新增</a>
<a onclick="editchecklisttaskset()" class="easyui-linkbutton"
data-options="iconCls:'fa-pencil',plain:true">编辑</a>
<a onclick="togglechecklisttaskset()" class="easyui-linkbutton"
data-options="iconCls:'fa-pencil',plain:true">暂停/启用派发</a>
<a onclick="delchecklisttaskset()" class="easyui-linkbutton"
data-options="iconCls:'fa-trash',plain:true">删除</a>
</div>
<table id="checklisttasksettable" style="height:100%;"></table>
</div>
</div>
</div>
<div id="checklistdg" class="easyui-dialog" style="width:400px;height:400px;padding:5px 15px;"
data-options="resizable:true,modal:true,closed:true,border:false">
<form method="post" id="checklistff">
<input id="checklist" name="id" type="hidden">
<div style="margin-bottom:10px">
<input id="checklistname" name="name" data-options="label:'表名'" class="easyui-textbox" style="width:300px"
required></input>
</div>
<div style="margin-bottom:10px;text-align: center;" id="qrcodediv">
<div class="labeldiv">检查表二维码</div>
<img id="qrcode" height=160px width=160px>
</div>
<div style="text-align: center;">
<a class="easyui-linkbutton" iconCls="fa-floppy-o" onclick="savechecklist()">保存</a>
</div>
</form>
</div>
<div id="checkitemdg" class="easyui-dialog" style="width:400px;height:200px;padding:5px 15px;"
data-options="resizable:true,modal:true,closed:true,border:false">
<form method="post" id="checkitemff">
<input name="id" type="hidden">
<input name="riskact" type="hidden" id = "checklistId">
<div style="margin-bottom:10px">
<input id="checkitemname" name="content" data-options="label:'条目描述',multiline:true" class="easyui-textbox"
style="width:300px;height:60px" required></input>
</div>
<div style="text-align: center;">
<a class="easyui-linkbutton" iconCls="fa-floppy-o" onclick="savecheckitem()">保存</a>
</div>
</form>
</div>
<script>
var table_type = 2
var checklist_cu_url = "/api/riskact?a=add";
var checkitem_cu_url = "/api/risk?a=add";
$('#checklisttable').datagrid({
url: 'api/riskact?a=listall&table_type='+table_type,
singleSelect:true,
rownumbers: true,
fitColumns: true,
striped: true,
method: 'get',
toolbar: '#checklistbar',
pagination: 'true',
pageSize: 20,
columns: [[
// { field: 'ck', checkbox:true },
{ field: 'id', title: 'ID', hidden: true },
{ field: 'name', title: '名称', width: 100 },
{ field: 'createtime', title: '创建时间', width: 60 },
]],
onSelect: function (index, data) {
$('#checkitemtable').datagrid({url:'api/risk?a=listall&riskact='+data.id + '&table_type=2'})
$('#checklisttasksettable').datagrid({url:'api/gridtaskset/?a=listall&riskact='+data.id + '&table_type=2'})
}
})
$('#checkitemtable').datagrid({
url: '',
rownumbers: true,
singleSelect: true,
striped: true,
fitColumns: true,
method: 'get',
toolbar: '#checkitembar',
pagination: 'true',
pageSize: 20,
columns: [[
{ field: 'id', title: 'ID', hidden: true },
{ field: 'content', title: '内容', width: 100 },
{ field: 'createtime', title: '创建时间', width: 20 },
]],
});
$('#checklisttasksettable').datagrid({
url: '',
rownumbers: true,
singleSelect: true,
striped: true,
method: 'get',
toolbar: '#checklisttasksetbar',
pagination: 'true',
pageSize: 20,
columns: [[
{ field: 'id', title: 'ID', hidden: true },
{ field: 'user__name', title: '执行人', width: 100 },
{ field: 'myschedule__name', title: '任务策略', width: 200 ,
// formatter: function (value, row, index) {
// if(value.hasOwnProperty('interval')){
// return value.interval.replace(',hours', '小时').replace(',days', '天').replace(',weeks', '星期').replace(',months', '月').replace(',years', '年').replace(',seconds', '秒')
// }
// }
},
{ field: 'last_run_at', title: '最近派发时间', width: 150 },
{ field: 'periodictask__enabled', title: '派发状态', width: 100,
formatter: function (value, row, index) {
switch (value) {
case true: return '正常'; break;
case false: return '暂停'; break;
}
},
styler: function (value, row, index) {
switch (value) {
case true: return 'font-weight:bold;color:green'; break;
case false: return 'color:red;font-weight:bold'; break;
}
}
},
{ field: 'count', title: '已派发次数', width: 100 },
{ field: 'note', title: '执行备注', width: 100 },
]],
});
function addchecklist() {
$('#checklistdg').dialog('open').dialog('setTitle', '创建检查表').window('center');
$('#checklistff').form('clear');
$('#qrcodediv').hide()
checklist_cu_url = '/api/riskact?a=add'
}
function editchecklist() {
var row = $('#checklisttable').datagrid('getSelected');
if(row){
$('#checklistdg').dialog('open').dialog('setTitle', '编辑检查表').window('center');
$('#checklistff').form('load', row);
$('#qrcodediv').show();
$('#qrcode').attr('src',row.qrcode);
checklist_cu_url = '/api/riskact?a=edit&id=' + row.id}
else{
$.messager.alert('提示', '请选择一条数据!');
}
}
function savechecklist() {
var data = $('#checklistff').serializeJSON();
data['table_type'] = 2
$.ajax({
type: "POST",
url: checklist_cu_url,
data: JSON.stringify(data),
datatype: "json",
processData: false,
contentType: "application/json;charset=utf-8",
beforeSend: function () {
return $('#checklistff').form('validate')
},
success: function (data) {
if (data.code == 1) {
$("#checklisttable").datagrid('reload');
$("#checklistdg").dialog("close");
} else { $.messager.alert('提示', '失败!'); }
},
});
}
function addcheckitem() {
$('#checkitemff').form('clear');
var row = $('#checklisttable').datagrid('getSelected');
if(row){
$('#checklistId').attr('value', row.id);
checkitem_cu_url = '/api/risk?a=add'
$('#checkitemdg').dialog('open').dialog('setTitle', '新增项目').window('center');
}else{
$.messager.alert('提示', '请选择一张检查表!');
}
}
function editcheckitem() {
var row = $('#checkitemtable').datagrid('getSelected');
if(row){
$('#checkitemdg').dialog('open').dialog('setTitle', '编辑项目').window('center');
$('#checkitemff').form('load', row);
checkitem_cu_url = '/api/risk?a=update&id=' + row.id}
else{
$.messager.alert('提示', '请选择一条数据!');
}
}
function savecheckitem() {
var data = $('#checkitemff').serializeJSON();
$.ajax({
type: "POST",
url: checkitem_cu_url,
data: JSON.stringify(data),
datatype: "json",
processData: false,
contentType: "application/json;charset=utf-8",
beforeSend: function () {
return $('#checkitemff').form('validate')
},
success: function (data) {
if (data.code == 1) {
$("#checkitemtable").datagrid('reload');
$("#checkitemdg").dialog("close");
} else { $.messager.alert('提示', '失败!'); }
},
});
}
//ajax接收的才是js对象
function delcheckitem() {
var row = $('#checkitemtable').datagrid('getSelected');
if (row) {
$.messager.confirm('提示', '确定删除吗?', function (r) {
if (r) {
$.ajax({
type: "GET",
url: 'api/risk?a=del&id=' + row.id,
datatype: "json",
beforeSend: function () { },
success: function (data) {
if (data.code == 1) {
$("#checkitemtable").datagrid('reload');
$("#checklisttable").datagrid('reload');
} else {
$.messager.alert('提示', '您无权删除!');
}
},
complete: function (XMLHttpRequest, textStatus) {
},
error: function () {
}
});
}
}
);
}
else {
$.messager.alert('提示', '未选择数据!');
}
}
function delchecklist() {
var row = $('#checklisttable').datagrid('getSelected');
if (row) {
$.messager.confirm('提示', '确定删除吗?', function (r) {
if (r) {
$.ajax({
type: "GET",
url: 'api/riskact?a=del&id=' + row.id,
datatype: "json",
beforeSend: function () { },
success: function (data) {
if (data.code == 1) {
$("#checkitemtable").datagrid('reload');
$("#checklisttable").datagrid('reload');
} else {
$.messager.alert('提示', '您无权删除!');
}
},
complete: function (XMLHttpRequest, textStatus) {
},
error: function () {
}
});
}
}
);
}
else {
$.messager.alert('提示', '未选择数据!');
}
}
function addchecklisttaskset(){
var row = $('#checklisttable').datagrid('getSelected');
if (row) {
opendg('新增','html/gridtaskset/add/' + row.id + '/?table_type=2')
}
else {
$.messager.alert('提示', '请先选择一份检查表!');
}
}
function editchecklisttaskset(){
var row = $('#checklisttasksettable').datagrid('getSelected');
if (row) {
opendg('编辑','html/gridtaskset/edit/' + row.id)
}
else {
$.messager.alert('提示', '请先选择一个任务配置!');
}
}
function togglechecklisttaskset() {
var row = $('#checklisttasksettable').datagrid('getSelected');
if (row) {
var msg = '确定启动派发吗?'
if(row.periodictask__enabled){
msg = '确定暂停派发吗?'
}
$.messager.confirm('提示', msg, function (r) {
if (r) {
$.ajax({
type: "GET",
url: 'api/gridtaskset?a=toggle&id=' + row.id,
datatype: "json",
beforeSend: function () { },
success: function (data) {
$("#checklisttasksettable").datagrid('reload');
},
complete: function (XMLHttpRequest, textStatus) {
},
error: function () {
}
});
}
}
);
}
else {
$.messager.alert('提示', '未选择数据!');
}
}
function delchecklisttaskset() {
var row = $('#checklisttasksettable').datagrid('getSelected');
if (row) {
$.messager.confirm('提示', '确定删除吗?', function (r) {
if (r) {
$.ajax({
type: "GET",
url: 'api/gridtaskset?a=del&id=' + row.id,
datatype: "json",
beforeSend: function () { },
success: function (data) {
if (data.code == 1) {
$("#checklisttasksettable").datagrid('reload');
} else {
$.messager.alert('提示', '您无权删除!');
}
},
complete: function (XMLHttpRequest, textStatus) {
},
error: function () {
}
});
}
}
);
}
else {
$.messager.alert('提示', '未选择数据!');
}
}
</script>