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:
volpino
2012-11-08 18:57:29 +01:00
parent 9143301875
commit 9f5402f896
13 changed files with 125 additions and 157 deletions

View File

@ -1,7 +1,8 @@
{% extends "euscan/_datatable.html" %}
{% load djeuscan_helpers %}
{% load url from future %}
{% load djeuscan_helpers %}
{% load euscan_accounts_helpers %}
{% block title %}
{{ block.super }} - Herd: {{ herd.herd }}
@ -21,13 +22,8 @@
<h2>
Herd: {{ herd.herd }}
{% if user.is_authenticated %}
<span class="pull-right">
<button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_herd" herd.herd %}">
<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_herd" herd.herd %}">
<img src="{{ STATIC_URL}}/img/unwatch-icon.png" alt="Unwatch" />
</button>
<span class="pull-right padding-bottom10">
{% favourite_buttons "herd" herd.herd %}
</span>
{% endif %}
@ -51,24 +47,7 @@
<img alt="packages monthly" src="{% url "chart_herd" herd.herd 'packages-monthly' %}" />
</p>
<script type="text/javascript">
$(document).ready(function () {
$(".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 %}
{% block menus %}