Bug 583103, edit reviews inline- ooooo

This commit is contained in:
Matt Claypotch 2010-08-23 18:04:19 -07:00
Родитель 7802d67951
Коммит 9fac297667
4 изменённых файлов: 68 добавлений и 3 удалений

Просмотреть файл

@ -8,7 +8,8 @@
{% endif %}
<div class="review article {% if is_reply %}reply{% endif %}
{% if is_flagged %}flagged{% endif %}"
id="review-{{ review.id }}">
id="review-{{ review.id }}"
data-rating="{{ review.rating }}">
<h5>{{ review.title }}</h5>
{% if not is_reply %}{{ review.rating|float|stars }}{% endif %}
<div class="reviewed-on">
@ -25,9 +26,9 @@
and review.ip_address != '0.0.0.0' %}
<span>[{{ review.ip_address }}]</span>
{% endif %}
<a href="{{ url('reviews.detail', addon.id, review.id) }}">#</a>
<a class="permalink" href="{{ url('reviews.detail', addon.id, review.id) }}">#</a>
</div>
<p>{{ review.body|nl2br }}</p>
<p class="review-body">{{ review.body|nl2br }}</p>
{% if outdated and not is_reply %}
{# L10n: {0} is a version number (like 1.01) #}
<span class="review-note">{{ _('This review is for a previous version of the add-on ({0}).')|f(review.version.version) }}&nbsp;</span>
@ -65,6 +66,12 @@
{{ _('Reply to review') }}</a>
</li>
{% endif %}
{% if (review.user.id == request.user.id) %}
<li>
<a class="review-edit" href="#">
{{ _('Edit review') }}</a>
</li>
{% endif %}
{% if perms.can_delete %}
<li>
<a class="delete-review" href="{{ url('reviews.delete', addon.id, review.id) }}">

Просмотреть файл

@ -58,6 +58,18 @@
{% endfor %}
{{ reviews|paginator }}
{% endblock review_list %}
<div class="hidden">
<form method="post" id='review-edit-form' action="#" class="review article">
{{ csrf() }}
{{ field(form.title, _('Title:')) }}
{{ field(form.rating, _('Rating:')) }}
{{ field(form.body, _('Review:')) }}
<p>
<input type="submit" value="{{ _('Submit review') }}">
or <a href="#" id="review-edit-cancel">Cancel</a>
</p>
</form>
</div>
</div>
<div class="secondary">

Просмотреть файл

@ -30,6 +30,8 @@ def review_list(request, addon_id, review_id=None, user_id=None):
'grouped_ratings': GroupedRating.get(addon_id)}
ctx.update(flag_context())
ctx['form'] = forms.ReviewForm(None)
if review_id is not None:
ctx['page'] = 'detail'
# If this is a dev reply, find the first msg for context.

Просмотреть файл

@ -44,6 +44,50 @@ $(document).ready(function() {
el.click();
};
$('.primary').delegate('.review-edit', 'click', function(e) {
e.preventDefault();
var $form = $("#review-edit-form"),
$review = $(this).parents(".review"),
rating = $review.attr("data-rating"),
edit_url = $("a.permalink", $review).attr("href") + "edit";
$review.attr("action", edit_url);
$form.detach().insertAfter($review);
$("#id_title").val($review.children("h5").text());
$(".ratingwidget input:radio[value=" + rating + "]", $form).click();
$("#id_body").val($review.children("p.review-body").text());
$review.hide();
$form.show();
$("#review-edit-cancel").click(function(e) {
e.preventDefault();
$form.hide();
$review.show();
$(this).die();
});
$form.submit(function (e) {
e.preventDefault();
$.ajax({type: 'POST',
url: edit_url,
data: $form.serialize(),
success: function(response, status) {
$review.children("h5").text($("#id_title").val());
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.review-body").text($("#id_body").val());
$review.show();
$form.hide();
$('#review-edit-cancel').die();
},
dataType: 'json'
});
return false;
});
});
$('.delete-review').click(function(e) {
e.preventDefault();
var target = $(e.target);