aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2021-01-16 16:11:30 -0500
committerGravatar GitHub <noreply@github.com> 2021-01-16 22:11:30 +0100
commit5c18c64afbdc8b888fdedf2d7cc45e1930225f02 (patch)
tree3d20526df907da7c2435774ae4647841376ae821
parentbf639f9b984185e1fb8157a24cc11e2f49b827c7 (diff)
Change integration configuration page (#3372)
I've refactored the user query code to be able to use it also on the integration configuration page. Now, items can be re-organized as in the user query list.
-rwxr-xr-xapp/Controllers/configureController.php5
-rw-r--r--app/views/configure/integration.phtml10
-rw-r--r--app/views/configure/queries.phtml2
-rw-r--r--p/scripts/draggable.js (renamed from p/scripts/user.query.js)56
-rw-r--r--p/scripts/extra.js42
-rw-r--r--p/scripts/integration.js54
6 files changed, 92 insertions, 77 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index b37d2cefa..9316f6ea6 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -145,6 +145,9 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* some unwanted behavior when the end-user was using an ad-blocker.
*/
public function integrationAction() {
+ Minz_View::appendScript(Minz_Url::display('/scripts/integration.js?' . @filemtime(PUBLIC_PATH . '/scripts/integration.js')));
+ Minz_View::appendScript(Minz_Url::display('/scripts/draggable.js?' . @filemtime(PUBLIC_PATH . '/scripts/draggable.js')));
+
if (Minz_Request::isPost()) {
$params = Minz_Request::fetchPOST();
FreshRSS_Context::$user_conf->sharing = $params['share'];
@@ -275,7 +278,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* checking if categories and feeds are still in use.
*/
public function queriesAction() {
- Minz_View::appendScript(Minz_Url::display('/scripts/user.query.js?' . @filemtime(PUBLIC_PATH . '/scripts/user.query.js')));
+ Minz_View::appendScript(Minz_Url::display('/scripts/draggable.js?' . @filemtime(PUBLIC_PATH . '/scripts/draggable.js')));
$category_dao = FreshRSS_Factory::createCategoryDao();
$feed_dao = FreshRSS_Factory::createFeedDao();
diff --git a/app/views/configure/integration.phtml b/app/views/configure/integration.phtml
index 80779ab18..19d46d8a3 100644
--- a/app/views/configure/integration.phtml
+++ b/app/views/configure/integration.phtml
@@ -5,7 +5,7 @@
<form method="post" action="<?= _url('configure', 'integration') ?>"
data-simple='<div class="form-group" id="group-share-##key##"><label class="group-name">##label##</label><div class="group-controls"><div class="stick"><input type="text" id="share_##key##_name" name="share[##key##][name]" class="extend" value="##label##" placeholder="<?= _t('conf.sharing.share_name') ?>" size="64" />
- <input type="url" id="share_##key##_url" name="share[##key##][url]" class="extend" value="" placeholder="<?= _t('gen.short.not_applicable') ?>" size="64" disabled /><a href="#" class="remove btn btn-attention" data-remove="group-share-##key##"><?= _i('close') ?></a></div>
+ <input type="url" id="share_##key##_url" name="share[##key##][url]" class="extend" value="" placeholder="<?= _t('gen.short.not_applicable') ?>" size="64" disabled /><a href="#" class="remove btn btn-attention"><?= _i('close') ?></a></div>
<input type="hidden" id="share_##key##_type" name="share[##key##][type]" value="##type##" /></div></div>'
data-advanced='<div class="form-group" id="group-share-##key##"><label class="group-name">##label##</label><div class="group-controls">
<input type="hidden" id="share_##key##_type" name="share[##key##][type]" value="##type##" />
@@ -14,9 +14,9 @@
<div class="stick">
<input type="text" id="share_##key##_name" name="share[##key##][name]" class="extend" value="" placeholder="<?= _t('conf.sharing.share_name') ?>" size="64" />
<input type="url" id="share_##key##_url" name="share[##key##][url]" class="extend" value="" placeholder="<?= _t('conf.sharing.share_url') ?>" size="64" />
- <a href="#" class="remove btn btn-attention" data-remove="group-share-##key##" title="<?= _t('conf.sharing.remove') ?>"><?= _i('close') ?></a></div>
+ <a href="#" class="remove btn btn-attention" title="<?= _t('conf.sharing.remove') ?>"><?= _i('close') ?></a></div>
<a target="_blank" rel="noreferrer" class="btn" title="<?= _t('conf.sharing.more_information') ?>" href="##help##"><?= _i('help') ?></a>
- </div></div>'>
+ </div></div>' class="draggableList">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
<legend><?= _t('conf.sharing') ?></legend>
<?php
@@ -24,7 +24,7 @@
$share = FreshRSS_Share::get($share_options['type']);
$share->update($share_options);
?>
- <div class="form-group group-share" id="group-share-<?= $key ?>">
+ <div class="form-group group-share" id="group-share-<?= $key ?>" draggable="true">
<label class="group-name">
<?= $share->name(true) ?>
</label>
@@ -39,7 +39,7 @@
<?php } else { ?>
<input type="url" id="share_<?= $key ?>_url" name="share[<?= $key ?>][url]" class="extend" value="<?= $share->baseUrl() ?>" placeholder="<?= _t('gen.short.not_applicable') ?>" size="64" disabled/>
<?php } ?>
- <a href='#' class='remove btn btn-attention' data-remove="group-share-<?= $key ?>" title="<?= _t('conf.sharing.remove') ?>"><?= _i('close') ?></a>
+ <a href='#' class='remove btn btn-attention' title="<?= _t('conf.sharing.remove') ?>"><?= _i('close') ?></a>
</div>
<?php if ($share->formType() === 'advanced') { ?>
<a target="_blank" rel="noreferrer" class="btn" title="<?= _t('conf.sharing.more_information') ?>" href="<?= $share->help() ?>"><?= _i('help') ?></a>
diff --git a/app/views/configure/queries.phtml b/app/views/configure/queries.phtml
index 7de2e752e..9c13eeb0e 100644
--- a/app/views/configure/queries.phtml
+++ b/app/views/configure/queries.phtml
@@ -3,7 +3,7 @@
<div class="post">
<a href="<?= _url('index', 'index') ?>"><?= _t('gen.action.back_to_rss_feeds') ?></a>
- <form method="post" action="<?= _url('configure', 'queries') ?>" id="configureQueries">
+ <form method="post" action="<?= _url('configure', 'queries') ?>" class="draggableList">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
<legend><?= _t('conf.query') ?></legend>
diff --git a/p/scripts/user.query.js b/p/scripts/draggable.js
index 17bf041a6..d9d1d1cc0 100644
--- a/p/scripts/user.query.js
+++ b/p/scripts/draggable.js
@@ -2,96 +2,96 @@
"use strict";
/* jshint esversion:6, strict:global */
-const init_draggable = function() {
+const init_draggable_list = function() {
if (!window.context) {
if (window.console) {
- console.log('FreshRSS user query waiting for JS…');
+ console.log('FreshRSS draggable list waiting for JS…');
}
- setTimeout(init_draggable, 50);
+ setTimeout(init_draggable_list, 50);
return;
}
-
+
let source;
- const configureQueries = document.querySelector('#configureQueries');
+ const draggableList = document.querySelector('.draggableList');
const addMarker = (position, element) => {
- const hr = configureQueries.querySelector('hr.drag-drop-marker');
+ const hr = draggableList.querySelector('hr.drag-drop-marker');
if (null === hr) {
element.insertAdjacentHTML(position, '<hr class="drag-drop-marker" />');
}
};
const removeMarker = () => {
- const hr = configureQueries.querySelector('hr.drag-drop-marker');
+ const hr = draggableList.querySelector('hr.drag-drop-marker');
if (null !== hr) {
hr.remove();
}
};
- configureQueries.addEventListener('dragstart', event => {
+ draggableList.addEventListener('dragstart', event => {
source = event.target.closest('[draggable="true"]');
event.dataTransfer.setData('text/html', source.outerHTML);
event.dataTransfer.effectAllowed = 'move';
});
- configureQueries.addEventListener('dragover', event => {
+ draggableList.addEventListener('dragover', event => {
event.preventDefault();
if (!event.target || !event.target.closest) {
return;
}
- const dropQuery = event.target.closest('[draggable="true"]');
- if (null === dropQuery || source === dropQuery) {
+ const draggableItem = event.target.closest('[draggable="true"]');
+ if (null === draggableItem || source === draggableItem) {
return;
}
- const rect = dropQuery.getBoundingClientRect();
+ const rect = draggableItem.getBoundingClientRect();
if (event.clientY < (rect.top + rect.height / 2)) {
- addMarker('beforebegin', dropQuery);
+ addMarker('beforebegin', draggableItem);
} else {
- addMarker('afterend', dropQuery);
+ addMarker('afterend', draggableItem);
}
});
- configureQueries.addEventListener('dragleave', event => {
+ draggableList.addEventListener('dragleave', event => {
event.preventDefault();
removeMarker();
});
- configureQueries.addEventListener('drop', event => {
+ draggableList.addEventListener('drop', event => {
event.preventDefault();
event.stopPropagation();
if (!event.target || !event.target.closest) {
return;
}
- const dropQuery = event.target.closest('[draggable="true"]');
- if (null === dropQuery || source === dropQuery) {
+ const draggableItem = event.target.closest('[draggable="true"]');
+ if (null === draggableItem || source === draggableItem) {
return;
}
- const rect = dropQuery.getBoundingClientRect();
+ const rect = draggableItem.getBoundingClientRect();
if (event.clientY < (rect.top + rect.height / 2)) {
- dropQuery.insertAdjacentHTML('beforebegin', event.dataTransfer.getData('text/html'));
+ draggableItem.insertAdjacentHTML('beforebegin', event.dataTransfer.getData('text/html'));
} else {
- dropQuery.insertAdjacentHTML('afterend', event.dataTransfer.getData('text/html'));
+ draggableItem.insertAdjacentHTML('afterend', event.dataTransfer.getData('text/html'));
}
source.remove();
removeMarker();
- configureQueries.submit();
+ draggableList.submit();
});
// This is needed to work around a Firefox bug → https://bugzilla.mozilla.org/show_bug.cgi?id=800050
- configureQueries.addEventListener('focusin', event => {
+ draggableList.addEventListener('focusin', event => {
if (!event.target || !event.target.closest) {
return;
}
- const queryName = event.target.closest('input[id^="queries_"][id$="_name"]');
- if (null !== queryName) {
- queryName.select();
+ const itemName = event.target.closest('input[type="text"]');
+ if (null !== itemName) {
+ itemName.select();
}
});
};
if (document.readyState && document.readyState !== 'loading') {
- init_draggable();
+ init_draggable_list();
} else if (document.addEventListener) {
- document.addEventListener('DOMContentLoaded', event => init_draggable(), false);
+ document.addEventListener('DOMContentLoaded', event => init_draggable_list(), false);
}
// @license-end
diff --git a/p/scripts/extra.js b/p/scripts/extra.js
index 3cb7b93aa..a78b5b10d 100644
--- a/p/scripts/extra.js
+++ b/p/scripts/extra.js
@@ -93,46 +93,6 @@ function init_crypto_form() {
}
//</crypto form (Web login)>
-function init_share_observers() {
- let shares = document.querySelectorAll('.group-share').length;
- const shareAdd = document.querySelector('.share.add');
- if (shareAdd) {
- shareAdd.onclick = function (ev) {
- const s = this.parentElement.querySelector('select'),
- opt = s.options[s.selectedIndex];
- let row = this.closest('form').getAttribute('data-' + opt.getAttribute('data-form'));
- row = row.replace(/##label##/g, opt.text);
- row = row.replace(/##type##/g, opt.value);
- row = row.replace(/##help##/g, opt.getAttribute('data-help'));
- row = row.replace(/##key##/g, shares);
- row = row.replace(/##method##/g, opt.getAttribute('data-method'));
- row = row.replace(/##field##/g, opt.getAttribute('data-field'));
- this.closest('.form-group').insertAdjacentHTML('beforebegin', row);
- shares++;
- return false;
- };
- }
-}
-
-
-function init_remove_observers() {
- document.querySelectorAll('.post').forEach(function (div) {
- div.onclick = function (ev) {
- const a = ev.target.closest('a.remove');
- if (a) {
- const remove_what = a.getAttribute('data-remove');
- if (remove_what !== undefined) {
- const d = document.getElementById(remove_what);
- if (d) {
- d.remove();
- }
- }
- return false;
- }
- };
- });
-}
-
function init_password_observers() {
document.querySelectorAll('.toggle-password').forEach(function (a) {
a.onmousedown = function (ev) {
@@ -248,8 +208,6 @@ function init_extra() {
return;
}
init_crypto_form();
- init_share_observers();
- init_remove_observers();
init_password_observers();
init_select_observers();
init_slider_observers();
diff --git a/p/scripts/integration.js b/p/scripts/integration.js
new file mode 100644
index 000000000..076f379ec
--- /dev/null
+++ b/p/scripts/integration.js
@@ -0,0 +1,54 @@
+// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
+"use strict";
+/* jshint esversion:6, strict:global */
+
+const init_integration = function() {
+ if (!window.context) {
+ if (window.console) {
+ console.log('FreshRSS integration waiting for JS…');
+ }
+ setTimeout(init_integration, 50);
+ return;
+ }
+
+ let shares = document.querySelectorAll('.group-share').length;
+ document.querySelector('.share.add').addEventListener('click', event => {
+ const shareTypes = event.target.closest('.group-controls').querySelector('select');
+ const shareType = shareTypes.options[shareTypes.selectedIndex];
+ let newShare = event.target.closest('form').getAttribute(`data-${shareType.getAttribute('data-form')}`);
+ newShare = newShare.replace(/##label##/g, shareType.text);
+ newShare = newShare.replace(/##type##/g, shareType.value);
+ newShare = newShare.replace(/##help##/g, shareType.getAttribute('data-help'));
+ newShare = newShare.replace(/##key##/g, shares);
+ newShare = newShare.replace(/##method##/g, shareType.getAttribute('data-method'));
+ newShare = newShare.replace(/##field##/g, shareType.getAttribute('data-field'));
+ event.target.closest('.form-group').insertAdjacentHTML('beforebegin', newShare);
+ shares++;
+ });
+
+ document.querySelector('.post').addEventListener('click', event => {
+ if (!event.target || !event.target.closest) {
+ return;
+ }
+
+ const deleteButton = event.target.closest('a.remove');
+ if (null === deleteButton || !deleteButton.closest) {
+ return;
+ }
+
+ const share = deleteButton.closest('.group-share');
+ const form = deleteButton.closest('form');
+ if (!share.remove || !form.submit) {
+ return;
+ }
+ share.remove();
+ form.submit();
+ });
+};
+
+if (document.readyState && document.readyState !== 'loading') {
+ init_integration();
+} else if (document.addEventListener) {
+ document.addEventListener('DOMContentLoaded', event => init_integration(), false);
+}
+// @license-end