From 8ebc71cd963b3736de9ee3da0f7ac7976f186289 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Apr 2021 11:19:12 +0200 Subject: [PATCH] Disable calendar notifications --- www/common/outer/calendar.js | 3 ++- www/common/outer/mailbox.js | 10 +++++++-- www/settings/inner.js | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/www/common/outer/calendar.js b/www/common/outer/calendar.js index b3d4c707a..07640a711 100644 --- a/www/common/outer/calendar.js +++ b/www/common/outer/calendar.js @@ -109,7 +109,8 @@ define([ } var send = function () { - console.error(ev); + var hide = Util.find(ctx, ['store', 'proxy', 'settings', 'general', 'calendar', 'hideNotif']); + if (hide) { console.error('hidden'); return; } ctx.store.mailbox.showMessage('reminders', { msg: { ctime: +new Date(), diff --git a/www/common/outer/mailbox.js b/www/common/outer/mailbox.js index eea275093..4c652e292 100644 --- a/www/common/outer/mailbox.js +++ b/www/common/outer/mailbox.js @@ -520,7 +520,10 @@ proxy.mailboxes = { msg: ctx.boxes[type].content[h], hash: h }; - showMessage(ctx, type, message, cId); + showMessage(ctx, type, message, cId, function (obj) { + Notify.system(undefined, obj.msg); + cb(); + }); }); }); // Subscribe to new notifications @@ -610,7 +613,10 @@ proxy.mailboxes = { // Hide existing messages for this event hideMessage(ctx, type, msg.hash, ctx.clients); } - showMessage(ctx, type, msg, cId, cb); + showMessage(ctx, type, msg, cId, function (obj) { + Notify.system(undefined, obj.msg); + if (cb) { cb(); } + }); }; mailbox.open = function (key, m, cb, team, opts) { diff --git a/www/settings/inner.js b/www/settings/inner.js index 5404d399c..338b1ccc6 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -95,6 +95,9 @@ define([ 'kanban': [ // Msg.settings_cat_kanban 'cp-settings-kanban-tags', ], + 'notifications': [ + 'cp-settings-notif-calendar' + ], 'subscription': { onClick: function() { var urls = common.getMetadataMgr().getPrivateData().accounts; @@ -1566,6 +1569,43 @@ define([ cb($d); }, true); + Messages.settings_notifCalendarTitle = "Calendar notifications"; + Messages.settings_notifCalendarHint = "You can disable completely calendar notifications for incoming events."; + Messages.settings_notifCalendarCheckbox = "Enable calendar notifications"; + + makeBlock('notif-calendar', function(cb) { // Msg.settings_notifCalendarHint, .settings_notifCalendarTitle + + var $cbox = $(UI.createCheckbox('cp-settings-cache', + Messages.settings_notifCalendarCheckbox, + false, { label: { class: 'noTitle' } })); + var spinner = UI.makeSpinner($cbox); + + var $checkbox = $cbox.find('input').on('change', function() { + spinner.spin(); + var val = !$checkbox.is(':checked'); + common.setAttribute(['general', 'calendar', 'hideNotif'], val, function(e) { + if (e) { + console.error(e); + // error: restore previous value + if (val) { $checkbox.attr('checked', ''); } + else { $checkbox.attr('checked', 'checked'); } + spinner.hide(); + return void console.error(e); + } + spinner.done(); + }); + }); + + common.getAttribute(['general', 'calendar', 'hideNotif'], function(e, val) { + if (e) { return void console.error(e); } + if (!val) { + $checkbox.attr('checked', 'checked'); + } + }); + + cb($cbox[0]); + }, true); + // Settings app var createUsageButton = function() { @@ -1595,8 +1635,10 @@ define([ subscription: 'fa fa-star-o', kanban: 'cptools cptools-kanban', style: 'cptools cptools-palette', + notifications: 'fa fa-bell' }; + Messages.settings_cat_notifications = Messages.notificationsPage; var createLeftside = function() { var $categories = $('
', { 'class': 'cp-sidebarlayout-categories' }) .appendTo(APP.$leftside);