diff --git a/seahub/forms.py b/seahub/forms.py index 89775acf92..115a04229a 100644 --- a/seahub/forms.py +++ b/seahub/forms.py @@ -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)')}) diff --git a/seahub/templates/sysadmin/useradmin_js.html b/seahub/templates/sysadmin/useradmin_js.html index 7015e02ba5..be46fe71d1 100644 --- a/seahub/templates/sysadmin/useradmin_js.html +++ b/seahub/templates/sysadmin/useradmin_js.html @@ -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; diff --git a/seahub/templates/sysadmin/useradmin_table.html b/seahub/templates/sysadmin/useradmin_table.html index 8a4fcae400..ab5c5ce82a 100644 --- a/seahub/templates/sysadmin/useradmin_table.html +++ b/seahub/templates/sysadmin/useradmin_table.html @@ -9,7 +9,7 @@ {% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %} {% trans "Status" %} {% endif %} - {% trans "Space Used" %} + {% trans "Space Used / Quota" %} {% trans "Create At / Last Login" %} {% trans "Operations" %} @@ -70,7 +70,15 @@ {% endif %} -

{{ user.space_usage|seahub_filesizeformat }} {% if user.space_quota > 0 %} / {{ user.space_quota|seahub_filesizeformat }} {% endif %}

+ {{ user.space_usage|seahub_filesizeformat }} / + {% if user.space_quota > 0 %} + {{ user.space_quota|seahub_filesizeformat }} + {% else %} + -- + {% endif %} + {% if user.source == "DB" %} + + {% endif %} {% if user.source == "DB" %} @@ -94,3 +102,13 @@ {% endfor %} + +{% if user.source == "DB" %} +
{% csrf_token %} +

{% trans "Set user storage limit" %}

+ MB +

{% trans "Tip: 0 means default limit" %}

+

+ +
+{% endif %} diff --git a/seahub/templates/sysadmin/userinfo.html b/seahub/templates/sysadmin/userinfo.html index 5a301b3456..5953822647 100644 --- a/seahub/templates/sysadmin/userinfo.html +++ b/seahub/templates/sysadmin/userinfo.html @@ -78,7 +78,7 @@ {% else %} -- {% endif %} - + @@ -98,7 +98,6 @@
{% csrf_token %}

{% trans "Set user storage limit" %}

- MB

{% trans "Tip: 0 means default limit" %}

@@ -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; diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index ac5df5580e..adb1fdc1ee 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -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')