mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +00:00
[system admin] users: added 'set quota / delete users in batch'
This commit is contained in:
@@ -135,7 +135,7 @@ function showConfirm(title, content, yesCallback) {
|
||||
|
||||
$cont.html('<h3>' + title + '</h3><p>' + content + '</p>');
|
||||
$popup.modal({appendTo: '#main'});
|
||||
$('#simplemodal-container').css({'height':'auto'});
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
|
||||
$yesBtn.click(yesCallback);
|
||||
}
|
||||
|
@@ -18,21 +18,30 @@
|
||||
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_ldap_imported' %}">{% trans "LDAP(imported)" %}</a></li>
|
||||
<li class="tabnav-tab"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
||||
</ul>
|
||||
<a class="sf-btn-link btn-white js-export-excel fright" href="{% url "sys_useradmin_export_excel" %}">{% trans "Export Excel" %}</a>
|
||||
|
||||
<div class="js-op-for-all fright">
|
||||
<button id="export-excel">{% trans "Export Excel" %}</button>
|
||||
</div>
|
||||
<div class="js-op-for-selected fright hide">
|
||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if users %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="36%">{% trans "Email" %}</th>
|
||||
<th width="3%"><input type="checkbox" /></th>
|
||||
<th width="33%">{% trans "Email" %}</th>
|
||||
<th width="12%">{% trans "Status" %}</th>
|
||||
<th width="18%">{% trans "Space Used / Quota" %}</th>
|
||||
<th width="18%">{% trans "Last Login" %}</th>
|
||||
<th width="16%">{% trans "Operations" %}</th>
|
||||
<th width="16%"></th>
|
||||
</tr>
|
||||
|
||||
{% for user in users %}
|
||||
<tr data-userid="{{user.email}}">
|
||||
<td><input type="checkbox" /></td>
|
||||
<td>
|
||||
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
||||
{% if user.name %}<br />{{ user.name }}{% endif %}
|
||||
@@ -98,6 +107,9 @@
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript">
|
||||
$("#export-excel").click(function() {
|
||||
location.href = "{% url 'sys_useradmin_export_excel' %}";
|
||||
});
|
||||
{% include "sysadmin/useradmin_js.html" %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@@ -21,11 +21,16 @@
|
||||
<li class="tabnav-tab"><a href="{% url 'sys_useradmin' %}?filter=paid">Paid</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="fright">
|
||||
|
||||
<div class="js-op-for-all fright">
|
||||
<button id="import-users-btn">{% trans "Import users" %}</button>
|
||||
<button id="add-user-btn">{% trans "Add user" %}</button>
|
||||
<button id="export-excel">{% trans "Export Excel" %}</button>
|
||||
</div>
|
||||
<div class="js-op-for-selected fright hide">
|
||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
||||
|
@@ -18,7 +18,14 @@
|
||||
{% endif %}
|
||||
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
||||
</ul>
|
||||
<button id="add-admin-btn" class="fright">{% trans "Add admin" %}</button>
|
||||
|
||||
<div class="js-op-for-all fright">
|
||||
<button id="add-admin-btn">{% trans "Add admin" %}</button>
|
||||
</div>
|
||||
<div class="js-op-for-selected fright hide">
|
||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form id="add-admin-form" method="post" name="add-admin-form" class="tab-popup hide">{% csrf_token %}
|
||||
|
@@ -10,7 +10,13 @@
|
||||
<label>{% trans "Email" %}</label><input type="text" name="email" class="input" value="{{email}}" /><br />
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
<h3>{% trans "Result"%}</h3>
|
||||
<div class="ovhd">
|
||||
<h3 class="fleft">{% trans "Result"%}</h3>
|
||||
<div class="js-op-for-selected fright hide">
|
||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% if users %}
|
||||
{% include "sysadmin/useradmin_table.html"%}
|
||||
{% else %}
|
||||
|
@@ -81,12 +81,112 @@ $('.user-status-select, .user-role-select').change(function() {
|
||||
});
|
||||
});
|
||||
|
||||
{% if user.source == "DB" or user.source == 'LDAPImport' %}
|
||||
// for 'select'
|
||||
var $opForAll = $('.js-op-for-all');
|
||||
var $opForSelected = $('.js-op-for-selected');
|
||||
$('th [type="checkbox"]').click(function() {
|
||||
var all_checked = $(this).prop('checked');
|
||||
if (all_checked) {
|
||||
$('td [type="checkbox"]').prop('checked', true);
|
||||
$opForAll.hide();
|
||||
$opForSelected.show();
|
||||
} else {
|
||||
$('td [type="checkbox"]').prop('checked', false);
|
||||
$opForAll.show();
|
||||
$opForSelected.hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('td [type="checkbox"]').click(function() {
|
||||
if ($('td [type="checkbox"]:checked').length) {
|
||||
$opForAll.hide();
|
||||
$opForSelected.show();
|
||||
} else {
|
||||
$opForAll.show();
|
||||
$opForSelected.hide();
|
||||
}
|
||||
|
||||
if ($('td [type="checkbox"]:checked').length == $('td [type="checkbox"]').length) {
|
||||
$('th [type="checkbox"]').prop('checked', true);
|
||||
} else {
|
||||
$('th [type="checkbox"]').prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
$('#set-quota-btn').click(function() {
|
||||
$('#set-quota-form').data({'batch': true}).modal();
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
});
|
||||
|
||||
$('#delete-users-btn').click(function() {
|
||||
var title = "{% trans "Delete User" %}";
|
||||
var content = "{% trans "Are you sure you want to delete the selected user(s) ?" %}";
|
||||
var yesCallback = function() {
|
||||
var emails = [];
|
||||
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
||||
var email = $(item).attr('data-userid');
|
||||
if (email != "{{request.user.username|escapejs}}") {
|
||||
emails.push(email);
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: '{% url "api-v2.1-admin-users-batch" %}',
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
data: {
|
||||
'operation': 'delete-user',
|
||||
'email': emails
|
||||
},
|
||||
traditional: true,
|
||||
dataType: 'json',
|
||||
beforeSend: prepareCSRFToken,
|
||||
success: function(data) {
|
||||
if (data.success.length) {
|
||||
var emails = [];
|
||||
$(data.success).each(function(index, item) {
|
||||
$('tr[data-userid="' + item.email + '"]').remove();
|
||||
emails.push(item.email);
|
||||
});
|
||||
var msg = "{% trans "Successfully deleted {users}." %}".replace('{users}', HTMLescape(emails.join(', ')));
|
||||
feedback(msg, 'success');
|
||||
}
|
||||
|
||||
// all selected items are deleted
|
||||
if ($('td [type="checkbox"]:checked').length == 0) {
|
||||
$opForAll.show();
|
||||
$opForSelected.hide();
|
||||
}
|
||||
|
||||
if (data.failed.length) {
|
||||
var err_msg = '';
|
||||
$(data.failed).each(function(index, item) {
|
||||
err_msg += HTMLescape(item.email) + ': ' + item.error_msg + '<br />';
|
||||
});
|
||||
setTimeout(function() { feedback(err_msg, 'error'); }, 1500);
|
||||
}
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
var err_msg;
|
||||
if (xhr.responseText) {
|
||||
err_msg = $.parseJSON(xhr.responseText).error_msg;
|
||||
} else {
|
||||
err_msg = "{% trans "Failed. Please check the network." %}";
|
||||
}
|
||||
feedback(err_msg, 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
showConfirm(title, content, yesCallback);
|
||||
});
|
||||
|
||||
// edit quota
|
||||
$('.quota-edit-icon').click(function() {
|
||||
var email = $(this).closest('tr').attr('data-userid');
|
||||
var $spaceQuota = $(this).prev('.user-space-quota');
|
||||
$('#set-quota-form').data({'email': email, '$spaceQuota': $spaceQuota}).modal();
|
||||
$('#set-quota-form').data({'batch': false, 'email': email, '$spaceQuota': $spaceQuota}).modal();
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
});
|
||||
|
||||
@@ -101,14 +201,54 @@ $('#set-quota-form').submit(function() {
|
||||
var $submitBtn = $('[type="submit"]', $(this));
|
||||
disable($submitBtn);
|
||||
|
||||
var batch = $(this).data('batch');
|
||||
var options = {};
|
||||
if (batch) {
|
||||
var emails = [];
|
||||
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
||||
emails.push($(item).attr('data-userid'));
|
||||
});
|
||||
options = {
|
||||
url: '{% url "api-v2.1-admin-users-batch" %}',
|
||||
type: 'POST',
|
||||
data: {
|
||||
'operation': 'set-quota',
|
||||
'email': emails,
|
||||
'quota_total': space_quota
|
||||
},
|
||||
traditional: true,
|
||||
success: function(data) {
|
||||
if (data.success.length) {
|
||||
var emails = [];
|
||||
$(data.success).each(function(index, item) {
|
||||
var $tr = $('tr[data-userid="' + item.email + '"]');
|
||||
var $quota = $('.user-space-quota', $tr);
|
||||
if (space_quota == 0) {
|
||||
$quota.html('--');
|
||||
} else {
|
||||
$quota.html(quotaSizeFormat(parseInt(item.quota_total), 1));
|
||||
}
|
||||
emails.push(item.email);
|
||||
});
|
||||
var msg = "{% trans "Successfully set quota for {users}." %}".replace('{users}', HTMLescape(emails.join(', ')));
|
||||
feedback(msg, 'success');
|
||||
}
|
||||
if (data.failed.length) {
|
||||
var err_msg = '';
|
||||
$(data.failed).each(function(index, item) {
|
||||
err_msg += HTMLescape(item.email) + ': ' + item.error_msg + '<br />';
|
||||
});
|
||||
setTimeout(function() { feedback(err_msg, 'error'); }, 1500);
|
||||
}
|
||||
$.modal.close();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
var email = $(this).data('email');
|
||||
var $spaceQuota = $(this).data('$spaceQuota');
|
||||
$.ajax({
|
||||
options = {
|
||||
url: '{{ SITE_ROOT }}api2/accounts/' + encodeURIComponent(email) + '/',
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: prepareCSRFToken,
|
||||
data: {'storage': space_quota},
|
||||
success: function(data) {
|
||||
if (space_quota == 0) {
|
||||
@@ -116,8 +256,17 @@ $('#set-quota-form').submit(function() {
|
||||
} else {
|
||||
$spaceQuota.html(quotaSizeFormat(parseInt(data['total']), 1));
|
||||
}
|
||||
var msg = "{% trans "Successfully set quota for {user}." %}".replace('{user}', HTMLescape(data.email));
|
||||
feedback(msg, 'success');
|
||||
$.modal.close();
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$.ajax($.extend({
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: prepareCSRFToken,
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
var err_msg;
|
||||
if (xhr.responseText) {
|
||||
@@ -128,11 +277,10 @@ $('#set-quota-form').submit(function() {
|
||||
$error.html(err_msg).show();
|
||||
enable($submitBtn);
|
||||
}
|
||||
});
|
||||
}, options));
|
||||
|
||||
return false;
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
// select shows, but the user doesn't select a value, or doesn't change the permission, click other place to hide the select
|
||||
$(document).click(function(e) {
|
||||
|
@@ -1,21 +1,23 @@
|
||||
{% load seahub_tags i18n %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="3%"><input type="checkbox" /></th>
|
||||
{% if is_pro %}
|
||||
<th width="24%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||
<th width="21%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||
<th width="12%">{% trans "Status" %}</th>
|
||||
<th width="12%">{% trans "Role" %}</th>
|
||||
{% else %}
|
||||
<th width="36%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||
<th width="33%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||
<th width="12%">{% trans "Status" %}</th>
|
||||
{% endif %}
|
||||
<th width="16%">{% trans "Space Used / Quota" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="14%">{% trans "Operations" %}</th>
|
||||
<th width="14%"></th>
|
||||
</tr>
|
||||
|
||||
{% for user in users %}
|
||||
<tr data-userid="{{user.email}}">
|
||||
<td><input type="checkbox" /></td>
|
||||
<td>
|
||||
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
||||
{% if user.name %}<br />{{ user.name }}{% endif %}
|
||||
@@ -105,7 +107,6 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% if user.source == "DB" or user.source == 'LDAPImport' %}
|
||||
<form id="set-quota-form" method="post" action="" class="hide">{% csrf_token %}
|
||||
<h3>{% trans "Set user storage limit" %}</h3>
|
||||
<input type="text" name="space_quota" class="input" /> MB
|
||||
@@ -116,4 +117,3 @@
|
||||
<p class="error hide"></p>
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user