euscanwww: Favourite/Unfavourite template code refactored
* Now is more DRY, the JS code and the HTML code are in one place * It works even without JS Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
{% extends "euscan/_datatable.html" %}
|
||||
|
||||
{% load sub %}
|
||||
{% load url from future %}
|
||||
{% load sub %}
|
||||
{% load euscan_accounts_helpers %}
|
||||
|
||||
{% block meta %}
|
||||
{{ block.super }}
|
||||
@ -34,7 +35,7 @@
|
||||
{{ package.category }}/{{ package.name }}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<span class="pull-right">
|
||||
<div class="pull-right">
|
||||
<form class="refresh-form inline"
|
||||
method="POST"
|
||||
action="{% url "refresh_package" package.category package.name %}">
|
||||
@ -46,13 +47,9 @@
|
||||
<button class="btn refresh-button-disabled disabled {% if not refresh_requested %}hide{% endif %}">
|
||||
<img src="{{ STATIC_URL}}/img/refresh-inactive.png" alt="Refresh" />
|
||||
</button>
|
||||
<button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_package" package.category package.name %}">
|
||||
<img src="{{ STATIC_URL}}/img/watch-icon.png" alt="Watch" />
|
||||
</button>
|
||||
<button class="btn unfavourite-button {% if not favourited %}hide{% endif %}" data-url="{% url "unfavourite_package" package.category package.name %}">
|
||||
<img src="{{ STATIC_URL}}/img/unwatch-icon.png" alt="Unwatch" />
|
||||
</button>
|
||||
</span>
|
||||
|
||||
{% favourite_buttons "package" package.category package.name %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</h2>
|
||||
|
||||
@ -84,22 +81,9 @@
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$(".favourite-button").click(function() {
|
||||
$.post($(this).data("url"), function() {
|
||||
$(".unfavourite-button").removeClass("hide");
|
||||
$(".favourite-button").addClass("hide");
|
||||
});
|
||||
});
|
||||
|
||||
$(".unfavourite-button").click(function() {
|
||||
$.post($(this).data("url"), function() {
|
||||
$(".favourite-button").removeClass("hide");
|
||||
$(".unfavourite-button").addClass("hide");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="{{ STATIC_URL }}js/favourite.js" type="text/javascript"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user