Remember selected delete state on table redraw

This commit is contained in:
Jonathan Wong 2015-08-24 14:21:21 -07:00
parent 609549f974
commit 41c94741e2
2 changed files with 19 additions and 14 deletions

View file

@ -14,7 +14,7 @@
<span><i class="fa fa-history"></i> History</span>
</div>
<div class="button-bar">
<span data-toggle="popover" data-placement="left" data-content="Data deleting does not occur until after exiting delete mode." id="delete-message">
<span data-toggle="popover" data-placement="left" data-content="Select rows to delete. Data is deleted upon exiting delete mode." id="delete-message">
<button class="btn btn-danger" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode">
<i class="fa fa-trash-o"></i> Delete mode
</button>&nbsp
@ -54,7 +54,7 @@
<h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
</div>
<div class="modal-body" style="text-align: center;">
<p>Are you REALLY sure you want to delete this history?</p>
<p>Are you REALLY sure you want to delete <strong><span id="deleteCount"></span></strong> history item(s)?</p>
<p>This is permanent and cannot be undone!</p>
</div>
<div class="modal-footer">
@ -90,22 +90,18 @@
clearSearchButton('history_table', history_table);
var history_to_purge = [];
$('#row-edit-mode').on('click', function() {
$('#delete-message').popover();
if ($(this).hasClass('active')) {
history_to_purge = [];
$('.delete-control button.btn-danger').map(function () {
history_to_purge.push($(this).attr('data-id'));
});
if (history_to_purge.length > 0) {
if (history_to_delete.length > 0) {
$('#deleteCount').text(history_to_delete.length);
$('#confirm-modal').modal();
$('#confirm-modal').one('click', '#confirm-delete', function () {
for (var i = 0; i < history_to_purge.length; i++) {
for (var i = 0; i < history_to_delete.length; i++) {
$.ajax({
url: 'delete_history_rows',
data: { row_id: history_to_purge[i] },
data: { row_id: history_to_delete[i] },
async: true,
success: function (data) {
var msg = "User history purged";
@ -123,6 +119,7 @@
});
} else {
history_to_delete = [];
$('.delete-control').each(function() {
$(this).removeClass('hidden');
});

View file

@ -1,5 +1,6 @@
var date_format = 'YYYY-MM-DD';
var time_format = 'hh:mm a';
var history_to_delete = [];
$.ajax({
url: 'get_date_formats',
@ -18,7 +19,7 @@ history_table_options = {
"info":"Showing _START_ to _END_ of _TOTAL_ history items",
"infoEmpty":"Showing 0 to 0 of 0 entries",
"infoFiltered":"(filtered from _MAX_ total entries)",
"emptyTable": "No data in table",
"emptyTable": "No data in table"
},
"pagingType": "bootstrap",
"stateSave": true,
@ -238,6 +239,11 @@ history_table_options = {
"preDrawCallback": function(settings) {
var msg = "<div class='msg'><i class='fa fa-refresh fa-spin'></i>&nbspFetching rows...</div>";
showMsg(msg, false, false, 0)
},
"rowCallback": function (row, rowData) {
if ($.inArray(rowData['id'], history_to_delete) !== -1) {
$(row).find('button[data-id="' + rowData['id'] + '"]').toggleClass('btn-warning').toggleClass('btn-danger');
}
}
}
@ -287,9 +293,11 @@ $('#history_table').on('click', 'td.delete-control > button', function () {
var row = history_table.row( tr );
var rowData = row.data();
if ($(this).hasClass('active')) {
$(this).toggleClass('btn-warning').toggleClass('btn-danger');
var index = $.inArray(rowData['id'], history_to_delete);
if (index === -1) {
history_to_delete.push(rowData['id']);
} else {
$(this).toggleClass('btn-danger').toggleClass('btn-warning');
history_to_delete.splice(index, 1);
}
$(this).toggleClass('btn-warning').toggleClass('btn-danger');
});