aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-02-09 17:59:53 +0100
committerArthurHoaro <arthur@hoa.ro>2019-02-09 17:59:53 +0100
commit8d03f705ebbc891e216d509d4de0419842ebd317 (patch)
treebebafd238e43679e23c1f626eb7e13ee351adfe1
parent905f8675a728841b03b300d2c7dc909a1c4f7f03 (diff)
downloadShaarli-8d03f705ebbc891e216d509d4de0419842ebd317.tar.gz
Shaarli-8d03f705ebbc891e216d509d4de0419842ebd317.tar.zst
Shaarli-8d03f705ebbc891e216d509d4de0419842ebd317.zip
Bulk action: set visibility
Added 2 buttons when link checkboxes are checked to set them either public or private. Related to #572 #1160
-rw-r--r--application/Router.php6
-rw-r--r--assets/default/js/base.js22
-rw-r--r--index.php45
-rw-r--r--tpl/default/page.header.html13
4 files changed, 85 insertions, 1 deletions
diff --git a/application/Router.php b/application/Router.php
index 05877acd..d7187487 100644
--- a/application/Router.php
+++ b/application/Router.php
@@ -38,6 +38,8 @@ class Router
38 38
39 public static $PAGE_DELETELINK = 'delete_link'; 39 public static $PAGE_DELETELINK = 'delete_link';
40 40
41 public static $PAGE_CHANGE_VISIBILITY = 'change_visibility';
42
41 public static $PAGE_PINLINK = 'pin'; 43 public static $PAGE_PINLINK = 'pin';
42 44
43 public static $PAGE_EXPORT = 'export'; 45 public static $PAGE_EXPORT = 'export';
@@ -149,6 +151,10 @@ class Router
149 return self::$PAGE_DELETELINK; 151 return self::$PAGE_DELETELINK;
150 } 152 }
151 153
154 if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
155 return self::$PAGE_CHANGE_VISIBILITY;
156 }
157
152 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) { 158 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
153 return self::$PAGE_PINLINK; 159 return self::$PAGE_PINLINK;
154 } 160 }
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 99e03370..d5c29c69 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -466,6 +466,28 @@ function init(description) {
466 }); 466 });
467 } 467 }
468 468
469 const changeVisibilityButtons = document.querySelectorAll('.actions-change-visibility');
470 if (changeVisibilityButtons != null && token != null) {
471 [...changeVisibilityButtons].forEach((button) => {
472 button.addEventListener('click', (event) => {
473 event.preventDefault();
474 const visibility = event.target.getAttribute('data-visibility');
475
476 const links = [];
477 const linkCheckedCheckboxes = document.querySelectorAll('.link-checkbox:checked');
478 [...linkCheckedCheckboxes].forEach((checkbox) => {
479 links.push({
480 id: checkbox.value,
481 title: document.querySelector(`.linklist-item[data-id="${checkbox.value}"] .linklist-link`).innerHTML,
482 });
483 });
484
485 const ids = links.map(item => item.id);
486 window.location = `?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`;
487 });
488 });
489 }
490
469 /** 491 /**
470 * Select all button 492 * Select all button
471 */ 493 */
diff --git a/index.php b/index.php
index 633ab89e..322c360c 100644
--- a/index.php
+++ b/index.php
@@ -1273,6 +1273,51 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1273 exit; 1273 exit;
1274 } 1274 }
1275 1275
1276 // -------- User clicked either "Set public" or "Set private" bulk operation
1277 if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
1278 if (! $sessionManager->checkToken($_GET['token'])) {
1279 die(t('Wrong token.'));
1280 }
1281
1282 $ids = trim($_GET['ids']);
1283 if (strpos($ids, ' ') !== false) {
1284 // multiple, space-separated ids provided
1285 $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
1286 } else {
1287 // only a single id provided
1288 $ids = [$ids];
1289 }
1290
1291 // assert at least one id is given
1292 if (!count($ids)) {
1293 die('no id provided');
1294 }
1295 // assert that the visibility is valid
1296 if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
1297 die('invalid visibility');
1298 } else {
1299 $private = $_GET['newVisibility'] === 'private';
1300 }
1301 foreach ($ids as $id) {
1302 $id = (int) escape($id);
1303 $link = $LINKSDB[$id];
1304 $link['private'] = $private;
1305 $pluginManager->executeHooks('save_link', $link);
1306 $LINKSDB[$id] = $link;
1307 }
1308 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1309
1310 $location = '?';
1311 if (isset($_SERVER['HTTP_REFERER'])) {
1312 $location = generateLocation(
1313 $_SERVER['HTTP_REFERER'],
1314 $_SERVER['HTTP_HOST']
1315 );
1316 }
1317 header('Location: ' . $location); // After deleting the link, redirect to appropriate location
1318 exit;
1319 }
1320
1276 // -------- User clicked the "EDIT" button on a link: Display link edit form. 1321 // -------- User clicked the "EDIT" button on a link: Display link edit form.
1277 if (isset($_GET['edit_link'])) { 1322 if (isset($_GET['edit_link'])) {
1278 $id = (int) escape($_GET['edit_link']); 1323 $id = (int) escape($_GET['edit_link']);
diff --git a/tpl/default/page.header.html b/tpl/default/page.header.html
index 4f6dd4d8..4b665023 100644
--- a/tpl/default/page.header.html
+++ b/tpl/default/page.header.html
@@ -118,7 +118,18 @@
118 <div id="actions" class="subheader-form"> 118 <div id="actions" class="subheader-form">
119 <div class="pure-g"> 119 <div class="pure-g">
120 <div class="pure-u-1"> 120 <div class="pure-u-1">
121 <a href="" id="actions-delete" class="button">{'Delete'|t}</a> 121 <a href="" id="actions-delete" class="button">
122 <i class="fa fa-trash"></i>
123 {'Delete'|t}
124 </a>&nbsp;
125 <a href="" class="actions-change-visibility button" data-visibility="public">
126 <i class="fa fa-globe"></i>
127 {'Set public'|t}
128 </a>&nbsp;
129 <a href="" class="actions-change-visibility button" data-visibility="private">
130 <i class="fa fa-user-secret"></i>
131 {'Set private'|t}
132 </a>
122 </div> 133 </div>
123 </div> 134 </div>
124 </div> 135 </div>