euscanwww: Refresh package button works even without JS

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-11-08 16:22:03 +01:00
parent 853e92c56e
commit 9143301875
3 changed files with 31 additions and 14 deletions

View File

@ -35,9 +35,14 @@
{% if user.is_authenticated %} {% if user.is_authenticated %}
<span class="pull-right"> <span class="pull-right">
<button class="btn refresh-button {% if refresh_requested %}hide{% endif %}" data-category="{{ package.category }}" data-package="{{ package.name }}"> <form class="refresh-form inline"
<img src="{{ STATIC_URL}}/img/refresh-active.png" alt="Refresh" /> method="POST"
</button> action="{% url "refresh_package" package.category package.name %}">
<button class="btn refresh-button {% if refresh_requested %}hide{% endif %}" type="submit">
<img src="{{ STATIC_URL}}/img/refresh-active.png" alt="Refresh" />
</button>
<input type="hidden" name="nojs" value="true" />
</form>
<button class="btn refresh-button-disabled disabled {% if not refresh_requested %}hide{% endif %}"> <button class="btn refresh-button-disabled disabled {% if not refresh_requested %}hide{% endif %}">
<img src="{{ STATIC_URL}}/img/refresh-inactive.png" alt="Refresh" /> <img src="{{ STATIC_URL}}/img/refresh-inactive.png" alt="Refresh" />
</button> </button>
@ -65,15 +70,19 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
$(".refresh-button").click(function() { $(".refresh-form").submit(function(e) {
var url = "{% url "refresh_package" "XXX" "YYY" %}"; var url = $(this).attr("action");
$.post(url.replace("XXX", $(this).data("category")).replace("YYY", $(this).data("package")),
function(data) { e.preventDefault();
$(".refresh-button").addClass("hide"); e.stopPropagation();
$(".refresh-button-disabled").removeClass("hide");
$("#refresh-pos").text(data.position); $.post(url, function(data) {
$(".refresh-alert").show("slow"); $(".refresh-button").addClass("hide");
}); $(".refresh-button-disabled").removeClass("hide");
$("#refresh-pos").text(data.position);
$(".refresh-alert").show("slow");
});
return false;
}); });
$(".favourite-button").click(function() { $(".favourite-button").click(function() {

View File

@ -4,7 +4,8 @@ import inspect
from annoying.decorators import render_to, ajax_request from annoying.decorators import render_to, ajax_request
from django.http import HttpResponse, HttpResponseNotFound from django.http import HttpResponse, HttpResponseNotFound
from django.shortcuts import get_object_or_404 from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
@ -450,4 +451,7 @@ def refresh_package(request, category, package):
if created: if created:
from djeuscan.tasks import consume_refresh_queue from djeuscan.tasks import consume_refresh_queue
consume_refresh_queue.delay() consume_refresh_queue.delay()
return {"result": "success", "position": obj.position} if "nojs" in request.POST:
return redirect(reverse("package", args=(category, package)))
else:
return {"result": "success", "position": obj.position}

View File

@ -234,3 +234,7 @@ textarea {
.errorlist + input { .errorlist + input {
border: 1px solid red; border: 1px solid red;
} }
.inline {
display: inline;
}