Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: options.js

Issue 29321084: Issue 2195 - Added notification opt-out (Platform) (Closed)
Patch Set: Created June 25, 2015, 1:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -39,6 +39,7 @@
var Prefs = require("prefs").Prefs;
var Synchronizer = require("synchronizer").Synchronizer;
var Utils = require("utils").Utils;
+var NotificationStorage = require("notification").Notification;
// Loads options from localStorage and sets UI elements accordingly
function loadOptions()
@@ -76,6 +77,22 @@
// Popuplate option checkboxes
initCheckbox("shouldShowBlockElementMenu");
+ if (Prefs.notifications_showui)
+ {
+ initCheckbox("shouldShowNotifications", {
+ get: function()
+ {
+ return Prefs.notifications_ignoredcategories.indexOf("*") == -1;
+ },
+ toggle: function()
+ {
+ NotificationStorage.toggleIgnoreCategory("*");
+ return Prefs.notifications_ignoredcategories.indexOf("*") == -1;
Sebastian Noack 2015/06/25 13:55:04 How about |this.get()| to avoid code duplication?
Thomas Greiner 2015/06/25 16:48:44 Done.
+ }
+ });
+ }
+ else
+ document.getElementById("shouldShowNotificationsContainer").hidden = true;
ext.onMessage.addListener(onMessage);
@@ -131,12 +148,19 @@
FilterNotifier.removeListener(onFilterChange);
}
-function initCheckbox(id)
+function initCheckbox(id, descriptor)
{
var checkbox = document.getElementById(id);
- checkbox.checked = Prefs[id];
+ if (descriptor && descriptor.get)
+ checkbox.checked = descriptor.get();
+ else
+ checkbox.checked = Prefs[id];
+
checkbox.addEventListener("click", function()
{
+ if (descriptor && descriptor.toggle)
+ checkbox.checked = descriptor.toggle();
+
Prefs[id] = checkbox.checked;
}, false);
}

Powered by Google App Engine
This is Rietveld