Bulk action: set visibility
Added 2 buttons when link checkboxes are checked to set them either public or private. Related to #572 #1160
This commit is contained in:
parent
905f8675a7
commit
8d03f705eb
4 changed files with 85 additions and 1 deletions
|
@ -38,6 +38,8 @@ class Router
|
||||||
|
|
||||||
public static $PAGE_DELETELINK = 'delete_link';
|
public static $PAGE_DELETELINK = 'delete_link';
|
||||||
|
|
||||||
|
public static $PAGE_CHANGE_VISIBILITY = 'change_visibility';
|
||||||
|
|
||||||
public static $PAGE_PINLINK = 'pin';
|
public static $PAGE_PINLINK = 'pin';
|
||||||
|
|
||||||
public static $PAGE_EXPORT = 'export';
|
public static $PAGE_EXPORT = 'export';
|
||||||
|
@ -149,6 +151,10 @@ public static function findPage($query, $get, $loggedIn)
|
||||||
return self::$PAGE_DELETELINK;
|
return self::$PAGE_DELETELINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
|
||||||
|
return self::$PAGE_CHANGE_VISIBILITY;
|
||||||
|
}
|
||||||
|
|
||||||
if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
|
if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
|
||||||
return self::$PAGE_PINLINK;
|
return self::$PAGE_PINLINK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,6 +466,28 @@ function init(description) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const changeVisibilityButtons = document.querySelectorAll('.actions-change-visibility');
|
||||||
|
if (changeVisibilityButtons != null && token != null) {
|
||||||
|
[...changeVisibilityButtons].forEach((button) => {
|
||||||
|
button.addEventListener('click', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const visibility = event.target.getAttribute('data-visibility');
|
||||||
|
|
||||||
|
const links = [];
|
||||||
|
const linkCheckedCheckboxes = document.querySelectorAll('.link-checkbox:checked');
|
||||||
|
[...linkCheckedCheckboxes].forEach((checkbox) => {
|
||||||
|
links.push({
|
||||||
|
id: checkbox.value,
|
||||||
|
title: document.querySelector(`.linklist-item[data-id="${checkbox.value}"] .linklist-link`).innerHTML,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const ids = links.map(item => item.id);
|
||||||
|
window.location = `?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select all button
|
* Select all button
|
||||||
*/
|
*/
|
||||||
|
|
45
index.php
45
index.php
|
@ -1273,6 +1273,51 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- User clicked either "Set public" or "Set private" bulk operation
|
||||||
|
if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
|
||||||
|
if (! $sessionManager->checkToken($_GET['token'])) {
|
||||||
|
die(t('Wrong token.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = trim($_GET['ids']);
|
||||||
|
if (strpos($ids, ' ') !== false) {
|
||||||
|
// multiple, space-separated ids provided
|
||||||
|
$ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
|
||||||
|
} else {
|
||||||
|
// only a single id provided
|
||||||
|
$ids = [$ids];
|
||||||
|
}
|
||||||
|
|
||||||
|
// assert at least one id is given
|
||||||
|
if (!count($ids)) {
|
||||||
|
die('no id provided');
|
||||||
|
}
|
||||||
|
// assert that the visibility is valid
|
||||||
|
if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
|
||||||
|
die('invalid visibility');
|
||||||
|
} else {
|
||||||
|
$private = $_GET['newVisibility'] === 'private';
|
||||||
|
}
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$id = (int) escape($id);
|
||||||
|
$link = $LINKSDB[$id];
|
||||||
|
$link['private'] = $private;
|
||||||
|
$pluginManager->executeHooks('save_link', $link);
|
||||||
|
$LINKSDB[$id] = $link;
|
||||||
|
}
|
||||||
|
$LINKSDB->save($conf->get('resource.page_cache')); // save to disk
|
||||||
|
|
||||||
|
$location = '?';
|
||||||
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
||||||
|
$location = generateLocation(
|
||||||
|
$_SERVER['HTTP_REFERER'],
|
||||||
|
$_SERVER['HTTP_HOST']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
header('Location: ' . $location); // After deleting the link, redirect to appropriate location
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// -------- User clicked the "EDIT" button on a link: Display link edit form.
|
// -------- User clicked the "EDIT" button on a link: Display link edit form.
|
||||||
if (isset($_GET['edit_link'])) {
|
if (isset($_GET['edit_link'])) {
|
||||||
$id = (int) escape($_GET['edit_link']);
|
$id = (int) escape($_GET['edit_link']);
|
||||||
|
|
|
@ -118,7 +118,18 @@
|
||||||
<div id="actions" class="subheader-form">
|
<div id="actions" class="subheader-form">
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
<div class="pure-u-1">
|
<div class="pure-u-1">
|
||||||
<a href="" id="actions-delete" class="button">{'Delete'|t}</a>
|
<a href="" id="actions-delete" class="button">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
{'Delete'|t}
|
||||||
|
</a>
|
||||||
|
<a href="" class="actions-change-visibility button" data-visibility="public">
|
||||||
|
<i class="fa fa-globe"></i>
|
||||||
|
{'Set public'|t}
|
||||||
|
</a>
|
||||||
|
<a href="" class="actions-change-visibility button" data-visibility="private">
|
||||||
|
<i class="fa fa-user-secret"></i>
|
||||||
|
{'Set private'|t}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue