1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 10:58:33 +00:00

[sys useradmin] enable 'set quota' for DB useradmin; modified 'set quota' in user info page

This commit is contained in:
llj
2016-12-21 18:24:22 +08:00
parent d3ab1d76a3
commit bb6e1d1419
5 changed files with 78 additions and 17 deletions

View File

@@ -150,7 +150,6 @@ class SetUserQuotaForm(forms.Form):
"""
Form for setting user quota.
"""
email = forms.CharField(error_messages={'required': _('Email is required')})
space_quota = forms.IntegerField(min_value=0,
error_messages={'required': _('Space quota can\'t be empty'),
'min_value': _('Space quota is too low (minimum value is 0)')})

View File

@@ -80,6 +80,53 @@ $('.user-status-select, .user-role-select').change(function() {
}
});
});
{% if user.source == "DB" %}
// edit quota
$('.quota-edit-icon').click(function() {
var email = $(this).closest('tr').attr('data-userid');
$('#set-quota-form').data('email', email).modal();
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
});
$('#set-quota-form').submit(function() {
var space_quota = $.trim($('[name="space_quota"]', $(this)).val());
var $error = $('.error', $(this));
if (!space_quota) {
$error.html("{% trans "It is required." %}").show();
return false;
}
var $submitBtn = $('[type="submit"]', $(this));
disable($submitBtn);
var email = $(this).data('email');
$.ajax({
url: '{{ SITE_ROOT }}useradmin/' + encodeURIComponent(email) + '/set_quota/',
type: 'POST',
dataType: 'json',
cache: false,
beforeSend: prepareCSRFToken,
data: {'space_quota': space_quota},
success: function() {
location.reload(true);
},
error: function(xhr, textStatus, errorThrown) {
var err_msg;
if (xhr.responseText) {
err_msg = $.parseJSON(xhr.responseText).error;
} else {
err_msg = "{% trans "Failed. Please check the network." %}";
}
$error.html(err_msg).show();
enable($submitBtn);
}
});
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) {
var target = e.target || event.srcElement;

View File

@@ -9,7 +9,7 @@
<th width="36%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
<th width="12%">{% trans "Status" %}</th>
{% endif %}
<th width="16%">{% trans "Space Used" %}</th>
<th width="16%">{% trans "Space Used / Quota" %}</th>
<th width="22%">{% trans "Create At / Last Login" %}</th>
<th width="14%">{% trans "Operations" %}</th>
</tr>
@@ -70,7 +70,15 @@
{% endif %}
<td style="font-size:11px;">
<p> {{ user.space_usage|seahub_filesizeformat }} {% if user.space_quota > 0 %} / {{ user.space_quota|seahub_filesizeformat }} {% endif %} </p>
{{ user.space_usage|seahub_filesizeformat }} /
{% if user.space_quota > 0 %}
{{ user.space_quota|seahub_filesizeformat }}
{% else %}
--
{% endif %}
{% if user.source == "DB" %}
<span title="{% trans "Edit Quota" %}" class="quota-edit-icon sf2-icon-edit op-icon vh"></span>
{% endif %}
</td>
<td>
{% if user.source == "DB" %}
@@ -94,3 +102,13 @@
</tr>
{% endfor %}
</table>
{% if user.source == "DB" %}
<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" /> MB
<p class="tip">{% trans "Tip: 0 means default limit" %}</p>
<p class="error hide"></p>
<input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>
{% endif %}

View File

@@ -78,7 +78,7 @@
{% else %}
--
{% endif %}
<span id="set-quota" title="{% trans "Edit" %}" class="sf2-icon-edit op-icon"></span>
<span id="set-quota" title="{% trans "Edit Quota" %}" class="sf2-icon-edit op-icon"></span>
</dd>
</dl>
@@ -98,7 +98,6 @@
<form id="set-quota-form" method="post" class="hide">{% csrf_token %}
<h3>{% trans "Set user storage limit" %}</h3>
<input type="hidden" name="email" value="{{ email }}" />
<input type="text" name="space_quota" /> MB
<p class="tip">{% trans "Tip: 0 means default limit" %}</p>
<p class="error hide"></p>
@@ -383,28 +382,27 @@ $('#set-dept-form').submit(function() {
return false;
});
$('#set-quota-form .submit').click(function() {
var form = $('#set-quota-form'),
$('#set-quota-form').submit(function() {
var form = $(this),
form_id = form.attr('id'),
space_quota = $('input[name="space_quota"]', form).val();
space_quota = $.trim($('input[name="space_quota"]', form).val());
if (!$.trim(space_quota)) {
apply_form_error(form_id, "{% trans "Space Quota can't be empty" %}");
if (!space_quota) {
apply_form_error(form_id, "{% trans "It is required." %}");
return false;
}
data = { 'email': $('input[name="email"]', form).val(), 'space_quota': space_quota };
var $submitBtn = $('[type="submit"]', $(this));
disable($submitBtn);
var sb_btn = $(this);
disable(sb_btn);
$.ajax({
url: '{% url 'user_set_quota' email %}',
type: 'POST',
dataType: 'json',
cache: false,
beforeSend: prepareCSRFToken,
data: data,
success: function(data) {
data: {'space_quota': space_quota},
success: function() {
location.reload(true);
},
error: function(xhr, textStatus, errorThrown) {
@@ -413,7 +411,7 @@ $('#set-quota-form .submit').click(function() {
} else {
apply_form_error(form_id, "{% trans "Failed. Please check the network." %}");
}
enable(sb_btn);
enable($submitBtn);
}
});
return false;

View File

@@ -646,7 +646,6 @@ def user_set_quota(request, email):
f = SetUserQuotaForm(request.POST)
if f.is_valid():
email = f.cleaned_data['email']
space_quota_mb = f.cleaned_data['space_quota']
space_quota = space_quota_mb * get_file_size_unit('MB')