mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/17010] Add missing words & loading indicator, fix invalid twig code
PHPBB3-17010
This commit is contained in:
parent
b3777894cb
commit
e97313839e
3 changed files with 35 additions and 25 deletions
|
@ -356,9 +356,10 @@ $lang = array_merge($lang, array(
|
|||
'NOTIFY_METHOD_EXPLAIN' => 'Method for sending messages sent via this board.',
|
||||
'NOTIFY_METHOD_IM' => 'Jabber only',
|
||||
'NOTIFY_ON_PM' => 'Notify me on new private messages',
|
||||
'NOTIFY_WEBPUSH_ACTIVATE' => 'Activate push notifications',
|
||||
'NOTIFY_WEBPUSH_ENABLE' => 'Enable receiving webpush notifications',
|
||||
'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enable receiving browser-based push notifications.<br>The notifications can be turned off at any time in your browser settings or by disabling the push notifications below.',
|
||||
'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enable receiving browser-based push notifications.<br>The notifications can be turned off at any time in your browser settings, by unsubscribing, or by disabling the push notifications below.',
|
||||
'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Subscribe',
|
||||
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Unsubscribe',
|
||||
'NOT_ADDED_FRIENDS_ANONYMOUS' => 'You cannot add the anonymous user to your friends list.',
|
||||
'NOT_ADDED_FRIENDS_BOTS' => 'You cannot add bots to your friends list.',
|
||||
'NOT_ADDED_FRIENDS_FOES' => 'You cannot add users to your friends list who are on your foes list.',
|
||||
|
|
|
@ -30,7 +30,6 @@ function PhpbbWebpush() {
|
|||
this.init = function() {
|
||||
subscribeButton = document.querySelector('#subscribe_webpush');
|
||||
unsubscribeButton = document.querySelector('#unsubscribe_webpush');
|
||||
let serviceWorkerRegistered = false;
|
||||
|
||||
// Service workers are only supported in secure context
|
||||
if (window.isSecureContext !== true) {
|
||||
|
@ -41,21 +40,18 @@ function PhpbbWebpush() {
|
|||
if ('serviceWorker' in navigator && 'PushManager' in window) {
|
||||
navigator.serviceWorker.register(serviceWorkerUrl)
|
||||
.then(() => {
|
||||
serviceWorkerRegistered = true;
|
||||
})
|
||||
.catch(error => {
|
||||
console.info(error);
|
||||
});
|
||||
}
|
||||
|
||||
if (serviceWorkerRegistered) {
|
||||
subscribeButton.addEventListener('click', subscribeButtonHandler);
|
||||
unsubscribeButton.addEventListener('click', unsubscribeButtonHandler);
|
||||
|
||||
updateButtonState();
|
||||
} else {
|
||||
})
|
||||
.catch(error => {
|
||||
console.info(error);
|
||||
// Service worker could not be registered
|
||||
subscribeButton.disabled = true;
|
||||
});
|
||||
} else {
|
||||
subscribeButton.disabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -127,6 +123,7 @@ function PhpbbWebpush() {
|
|||
applicationServerKey: urlB64ToUint8Array(VAPID_PUBLIC_KEY)
|
||||
});
|
||||
|
||||
const loadingIndicator = phpbb.loadingIndicator();
|
||||
fetch(subscribeUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -134,10 +131,14 @@ function PhpbbWebpush() {
|
|||
},
|
||||
body: getFormData(newSubscription)
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((response) => {
|
||||
loadingIndicator.fadeOut(phpbb.alertTime);
|
||||
return response.json();
|
||||
})
|
||||
.then(handleSubscribe)
|
||||
.catch((error) => {
|
||||
phpbb.alert({{ lang('AJAX_ERROR_TITLE') }}, error);
|
||||
loadingIndicator.fadeOut(phpbb.alertTime);
|
||||
phpbb.alert('{{ lang('AJAX_ERROR_TITLE') }}', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -156,18 +157,26 @@ function PhpbbWebpush() {
|
|||
}
|
||||
|
||||
const subscription = await registration.pushManager.getSubscription();
|
||||
const loadingIndicator = phpbb.loadingIndicator();
|
||||
fetch(unsubscribeUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: getFormData({endpoint: subscription.endpoint})
|
||||
}).then(() => {
|
||||
})
|
||||
.then(() => {
|
||||
loadingIndicator.fadeOut(phpbb.alertTime);
|
||||
return subscription.unsubscribe();
|
||||
}).then((unsubscribed) => {
|
||||
})
|
||||
.then((unsubscribed) => {
|
||||
if (unsubscribed) {
|
||||
setSubscriptionState(false);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
loadingIndicator.fadeOut(phpbb.alertTime);
|
||||
phpbb.alert('{{ lang('AJAX_ERROR_TITLE') }}', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -194,7 +203,7 @@ function PhpbbWebpush() {
|
|||
function getFormData(data) {
|
||||
let formData = new FormData();
|
||||
formData.append('form_token', phpbb.webpush.formTokens.formToken);
|
||||
formData.append('creation_time', phpbb.webpush.formTokens.creationTime);
|
||||
formData.append('creation_time', phpbb.webpush.formTokens.creationTime.toString());
|
||||
formData.append('data', JSON.stringify(data));
|
||||
|
||||
return formData;
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
<dl>
|
||||
<dt><label for="subscribe_webpush">{{ lang('NOTIFY_WEBPUSH_ENABLE') ~ lang('COLON') }}</label><br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span></dt>
|
||||
<dd>
|
||||
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_ACTIVATE') }}" class="button1 button button-form">
|
||||
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_DEACTIVATE') }}" class="button1 button button-form hidden">
|
||||
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_SUBSCRIBE') }}" class="button1 button button-form">
|
||||
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_UNSUBSCRIBE') }}" class="button1 button button-form hidden">
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
|
Loading…
Add table
Reference in a new issue