Commit 8aeeaf06 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

add radio buttons for delete export

parent 1c6c92aa
......@@ -6,8 +6,10 @@ $(document).ready(function() {
// var AJAX_URL = 'https://localhost:3002';
var selectAllChk = '#select-all';
var chk = '.checkbox';
var counter = '.actions-delete-counter';
var chkExport = '.checkbox-export';
var chkDelete = '.checkbox-delete';
var counter = '.actions-counter';
var counterExport = '.actions-export-counter';
var deleteBtn = '.js-delete-items';
var exportBtn = '.js-export-items'
......@@ -26,16 +28,16 @@ $(document).ready(function() {
return elementDetails;
}
function updateCounter() {
function updateCounter(chkBoxSelector, button) {
var count = 0;
var presentSelected = $('.checkbox:checked').length > 0 ? false : true;
var selectedLength = $('.checkbox').each(function(index, item) {
var presentSelected = $(chkBoxSelector + ':checked').length > 0 ? false : true;
var selectedLength = $(chkBoxSelector).each(function(index, item) {
$(item).prop('checked') === true
? count++
: ''
});
$(counter).text(count);
$(deleteBtn).prop('disabled', presentSelected);
$(button).find(counter).text(count);
$(button).prop('disabled', presentSelected);
}
function deleteData() {
......@@ -43,9 +45,9 @@ $(document).ready(function() {
id: [],
type: 'deleteAll'
};
var selectedLength = $('.checkbox').each(function(index, item) {
var selectedLength = $('.checkbox-delete').each(function(index, item) {
$(item).prop('checked') === true
? items.id.push($(item).prop('id'))
? items.id.push($(item).closest('tr').prop('id'))
: ''
});
return items;
......@@ -56,9 +58,9 @@ $(document).ready(function() {
id: [],
type: 'exportAll'
};
var selectedLength = $('.checkbox').each(function(index, item) {
var selectedLength = $('.checkbox-export').each(function(index, item) {
$(item).prop('checked') === true
? items.id.push($(item).prop('id'))
? items.id.push($(item).closest('tr').prop('id'))
: ''
});
console.log(items);
......@@ -90,28 +92,52 @@ $(document).ready(function() {
async: true,
contentType: "application/json; charset=utf-8",
success: function (msg) {
console.log(msg);
window.location.replace(window.location.href);
var ids = data.id
console.log(ids)
if (data.type === 'deleteAll') {
removeItems(ids)
updateButtons()
}
})
if (data.type === 'exportAll') {
removeItems(ids)
updateButtons()
}
// window.location.reload()
// window.location.replace(window.location.href);
updateCounter();
$(selectAllChk).click(function () {
$(chk).prop('checked', $(this).prop('checked'));
updateCounter();
});
}
})
}
function removeItems (ids) {
ids.forEach(function(item) {
$('.form').find('tr').each(function(index, itemRow) {
$(itemRow).attr('id') === item
? $(itemRow).remove()
: ''
})
})
}
function updateButtons () {
updateCounter(chkExport, exportBtn);
updateCounter(chkDelete, deleteBtn);
}
updateButtons()
// $(selectAllChk).click(function () {
// $(chk).prop('checked', $(this).prop('checked'));
// updateCounter();
// });
$(chk).on('click', updateCounter);
$(chkDelete).on('click', updateButtons);
$(chkExport).on('click', updateButtons);
$(deleteBtn).on('click', function(e) {
e.preventDefault()
var data = deleteData();
ajaxPost('/news/', data);
});
$(exportBtn).on('click', function(e) {
e.preventDefault()
var data = exportData();
ajaxPost('/news/', data);
});
......
......@@ -33,10 +33,10 @@
<div>
<a href="/" class="btn btn-primary">Add</a>
<button class="js-delete-items btn btn-danger">
<span>Delete(</span><span class="actions-delete-counter">0</span><span>)</span>
<span>Delete(</span><span class="actions-counter">0</span><span>)</span>
</button>
<button class="js-export-items btn btn-success">
<span>Export(</span><span class="actions-delete-counter">0</span><span>)</span>
<span>Export(</span><span class="actions-counter">0</span><span>)</span>
</button>
</div>
......@@ -72,7 +72,7 @@
</thead>
<tbody>
{% for i in news %}
<tr>
<tr id="{{ i.id }}">
<td>
<span><a href="{% url 'view_news' i.id %}">{{ i.title }}</a></span>
<div class="action-block">
......@@ -82,9 +82,9 @@
<a href="{% url 'edit_news' i.id %}" data-type="edit"
class="action-block-edit"><strong>Edit</strong></a>
<span class="divider">|</span>
<a href="#" data-type="delete" class="action-block-delete"><strong>Delete</strong></a>
<span class="action-block-delete"><input id="{{ i.id }}_d" class="checkbox-delete" name="{{ i.id }}" type="radio"><label for="{{ i.id }}_d"><strong>Delete</strong></label></span>
<span class="divider">|</span>
<span class="action-block-edit"><input id="{{ i.id }}" class="checkbox" type="checkbox"><strong>Export</strong></span>
<span class="action-block-edit"><input id="{{ i.id }}_e" class="checkbox-export" name="{{ i.id }}" type="radio" checked><label for="{{ i.id }}_e"><strong>Export</strong></label></span>
</div>
</td>
<td>{{ i.get_media }}</td>
......@@ -96,15 +96,9 @@
</tbody>
</table>
</form>
<!--<div class="pagination" align="right">-->
<!--{% show_pages %}-->
<!--</div>-->
<div style="text-align:center">
{% show_pages %}
</div>
{% get_pages %}
<ul class="pagination">
{% for page in pages %}
<li><a href="{{ page.url }}">{{ page.number }}</a></li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
......@@ -60,6 +60,7 @@ class ListNewsView(ListView):
for i in News.objects.filter(pk__in=ids):
i.export_news()
return HttpResponse(200)
return HttpResponse(200)
def paginate(self, query, page):
paginator = Paginator(query, 25)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment