From 01d96153c69dbd6211b75cdf4cd65d4567bc8983 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 7 Sep 2021 23:09:56 +0200 Subject: [PATCH] Cleanup checkbox component --- dev/Component/AbstractCheckbox.js | 17 ++++------------- dev/Settings/User/General.js | 2 +- dev/Stores/User/Notification.js | 4 ++-- .../templates/Views/Components/Checkbox.html | 2 +- .../Components/CheckboxMaterialDesign.html | 2 +- .../templates/Views/User/SettingsGeneral.html | 4 ++-- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/dev/Component/AbstractCheckbox.js b/dev/Component/AbstractCheckbox.js index e84824299..67e13b692 100644 --- a/dev/Component/AbstractCheckbox.js +++ b/dev/Component/AbstractCheckbox.js @@ -8,20 +8,11 @@ class AbstractCheckbox extends AbstractComponent { constructor(params = {}) { super(); - this.value = params.value; - if (undefined === this.value || !this.value.subscribe) { - this.value = ko.observable(!!this.value); - } + this.value = ko.isObservable(params.value) ? params.value + : ko.observable(!!params.value); - this.enable = params.enable; - if (undefined === this.enable || !this.enable.subscribe) { - this.enable = ko.observable(undefined === this.enable || !!this.enable); - } - - this.disable = params.disable; - if (undefined === this.disable || !this.disable.subscribe) { - this.disable = ko.observable(!!this.disable); - } + this.enable = ko.isObservable(params.enable) ? params.enable + : ko.observable(undefined === params.enable || !!params.enable); this.label = params.label || ''; this.inline = !!params.inline; diff --git a/dev/Settings/User/General.js b/dev/Settings/User/General.js index db5981378..c3da9408c 100644 --- a/dev/Settings/User/General.js +++ b/dev/Settings/User/General.js @@ -35,7 +35,7 @@ export class GeneralUserSettings { this.notificationSounds = ko.observableArray(SettingsGet('NewMailSounds')); this.enableDesktopNotification = NotificationUserStore.enableDesktopNotification; - this.isDesktopNotificationDenied = NotificationUserStore.isDesktopNotificationDenied; + this.isDesktopNotificationAllowed = NotificationUserStore.isDesktopNotificationAllowed; this.showImages = SettingsUserStore.showImages; this.removeColors = SettingsUserStore.removeColors; diff --git a/dev/Stores/User/Notification.js b/dev/Stores/User/Notification.js index 9320129e7..3a0b79811 100644 --- a/dev/Stores/User/Notification.js +++ b/dev/Stores/User/Notification.js @@ -41,13 +41,13 @@ export const NotificationUserStore = new class { this.enableDesktopNotification = ko.observable(false)/*.extend({ notify: 'always' })*/; - this.isDesktopNotificationDenied = ko.observable(NotificationsDenied()); + this.isDesktopNotificationAllowed = ko.observable(!NotificationsDenied()); this.enableDesktopNotification.subscribe(value => { DesktopNotifications = !!value; if (value && HTML5Notification && !NotificationsGranted()) { HTML5Notification.requestPermission(() => - this.isDesktopNotificationDenied(NotificationsDenied()) + this.isDesktopNotificationAllowed(!NotificationsDenied()) ); } }); diff --git a/snappymail/v/0.0.0/app/templates/Views/Components/Checkbox.html b/snappymail/v/0.0.0/app/templates/Views/Components/Checkbox.html index d07ccb4ae..4c560114a 100644 --- a/snappymail/v/0.0.0/app/templates/Views/Components/Checkbox.html +++ b/snappymail/v/0.0.0/app/templates/Views/Components/Checkbox.html @@ -1,4 +1,4 @@ - + diff --git a/snappymail/v/0.0.0/app/templates/Views/Components/CheckboxMaterialDesign.html b/snappymail/v/0.0.0/app/templates/Views/Components/CheckboxMaterialDesign.html index c1975b3de..8870dc970 100644 --- a/snappymail/v/0.0.0/app/templates/Views/Components/CheckboxMaterialDesign.html +++ b/snappymail/v/0.0.0/app/templates/Views/Components/CheckboxMaterialDesign.html @@ -1,4 +1,4 @@ - +