aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/templates/home.html
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-06-28 15:01:04 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-06-28 15:01:04 +0200
commitfe6daa5852d1084cee2efc0f16ee5c8c26847539 (patch)
treea3b4d55d0b2d54a9256e88797b1c294377fef94d /pyaggr3g470r/templates/home.html
parentTable rows of the dashboard are colored for inactive accounts. (diff)
downloadnewspipe-fe6daa5852d1084cee2efc0f16ee5c8c26847539.tar.gz
newspipe-fe6daa5852d1084cee2efc0f16ee5c8c26847539.tar.bz2
newspipe-fe6daa5852d1084cee2efc0f16ee5c8c26847539.zip
Try to star an article with a jQuery PUT call.
Diffstat (limited to 'pyaggr3g470r/templates/home.html')
-rw-r--r--pyaggr3g470r/templates/home.html50
1 files changed, 47 insertions, 3 deletions
diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html
index 1290038d..2c9460df 100644
--- a/pyaggr3g470r/templates/home.html
+++ b/pyaggr3g470r/templates/home.html
@@ -99,11 +99,11 @@
<td class="date">{{ article.date|datetime }}</a></td>
<td>
<a href="/delete/{{ article.id }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this article') }}"></i></a>
- <a href="/like/{{ article.id }}">
+ <a href="#">
{% if article.like %}
- <i class="glyphicon glyphicon-star" title="{{ _('One of your favorites') }}"></i>
+ <i class="glyphicon glyphicon-star like" title="{{ _('One of your favorites') }}"></i>
{% else %}
- <i class="glyphicon glyphicon-star-empty" title="{{ _('Click if you like this article') }}"></i>
+ <i class="glyphicon glyphicon-star-empty like" title="{{ _('Click if you like this article') }}"></i>
{% endif %}
</a>
{% if article.readed %}
@@ -132,4 +132,48 @@
{% endif %}
</div><!-- /.container -->
{% endif %}
+
+<script type="text/javascript" class="source">
+
+$(document).ready(function() {
+
+ // Like or unlike an article
+ $('.like').on('click', function() {
+ var article_id = $(this).parent().parent().parent().attr("data-article");
+
+ var data;
+ if ($(this).hasClass("glyphicon-star")) {
+ data = JSON.stringify({
+ like: false
+ })
+ $(this).removeClass('glyphicon-star').addClass('glyphicon-star-empty');
+ }
+ else {
+ data = JSON.stringify({
+ like: true
+ })
+ $(this).removeClass('glyphicon-star-empty').addClass('glyphicon-star');
+ }
+
+ // sends the updates to the server
+ $.ajax({
+ type: 'PUT',
+ // Provide correct Content-Type, so that Flask will know how to process it.
+ contentType: 'application/json',
+ // Encode your data as JSON.
+ data: data,
+ // This is the type of data you're expecting back from the server.
+ url: "/api/v1.0/articles/"+article_id,
+ success: function (result) {
+ //console.log(result);
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown){
+ console.log(XMLHttpRequest.responseText);
+ }
+ }); // ajax closed
+ });
+
+})
+
+</script>
{% endblock %}
bgstack15