Merge pull request #819 from ArthurHoaro/feature/multi-delete
Bulk deletion
This commit is contained in:
commit
8b27824338
5 changed files with 93 additions and 17 deletions
13
index.php
13
index.php
|
@ -1311,18 +1311,21 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
|
||||||
// -------- User clicked the "Delete" button when editing a link: Delete link from database.
|
// -------- User clicked the "Delete" button when editing a link: Delete link from database.
|
||||||
if ($targetPage == Router::$PAGE_DELETELINK)
|
if ($targetPage == Router::$PAGE_DELETELINK)
|
||||||
{
|
{
|
||||||
// We do not need to ask for confirmation:
|
|
||||||
// - confirmation is handled by JavaScript
|
|
||||||
// - we are protected from XSRF by the token.
|
|
||||||
|
|
||||||
if (! tokenOk($_GET['token'])) {
|
if (! tokenOk($_GET['token'])) {
|
||||||
die('Wrong token.');
|
die('Wrong token.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = intval(escape($_GET['lf_linkdate']));
|
if (strpos($_GET['lf_linkdate'], ' ') !== false) {
|
||||||
|
$ids = array_values(array_filter(preg_split('/\s+/', escape($_GET['lf_linkdate']))));
|
||||||
|
} else {
|
||||||
|
$ids = [$_GET['lf_linkdate']];
|
||||||
|
}
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$id = (int) escape($id);
|
||||||
$link = $LINKSDB[$id];
|
$link = $LINKSDB[$id];
|
||||||
$pluginManager->executeHooks('delete_link', $link);
|
$pluginManager->executeHooks('delete_link', $link);
|
||||||
unset($LINKSDB[$id]);
|
unset($LINKSDB[$id]);
|
||||||
|
}
|
||||||
$LINKSDB->save($conf->get('resource.page_cache')); // save to disk
|
$LINKSDB->save($conf->get('resource.page_cache')); // save to disk
|
||||||
$history->deleteLink($link);
|
$history->deleteLink($link);
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,19 @@ body, .pure-g [class*="pure-u"] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.subheader-form a.button {
|
||||||
|
color: #f5f5f5;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none;
|
||||||
|
border: 2px solid #f5f5f5;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 3px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linklist-item-editbuttons .delete-checkbox {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
#header-login-form input[type="text"], #header-login-form input[type="password"] {
|
#header-login-form input[type="text"], #header-login-form input[type="password"] {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,14 +216,14 @@ window.onload = function () {
|
||||||
/**
|
/**
|
||||||
* Autofocus text fields
|
* Autofocus text fields
|
||||||
*/
|
*/
|
||||||
// ES6 syntax
|
var autofocusElements = document.querySelectorAll('.autofocus');
|
||||||
let autofocusElements = document.querySelectorAll('.autofocus');
|
var breakLoop = false;
|
||||||
for (let autofocusElement of autofocusElements) {
|
[].forEach.call(autofocusElements, function(autofocusElement) {
|
||||||
if (autofocusElement.value == '') {
|
if (autofocusElement.value == '' && ! breakLoop) {
|
||||||
autofocusElement.focus();
|
autofocusElement.focus();
|
||||||
break;
|
breakLoop = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle sub menus/forms
|
* Handle sub menus/forms
|
||||||
|
@ -362,6 +362,56 @@ window.onload = function () {
|
||||||
});
|
});
|
||||||
hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false);
|
hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk actions
|
||||||
|
*/
|
||||||
|
var linkCheckboxes = document.querySelectorAll('.delete-checkbox');
|
||||||
|
var bar = document.getElementById('actions');
|
||||||
|
[].forEach.call(linkCheckboxes, function(checkbox) {
|
||||||
|
checkbox.style.display = 'block';
|
||||||
|
checkbox.addEventListener('click', function(event) {
|
||||||
|
var count = 0;
|
||||||
|
var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
|
||||||
|
[].forEach.call(linkCheckedCheckboxes, function(checkbox) {
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
if (count == 0 && bar.classList.contains('open')) {
|
||||||
|
bar.classList.toggle('open');
|
||||||
|
} else if (count > 0 && ! bar.classList.contains('open')) {
|
||||||
|
bar.classList.toggle('open');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var deleteButton = document.getElementById('actions-delete');
|
||||||
|
var token = document.querySelector('input[type="hidden"][name="token"]');
|
||||||
|
if (deleteButton != null && token != null) {
|
||||||
|
deleteButton.addEventListener('click', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
var links = [];
|
||||||
|
var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
|
||||||
|
[].forEach.call(linkCheckedCheckboxes, function(checkbox) {
|
||||||
|
links.push({
|
||||||
|
'id': checkbox.value,
|
||||||
|
'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var message = 'Are you sure you want to delete '+ links.length +' links?\n';
|
||||||
|
message += 'This action is IRREVERSIBLE!\n\nTitles:\n';
|
||||||
|
var ids = '';
|
||||||
|
links.forEach(function(item) {
|
||||||
|
message += ' - '+ item['title'] +'\n';
|
||||||
|
ids += item['id'] +'+';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (window.confirm(message)) {
|
||||||
|
window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function activateFirefoxSocial(node) {
|
function activateFirefoxSocial(node) {
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="token" value="{$token}">
|
||||||
|
|
||||||
<div id="search-linklist">
|
<div id="search-linklist">
|
||||||
|
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
|
@ -121,7 +123,7 @@
|
||||||
<div class="pure-u-lg-20-24 pure-u-22-24">
|
<div class="pure-u-lg-20-24 pure-u-22-24">
|
||||||
{loop="links"}
|
{loop="links"}
|
||||||
<div class="anchor" id="{$value.shorturl}"></div>
|
<div class="anchor" id="{$value.shorturl}"></div>
|
||||||
<div class="linklist-item{if="$value.class"} {$value.class}{/if}">
|
<div class="linklist-item linklist-item{if="$value.class"} {$value.class}{/if}" data-id="{$value.id}">
|
||||||
|
|
||||||
<div class="linklist-item-title">
|
<div class="linklist-item-title">
|
||||||
{if="isLoggedIn()"}
|
{if="isLoggedIn()"}
|
||||||
|
@ -129,6 +131,7 @@
|
||||||
{if="$value.private"}
|
{if="$value.private"}
|
||||||
<span class="label label-private">{'Private'|t}</span>
|
<span class="label label-private">{'Private'|t}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
<input type="checkbox" class="delete-checkbox" value="{$value.id}">
|
||||||
<!-- FIXME! JS translation -->
|
<!-- FIXME! JS translation -->
|
||||||
<a href="?edit_link={$value.id}" title="{'Edit'|t}"><i class="fa fa-pencil-square-o edit-link"></i></a>
|
<a href="?edit_link={$value.id}" title="{'Edit'|t}"><i class="fa fa-pencil-square-o edit-link"></i></a>
|
||||||
<a href="#" title="{'Fold'|t}" class="fold-button"><i class="fa fa-chevron-up"></i></a>
|
<a href="#" title="{'Fold'|t}" class="fold-button"><i class="fa fa-chevron-up"></i></a>
|
||||||
|
|
|
@ -122,6 +122,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="actions" class="subheader-form">
|
||||||
|
<div class="pure-g">
|
||||||
|
<div class="pure-u-1">
|
||||||
|
<a href="" id="actions-delete" class="button">Delete</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{if="!isLoggedIn()"}
|
{if="!isLoggedIn()"}
|
||||||
<form method="post" name="loginform">
|
<form method="post" name="loginform">
|
||||||
<div class="subheader-form" id="header-login-form">
|
<div class="subheader-form" id="header-login-form">
|
||||||
|
|
Loading…
Reference in a new issue