notification param in talent/me + delayed trigger on 3 times entreprise viewed
This commit is contained in:
@@ -166,6 +166,10 @@
|
||||
<source>company.account.password.modify.label</source>
|
||||
<target>Modifier le mot de passe</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="company.account.notifications.title">
|
||||
<source>company.account.notifications.title</source>
|
||||
<target>Notifications</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="profile.edit.submit">
|
||||
<source>profile.edit.submit</source>
|
||||
<target>Sauvegarder mon profil</target>
|
||||
|
||||
@@ -188,6 +188,10 @@
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDYV8IJGtIoWLfXJQQvIuDQ88n2aEuRgpg&libraries=places"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
//asking for push
|
||||
EdeclicLib = window.EdeclicLib || {};
|
||||
EdeclicLib.delayedAsk();
|
||||
//
|
||||
$('.tooltipped').tooltip();
|
||||
$.get( "{{ path('ad_ajaxRecStat',{'id': ad.id }) }}", function( data ) {});
|
||||
if ($('#modal-answer').length > 0) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<!-- Parameters used in EdeclicPushAndNotificationClient.js -->
|
||||
<!-- props_settings.html.twig Parameters used in EdeclicPushAndNotificationClient.js -->
|
||||
<div id="pushParams"
|
||||
data-service-worker-url="{{ app.request.uriForPath('/Edeclic-service-worker.js') | replace({'/app_dev.php': ''}) }}"
|
||||
data-delete-subscription-url="{{ url('delete-subscription') }}"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{% extends 'talent/base_dashboard_talent.html.twig' %}
|
||||
|
||||
|
||||
{% block dashContent %}
|
||||
|
||||
{% include 'default/props_settings.html.twig' %}
|
||||
{% include 'default/flash_message.html.twig' %}
|
||||
<div class=" row bg-bordered p-20">
|
||||
{#<h1 class="alttitle">{{ 'profile.talent.account.title'|trans }}</h1>#}
|
||||
@@ -19,10 +19,63 @@
|
||||
{{ form_start(formPw) }}
|
||||
{{ form_rest(formPw) }}
|
||||
<br/>
|
||||
<input class="btn btn-default" type="submit"
|
||||
value="{{ 'company.account.password.modify.label'|trans }}"/>
|
||||
<input class="btn btn-default" type="submit" value="{{ 'company.account.password.modify.label'|trans }}"/>
|
||||
{{ form_end(formPw) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class=" row bg-bordered p-20">
|
||||
<div class="row flexcontainer">
|
||||
<div class="col s12">
|
||||
<h4>{{ 'company.account.notifications.title'|trans }}</h4>
|
||||
|
||||
<br/>
|
||||
|
||||
<input type="checkbox" id="notificationChecked" name="notificationChecked" {{isNotificationAllowed ? "checked=checked":""}}/>
|
||||
|
||||
<label for="notificationChecked">Autoriser les notificaitons</label>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block javascripts %}
|
||||
{{ parent() }}
|
||||
<script type="text/javascript">
|
||||
|
||||
$('#notificationChecked').on('click', function (event) {
|
||||
|
||||
let EdeclicLib = window.EdeclicLib;
|
||||
let notifConsent = $('#notificationChecked').is(":checked");
|
||||
|
||||
if (notifConsent == true) {
|
||||
//ask for subscription
|
||||
var promise1 = new Promise(EdeclicLib.askForNotifications)
|
||||
.then(() => $('#notificationChecked').prop('checked', true), () => $('#notificationChecked').prop('checked', false))
|
||||
.catch((err) => {
|
||||
$('#notificationChecked').prop('checked', false);
|
||||
alert(err);
|
||||
});
|
||||
|
||||
} else {
|
||||
//require unsubscription
|
||||
EdeclicLib.unsubscribe();
|
||||
$.ajax({
|
||||
async: true,
|
||||
type: 'POST',
|
||||
url: '{{ url('talent_notification_consent') }}',
|
||||
data: JSON.stringify({'notificationConsent': false}),
|
||||
|
||||
success: function (data) {
|
||||
data = JSON.parse(data);
|
||||
$('#notificationChecked').prop('checked', data['notificationConsent']);
|
||||
},
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -26,7 +26,7 @@ assetic:
|
||||
- 'js/global.js'
|
||||
- 'js/register.js'
|
||||
- 'js/tags.js'
|
||||
# - 'js/Edeclic-service-worker.js'
|
||||
- 'js/EdeclicTools.js'
|
||||
- 'js/EdeclicPushAndNotificationClient.js'
|
||||
|
||||
company:
|
||||
|
||||
@@ -95,17 +95,52 @@ class TalentController extends Controller
|
||||
{
|
||||
$userManager = $this->get('fos_user.user_manager');
|
||||
$user = $this->getUser();
|
||||
|
||||
$formFactory = $this->container->get('fos_user.change_password.form.factory');
|
||||
$formPw = $formFactory->createForm();
|
||||
$formPw->setData($user);
|
||||
|
||||
if ($formPw->isSubmitted() && $formPw->isValid()) {
|
||||
$userManager->updateUser($user);
|
||||
}
|
||||
|
||||
$manager = $this->container->get("app.user_subscription_manager");
|
||||
$subscriptions = $manager->findByUser($user);
|
||||
$isNotificationAllowed = !empty($subscriptions);
|
||||
|
||||
return $this->render('talent/my_account.html.twig', [
|
||||
'formPw' => $formPw->createView(),
|
||||
'isNotificationAllowed' => $isNotificationAllowed
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/talent/me/notificationConsent", name="talent_notification_consent")
|
||||
*/
|
||||
public function notificationConsent(Request $request)
|
||||
{
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
$consent = $data["notificationConsent"];
|
||||
|
||||
if($consent === false)
|
||||
{
|
||||
//delete all existing user_subscription
|
||||
$user = $this->getUser();
|
||||
$manager = $this->container->get("app.user_subscription_manager");
|
||||
|
||||
$subscriptions = $manager->findByUser($user);
|
||||
foreach ($subscriptions as $key => $value) {
|
||||
$manager->delete($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$encode = array('notificationConsent' => $consent);
|
||||
|
||||
return new JsonResponse(json_encode($encode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/talent/me/espace-oe", name="talent_ad_space")
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// src/AppBundle/Form/TaskType.php
|
||||
namespace AppBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
|
||||
|
||||
class NotificationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$options['data'];
|
||||
$builder
|
||||
->add('notifications', CheckboxType::class, array(
|
||||
'label' => 'Autoriser les notifications'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -54,8 +54,8 @@ class UserSubscriptionRepository extends \Doctrine\ORM\EntityRepository
|
||||
CASE WHEN u.lastname IS NOT NULL THEN 1 ELSE 0 END +
|
||||
CASE WHEN u.photo IS NOT NULL THEN 1 ELSE 0 END +
|
||||
CASE WHEN u.username IS NOT NULL THEN 1 ELSE 0 END +
|
||||
|
||||
CASE WHEN c.addresses IS NOT NULL THEN 1 ELSE 0 END +
|
||||
|
||||
CASE WHEN c.alias IS NOT NULL THEN 1 ELSE 0 END +
|
||||
CASE WHEN c.brandName IS NOT NULL THEN 1 ELSE 0 END +
|
||||
CASE WHEN c.businessName IS NOT NULL THEN 1 ELSE 0 END +
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/// inspired by https://github.com/gauntface/web-push-book
|
||||
///
|
||||
|
||||
|
||||
; (function () {
|
||||
"use strict";
|
||||
|
||||
@@ -111,6 +112,12 @@ self.addEventListener('push', function(event) {
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
|
||||
ga('send', 'event', {
|
||||
eventCategory: 'Push clicked',
|
||||
eventAction: 'click',
|
||||
eventLabel: event.notification.data["link"]
|
||||
});
|
||||
event.notification.close();
|
||||
switch (event.notification.tag) {
|
||||
case 'open-window':
|
||||
@@ -128,7 +135,11 @@ const notificationCloseAnalytics = () => {
|
||||
|
||||
self.addEventListener('notificationclose', function (event) {
|
||||
const dismissedNotification = event.notification;
|
||||
console.log('notificationclose.');
|
||||
ga('send', 'event', {
|
||||
eventCategory: 'Push close',
|
||||
eventAction: 'click',
|
||||
eventLabel: event.notification.data["link"]
|
||||
});
|
||||
const promiseChain = notificationCloseAnalytics();
|
||||
event.waitUntil(promiseChain);
|
||||
});
|
||||
|
||||
@@ -421,26 +421,62 @@ $('#ad_soft_publicTag').materialtags({
|
||||
$('#ad_privateTag').materialtags({
|
||||
maxTags: 5
|
||||
});
|
||||
///
|
||||
|
||||
EdeclicLib = window.EdeclicLib || {},
|
||||
function (d) {
|
||||
|
||||
"use strict";
|
||||
d.extend(EdeclicLib, {
|
||||
/* GESTION des cookies pour la modal du tuto */
|
||||
setCookie: function (name, value, days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
},
|
||||
getCookie: function (name) {
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
eraseCookie: function (name) {
|
||||
document.cookie = name + '=; Max-Age=-99999999;';
|
||||
}
|
||||
})
|
||||
}(jQuery);
|
||||
|
||||
/// EdeclicPushAndNotificationClient.js
|
||||
/// A push and notification client
|
||||
/// inspired by https://github.com/gauntface/web-push-book
|
||||
///
|
||||
|
||||
; (function () {
|
||||
EdeclicLib = window.EdeclicLib || {},
|
||||
function (d) {
|
||||
"use strict";
|
||||
console.log("- A push and notification client - ");
|
||||
|
||||
d.extend(EdeclicLib, {
|
||||
|
||||
askForNotifications: function (resolve, reject) {
|
||||
var publicKey, saveUrl, deleteUrl, serviceWorkerUrl;
|
||||
function AskForNotifications() {
|
||||
console.log('AskForNotifications');
|
||||
|
||||
if (!IsFeatureDetected()) {
|
||||
//alert feature unavailable
|
||||
alert("Push feature not available on your side");
|
||||
alert("Votre navigateur ne permet pas d'envoyer des push.");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
var conf = document.getElementById('pushParams');
|
||||
if (conf === null) {
|
||||
console.warn('The pushParams div is not found. can\'t get datadash config.');
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
publicKey = conf.dataset.pushPublicKey;
|
||||
@@ -459,7 +495,8 @@ $('#ad_privateTag').materialtags({
|
||||
if (currentPermissionState === 'denied') {
|
||||
console.warn('The notification permission has been blocked. Nothing we can do.');
|
||||
|
||||
alert("The notification permission has been blocked. Please, review your settings.");
|
||||
alert("Les notifications sont désactivés, veuillez modifier vos paramètres pour bénéficier de cette fonctionnalité.");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
let promiseChain = Promise.resolve();
|
||||
@@ -483,18 +520,27 @@ $('#ad_privateTag').materialtags({
|
||||
// We got a subscription AND it was sent to our backend,
|
||||
// re-enable our UI and set up state.
|
||||
console.log('SUBSCRIPTION', subscription);
|
||||
resolve();
|
||||
return;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error('Failed to subscribe the user.', err);
|
||||
reject();
|
||||
return;
|
||||
});
|
||||
|
||||
if (currentPermissionState !== 'granted') {
|
||||
// If permission isn't granted then we can't be subscribed for Push.
|
||||
console.log("permission isn't granted then we can't be subscribed for Push.");
|
||||
}
|
||||
}
|
||||
// if (currentPermissionState !== 'granted') {
|
||||
// // If permission isn't granted then we can't be subscribed for Push.
|
||||
// console.log("permission isn't granted then we can't be subscribed for Push.");
|
||||
|
||||
// return;
|
||||
// }
|
||||
},
|
||||
reject
|
||||
).catch(function (err) {
|
||||
console.log('Unable to register the service worker: ' + err);
|
||||
reject();
|
||||
return;
|
||||
});
|
||||
|
||||
function IsFeatureDetected() {
|
||||
@@ -554,7 +600,7 @@ $('#ad_privateTag').materialtags({
|
||||
}
|
||||
|
||||
function getSWRegistration() {
|
||||
return navigator.serviceWorker.register('Edeclic-service-worker.js');
|
||||
return navigator.serviceWorker.register(serviceWorkerUrl);
|
||||
}
|
||||
|
||||
function urlBase64ToUint8Array(base64String) {
|
||||
@@ -573,8 +619,6 @@ $('#ad_privateTag').materialtags({
|
||||
}
|
||||
|
||||
function subscribeUserToPush() {
|
||||
console.log('subscribingUserToPush');
|
||||
|
||||
getSWRegistration();
|
||||
return navigator.serviceWorker.ready.then(function (registration) {
|
||||
const subscribeOptions = {
|
||||
@@ -592,13 +636,12 @@ $('#ad_privateTag').materialtags({
|
||||
return registration.pushManager.subscribe(subscribeOptions);
|
||||
})
|
||||
.then(function (pushSubscription) {
|
||||
console.log('Received PushSubscription: ', JSON.stringify(pushSubscription));
|
||||
|
||||
return pushSubscription;
|
||||
});
|
||||
}
|
||||
|
||||
function sendSubscriptionToBackEnd(subscription) {
|
||||
console.log('sendSubscriptionToBackEnd: ', JSON.stringify(subscription));
|
||||
|
||||
return fetch(saveUrl, {
|
||||
method: 'POST',
|
||||
@@ -622,7 +665,57 @@ $('#ad_privateTag').materialtags({
|
||||
});
|
||||
}
|
||||
|
||||
function unsubscribeUserFromPush() {
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
|
||||
var toastHTML = '<div class="card white horizontal"><div class="card-image">' +
|
||||
'<img style="max-height:100px;" src="' +
|
||||
event.data.image + '"></div><div class="card-stacked"><div class="card-content dark-text">' +
|
||||
'<span class="card-title dark-text">' +
|
||||
event.data.title +
|
||||
'</span>' +
|
||||
'<p>' +
|
||||
event.data.body +
|
||||
'</p>' +
|
||||
'</div><div class="card-action right-align">' +
|
||||
'<a href="' + event.data.data.link + '">Voir</a>' +
|
||||
'</div></div></div>'
|
||||
Materialize.toast(toastHTML, 10000000);
|
||||
});
|
||||
|
||||
},
|
||||
delayedAsk: function () {
|
||||
var pushTrigger = EdeclicLib.getCookie("pushTrigger") * 1;
|
||||
if (pushTrigger == 3) {
|
||||
new Promise(EdeclicLib.askForNotifications)
|
||||
.then(() =>Materialize.toast("Vous êtes bien enregistré.", 4000));
|
||||
|
||||
}
|
||||
|
||||
if (pushTrigger <= 3) {
|
||||
EdeclicLib.setCookie("pushTrigger", pushTrigger + 1);
|
||||
}
|
||||
},
|
||||
unsubscribe: function () {
|
||||
navigator.serviceWorker.ready
|
||||
.then((serviceWorkerRegistration) => {
|
||||
serviceWorkerRegistration.pushManager.getSubscription()
|
||||
.then((subscription) => {
|
||||
if (!subscription) {
|
||||
console.log("Not subscribed, nothing to do.");
|
||||
return;
|
||||
}
|
||||
|
||||
subscription.unsubscribe()
|
||||
.then(function () {
|
||||
console.log("Successfully unsubscribed!.");
|
||||
})
|
||||
.catch((e) => {
|
||||
logger.error('Error thrown while unsubscribing from push messaging', e);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
unsubscribeUserFromPush: function () {
|
||||
|
||||
return registration.pushManager.getSubscription()
|
||||
|
||||
@@ -634,7 +727,11 @@ $('#ad_privateTag').materialtags({
|
||||
})
|
||||
.then(function () {
|
||||
return fetch(deleteUrl, {
|
||||
method: 'GET'
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(subscription)
|
||||
})
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
@@ -658,33 +755,5 @@ $('#ad_privateTag').materialtags({
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
// var toastHTML = '<div >'+
|
||||
// '<img style="max-height:100px;" src="'+event.data.image+'" alt="push received"/>'+
|
||||
// '</br>'+
|
||||
// '<span>'+event.data.title+' - </span>'+
|
||||
// '<span>'+event.data.body+' </span>'+
|
||||
// '<a href="'+event.data.data.link+'">Voir</a>'+
|
||||
// '</div>'
|
||||
// ;
|
||||
var toastHTML = '<div class="card white horizontal"><div class="card-image">'+
|
||||
'<img style="max-height:100px;" src="' +
|
||||
event.data.image + '"></div><div class="card-stacked"><div class="card-content dark-text">' +
|
||||
'<span class="card-title dark-text">' +
|
||||
event.data.title +
|
||||
'</span>' +
|
||||
'<p>' +
|
||||
event.data.body +
|
||||
'</p>' +
|
||||
'</div><div class="card-action right-align">' +
|
||||
'<a href="'+event.data.data.link+'">Voir</a>'+
|
||||
'</div></div></div>'
|
||||
Materialize.toast(toastHTML, 10000000);
|
||||
});
|
||||
|
||||
|
||||
//TODO: to be set a the right place
|
||||
AskForNotifications();
|
||||
})()
|
||||
}(jQuery)
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,22 +2,26 @@
|
||||
/// A push and notification client
|
||||
/// inspired by https://github.com/gauntface/web-push-book
|
||||
///
|
||||
|
||||
; (function () {
|
||||
EdeclicLib = window.EdeclicLib || {},
|
||||
function (d) {
|
||||
"use strict";
|
||||
console.log("- A push and notification client - ");
|
||||
|
||||
d.extend(EdeclicLib, {
|
||||
|
||||
askForNotifications: function (resolve, reject) {
|
||||
var publicKey, saveUrl, deleteUrl, serviceWorkerUrl;
|
||||
function AskForNotifications() {
|
||||
console.log('AskForNotifications');
|
||||
|
||||
if (!IsFeatureDetected()) {
|
||||
//alert feature unavailable
|
||||
alert("Push feature not available on your side");
|
||||
alert("Votre navigateur ne permet pas d'envoyer des push.");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
var conf = document.getElementById('pushParams');
|
||||
if (conf === null) {
|
||||
console.warn('The pushParams div is not found. can\'t get datadash config.');
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
publicKey = conf.dataset.pushPublicKey;
|
||||
@@ -36,7 +40,8 @@
|
||||
if (currentPermissionState === 'denied') {
|
||||
console.warn('The notification permission has been blocked. Nothing we can do.');
|
||||
|
||||
alert("The notification permission has been blocked. Please, review your settings.");
|
||||
alert("Les notifications sont désactivés, veuillez modifier vos paramètres pour bénéficier de cette fonctionnalité.");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
let promiseChain = Promise.resolve();
|
||||
@@ -60,18 +65,27 @@
|
||||
// We got a subscription AND it was sent to our backend,
|
||||
// re-enable our UI and set up state.
|
||||
console.log('SUBSCRIPTION', subscription);
|
||||
resolve();
|
||||
return;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error('Failed to subscribe the user.', err);
|
||||
reject();
|
||||
return;
|
||||
});
|
||||
|
||||
if (currentPermissionState !== 'granted') {
|
||||
// If permission isn't granted then we can't be subscribed for Push.
|
||||
console.log("permission isn't granted then we can't be subscribed for Push.");
|
||||
}
|
||||
}
|
||||
// if (currentPermissionState !== 'granted') {
|
||||
// // If permission isn't granted then we can't be subscribed for Push.
|
||||
// console.log("permission isn't granted then we can't be subscribed for Push.");
|
||||
|
||||
// return;
|
||||
// }
|
||||
},
|
||||
reject
|
||||
).catch(function (err) {
|
||||
console.log('Unable to register the service worker: ' + err);
|
||||
reject();
|
||||
return;
|
||||
});
|
||||
|
||||
function IsFeatureDetected() {
|
||||
@@ -131,7 +145,7 @@
|
||||
}
|
||||
|
||||
function getSWRegistration() {
|
||||
return navigator.serviceWorker.register('Edeclic-service-worker.js');
|
||||
return navigator.serviceWorker.register(serviceWorkerUrl);
|
||||
}
|
||||
|
||||
function urlBase64ToUint8Array(base64String) {
|
||||
@@ -150,8 +164,6 @@
|
||||
}
|
||||
|
||||
function subscribeUserToPush() {
|
||||
console.log('subscribingUserToPush');
|
||||
|
||||
getSWRegistration();
|
||||
return navigator.serviceWorker.ready.then(function (registration) {
|
||||
const subscribeOptions = {
|
||||
@@ -169,13 +181,12 @@
|
||||
return registration.pushManager.subscribe(subscribeOptions);
|
||||
})
|
||||
.then(function (pushSubscription) {
|
||||
console.log('Received PushSubscription: ', JSON.stringify(pushSubscription));
|
||||
|
||||
return pushSubscription;
|
||||
});
|
||||
}
|
||||
|
||||
function sendSubscriptionToBackEnd(subscription) {
|
||||
console.log('sendSubscriptionToBackEnd: ', JSON.stringify(subscription));
|
||||
|
||||
return fetch(saveUrl, {
|
||||
method: 'POST',
|
||||
@@ -199,7 +210,56 @@
|
||||
});
|
||||
}
|
||||
|
||||
function unsubscribeUserFromPush() {
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
|
||||
var toastHTML = '<div class="card white horizontal"><div class="card-image">' +
|
||||
'<img style="max-height:100px;" src="' +
|
||||
event.data.image + '"></div><div class="card-stacked"><div class="card-content dark-text">' +
|
||||
'<span class="card-title dark-text">' +
|
||||
event.data.title +
|
||||
'</span>' +
|
||||
'<p>' +
|
||||
event.data.body +
|
||||
'</p>' +
|
||||
'</div><div class="card-action right-align">' +
|
||||
'<a href="' + event.data.data.link + '">Voir</a>' +
|
||||
'</div></div></div>'
|
||||
Materialize.toast(toastHTML, 10000000);
|
||||
});
|
||||
|
||||
},
|
||||
delayedAsk: function () {
|
||||
var pushTrigger = EdeclicLib.getCookie("pushTrigger") * 1;
|
||||
if (pushTrigger == 3) {
|
||||
new Promise(EdeclicLib.askForNotifications)
|
||||
.then(() =>Materialize.toast("Vous êtes bien enregistré aux alertes.", 5000));
|
||||
}
|
||||
|
||||
if (pushTrigger <= 3) {
|
||||
EdeclicLib.setCookie("pushTrigger", pushTrigger + 1);
|
||||
}
|
||||
},
|
||||
unsubscribe: function () {
|
||||
navigator.serviceWorker.ready
|
||||
.then((serviceWorkerRegistration) => {
|
||||
serviceWorkerRegistration.pushManager.getSubscription()
|
||||
.then((subscription) => {
|
||||
if (!subscription) {
|
||||
console.log("Not subscribed, nothing to do.");
|
||||
return;
|
||||
}
|
||||
|
||||
subscription.unsubscribe()
|
||||
.then(function () {
|
||||
console.log("Successfully unsubscribed!.");
|
||||
})
|
||||
.catch((e) => {
|
||||
logger.error('Error thrown while unsubscribing from push messaging', e);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
unsubscribeUserFromPush: function () {
|
||||
|
||||
return registration.pushManager.getSubscription()
|
||||
|
||||
@@ -239,26 +299,5 @@
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
|
||||
var toastHTML = '<div class="card white horizontal"><div class="card-image">'+
|
||||
'<img style="max-height:100px;" src="' +
|
||||
event.data.image + '"></div><div class="card-stacked"><div class="card-content dark-text">' +
|
||||
'<span class="card-title dark-text">' +
|
||||
event.data.title +
|
||||
'</span>' +
|
||||
'<p>' +
|
||||
event.data.body +
|
||||
'</p>' +
|
||||
'</div><div class="card-action right-align">' +
|
||||
'<a href="'+event.data.data.link+'">Voir</a>'+
|
||||
'</div></div></div>'
|
||||
Materialize.toast(toastHTML, 10000000);
|
||||
});
|
||||
|
||||
|
||||
//TODO: to be set a the right place
|
||||
AskForNotifications();
|
||||
})()
|
||||
}(jQuery)
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
EdeclicLib = window.EdeclicLib || {},
|
||||
function (d) {
|
||||
|
||||
"use strict";
|
||||
d.extend(EdeclicLib, {
|
||||
/* GESTION des cookies pour la modal du tuto */
|
||||
setCookie: function (name, value, days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
},
|
||||
getCookie: function (name) {
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
eraseCookie: function (name) {
|
||||
document.cookie = name + '=; Max-Age=-99999999;';
|
||||
}
|
||||
})
|
||||
}(jQuery);
|
||||
@@ -1,6 +1,8 @@
|
||||
EdeclicLib = window.EdeclicLib || {};
|
||||
|
||||
function closeModal(){
|
||||
$('#modal-tuto').modal('close');
|
||||
setCookie('ttcookie','modal_tuto',7);
|
||||
EdeclicLib.setCookie('ttcookie','modal_tuto',7);
|
||||
}
|
||||
|
||||
$('.next-slide').click(function() {
|
||||
@@ -50,7 +52,7 @@ $(document).ready(function(){
|
||||
});
|
||||
}
|
||||
});
|
||||
var cookie = getCookie('ttcookie');
|
||||
var cookie = EdeclicLib.getCookie('ttcookie');
|
||||
if(!cookie) {
|
||||
openModal();
|
||||
}
|
||||
@@ -74,30 +76,6 @@ $(document).ready(function(){
|
||||
}
|
||||
});
|
||||
|
||||
/* GESTION des cookies pour la modal du tuto */
|
||||
function setCookie(name,value,days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days*24*60*60*1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
}
|
||||
function getCookie(name) {
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0;i < ca.length;i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function eraseCookie(name) {
|
||||
document.cookie = name+'=; Max-Age=-99999999;';
|
||||
}
|
||||
|
||||
/* GESTON de la webcam */
|
||||
var elementExists = document.getElementById("myCvVideo");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user