show errors for Review Edit and Submit (bug 688799)
This commit is contained in:
Родитель
7720020ef1
Коммит
0f497a7f94
|
@ -179,10 +179,14 @@ class TestCreate(ReviewTest):
|
|||
self.qs = Review.objects.filter(addon=1865)
|
||||
self.log_count = ActivityLog.objects.count
|
||||
|
||||
def test_no_body(self):
|
||||
r = self.client.post(self.add, {'body': ''})
|
||||
self.assertFormError(r, 'form', 'body', 'This field is required.')
|
||||
eq_(len(mail.outbox), 0)
|
||||
|
||||
def test_no_rating(self):
|
||||
r = self.client.post(self.add, {'body': 'no rating'})
|
||||
self.assertFormError(r, 'form', 'rating', 'This field is required.')
|
||||
|
||||
eq_(len(mail.outbox), 0)
|
||||
|
||||
def test_title_maxlength(self):
|
||||
|
|
|
@ -293,6 +293,7 @@ def impala_add(request, addon):
|
|||
|
||||
|
||||
@addon_view
|
||||
@json_view
|
||||
@login_required(redirect=False)
|
||||
@post_required
|
||||
def edit(request, addon, review_id):
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
function clearErrors(context) {
|
||||
$('.errorlist', context).remove();
|
||||
$('.error', context).removeClass('error');
|
||||
}
|
||||
|
||||
|
||||
function populateErrors(context, o) {
|
||||
clearErrors(context);
|
||||
var $list = $('<ul class="errorlist"></ul>');
|
||||
$.each(o, function(i, v) {
|
||||
var $row = $('[name=' + i + ']', context).closest('.row');
|
||||
$row.addClass('error');
|
||||
$row.append($list.append($(format('<li>{0}</li>', v))));
|
||||
});
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
var report = $('.review-reason').html();
|
||||
|
||||
$('.review-reason').popup('.flag-review', {
|
||||
|
@ -54,11 +55,12 @@ $(document).ready(function() {
|
|||
$('.primary').delegate('.review-edit', 'click', function(e) {
|
||||
e.preventDefault();
|
||||
var $form = $('#review-edit-form'),
|
||||
$review = $(this).parents('.review'),
|
||||
$review = $(this).closest('.review'),
|
||||
rating = $review.attr('data-rating'),
|
||||
edit_url = $('a.permalink', $review).attr('href') + 'edit',
|
||||
$cancel = $('#review-edit-cancel');
|
||||
|
||||
clearErrors($form);
|
||||
$review.attr('action', edit_url);
|
||||
$form.detach().insertAfter($review);
|
||||
$('#id_title').val($review.find('h3 > b').text());
|
||||
|
@ -66,8 +68,10 @@ $(document).ready(function() {
|
|||
$('#id_body').val($review.children('p.description').text());
|
||||
$review.hide();
|
||||
$form.show();
|
||||
location.hash = '#review-edit-form';
|
||||
|
||||
function done_edit() {
|
||||
clearErrors($form);
|
||||
$form.unbind().hide();
|
||||
$review.show();
|
||||
$cancel.unbind();
|
||||
|
@ -81,12 +85,17 @@ $(document).ready(function() {
|
|||
url: edit_url,
|
||||
data: $form.serialize(),
|
||||
success: function(response, status) {
|
||||
$review.find('h3 > b').text($('#id_title').val());
|
||||
var rating = $('.ratingwidget input:radio:checked', $form).val();
|
||||
$('.stars', $review).removeClass('stars-0 stars-1 stars-2 stars-3 stars-4 stars-5').addClass('stars-' + rating);
|
||||
rating = $review.attr('data-rating', rating);
|
||||
$review.children('p.description').text($('#id_body').val());
|
||||
done_edit();
|
||||
clearErrors($form);
|
||||
$review.find('h3 > b').text($('#id_title').val());
|
||||
var rating = $('.ratingwidget input:radio:checked', $form).val();
|
||||
$('.stars', $review).removeClass('stars-0 stars-1 stars-2 stars-3 stars-4 stars-5').addClass('stars-' + rating);
|
||||
rating = $review.attr('data-rating', rating);
|
||||
$review.children('p.description').text($('#id_body').val());
|
||||
done_edit();
|
||||
},
|
||||
error: function(xhr) {
|
||||
var errors = $.parseJSON(xhr.responseText);
|
||||
populateErrors($form, errors);
|
||||
},
|
||||
dataType: 'json'
|
||||
});
|
||||
|
|
|
@ -596,6 +596,7 @@ MINIFY_BUNDLES = {
|
|||
'js/impala/ratingwidget.js',
|
||||
'js/lib/jquery-ui/jqModal.js',
|
||||
'js/zamboni/l10n.js',
|
||||
'js/impala/forms.js',
|
||||
|
||||
# Homepage
|
||||
'js/impala/homepage.js',
|
||||
|
|
Загрузка…
Ссылка в новой задаче