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:
		@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
{% load url from future %}
 | 
			
		||||
{% load djeuscan_helpers %}
 | 
			
		||||
{% load euscan_accounts_helpers %}
 | 
			
		||||
 | 
			
		||||
{% block title %}
 | 
			
		||||
{{ block.super }} - World Scan
 | 
			
		||||
@@ -23,13 +24,8 @@
 | 
			
		||||
<h2>
 | 
			
		||||
  World scan:
 | 
			
		||||
  {% if user.is_authenticated %}
 | 
			
		||||
    <span class="pull-right">
 | 
			
		||||
      <button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_world" %}">
 | 
			
		||||
        <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_world" %}">
 | 
			
		||||
        <img src="{{ STATIC_URL}}/img/unwatch-icon.png" alt="Unwatch" />
 | 
			
		||||
      </button>
 | 
			
		||||
    <span class="pull-right padding-bottom10">
 | 
			
		||||
      {% favourite_buttons "world" %}
 | 
			
		||||
    </span>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
</h2>
 | 
			
		||||
@@ -37,23 +33,9 @@
 | 
			
		||||
{% packages packages %}
 | 
			
		||||
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
  $(document).ready(function () {
 | 
			
		||||
    var packages = [{{packages_ids|join:","}}];
 | 
			
		||||
 | 
			
		||||
    $(".favourite-button").click(function() {
 | 
			
		||||
      $.post($(this).data("url"), {packages: packages}, function() {
 | 
			
		||||
        $(".unfavourite-button").removeClass("hide");
 | 
			
		||||
        $(".favourite-button").addClass("hide");
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $(".unfavourite-button").click(function() {
 | 
			
		||||
      $.post($(this).data("url"), {packages: packages}, function() {
 | 
			
		||||
        $(".favourite-button").removeClass("hide");
 | 
			
		||||
        $(".unfavourite-button").addClass("hide");
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  window.packages = [{{ packages_ids|join:"," }}];
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<script src="{{ STATIC_URL }}js/favourite.js" type="text/javascript"></script>
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user