MrDoc/template/app_doc/manage/manage_project.html
2020-12-02 21:25:59 +08:00

283 lines
11 KiB
HTML

{% extends 'app_doc/user/user_base.html' %}
{% load static %}
{% load i18n %}
{% block title %}文集管理{% endblock %}
{% block content %}
<div class="layui-card">
<div class="layui-card-body">
<table id="project-table" lay-filter="project-table"></table>
</div>
</div>
<!-- 表格工具栏 -->
<script type="text/html" id="project-toolbar">
<div class="layui-input-inline">
<input type="text" name="project-search-kw" placeholder="" class="layui-input" >
</div>
<button class="layui-btn layui-btn-primary pear-btn-sm" lay-event="search">
<i class="layui-icon layui-icon-search"></i>
</button>
<button class="layui-btn layui-btn-normal pear-btn-sm" lay-event="add">
<i class="layui-icon layui-icon-add-1"></i>
</button>
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="batchRemove">
<i class="layui-icon layui-icon-delete"></i>
</button>
</script>
<!-- 文集名称 -->
<script type="text/html" id="project-name">
{% verbatim %}
<a href="/project-{{d.id}}/" target="_blank">
{{d.name}}
{{#if (d.role == 0) { }}
{{# }else if(d.role == 1){ }}
<span tooltip="私密" placement="right"><i class="layui-icon layui-icon-password"></i></span>
{{# }else if(d.role == 2){ }}
<span tooltip="指定用户" placement="right"><i class="layui-icon layui-icon-user"></i></span>
{{# }else if(d.role == 3){ }}
<span tooltip="访问码" placement="right"><i class="layui-icon layui-icon-key"></i></span>
{{# } }}
</a>
{% endverbatim %}
</script>
<!-- 单个文集操作 -->
<script type="text/html" id="project-bar">
{% verbatim %}
<a href="/manage_pro_doc_sort/{{d.id}}/" class="layui-btn layui-btn-primary pear-btn-sm" lay-event="sort"><i class="layui-icon layui-icon-cols"></i></a>
<a href="/modify_pro/?pro_id={{d.id}}" title="修改文集配置" class="layui-btn layui-btn-primary pear-btn-sm"><i class="layui-icon layui-icon-set"></i></a>
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
{% endverbatim %}
</script>
<!-- 文集权限 -->
<script type="text/html" id="project-role">
{% verbatim %}
{{#if (d.role == 0) { }}
<span>公开</span>
{{# }else if(d.role == 1){ }}
<span>私密</span>
{{# }else if(d.role == 2){ }}
<span>指定用户</span>
{{# }else if(d.role == 3){ }}
<span>访问码</span>
{{# } }}
{% endverbatim %}
</script>
<!-- 协作人数 -->
<script type="text/html" id="colla-cnt">
{% verbatim %}
<span>{{d.colla_total}}</span> <a href="/manage_project_colla/{{d.id}}/" title=""><i class="layui-icon layui-icon-set"></i></a>
{% endverbatim %}
</script>
<!-- 创建时间 -->
<script type="text/html" id="project-create-time">
{% verbatim %}
{{layui.util.toDateString(d.create_time, "yyyy-MM-dd HH:mm:ss")}}
{% endverbatim %}
</script>
{% endblock %}
{% block custom_script %}
<script>
layui.use(['table', 'form', 'jquery', 'layer'], function() {
let table = layui.table;
let form = layui.form;
let $ = layui.jquery;
let layer = layui.layer;
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
let cols = [
[
{type: 'checkbox',width:20},
{title: '文集名称',field: 'name',align: 'left',templet:"#project-name",minWidth:200},
// {title: '简介',field: 'intro',align: 'left',templet:"#share-type"},
// {title: '权限',field: 'role',align: 'left',templet:"#project-role"},
{title: '文档数',field: 'doc_total',align: 'left',width:90},
{title: '协作人数',field: 'colla_total',align: 'left',templet:"#colla-cnt",width:90},
{title: '创建时间',field: 'create_time',align: 'left',templet:"#project-create-time"},
{title: '操作',toolbar: '#project-bar',align: 'left',}
]
]
// 渲染表格
table.render({
elem: '#project-table',
method:'post',
where:{
'type':1
},
url: "{% url 'manage_project' %}",
page: true,
cols: cols,
skin: 'line',
toolbar: '#project-toolbar',
defaultToolbar: ['filter']
});
// 侦听文集删除按钮
table.on("tool(project-table)",function(obj){
if (obj.event === 'remove') {
// console.log(obj)
delProject(obj.data.id)
}
});
// 侦听表格工具栏
table.on("toolbar(project-table)",function(obj){
if (obj.event === 'add') { // 新增文集
createProject();
}else if(obj.event === 'batchRemove'){ // 批量删除文集
batchRemove(obj)
}else if(obj.event === 'search'){ // 搜索文集
console.log('搜索文集')
table.reload('project-table',{
where:{
'type':1,'kw':$('input[name="project-search-kw"]').val()
},
})
}
});
//创建文集
createProject = function(){
layer.open({
type:1,
title:'新建文集',
area:'300px;',
id:'createPro',//配置ID
content:'<div style="padding: 20px;"><input class="layui-input" type="text" id="pname" style="margin-bottom:10px;" placeholder="输入文集名" required lay-verify="required"><textarea name="desc" id="desc" placeholder="输入文集简介" class="layui-textarea"></textarea></div>',
btn:['确定','取消'], //添加按钮
btnAlign:'c', //按钮居中
yes:function (index,layero) {
layer.load(1);
data = {
'pname':$("#pname").val(),
'desc':$("#desc").val(),
}
$.post("{% url 'create_project' %}",data,function(r){
layer.closeAll('loading'); //关闭loading
if(r.status){
//创建成功
window.location.reload();
//layer.close(index)
}else{
//创建失败,提示
console.log(r)
}
})
},
});
};
//修改文集
modifyProject = function(pro_id,pro_name,pro_intro){
layer.open({
type:1,
title:'修改文集',
area:'300px;',
id:'modifyPro',//配置ID
content:'<div style="padding: 20px;"><input class="layui-input" type="text" id="pname" style="margin-bottom:10px;" placeholder="输入文集名" required lay-verify="required" value="'+pro_name+'"><textarea name="desc" id="desc" placeholder="输入文集简介" class="layui-textarea">'+pro_intro+'</textarea></div>',
btn:['确定','取消'], //添加按钮
btnAlign:'c', //按钮居中
yes:function (index,layero) {
layer.load(1);
data = {
'pro_id':pro_id,
'name':$("#pname").val(),
'desc':$("#desc").val(),
}
$.post("{% url 'modify_project' %}",data,function(r){
layer.closeAll('loading'); //关闭loading
if(r.status){
//修改成功
window.location.reload();
//layer.close(index)
}else{
//修改失败,提示
// console.log(r)
layer.msg(r.data)
}
})
},
});
};
//删除文集
delProject = function(pro_id){
layer.open({
type:1,
title:'删除文集',
area:'300px;',
id:'delPro',//配置ID
content:'<div style="margin-left:10px;">警告:此操作将删除文集及文集下所有文档!</div>',
btn:['确定','取消'], //添加按钮
btnAlign:'c', //按钮居中
yes:function (index,layero) {
layer.load(1);
data = {
'pro_id':pro_id,
}
$.post("{% url 'del_project' %}",data,function(r){
layer.closeAll('loading'); //关闭loading
if(r.status){
//修改成功
window.location.reload();
//layer.close(index)
}else{
//修改失败,提示
console.log(r)
layer.msg(r.data)
}
})
},
});
}
// 批量删除文集
batchRemove = function(obj) {
let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) {
layer.msg("未选中任何文集", {
icon: 3,
time: 1000
});
return false;
}
let pro_id = "";
for (let i = 0; i < data.length; i++) {
pro_id += data[i].id + ",";
}
pro_id = pro_id.substr(0, pro_id.length - 1);
// console.log(pro_id)
layer.confirm('确定要删除这些文集?', {
icon: 3,
title: '提示'
}, function(index) {
layer.close(index);
let loading = layer.load();
$.ajax({
url: "{% url 'del_project' %}",
dataType: 'json',
type: 'post',
data:{'pro_id':pro_id,'range':'multi'},
success: function(r) {
layer.close(loading);
if (r.status) {
layer.msg("删除成功", {
icon: 1,
time: 1000
}, function() {
table.reload('project-table');
});
} else {
layer.msg(r.data, {
icon: 2,
time: 1000
});
}
}
})
});
}
})
</script>
{% endblock %}