mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 00:00:00 +00:00
[new-repo]added input valid in fe
This commit is contained in:
2
forms.py
2
forms.py
@@ -97,7 +97,7 @@ class RepoCreateForm(forms.Form):
|
|||||||
passwd = self.cleaned_data['passwd']
|
passwd = self.cleaned_data['passwd']
|
||||||
passwd_again = self.cleaned_data['passwd_again']
|
passwd_again = self.cleaned_data['passwd_again']
|
||||||
if passwd != passwd_again:
|
if passwd != passwd_again:
|
||||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
raise forms.ValidationError(_("Passwords don't match"))
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
class SharedRepoCreateForm(RepoCreateForm):
|
class SharedRepoCreateForm(RepoCreateForm):
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
{% load i18n %}
|
||||||
//repo-create-form
|
//repo-create-form
|
||||||
$('#repo-create')
|
$('#repo-create')
|
||||||
.click(function() {
|
.click(function() {
|
||||||
@@ -18,17 +19,48 @@ $('#encrypt-switch').click(function () {
|
|||||||
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#repo-create-submit').click(function() {
|
$('#repo-create-form').submit(function() {
|
||||||
var passwd = $('#repo-create-form input[name="passwd"]'),
|
var passwd = $(this).find('input[name="passwd"]'),
|
||||||
passwd_again = $('#repo-create-form input[name="passwd_again"]');
|
passwd_again = $(this).find('input[name="passwd_again"]');
|
||||||
var self = $(this);
|
|
||||||
self.attr('disabled', 'disabled');
|
|
||||||
|
|
||||||
|
var form = 'repo-create-form';
|
||||||
|
if (!$.trim($('#repo-name').val())) {
|
||||||
|
apply_form_error(form, "{% trans "Name can't be empty" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$.trim($('#repo-desc').val())) {
|
||||||
|
apply_form_error(form, "{% trans "Description can't be empty" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($('#encrypt-switch').attr('checked')) {
|
||||||
|
if (!$.trim(passwd.val())) {
|
||||||
|
apply_form_error(form, "{% trans "Please enter password" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($.trim(passwd.val()).length < 3) {
|
||||||
|
apply_form_error(form, "{% trans "Password is too short (minimum is 3 characters)" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($.trim(passwd.val()).length > 15) {
|
||||||
|
apply_form_error(form, "{% trans "Password is too long (maximum is 15 characters)" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$.trim(passwd_again.val())) {
|
||||||
|
apply_form_error(form, "{% trans "Please enter the password again" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($.trim(passwd.val()) != $.trim(passwd_again.val())) {
|
||||||
|
apply_form_error(form, "{% trans "Passwords don't match" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var submit_btn = $(this).find('input[type="submit"]');
|
||||||
|
disable(submit_btn);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{{ post_url }}',
|
url: '{{ post_url }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: 'false',
|
|
||||||
beforeSend: prepareCSRFToken,
|
beforeSend: prepareCSRFToken,
|
||||||
data: {
|
data: {
|
||||||
'repo_name': $('#repo-name').val(),
|
'repo_name': $('#repo-name').val(),
|
||||||
@@ -45,7 +77,7 @@ $('#repo-create-submit').click(function() {
|
|||||||
location.reload(true);
|
location.reload(true);
|
||||||
} else {
|
} else {
|
||||||
apply_form_error('repo-create-form', data['error']);
|
apply_form_error('repo-create-form', data['error']);
|
||||||
self.removeAttr('disabled');
|
enable(submit_btn);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(data, textStatus, jqXHR) {
|
error: function(data, textStatus, jqXHR) {
|
||||||
@@ -53,7 +85,7 @@ $('#repo-create-submit').click(function() {
|
|||||||
$.each(errors, function(index, value) {
|
$.each(errors, function(index, value) {
|
||||||
apply_form_error('repo-create-form', value[0]);
|
apply_form_error('repo-create-form', value[0]);
|
||||||
});
|
});
|
||||||
self.removeAttr('disabled');
|
enable(submit_btn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user