templates_users_messagesdir = $(templates_usersdir)/messages
-dist_templates_users_modules_DATA = \
- src/templates/users/modules/push-subscribe-button.html
-
-templates_users_modulesdir = $(templates_usersdir)/modules
-
# ------------------------------------------------------------------------------
#
dist_static_DATA = \
src/static/js/jquery.min.js \
src/static/js/job-log-stream.min.js \
src/static/js/notification-worker.min.js \
- src/static/js/pbs.min.js \
- src/static/js/user-push-subscribe-button.min.js
+ src/static/js/pbs.min.js
static_jsdir = $(staticdir)/js
src/static/js/builders-stats.js \
src/static/js/job-log-stream.js \
src/static/js/notification-worker.js \
- src/static/js/pbs.js \
- src/static/js/user-push-subscribe-button.js
+ src/static/js/pbs.js
CLEANFILES += \
$(static_js_DATA)
closeDropdowns();
}
});
+
+/*
+ * Push Subscriptions
+ *
+ * Request permission when the button is being clicked
+ */
+
+// Check if the browser supports notifications
+$(function() {
+ // Nothing to do if the browser supports notifications
+ if ("serviceWorker" in navigator && "PushManager" in window)
+ return;
+
+ // If not, we will disable the button
+ $("#push-subscribe-button").prop("disabled", true);
+});
+
+// Handle button click
+$("#push-subscribe-button").on("click", function() {
+ console.debug("Subscribe button clicked!");
+
+ // Fetch our application server key
+ const application_server_key = $(this).data("application-server-key");
+
+ // Request permission from the user
+ const request = new Promise(function (resolve, reject) {
+ const result = Notification.requestPermission(function (result) {
+ resolve(result);
+ });
+
+ if (result) {
+ result.then(resolve, reject);
+ }
+ }).then(function (result) {
+ if (result !== 'granted') {
+ throw new Error("We weren't granted permission.");
+ }
+ });
+
+ // Show some activity
+ $(this).addClass("is-loading");
+
+ // Register our service worker
+ var registration = navigator.serviceWorker.register("/static/js/notification-worker.min.js");
+
+ // Register with the push service
+ registration = registration.then(function (registration) {
+ return registration.pushManager.subscribe({
+ userVisibleOnly: true,
+ applicationServerKey: application_server_key,
+ });
+ })
+
+ // Fetch the PushSubscription
+ const subscription = registration.then(function (subscription) {
+ console.debug("Received PushSubscription: ", JSON.stringify(subscription));
+
+ // Send the PushSubscription to our server
+ $.post({
+ "url" : "/users/push/subscribe",
+
+ // Payload
+ "contentType" : "application/json",
+ "data" : JSON.stringify(subscription),
+ });
+
+ return subscription;
+ });
+});
+++ /dev/null
-/*
- * Request permission when the button is being clicked
- */
-
-// Check if the browser supports notifications
-$(function() {
- // Nothing to do if the browser supports notifications
- if ("serviceWorker" in navigator && "PushManager" in window)
- return;
-
- // If not, we will disable the button
- $("#push-subscribe-button").prop("disabled", true);
-});
-
-// Handle button click
-$("#push-subscribe-button").on("click", function() {
- console.debug("Subscribe button clicked!");
-
- // Fetch our application server key
- const application_server_key = $(this).data("application-server-key");
-
- // Request permission from the user
- const request = new Promise(function (resolve, reject) {
- const result = Notification.requestPermission(function (result) {
- resolve(result);
- });
-
- if (result) {
- result.then(resolve, reject);
- }
- }).then(function (result) {
- if (result !== 'granted') {
- throw new Error("We weren't granted permission.");
- }
- });
-
- // Show some activity
- $(this).addClass("is-loading");
-
- // Register our service worker
- var registration = navigator.serviceWorker.register("/static/js/notification-worker.min.js");
-
- // Register with the push service
- registration = registration.then(function (registration) {
- return registration.pushManager.subscribe({
- userVisibleOnly: true,
- applicationServerKey: application_server_key,
- });
- })
-
- // Fetch the PushSubscription
- const subscription = registration.then(function (subscription) {
- console.debug("Received PushSubscription: ", JSON.stringify(subscription));
-
- // Send the PushSubscription to our server
- $.post({
- "url" : "/users/push/subscribe",
-
- // Payload
- "contentType" : "application/json",
- "data" : JSON.stringify(subscription),
- });
-
- return subscription;
- });
-});
-
</div>
{% endfor %}
{% endmacro %}
+
+{% macro UserPushSubscribeButton() %}
+ {# Application Server Key #}
+ {% set application_server_key = backend.users.get_application_server_key() %}
+
+ <button id="push-subscribe-button" class="button is-primary is-fullwidth"
+ data-application-server-key="{{ application_server_key }}">
+ {{ _("Subscribe") }}
+ </button>
+{% endmacro %}
+++ /dev/null
-<button id="push-subscribe-button" class="button is-primary is-fullwidth"
- data-application-server-key="{{ application_server_key }}">
- {{ _("Subscribe") }}
-</button>
-{% extends "../modal.html" %}
+{% extends "modal.html" %}
-{% block title %}{{ _("Subscribe To Push Notifications") }}{% end block %}
+{% from "users/macros.html" import UserPushSubscribeButton with context %}
+
+{% block title %}{{ _("Subscribe To Push Notifications") }}{% endblock %}
{% block breadcrumbs %}
<nav class="breadcrumb" aria-label="breadcrumbs">
</li>
</ul>
</nav>
-{% end block %}
+{% endblock %}
{% block modal_title %}
<h4 class="title is-4">{{ _("Subscribe To Push Notifications") }}</h4>
-{% end block %}
+{% endblock %}
{% block modal %}
- {% raw xsrf_form_html() %}
+ {{ xsrf_form_html() | safe }}
<div class="content">
<p>
{# Submit! #}
<div class="field">
- {% module UserPushSubscribeButton() %}
+ {{ UserPushSubscribeButton() }}
</div>
-{% end block %}
+{% endblock %}
# Send empty response
self.set_status(204)
self.finish()
-
-
-#class PushSubscribeButton(ui_modules.UIModule):
-# def render(self):
-# # Fetch the application server key
-# application_server_key = self.backend.users.application_server_key
-#
-# return self.render_string("users/modules/push-subscribe-button.html",
-# application_server_key=application_server_key)
-#
-# def javascript_files(self):
-# return (
-# "js/user-push-subscribe-button.min.js",
-# )