poll xposting ui

This commit is contained in:
aymm 2021-04-18 13:44:11 +02:00
parent 2c735fef69
commit ad40cc92b4
Signed by: phlaym
GPG Key ID: A06651BAB6777237
3 changed files with 45 additions and 3 deletions

4
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d993b45e1a383647a4d2260a68ee1783",
"content-hash": "6fc1593cab1017ef65d6e12dc56c499c",
"packages": [
{
"name": "hutattedonmyarm/apnuti",
@ -12,7 +12,7 @@
"dist": {
"type": "path",
"url": "../APnutI",
"reference": "2b45c9fdd0df6a6b6186c1afb1075ae5a0b69bbe"
"reference": "51a798ea3e39570e47eb3d55fc838d61cc0967f6"
},
"require": {
"ext-curl": "*",

View File

@ -5,7 +5,7 @@ require_once __DIR__ .'/bootstrap.php';
use APnutI\Entities\Poll;
try {
echo get_page_header('Post Poll', true, []);
echo get_page_header('Post Poll', true, ['post_poll']);
} catch (\Exception $e) {
quit('Something went wrong :( "'.$e->getMessage().'"');
}
@ -62,6 +62,15 @@ $url = $scheme
. $dir_name
. '/view_poll.php?id='
. $poll_id;
$channels = [];
$channels_error_banner = '';
try {
$channels = $api->getSubscribedChannels(false);
} catch (\Exception $e) {
$channels_error_banner = make_banner('error', 'Could not load channels: "'.$e->getMessage().'"');
}
echo $channels_error_banner;
?>
Do you want to post about your poll?
<form method="POST" class="post-poll">
@ -72,6 +81,19 @@ Do you want to post about your poll?
</textarea><br>
<input type="hidden" name="poll_id" value="<?= $poll_id ?>">
<input type="hidden" name="poll_token" value="<?= $poll_token ?>">
<label>Post to channel
<select name="channelid">
<option value="-1">---</option>
<?php
foreach ($channels as $channel) { ?>
<option value="<?= $channel->id ?>"><?= $channel->name ?></option>
<?php } ?>
</select>
</label>
<br />
<label>Broadcast to global
<input type="checkbox" name="broadcast">
</label><br />
<button type="submit" name="submit" value="submit">Post to pnut</button>
</form>
<a href="/view_poll.php?id=<?= $poll_id ?>">Take me straight to the poll</a>

20
scripts/post_poll.js Normal file
View File

@ -0,0 +1,20 @@
window.addEventListener('DOMContentLoaded', () => {
const channelSelector = document.querySelector('select[name="channelid"]');
document.querySelector('input[name="broadcast"]').disabled = channelSelector.value === '-1';
channelSelector.onchange = validateBroadcastStatus;
});
function validateBroadcastStatus() {
const postToChannel = parseInt(this.value) > 0;
const checkbox = document.querySelector('input[name="broadcast"]');
if (!postToChannel) {
checkbox.dataset.wasChecked = checkbox.checked;
checkbox.checked = false;
checkbox.disabled = true;
} else {
if (checkbox.disabled && checkbox.dataset.wasChecked !== undefined) {
checkbox.checked = checkbox.dataset.wasChecked === 'true';
}
checkbox.disabled = false;
}
}