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

View File

@ -4,7 +4,8 @@ import inspect
from annoying.decorators import render_to, ajax_request
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.views.decorators.http import require_POST
@ -450,4 +451,7 @@ def refresh_package(request, category, package):
if created:
from djeuscan.tasks import consume_refresh_queue
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 {
border: 1px solid red;
}
.inline {
display: inline;
}