aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/static/js/articles.js33
-rw-r--r--pyaggr3g470r/templates/duplicates.html8
-rw-r--r--pyaggr3g470r/views/api/common.py3
3 files changed, 38 insertions, 6 deletions
diff --git a/pyaggr3g470r/static/js/articles.js b/pyaggr3g470r/static/js/articles.js
index e30c6979..a5ac82d0 100644
--- a/pyaggr3g470r/static/js/articles.js
+++ b/pyaggr3g470r/static/js/articles.js
@@ -131,7 +131,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Requires jQuery') }
var article_id = $(this).parent().parent().parent().attr("data-article");
$(this).parent().parent().parent().remove();
- // sends the updates to the server
+ // sends the updates to the server
$.ajax({
type: 'DELETE',
url: API_ROOT + "article/" + article_id,
@@ -144,4 +144,35 @@ if (typeof jQuery === 'undefined') { throw new Error('Requires jQuery') }
});
});
+
+ // Delete all duplicate articles (used in the page /duplicates)
+ $('.delete-all').click(function(){
+ var data = [];
+
+ var columnNo = $(this).parent().index();
+ $(this).closest("table")
+ .find("tr td:nth-child(" + (columnNo+1) + ")")
+ .each(function(line, column) {
+ data.push(parseInt(column.id));
+ }).remove();
+
+ data = JSON.stringify(data);
+
+ // sends the updates to the server
+ $.ajax({
+ type: 'DELETE',
+ // Provide correct Content-Type, so that Flask will know how to process it.
+ contentType: 'application/json',
+ data: data,
+ url: API_ROOT + "articles",
+ success: function (result) {
+ //console.log(result);
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown){
+ console.log(XMLHttpRequest.responseText);
+ }
+ });
+
+ });
+
}(jQuery);
diff --git a/pyaggr3g470r/templates/duplicates.html b/pyaggr3g470r/templates/duplicates.html
index 2c08306a..2c953fa3 100644
--- a/pyaggr3g470r/templates/duplicates.html
+++ b/pyaggr3g470r/templates/duplicates.html
@@ -8,16 +8,16 @@
<thead>
<tr>
<th>#</th>
- <th></th>
- <th></th>
+ <th><span class="delete-all">Delete all</span></th>
+ <th><span class="delete-all">Delete all</span></th>
</tr>
</thead>
<tbody>
{% for pair in duplicates %}
<tr>
<td>{{ loop.index }}</td>
- <td><a href="/delete/{{ pair[0].id }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this article') }}"></i></a>&nbsp;<a href="/article/{{ pair[0].id }}">{{ pair[0].title }}</a> ({{ pair[0].entry_id }})</td>
- <td><a href="/delete/{{ pair[1].id }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this article') }}"></i></a>&nbsp;<a href="/article/{{ pair[1].id }}">{{ pair[1].title }}</a> ({{ pair[1].entry_id }})</td>
+ <td id="{{ pair[0].id }}"><a href="/delete/{{ pair[0].id }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this article') }}"></i></a>&nbsp;<a href="/article/{{ pair[0].id }}">{{ pair[0].title }}</a> ({{ pair[0].entry_id }})</td>
+ <td id="{{ pair[1].id }}"><a href="/delete/{{ pair[1].id }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this article') }}"></i></a>&nbsp;<a href="/article/{{ pair[1].id }}">{{ pair[1].title }}</a> ({{ pair[1].entry_id }})</td>
</tr>
{% endfor %}
</tobdy>
diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py
index b1b0cd73..424df960 100644
--- a/pyaggr3g470r/views/api/common.py
+++ b/pyaggr3g470r/views/api/common.py
@@ -205,7 +205,8 @@ class PyAggResourceMulti(PyAggAbstractResource):
def delete(self):
"""will delete several objects,
a list of their ids should be in the payload"""
- if 'application/json' != request.headers.get('Content-Type'):
+ if 'application/json' not in request.headers.get('Content-Type'):
+ print(request.headers.get('Content-Type'))
raise BadRequest("Content-Type must be application/json")
status = 204
results = []
bgstack15