diff options
| author | 2022-03-22 23:09:50 +0100 | |
|---|---|---|
| committer | 2022-03-22 23:09:50 +0100 | |
| commit | 7d00ad8ed75cae5dafd4ac1f2cc6e15e94333628 (patch) | |
| tree | ea523dba448e8d1760e50e166bdc0a3881609120 | |
| parent | eabe95e28cccb921d4874ae7210bb2bf38b68e4d (diff) | |
Improve: manage feed in view within a slider (#4226)
* it works
* small improvements
* Update slider.js
* fixed JS syntax
* slider.js included in main.js
* fix syntax
* delete including of slider.js
* Update extra.js
| -rwxr-xr-x | app/Controllers/feedController.php | 31 | ||||
| -rwxr-xr-x | app/Controllers/indexController.php | 8 | ||||
| -rw-r--r-- | app/Controllers/subscriptionController.php | 20 | ||||
| -rw-r--r-- | app/layout/aside_feed.phtml | 10 | ||||
| -rw-r--r-- | app/views/configure/queries.phtml | 1 | ||||
| -rw-r--r-- | app/views/extension/index.phtml | 1 | ||||
| -rw-r--r-- | app/views/helpers/feed/update.phtml | 16 | ||||
| -rw-r--r-- | app/views/index/normal.phtml | 7 | ||||
| -rw-r--r-- | p/scripts/extra.js | 50 | ||||
| -rw-r--r-- | p/scripts/main.js | 64 |
10 files changed, 146 insertions, 62 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 0d1cd3230..cd4039470 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -738,16 +738,31 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { * @todo handle "r" redirection in Minz_Request::forward()? */ public function deleteAction() { - $redirect_url = Minz_Request::param('r', false, true); - if (!$redirect_url) { - $redirect_url = array('c' => 'subscription', 'a' => 'index'); - } - if (!Minz_Request::isPost()) { - Minz_Request::forward($redirect_url, true); - } - + $from = Minz_Request::param('from'); $id = Minz_Request::param('id'); + switch ($from) { + case 'stats': + $redirect_url = array('c' => 'stats', 'a' => 'idle'); + break; + case 'normal': + $get = Minz_Request::param('get'); + if ($get) { + $redirect_url = array('c' => 'index', 'a' => 'normal', 'params' => array('get' => $get)); + } else { + $redirect_url = array('c' => 'index', 'a' => 'normal'); + } + break; + default: + $redirect_url = Minz_Request::param('r', false, true); + if (!$redirect_url) { + $redirect_url = array('c' => 'subscription', 'a' => 'index'); + } + if (!Minz_Request::isPost()) { + Minz_Request::forward($redirect_url, true); + } + } + if (self::deleteFeed($id)) { Minz_Request::good(_t('feedback.sub.feed.deleted'), $redirect_url); } else { diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 4f2f0d451..34770fffb 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -26,6 +26,14 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { return; } + $id = Minz_Request::param('id'); + if ($id) { + $view = Minz_Request::param('a'); + $url_redirect = array('c' => 'subscription', 'a' => 'feed', 'params' => array('id' => $id, 'from' => $view)); + Minz_Request::forward($url_redirect, true); + return; + } + try { $this->updateContext(); } catch (FreshRSS_Context_Exception $e) { diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index 0b8c62128..60a433f50 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -225,11 +225,23 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController { invalidateHttpCache(); $from = Minz_Request::param('from'); - if ($from === false) { - $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id)); - } else { - $url_redirect = array('c' => 'stats', 'a' => 'idle', 'params' => array('id' => $id, 'from' => 'stats')); + switch ($from) { + case 'stats': + $url_redirect = array('c' => 'stats', 'a' => 'idle', 'params' => array('id' => $id, 'from' => 'stats')); + break; + case 'normal': + case 'reader': + $get = Minz_Request::param('get'); + if ($get) { + $url_redirect = array('c' => 'index', 'a' => $from, 'params' => array('get' => $get)); + } else { + $url_redirect = array('c' => 'index', 'a' => $from); + } + break; + default: + $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id)); } + if ($feedDAO->updateFeed($id, $values) !== false) { $feed->_category($cat); $feed->faviconPrepare(); diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index bb03bdfc6..10dc8e724 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -141,7 +141,15 @@ <li class="item"><a target="_blank" rel="noreferrer" href="http://example.net/"><?= _t('gen.action.see_website') ?></a></li> <?php if (FreshRSS_Auth::hasAccess()) { ?> <li class="separator"></li> - <li class="item"><a href="<?= _url('subscription', 'index', 'id', '------') ?>"><?= _t('gen.action.manage') ?></a></li> + <?php + $get = Minz_Request::param('get'); + if (!$get) { + $url = _url('subscription', 'feed', 'id', '------', 'from', $actual_view); + } else { + $url = _url('subscription', 'feed', 'id', '------', 'get', $get, 'from', $actual_view); + } + ?> + <li class="item"><a class="configure open-slider" href="<?= $url ?>"><?= _t('gen.action.manage') ?></a></li> <li class="item"><a href="<?= _url('feed', 'actualize', 'id', '------') ?>"><?= _t('gen.action.actualize') ?></a></li> <li class="item"> <?php $confirm = FreshRSS_Context::$user_conf->reading_confirm ? 'confirm" disabled="disabled' : ''; ?> diff --git a/app/views/configure/queries.phtml b/app/views/configure/queries.phtml index 3e4b3684b..e9f4aed41 100644 --- a/app/views/configure/queries.phtml +++ b/app/views/configure/queries.phtml @@ -71,5 +71,4 @@ } ?> </div> - </main> diff --git a/app/views/extension/index.phtml b/app/views/extension/index.phtml index 706d238e5..f72a25ed1 100644 --- a/app/views/extension/index.phtml +++ b/app/views/extension/index.phtml @@ -89,5 +89,4 @@ } ?> </div> - </main> diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 23906b36d..c22761bfa 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -23,7 +23,12 @@ if ($from === false) { $url = _url('subscription', 'feed', 'id', $this->feed->id()); } else { - $url = _url('subscription', 'feed', 'id', $this->feed->id(), 'from', $from); + $get = Minz_Request::param('get'); + if (!$get) { + $url = _url('subscription', 'feed', 'id', $this->feed->id(), 'from', $from); + } else { + $url = _url('subscription', 'feed', 'id', $this->feed->id(), 'from', $from, 'get', $get); + } } ?> <form method="post" action="<?= $url ?>" autocomplete="off"> @@ -129,9 +134,16 @@ <div class="group-controls"> <button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button> <button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button> + <?php + if ($from === false) { + $url = _url('feed', 'delete', 'id', $this->feed->id()); + } else { + $url = _url('feed', 'delete', 'id', $this->feed->id(), 'from', $from); + } + ?> <button type="submit" class="btn btn-attention confirm" data-str-confirm="<?= _t('gen.js.confirm_action_feed_cat') ?>" - formaction="<?= _url('feed', 'delete', 'id', $this->feed->id()) ?>" + formaction="<?= $url ?>" formmethod="post"><?= _t('gen.action.remove') ?></button> </div> </div> diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index 06323dcb0..92c10b1b7 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -114,7 +114,12 @@ $today = @strtotime('today'); if ($nbEntries > 0): call_user_func($this->callbackBeforePagination, $this, $nbEntries, $lastEntry); $this->renderHelper('stream-footer'); -?></main><?php +?><?php $class = $this->displaySlider ? ' class="active"' : ''; ?> +<a href="#" id="close-slider"<?= $class ?>> + <?= _i('close') ?> +</a> +<div id="slider"<?= $class ?>> +</div></main><?php else: ob_end_clean(); //Discard the articles headers, as we have no articles ?> diff --git a/p/scripts/extra.js b/p/scripts/extra.js index d89342720..a96e471b6 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -1,6 +1,6 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 'use strict'; -/* globals context, openNotification, openPopupWithSource, xmlHttpRequestJson */ +/* globals openNotification, openPopupWithSource, xmlHttpRequestJson */ function fix_popup_preview_selector() { const link = document.getElementById('popup-preview-selector'); @@ -165,50 +165,9 @@ function init_select_observers() { }); } -function init_slider_observers() { - const slider = document.getElementById('slider'); - const closer = document.getElementById('close-slider'); - if (!slider) { - return; - } - - document.querySelector('.post').onclick = function (ev) { - const a = ev.target.closest('.open-slider'); - if (a) { - if (!context.ajax_loading) { - context.ajax_loading = true; - - const req = new XMLHttpRequest(); - req.open('GET', a.href + '&ajax=1', true); - req.responseType = 'document'; - req.onload = function (e) { - slider.innerHTML = this.response.body.innerHTML; - slider.classList.add('active'); - closer.classList.add('active'); - context.ajax_loading = false; - fix_popup_preview_selector(); - init_extra(); - }; - req.send(); - return false; - } - } - }; - - closer.onclick = function (ev) { - if (data_leave_validation() || confirm(context.i18n.confirmation_default)) { - slider.querySelectorAll('form').forEach(function (f) { f.reset(); }); - closer.classList.remove('active'); - slider.classList.remove('active'); - return true; - } else { - return false; - } - }; -} - function data_leave_validation() { const ds = document.querySelectorAll('[data-leave-validation]'); + for (let i = ds.length - 1; i >= 0; i--) { const input = ds[i]; if (input.type === 'checkbox' || input.type === 'radio') { @@ -291,11 +250,14 @@ function init_extra() { init_password_observers(); init_url_observers(); init_select_observers(); - init_slider_observers(); init_configuration_alert(); fix_popup_preview_selector(); init_select_show(); init_valid_xpath(); + + if (window.console) { + console.log('FreshRSS extra init done.'); + } } if (document.readyState && document.readyState !== 'loading') { diff --git a/p/scripts/main.js b/p/scripts/main.js index be1f7c924..6e9f761cc 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1389,6 +1389,69 @@ function init_notifications() { } // </notification> +// <slider> +function init_slider_observers() { + const slider = document.getElementById('slider'); + const closer = document.getElementById('close-slider'); + if (!slider) { + return; + } + + window.onclick = open_slider_listener; + + closer.addEventListener('click', function (ev) { + if (slider_data_leave_validation() || confirm(context.i18n.confirmation_default)) { + slider.querySelectorAll('form').forEach(function (f) { f.reset(); }); + closer.classList.remove('active'); + slider.classList.remove('active'); + return true; + } else { + return false; + } + }); +} + +function open_slider_listener(ev) { + const a = ev.target.closest('.open-slider'); + if (a) { + if (!context.ajax_loading) { + location.href = '#'; // close menu/dropdown + context.ajax_loading = true; + + const req = new XMLHttpRequest(); + req.open('GET', a.href + '&ajax=1', true); + req.responseType = 'document'; + req.onload = function (e) { + const slider = document.getElementById('slider'); + const closer = document.getElementById('close-slider'); + slider.innerHTML = this.response.body.innerHTML; + slider.classList.add('active'); + closer.classList.add('active'); + context.ajax_loading = false; + }; + req.send(); + return false; + } + } +} + +function slider_data_leave_validation() { + const ds = document.querySelectorAll('[data-leave-validation]'); + + for (let i = ds.length - 1; i >= 0; i--) { + const input = ds[i]; + if (input.type === 'checkbox' || input.type === 'radio') { + if (input.checked != input.getAttribute('data-leave-validation')) { + return false; + } + } else if (input.value != input.getAttribute('data-leave-validation')) { + return false; + } + } + return true; +} +// </slider> + // <popup> let popup = null; let popup_iframe_container = null; @@ -1753,6 +1816,7 @@ function init_beforeDOM() { function init_afterDOM() { removeFirstLoadSpinner(); init_notifications(); + init_slider_observers(); init_popup(); init_confirm_action(); const stream = document.getElementById('stream'); |
