diff --git a/composer.lock b/composer.lock index 5c11969..a651ddb 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "*", diff --git a/post_poll.php b/post_poll.php index ae9dd76..029f132 100644 --- a/post_poll.php +++ b/post_poll.php @@ -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?
@@ -72,6 +81,19 @@ Do you want to post about your poll?
+ +
+
Take me straight to the poll diff --git a/scripts/post_poll.js b/scripts/post_poll.js new file mode 100644 index 0000000..96013d1 --- /dev/null +++ b/scripts/post_poll.js @@ -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; + } +} \ No newline at end of file