article_list.html 6.08 KB
Newer Older
luxcem's avatar
luxcem committed
1 2 3 4
{% extends "base.html" %}

{% block content %}

cynddl's avatar
cynddl committed
5
<div class="row">
6
<div class="col-md-12 white-bg">
cynddl's avatar
cynddl committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  <ul class="nav nav-integrated">
    <li class="nav-item{% if filter_view == 'flux' %} active{% endif %}">
      <a class="nav-link" href="{% url 'article-list' filter_view='flux'%}">
        Flux <img style="width: 2rem; margin-left: 0.5rem;" src="/static/img/cochon-01.png" alt="">
      </a>
    </li>
    <li class="nav-item {% if filter_view == 'draft' %} active{% endif %}">
      <a class="nav-link" href="{% url 'article-list' filter_view='draft'%}">
        En attente <span class="badge badge-default">{{nb_draft}}</span>
      </a>
    </li>
    <li class="nav-item {% if filter_view == 'published' %} active{% endif %}">
      <a class="nav-link" href="{% url 'article-list' filter_view='published'%}">Publiés</a>
    </li>
  </ul>

  <div class="well">
    {% if is_paginated %}
      <div class="pagination">
        <span class="page-links">
          {% if page_obj.has_previous %}
            <a href="?page={{ page_obj.previous_page_number }}"><<</a>
          {% endif %}
          <span class="page-current">
            Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
          </span>
          {% if page_obj.has_next %}
            <a href="?page={{ page_obj.next_page_number }}">>></a>
          {% endif %}
        </span>
      </div>
    {% endif %}

luxcem's avatar
luxcem committed
40 41 42 43 44 45
    {% if filter_view == "rejected" %}
      <div class="alert alert-danger" role="alert">
        {% trans "Rejected articles" %}
      </div>
    {% endif %}

cynddl's avatar
cynddl committed
46 47 48 49 50 51 52 53 54 55
    <table class="article-table table table-sm my-4">
      <thead>
        <tr>
          <th>Priority</th>
          <th>ID</th>
          <th>Date</th>
          <th>Language</th>
          <th>Title</th>
          <th>Note</th>
          <th>Added&nbsp;by</th>
cynddl's avatar
cynddl committed
56
          <th>Actions<img class="inline-image ml-2" role="img" src="{% static 'img/jedi.svg' %}" /></th>
cynddl's avatar
cynddl committed
57 58 59 60
        </tr>
      </thead>
    <tbody>
    {% for article in object_list|slice:":10" %}
61 62
      <tr id="row_empty_{{article.id}}" class="empty-row"><td colspan="8"></td></tr>
      <tr id="row_{{article.id}}">
cynddl's avatar
cynddl committed
63 64 65 66 67 68 69
        <td class="icon-cell"><i class="fa fa-dot-circle-o" aria-hidden="true" style="color:red"></i></td>
        <td>{{article.id}}</td>
        <td>{{article.created_at |date:'d/m/y'}}<br />{{article.created_at |date:'H:i'}}</td>
        <td>{{article.lang}}</td>
        <td class="title-cell"><a target="_blank" href="{{article.url}}"><strong>{{article.title}}</strong></a></td>
        <td>
          <ul class="votes-list">
70 71 72 73 74 75 76 77
            <li class="actions-item" onclick="javascript:call_upvote({{article.id}})">
              <span id="count_up_{{article.id}}">{{article.und_score_up}}</span>
              <i class="fa fa-thumbs-up" aria-hidden="true" style="color:green"></i>
            </li>
            <li class="actions-item" onclick="javascript:call_downvote({{article.id}})">
              <span id="count_down_{{article.id}}">{{article.und_score_down}}</span>
              <i class="fa fa-thumbs-down" aria-hidden="true" style="color:red"></i>
            </li>
cynddl's avatar
cynddl committed
78 79 80 81 82
          </ul>
        </td>
        <td>{{article.und_votes.first.username}}</td>
        <td class="actions-cell">
          <ul class="actions-list">
83
            {% if filter_view == 'flux' %}
84
            <li class="actions-item actions-item-draft"><a href="#">
85 86
              <i class="fa fa-chevron-right" aria-hidden="true"></i> Mettre en attente</a>
            </li>
87 88
            <li class="actions-item actions-item-reject" onclick="javascript:call_reject({{article.id}})">
              <i class="fa fa-times" aria-hidden="true"></i> Rejeter
89 90
            </li>
            {% else %}
91
            <li class="actions-item actions-item-edit"><a href="#">
cynddl's avatar
cynddl committed
92 93
              <i class="fa fa-pencil" aria-hidden="true"></i> Éditer</a>
            </li>
94 95
            <li class="actions-item actions-item-publish" onclick="javascript:call_publish({{article.id}})">
              <i class="fa fa-check" aria-hidden="true"></i> Publier
cynddl's avatar
cynddl committed
96
            </li>
97
            {% endif %}
cynddl's avatar
cynddl committed
98 99 100
          </ul>
        </td>
      </tr>
101
      {% if filter_view != 'flux' %}
102
      <tr id="row_tags_{{article.id}}" class="tags-row">
cynddl's avatar
cynddl committed
103 104 105 106
        <td colspan="8">
          <strong>Tags</strong> tags tags
        </td>
      </tr>
107
      {% endif %}
cynddl's avatar
cynddl committed
108 109 110 111 112 113
    {% endfor %}
    </tbody>
    </table>
  </div>
</div>
</div>
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

<script>
  function getCookie(name) {
      var cookieValue = null;
      if (document.cookie && document.cookie !== '') {
          var cookies = document.cookie.split(';');
          for (var i = 0; i < cookies.length; i++) {
              var cookie = jQuery.trim(cookies[i]);
              // Does this cookie string begin with the name we want?
              if (cookie.substring(0, name.length + 1) === (name + '=')) {
                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                  break;
              }
          }
      }
      return cookieValue;
  }
  var csrftoken = getCookie('csrftoken');

  function csrfSafeMethod(method) {
      // these HTTP methods do not require CSRF protection
      return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
  }
  $.ajaxSetup({
      beforeSend: function(xhr, settings) {
          if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
              xhr.setRequestHeader("X-CSRFToken", csrftoken);
          }
      }
  });

  function call_upvote(id) {
    $.post("/api/articles/" + id + "/upvote/", function response(data) {
      $("#count_up_" + id).text(data.und_score_up);
    });
  }

  function call_downvote(id) {
    $.post("/api/articles/" + id + "/downvote/", function response(data) {
      $("#count_down_" + id).text(data.und_score_down);
    });
  }

  function call_reject(id) {
    $.post("/api/articles/" + id + "/reject/", function response(data) {
      $("#row_" + id).hide();
      $("#row_empty_" + id).hide();
      $("#row_tags_" + id).hide();
    });
  }

  function call_publish(id) {
    $.post("/api/articles/" + id + "/publish/", function response(data) {
      $("#row_" + id).hide();
      $("#row_empty_" + id).hide();
      $("#row_tags_" + id).hide();
    });
  }
</script>
luxcem's avatar
luxcem committed
173
{% endblock %}