Commit 15dcc760 authored by xiaoyu's avatar xiaoyu

user list bulk update modal

parent d2197d99
......@@ -178,8 +178,8 @@ function activeNav() {
var url_array = document.location.pathname.split("/");
var app = url_array[1];
var resource = url_array[2];
if (app == ''){
$('#index').addClass('active')
if (app === ''){
$('#index').addClass('active');
} else {
$("#" + app).addClass('active');
$('#' + app + ' #' + resource).addClass('active');
......@@ -236,8 +236,24 @@ function objectDelete(obj, name, url){
swal('Deleted!' , "【"+name+"】"+"has been deleted.", "success");
$(obj).parent().parent().remove();
}
})
});
});
}
var jumpserver = {};
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,6 +4,8 @@
{% block custom_head_css_js %}
<link href="{% static "css/plugins/dataTables/dataTables.min.css" %}" rel="stylesheet">
<link href="{% static "css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" %}" rel="stylesheet">
<link href="{% static "css/plugins/select2/select2.min.css" %}" rel="stylesheet">
<script src="{% static "js/plugins/select2/select2.full.min.js" %}"></script>
<script src="{% static "js/plugins/dataTables/dataTables.min.js" %}"></script>
{% endblock %}
{% block content %}
......
{% load i18n %}
<div aria-hidden="true" role="dialog" tabindex="-1" id="{% block modal_id %}{% endblock %}" class="modal inmodal" style="display: none;">
<div aria-hidden="true" role="dialog" id="{% block modal_id %}{% endblock %}" class="modal inmodal">
<div class="modal-dialog">
<div class="modal-content animated fadeIn">
<div class="modal-header">
......
{% extends '_modal.html' %}
{% load i18n %}
{% block modal_id %}user_bulk_update_modal{% endblock %}
{% block modal_title%}{% trans "Update User" %}{% endblock %}
{% block modal_body %}
<p class="text-success text-center">{% trans "Hint: only change the field you want to update." %}</p>
<form method="post" class="form-horizontal" action="" id="fm_user_bulk_update">
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_role">{% trans "Role" %}</label>
<div class=" col-sm-9 col-lg-9 ">
<select class=" form-control" id="id_role" name="role">
<option value="">---------</option>
<option value="Admin">{% trans "Admin" %}</option>
<option value="User">{% trans "User" %}</option>
</select>
</div>
</div>
<div class="form-group">
<label for="groups" class="col-sm-2 control-label">{% trans 'Groups' %}</label>
<div class="col-sm-9" id="select2-container">
<select name="groups" id="select2_groups" data-placeholder="{% trans 'Select Group' %}" class="select2 form-control m-b" multiple>
{% for group in groups %}
<option value="{{ group.id }}">{{ group.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-lg-9 col-sm-offset-2">
<div class="checkbox checkbox-success">
<input type="checkbox" name="enable_otp" checked id="id_enable_otp"><label for="id_enable_otp">{% trans 'Enable-OTP' %}</label>
</div>
</div>
</div>
</form>
{% endblock %}
{% block modal_confirm_id %}btn_user_bulk_update{% endblock %}
......@@ -25,6 +25,7 @@
<tbody>
</tbody>
</table>
{% include "users/_user_bulk_update_modal.html" %}
{% endblock %}
{% block content_bottom_left %}
<div class="input-group">
......@@ -150,6 +151,7 @@ $(document).ready(function(){
});
APIUpdateAttr({url: the_url, method: 'PATCH', body: JSON.stringify(body)});
$data_table.ajax.reload();
jumpserver.checked = false;
}
function doDelete() {
swal({
......@@ -172,9 +174,12 @@ $(document).ready(function(){
};
var url_delete = the_url + '?id__in=' + JSON.stringify(plain_id_list);
APIUpdateAttr({url: url_delete, method: 'DELETE', success: success, error: fail});
jumpserver.checked = false;
});
}
function doUpdate() {}
function doUpdate() {
$('#user_bulk_update_modal').modal('show');
}
switch(action) {
case 'deactive':
doDeactive();
......@@ -232,6 +237,17 @@ $(document).ready(function(){
jumpserver.checked = false;
$('#user_list_table').DataTable().rows().deselect();
}
}).on('click', '#btn_user_bulk_update', function(){
var json_data = $('#fm_user_bulk_update').serializeObject();
var body = {};
body.enable_otp = (json_data.enable_otp === 'on')? true: false;
if (json_data.role != '') {
body.role = json_data.role;
}
if (json_data.groups != undefined) {
body.groups = json_data.groups;
}
console.log(body)
})
</script>
{% endblock %}
......
......@@ -26,7 +26,6 @@ urlpatterns = [
url(r'^user/(?P<pk>[0-9]+)/assets-perm$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/create$', views.UserCreateView.as_view(), name='user-create'),
url(r'^user/(?P<pk>[0-9]+)/update$', views.UserUpdateView.as_view(), name='user-update'),
url(r'^user/(?P<pk>[0-9]+)/delete$', views.UserDeleteView.as_view(), name='user-delete'),
url(r'^user-group$', views.UserGroupListView.as_view(), name='user-group-list'),
url(r'^user-group/(?P<pk>[0-9]+)$', views.UserGroupDetailView.as_view(), name='user-group-detail'),
url(r'^user-group/create$', views.UserGroupCreateView.as_view(), name='user-group-create'),
......
......@@ -7,7 +7,6 @@ from django.contrib.auth import login as auth_login, logout as auth_logout
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.core.files.storage import default_storage
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import reverse, redirect
from django.utils.decorators import method_decorator
......@@ -80,27 +79,12 @@ class UserLogoutView(TemplateView):
return super(UserLogoutView, self).get_context_data(**kwargs)
class UserListView(AdminUserRequiredMixin, ListView):
model = User
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
context_object_name = 'user_list'
template_name = 'users/asset_permission_list.html'
ordering = '-date_joined'
def get_queryset(self):
self.queryset = super(UserListView, self).get_queryset()
self.keyword = keyword = self.request.GET.get('keyword', '')
self.sort = sort = self.request.GET.get('sort')
if keyword:
self.queryset = self.queryset.filter(Q(username__icontains=keyword) |
Q(name__icontains=keyword))
if sort:
self.queryset = self.queryset.order_by(sort)
return self.queryset
class UserListView(AdminUserRequiredMixin, TemplateView):
template_name = 'users/user_list.html'
def get_context_data(self, **kwargs):
context = super(UserListView, self).get_context_data(**kwargs)
context.update({'app': _('Users'), 'action': _('User list'), 'keyword': self.keyword})
context.update({'app': _('Users'), 'action': _('User list'), 'groups': UserGroup.objects.all()})
return context
......@@ -153,26 +137,6 @@ class UserUpdateView(AdminUserRequiredMixin, UpdateView):
return context
class UserDeleteView(AdminUserRequiredMixin, DeleteView):
model = User
success_url = reverse_lazy('users:user-list')
template_name = 'users/user_delete_confirm.html'
def delete(self, request, *args, **kwargs):
"""
Calls the delete() method on the fetched object and then
redirects to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
if self.object.name == "admin" or self.object.id == request.session.get('_auth_user_id'):
pass
else:
self.object.delete()
return HttpResponseRedirect(success_url)
class UserDetailView(AdminUserRequiredMixin, DetailView):
model = User
template_name = 'users/user_detail.html'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment