删除部门后

pull/26/head
ibuler 2015-08-27 00:08:20 +08:00
parent 913f93b91f
commit 33c624c76f
13 changed files with 20 additions and 727 deletions

View File

@ -1,6 +1,6 @@
import datetime import datetime
from django.db import models from django.db import models
from juser.models import User, UserGroup, DEPT from juser.models import User, UserGroup
class IDC(models.Model): class IDC(models.Model):
@ -17,7 +17,6 @@ class BisGroup(models.Model):
('A', 'ASSET'), ('A', 'ASSET'),
) )
name = models.CharField(max_length=80, unique=True) name = models.CharField(max_length=80, unique=True)
dept = models.ForeignKey(DEPT)
comment = models.CharField(max_length=160, blank=True, null=True) comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self): def __unicode__(self):
@ -76,7 +75,6 @@ class Asset(models.Model):
port = models.IntegerField(max_length=6) port = models.IntegerField(max_length=6)
idc = models.ForeignKey(IDC) idc = models.ForeignKey(IDC)
bis_group = models.ManyToManyField(BisGroup) bis_group = models.ManyToManyField(BisGroup)
dept = models.ManyToManyField(DEPT)
login_type = models.CharField(max_length=1, choices=LOGIN_TYPE_CHOICES, default='L') login_type = models.CharField(max_length=1, choices=LOGIN_TYPE_CHOICES, default='L')
username = models.CharField(max_length=20, blank=True, null=True) username = models.CharField(max_length=20, blank=True, null=True)
password = models.CharField(max_length=80, blank=True, null=True) password = models.CharField(max_length=80, blank=True, null=True)

View File

@ -3,7 +3,7 @@ import datetime
from uuidfield import UUIDField from uuidfield import UUIDField
from django.db import models from django.db import models
from juser.models import UserGroup, DEPT from juser.models import UserGroup
from jasset.models import Asset, BisGroup from jasset.models import Asset, BisGroup
@ -18,7 +18,6 @@ class Perm(models.Model):
class CmdGroup(models.Model): class CmdGroup(models.Model):
name = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50, unique=True)
cmd = models.CharField(max_length=999) cmd = models.CharField(max_length=999)
dept = models.ForeignKey(DEPT)
comment = models.CharField(blank=True, null=True, max_length=50) comment = models.CharField(blank=True, null=True, max_length=50)
def __unicode__(self): def __unicode__(self):
@ -41,7 +40,6 @@ class Apply(models.Model):
applyer = models.CharField(max_length=20) applyer = models.CharField(max_length=20)
admin = models.CharField(max_length=20) admin = models.CharField(max_length=20)
approver = models.CharField(max_length=20) approver = models.CharField(max_length=20)
dept = models.CharField(max_length=20)
bisgroup = models.CharField(max_length=500) bisgroup = models.CharField(max_length=500)
asset = models.CharField(max_length=500) asset = models.CharField(max_length=500)
comment = models.TextField(blank=True, null=True) comment = models.TextField(blank=True, null=True)

View File

@ -19,7 +19,7 @@ from functools import partial
from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.template import RequestContext from django.template import RequestContext
from juser.models import User, UserGroup, DEPT from juser.models import User, UserGroup
from jasset.models import Asset, BisGroup, IDC from jasset.models import Asset, BisGroup, IDC
from jlog.models import Log from jlog.models import Log
from jasset.models import AssetAlias from jasset.models import AssetAlias

View File

@ -3,17 +3,8 @@
from django.db import models from django.db import models
class DEPT(models.Model):
name = models.CharField(max_length=80, unique=True)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
return self.name
class UserGroup(models.Model): class UserGroup(models.Model):
name = models.CharField(max_length=80, unique=True) name = models.CharField(max_length=80, unique=True)
dept = models.ForeignKey(DEPT)
comment = models.CharField(max_length=160, blank=True, null=True) comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self): def __unicode__(self):
@ -26,7 +17,7 @@ class UserGroup(models.Model):
class User(models.Model): class User(models.Model):
USER_ROLE_CHOICES = ( USER_ROLE_CHOICES = (
('SU', 'SuperUser'), ('SU', 'SuperUser'),
('DA', 'DeptAdmin'), ('GA', 'GroupAdmin'),
('CU', 'CommonUser'), ('CU', 'CommonUser'),
) )
username = models.CharField(max_length=80, unique=True) username = models.CharField(max_length=80, unique=True)
@ -34,7 +25,6 @@ class User(models.Model):
name = models.CharField(max_length=80) name = models.CharField(max_length=80)
email = models.EmailField(max_length=75) email = models.EmailField(max_length=75)
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU') role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
dept = models.ForeignKey(DEPT)
group = models.ManyToManyField(UserGroup) group = models.ManyToManyField(UserGroup)
ldap_pwd = models.CharField(max_length=128) ldap_pwd = models.CharField(max_length=128)
ssh_key_pwd = models.CharField(max_length=200) ssh_key_pwd = models.CharField(max_length=200)

View File

@ -7,14 +7,7 @@ urlpatterns = patterns('juser.views',
# url(r'^$', 'jumpserver.views.home', name='home'), # url(r'^$', 'jumpserver.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
(r'^dept_list/$', view_splitter, {'su': dept_list, 'adm': dept_list_adm}), (r'^group_add/$', group_add),
(r'^dept_add/$', 'dept_add'),
(r'^dept_del/$', 'dept_del'),
(r'^dept_detail/$', 'dept_detail'),
(r'^dept_del_ajax/$', 'dept_del_ajax'),
(r'^dept_edit/$', 'dept_edit'),
(r'^dept_user_ajax/$', 'dept_user_ajax'),
(r'^group_add/$', view_splitter, {'su': group_add, 'adm': group_add_adm}),
(r'^group_list/$', view_splitter, {'su': group_list, 'adm': group_list_adm}), (r'^group_list/$', view_splitter, {'su': group_list, 'adm': group_list_adm}),
(r'^group_detail/$', 'group_detail'), (r'^group_detail/$', 'group_detail'),
(r'^group_del/$', view_splitter, {'su': group_del, 'adm': group_del_adm}), (r'^group_del/$', view_splitter, {'su': group_del, 'adm': group_del_adm}),

View File

@ -12,51 +12,6 @@ from django.db.models import ObjectDoesNotExist
from juser.user_api import * from juser.user_api import *
@require_role(role='super')
def dept_add(request):
header_title, path1, path2 = '添加部门', '用户管理', '添加部门'
if request.method == 'POST':
name = request.POST.get('name', '')
comment = request.POST.get('comment', '')
try:
if not name:
raise ServerError('部门名称不能为空')
if DEPT.objects.filter(name=name):
raise ServerError(u'部门名称 %s 已存在' % name)
except ServerError, e:
error = e
else:
DEPT(name=name, comment=comment).save()
msg = u'添加部门 %s 成功' % name
return render_to_response('juser/dept_add.html', locals(), context_instance=RequestContext(request))
@require_role(role='super')
def dept_list(request):
header_title, path1, path2 = '查看部门', '用户管理', '查看部门'
keyword = request.GET.get('search')
if keyword:
contact_list = DEPT.objects.filter(Q(name__icontains=keyword) | Q(comment__icontains=keyword)).order_by('name')
else:
contact_list = DEPT.objects.all().order_by('id')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
return render_to_response('juser/dept_list.html', locals(), context_instance=RequestContext(request))
@require_role(role='admin')
def dept_list_adm(request):
header_title, path1, path2 = '查看部门', '用户管理', '查看部门'
user, dept = get_session_user_dept(request)
contact_list = [dept]
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
return render_to_response('juser/dept_list.html', locals(), context_instance=RequestContext(request))
def chg_role(request): def chg_role(request):
role = {'SU': 2, 'DA': 1, 'CU': 0} role = {'SU': 2, 'DA': 1, 'CU': 0}
user, dept = get_session_user_dept(request) user, dept = get_session_user_dept(request)
@ -67,177 +22,31 @@ def chg_role(request):
return HttpResponseRedirect('/') return HttpResponseRedirect('/')
@require_role(role='super')
def dept_detail(request):
dept_id = request.GET.get('id', None)
if not dept_id:
return HttpResponseRedirect('/juser/dept_list/')
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
users = dept.user_set.all()
return render_to_response('juser/dept_detail.html', locals(), context_instance=RequestContext(request))
@require_role(role='super')
def dept_del(request):
dept_id = request.GET.get('id', None)
if not dept_id or dept_id in ['1', '2']:
return HttpResponseRedirect('/juser/dept_list/')
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
dept.delete()
return HttpResponseRedirect('/juser/dept_list/')
def dept_member(dept_id):
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
return dept.user_set.all()
def dept_member_update(dept, users_id_list):
old_users = dept.user_set.all()
new_users = []
for user_id in users_id_list:
new_users.extend(User.objects.filter(id=user_id))
remove_user = [user for user in old_users if user not in new_users]
add_user = [user for user in new_users if user not in old_users]
for user in add_user:
user.dept = dept
user.save()
dept_default = DEPT.objects.get(id=2)
for user in remove_user:
user.dept = dept_default
user.save()
@require_role(role='super')
def dept_del_ajax(request):
dept_ids = request.POST.get('dept_ids')
for dept_id in dept_ids.split(','):
if int(dept_id) > 2:
DEPT.objects.filter(id=dept_id).delete()
return HttpResponse("删除成功")
@require_role(role='super')
def dept_edit(request):
header_title, path1, path2 = '部门编辑', '用户管理', '部门编辑'
if request.method == 'GET':
dept_id = request.GET.get('id', '')
if dept_id:
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
users = dept_member(dept_id)
users_all = User.objects.all()
users_other = [user for user in users_all if user not in users]
else:
error = 'id 错误'
else:
error = u'部门不存在'
else:
dept_id = request.POST.get('id', '')
name = request.POST.get('name', '')
users = request.POST.getlist('users_selected', [])
comment = request.POST.get('comment', '')
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept.update(name=name, comment=comment)
dept_member_update(dept[0], users)
else:
error = '部门不存在'
return HttpResponseRedirect('/juser/dept_list/')
return render_to_response('juser/dept_edit.html', locals(), context_instance=RequestContext(request))
def dept_user_ajax(request):
dept_id = request.GET.get('id', '4')
if dept_id not in ['1', '2']:
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
users = dept.user_set.all()
else:
users = User.objects.all()
return render_to_response('juser/dept_user_ajax.html', locals())
@require_role(role='super') @require_role(role='super')
def group_add(request): def group_add(request):
error = '' error = ''
msg = '' msg = ''
header_title, path1, path2 = '添加', '用户管理', '添加' header_title, path1, path2 = '添加用户组', '用户管理', '添加用户组'
user_all = User.objects.all() user_all = User.objects.all()
dept_all = DEPT.objects.all()
if request.method == 'POST': if request.method == 'POST':
group_name = request.POST.get('group_name', '') group_name = request.POST.get('group_name', '')
dept_id = request.POST.get('dept_id', '')
users_selected = request.POST.getlist('users_selected', '') users_selected = request.POST.getlist('users_selected', '')
comment = request.POST.get('comment', '') comment = request.POST.get('comment', '')
try: try:
if '' in [group_name, dept_id]: if not group_name:
error = u'组名 或 部门 不能为空' error = u'组名 不能为空'
raise ServerError(error) raise ServerError(error)
if UserGroup.objects.filter(name=group_name): if UserGroup.objects.filter(name=group_name):
error = u'组名已存在' error = u'组名已存在'
raise ServerError(error) raise ServerError(error)
db_add_group(name=group_name, users_id=users_selected, comment=comment)
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
else:
error = u'部门不存在'
raise ServerError(error)
db_add_group(name=group_name, users=users_selected, dept=dept, comment=comment)
except ServerError: except ServerError:
pass pass
except TypeError: except TypeError:
error = u'保存小组失败' error = u'添加小组失败'
else:
msg = u'添加组 %s 成功' % group_name
return render_to_response('juser/group_add.html', locals(), context_instance=RequestContext(request))
@require_role(role='admin')
def group_add_adm(request):
error = ''
msg = ''
header_title, path1, path2 = '添加小组', '用户管理', '添加小组'
user, dept = get_session_user_dept(request)
user_all = dept.user_set.all()
if request.method == 'POST':
group_name = request.POST.get('group_name', '')
users_selected = request.POST.getlist('users_selected', '')
comment = request.POST.get('comment', '')
try:
if not validate(request, user=users_selected):
raise ServerError('没有某用户权限')
if '' in [group_name]:
error = u'组名不能为空'
raise ServerError(error)
db_add_group(name=group_name, users=users_selected, dept=dept, comment=comment)
except ServerError:
pass
except TypeError:
error = u'保存小组失败'
else: else:
msg = u'添加组 %s 成功' % group_name msg = u'添加组 %s 成功' % group_name

View File

@ -1,100 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>填写基本信息</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<form id="deptForm" method="post" class="form-horizontal" action="">
{% if error %}
<div class="alert alert-warning text-center">{{ error }}</div>
{% endif %}
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<div class="form-group">
<label for="name" class="col-sm-2 control-label">部门名称<span class="red-fonts">*</span></label>
<div class="col-sm-8">
{% if error %}
<input id="name" name="name" placeholder="Department name" type="text" class="form-control" value="{{ name }}">
{% else %}
<input id="name" name="name" placeholder="Department name" type="text" class="form-control">
{% endif %}
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="comment" class="col-sm-2 control-label">备注</label>
<div class="col-sm-8">
{% if error %}
<input id="comment" name="comment" placeholder="Comment" type="text" class="form-control" value="{{ comment }}">
{% else %}
<input id="comment" name="comment" placeholder="Comment" type="text" class="form-control">
{% endif %}
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">取消</button>
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block self_footer_js %}
<script>
$('#deptForm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"name": {
rule: "required",
tip: "输入部门名称",
ok: "",
msg: {required: "必须填写!!"}
}
},
valid: function(form) {
form.submit();
}
});
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})
})
</script>
{% endblock %}

View File

@ -1,116 +0,0 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 查看部门 </h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="">
<a target="_blank" href="/juser/dept_add/" class="btn btn-sm btn-primary "> 添加部门 </a>
<a id="del_btn" class="btn btn-sm btn-danger"> 删除所选 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
<div class="input-group-btn">
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
Search
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="select_all" onclick="selectAll()" name="select_all">
</th>
<th class="text-center">部门名称</th>
<th class="text-center">小组数目</th>
<th class="text-center">成员数目</th>
<th class="text-center">主机数目</th>
<th class="text-center">备注</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
{% for dept in contacts.object_list %}
<tr class="gradeX">
<td class="text-center">
<input type="checkbox" name="selected" value="{{ dept.id }}">
</td>
<td class="text-center"> {{ dept.name }} </td>
<td class="text-center"> <a href="/juser/group_list/?did={{ dept.id }}">{{ dept.id | dept_group_num }}</a> </td>
<td class="text-center"> <a href="/juser/user_list/?did={{ dept.id }}">{{ dept.id | dept_user_num}} </a> </td>
<td class="text-center"> {{ dept.id | dept_asset_num}} </td>
<td class="text-center"> {{ dept.comment }} </td>
<td class="text-center">
<a href="../dept_detail/?id={{ dept.id }}" class="btn btn-xs btn-primary">详情</a>
<a href="../dept_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../dept_del/?id={{ dept.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
var check_array = []
$('#del_btn').click(function(){
if (confirm("确定删除")) {
$(".gradeX input:checked").each(function() {check_array.push($(this).attr("value")) })
$(".gradeX input:checked").closest("tr").remove()
$.post("/juser/dept_del_ajax/",
{dept_ids: check_array.join(",")},
function(data){
alert(data)
}
)
}
})
});
</script>
{% endblock %}

View File

@ -1,133 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>修改信息</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<form id="deptForm" method="post" class="form-horizontal" action="">
{% if error %}
<div class="alert alert-warning text-center">{{ error }}</div>
{% endif %}
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<div class="form-group">
<label for="name" class="col-sm-2 control-label">部门名称<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input name="id" type="text" value="{{ dept.id }}" style="display: none;">
<input id="name" name="name" placeholder="Dept name" type="text" class="form-control" value="{{ dept.name }}">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="users" class="col-lg-2 control-label">成员</label>
<div class="col-sm-3">
<select id="users" name="users" size="12" class="form-control m-b" multiple>
{% for user in users_other %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
<span class="help-block m-b-none">
用户部门是唯一的
</span>
</div>
<div class="col-sm-1">
<div class="btn-group" style="margin-top: 50px;">
<button type="button" class="btn btn-white" onclick="move('users', 'users_selected')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move('users_selected', 'users')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="comment" class="col-sm-2 control-label">备注</label>
<div class="col-sm-8">
<input id="comment" name="comment" placeholder="Comment" type="text" class="form-control" value="{{ dept.comment }}">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">取消</button>
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$('#deptForm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"name": {
rule: "required",
tip: "输入部门名称",
ok: "",
msg: {required: "必须填写!"}
}
},
valid: function(form) {
form.submit();
}
});
function change_type(type){
$.post('/juser/group_add_ajax/',
{'type': type},
function(data){
$('#users').html(data)
})
}
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})
})
</script>
{% endblock %}

View File

@ -1,126 +0,0 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 查看部门 </h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="">
<a target="_blank" href="/juser/dept_add/" class="btn btn-sm btn-primary "> 添加部门 </a>
<a id="del_btn" class="btn btn-sm btn-danger"> 删除所选 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
<div class="input-group-btn">
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
Search
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="select_all" onclick="selectAll()" name="select_all">
</th>
<th class="text-center">部门名称</th>
<th class="text-center">小组数目</th>
<th class="text-center">成员数目</th>
<th class="text-center">主机数目</th>
<th class="text-center">备注</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
{% for dept in contacts.object_list %}
<tr class="gradeX">
<td class="text-center">
<input type="checkbox" name="selected" value="{{ dept.id }}">
</td>
<td class="text-center"> {{ dept.name }} </td>
<td class="text-center"> <a href="/juser/group_list/?did={{ dept.id }}">{{ dept.id | dept_group_num }}</a> </td>
<td class="text-center"> <a href="/juser/user_list/?did={{ dept.id }}">{{ dept.id | dept_user_num}} </a> </td>
<td class="text-center"> <a href="/jasset/host_list/?did={{ dept.id }}">{{ dept.id | dept_asset_num}} </a> </td>
<td class="text-center"> {{ dept.comment }} </td>
<td class="text-center">
{# <a href="../dept_detail/?id={{ dept.id }}" class="btn btn-xs btn-primary">详情</a>#}
{% ifequal session_role_id 2 %}
<a href="../dept_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../dept_del/?id={{ dept.id }}" class="btn btn-xs btn-danger {% if dept.id < 3 %} disabled {% endif %} ">删除</a>
{% else %}
<a href="../dept_edit/?id={{ dept.id }}" class="btn btn-xs btn-info disabled">编辑</a>
<a href="../dept_del/?id={{ dept.id }}" class="btn btn-xs btn-danger disabled">删除</a>
{% endifequal %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var check_array = []
$('#del_btn').click(function(){
if (confirm("确定删除")) {
$(".gradeX input:checked").each(function() {
var id = $(this).attr("value");
if(id > 2){
check_array.push(id);
$(this).closest("tr").remove();
}
});
{# $(".gradeX input:checked").closest("tr").remove();#}
$.post("/juser/dept_del_ajax/",
{dept_ids: check_array.join(",")},
function(data){
alert(data)
}
)
}
})
});
</script>
{% endblock %}

View File

@ -1,3 +0,0 @@
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}

View File

@ -15,12 +15,6 @@
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i> <i class="fa fa-wrench"></i>
</a> </a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link"> <a class="close-link">
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
</a> </a>
@ -35,27 +29,15 @@
<div class="alert alert-success text-center">{{ msg }}</div> <div class="alert alert-success text-center">{{ msg }}</div>
{% endif %} {% endif %}
<div class="form-group"> <div class="form-group">
<label for="group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label> <label for="group_name" class="col-sm-2 control-label">用户组名<span class="red-fonts">*</span></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control" value="{{ group_name }}"> <input id="group_name" name="group_name" placeholder="User Group Name" type="text" class="form-control" value="{{ group_name }}">
</div> </div>
</div> </div>
{% ifequal session_role_id 2 %}
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="dept_id" class="col-sm-2 control-label">部门<span class="red-fonts">*</span></label> <label for="users" class="col-sm-2 control-label">用户</label>
<div class="col-sm-8">
<select id="dept_id" name="dept_id" class="form-control m-b" onchange="change_dept(this.value)">
{% for dept in dept_all %}
<option value="{{ dept.id }}" selected>{{ dept.name }}</option>
{% endfor %}
</select>
</div>
</div>
{% endifequal %}
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="users" class="col-lg-2 control-label">用户</label>
<div class="col-sm-3"> <div class="col-sm-3">
<select id="users" name="users" size="12" class="form-control m-b" multiple> <select id="users" name="users" size="12" class="form-control m-b" multiple>
{% for user in user_all %} {% for user in user_all %}
@ -98,6 +80,9 @@
</div> </div>
</div> </div>
{% endblock %}
{% block self_footer_js %}
<script> <script>
$('#groupForm').validator({ $('#groupForm').validator({
timely: 2, timely: 2,
@ -105,7 +90,7 @@ $('#groupForm').validator({
fields: { fields: {
"group_name": { "group_name": {
rule: "required", rule: "required",
tip: "输入组名", tip: "用户输入组名",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },

View File

@ -9,10 +9,8 @@
<li id="juser"> <li id="juser">
<a href="#"><i class="fa fa-rebel"></i> <span class="nav-label">用户管理</span><span class="fa arrow"></span></a> <a href="#"><i class="fa fa-rebel"></i> <span class="nav-label">用户管理</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level"> <ul class="nav nav-second-level">
<li class="dept_list dept_edit"><a href="/juser/dept_list/">查看部门</a></li> <li class="group_list group_edit"><a href="/juser/group_list/">查看用户组</a></li>
<li class="dept_add"><a href="/juser/dept_add/">添加部门</a></li> <li class="group_add"><a href="/juser/group_add/">添加用户组</a></li>
<li class="group_list group_edit"><a href="/juser/group_list/">查看小组</a></li>
<li class="group_add"><a href="/juser/group_add/">添加小组</a></li>
<li class="user_list user_edit user_detail"><a href="/juser/user_list/">查看用户<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li> <li class="user_list user_edit user_detail"><a href="/juser/user_list/">查看用户<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li>
<li class="user_add"><a href="/juser/user_add/">添加用户</a></li> <li class="user_add"><a href="/juser/user_add/">添加用户</a></li>
</ul> </ul>