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

Side by Side Diff: options.js

Issue 29329095: Issue 2747 - Added empty state for tables in options page (Closed)
Patch Set: Created Oct. 13, 2015, 2:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 12 matching lines...) Expand all
23 var recommendationsMap = Object.create(null); 23 var recommendationsMap = Object.create(null);
24 var filtersMap = Object.create(null); 24 var filtersMap = Object.create(null);
25 var collections = Object.create(null); 25 var collections = Object.create(null);
26 26
27 function Collection(details) 27 function Collection(details)
28 { 28 {
29 this.details = details; 29 this.details = details;
30 this.items = []; 30 this.items = [];
31 } 31 }
32 32
33 Collection.prototype._setEmpty = function(table, text)
34 {
35 var placeholder = table.querySelector(".empty-placeholder");
36 if (text && !placeholder)
37 {
38 placeholder = document.createElement("li");
39 placeholder.className = "empty-placeholder";
40 placeholder.textContent = ext.i18n.getMessage(text);
41 table.appendChild(placeholder);
42 }
43 else if (placeholder)
44 table.removeChild(placeholder);
45 }
46
33 Collection.prototype.addItems = function() 47 Collection.prototype.addItems = function()
34 { 48 {
35 var length = Array.prototype.push.apply(this.items, arguments); 49 var length = Array.prototype.push.apply(this.items, arguments);
36 if (length == 0) 50 if (length == 0)
37 return; 51 return;
38 52
39 this.items.sort(function(a, b) 53 this.items.sort(function(a, b)
40 { 54 {
41 var aValue = (a.title || a.text || a.url).toLowerCase(); 55 var aValue = (a.title || a.text || a.url).toLowerCase();
42 var bValue = (b.title || b.text || b.url).toLowerCase(); 56 var bValue = (b.title || b.text || b.url).toLowerCase();
(...skipping 15 matching lines...) Expand all
58 if (text) 72 if (text)
59 listItem.setAttribute("data-search", text.toLowerCase()); 73 listItem.setAttribute("data-search", text.toLowerCase());
60 74
61 var control = listItem.querySelector(".control"); 75 var control = listItem.querySelector(".control");
62 if (control) 76 if (control)
63 { 77 {
64 control.addEventListener("click", this.details[j].onClick, false); 78 control.addEventListener("click", this.details[j].onClick, false);
65 control.checked = item.disabled == false; 79 control.checked = item.disabled == false;
66 } 80 }
67 81
82 this._setEmpty(table, null);
saroyanm 2015/11/30 11:24:21 Doesn't it make more sense to call the _setEmpty m
Thomas Greiner 2015/12/11 16:49:35 I see your line of reasoning but I'd argue that it
68 if (table.hasChildNodes()) 83 if (table.hasChildNodes())
69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); 84 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]);
70 else 85 else
71 table.appendChild(listItem); 86 table.appendChild(listItem);
72 } 87 }
73 } 88 }
74 return length; 89 return length;
75 }; 90 };
76 91
77 Collection.prototype.removeItem = function(item) 92 Collection.prototype.removeItem = function(item)
78 { 93 {
79 var index = this.items.indexOf(item); 94 var index = this.items.indexOf(item);
80 if (index == -1) 95 if (index == -1)
81 return; 96 return;
82 97
83 this.items.splice(index, 1); 98 this.items.splice(index, 1);
84 var access = (item.url || item.text).replace(/'/g, "\\'");
85 for (var i = 0; i < this.details.length; i++) 99 for (var i = 0; i < this.details.length; i++)
86 { 100 {
87 var table = E(this.details[i].id); 101 var table = E(this.details[i].id);
88 var element = table.querySelector("[data-access='" + access + "']"); 102 var element = table.childNodes[index];
89 element.parentElement.removeChild(element); 103 element.parentElement.removeChild(element);
104 if (this.items.length == 0)
105 this._setEmpty(table, this.details[i].emptyText);
90 } 106 }
91 }; 107 };
92 108
93 Collection.prototype.clearAll = function() 109 Collection.prototype.clearAll = function()
94 { 110 {
111 this.items = [];
95 for (var i = 0; i < this.details.length; i++) 112 for (var i = 0; i < this.details.length; i++)
96 { 113 {
97 var table = E(this.details[i].id); 114 var table = E(this.details[i].id);
98 var template = table.querySelector("template"); 115 var template = table.querySelector("template");
99 table.innerHTML = ""; 116 table.innerHTML = "";
100 table.appendChild(template); 117 table.appendChild(template);
118 this._setEmpty(table, this.details[i].emptyText);
101 } 119 }
102 this.items.length = 0;
103 }; 120 };
104 121
105 function onToggleSubscriptionClick(e) 122 function onToggleSubscriptionClick(e)
106 { 123 {
107 e.preventDefault(); 124 e.preventDefault();
108 var subscriptionUrl = e.target.parentNode.getAttribute("data-access"); 125 var subscriptionUrl = e.target.parentNode.getAttribute("data-access");
109 if (!e.target.checked) 126 if (!e.target.checked)
110 { 127 {
111 ext.backgroundPage.sendMessage( 128 ext.backgroundPage.sendMessage({
112 { 129 type: "subscriptions.remove",
113 type: "subscriptions.remove", 130 url: subscriptionUrl
114 url: subscriptionUrl 131 });
115 });
116 } 132 }
117 else 133 else
118 addEnableSubscription(subscriptionUrl); 134 addEnableSubscription(subscriptionUrl);
119 } 135 }
120 136
121 function onAddLanguageSubscriptionClick(e) 137 function onAddLanguageSubscriptionClick(e)
122 { 138 {
123 e.preventDefault(); 139 e.preventDefault();
124 var url = this.parentNode.getAttribute("data-access"); 140 var url = this.parentNode.getAttribute("data-access");
125 addEnableSubscription(url); 141 addEnableSubscription(url);
(...skipping 13 matching lines...) Expand all
139 [ 155 [
140 { 156 {
141 id: "recommend-list-table", 157 id: "recommend-list-table",
142 onClick: onToggleSubscriptionClick 158 onClick: onToggleSubscriptionClick
143 } 159 }
144 ]); 160 ]);
145 collections.langs = new Collection( 161 collections.langs = new Collection(
146 [ 162 [
147 { 163 {
148 id: "blocking-languages-table", 164 id: "blocking-languages-table",
165 emptyText: "options_dialog_language_added_empty",
149 onClick: onToggleSubscriptionClick 166 onClick: onToggleSubscriptionClick
150 }, 167 },
151 { 168 {
152 id: "blocking-languages-dialog-table" 169 id: "blocking-languages-dialog-table",
170 emptyText: "options_dialog_language_added_empty"
153 } 171 }
154 ]); 172 ]);
155 collections.allLangs = new Collection( 173 collections.allLangs = new Collection(
156 [ 174 [
157 { 175 {
158 id: "all-lang-table", 176 id: "all-lang-table",
177 emptyText: "options_dialog_language_other_empty",
159 onClick: onAddLanguageSubscriptionClick 178 onClick: onAddLanguageSubscriptionClick
160 } 179 }
161 ]); 180 ]);
162 collections.acceptableAds = new Collection( 181 collections.acceptableAds = new Collection(
163 [ 182 [
164 { 183 {
165 id: "acceptableads-table", 184 id: "acceptableads-table",
166 onClick: onToggleSubscriptionClick 185 onClick: onToggleSubscriptionClick
167 } 186 }
168 ]); 187 ]);
169 collections.custom = new Collection( 188 collections.custom = new Collection(
170 [ 189 [
171 { 190 {
172 id: "custom-list-table", 191 id: "custom-list-table",
173 onClick: onToggleSubscriptionClick 192 onClick: onToggleSubscriptionClick
174 } 193 }
175 ]); 194 ]);
176 collections.whitelist = new Collection( 195 collections.whitelist = new Collection(
177 [ 196 [
178 { 197 {
179 id: "whitelisting-table", 198 id: "whitelisting-table",
199 emptyText: "options_whitelisted_empty",
180 onClick: onRemoveFilterClick 200 onClick: onRemoveFilterClick
181 } 201 }
182 ]); 202 ]);
183 collections.customFilters = new Collection( 203 collections.customFilters = new Collection(
184 [ 204 [
185 { 205 {
186 id: "custom-filters-table" 206 id: "custom-filters-table",
207 emptyText: "options_customFilters_empty"
187 } 208 }
188 ]); 209 ]);
189 210
190 function updateSubscription(subscription) 211 function updateSubscription(subscription)
191 { 212 {
192 var subscriptionUrl = subscription.url; 213 var subscriptionUrl = subscription.url;
193 var knownSubscription = subscriptionsMap[subscriptionUrl]; 214 var knownSubscription = subscriptionsMap[subscriptionUrl];
194 if (knownSubscription) 215 if (knownSubscription)
195 knownSubscription.disabled = subscription.disabled; 216 knownSubscription.disabled = subscription.disabled;
196 else 217 else
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 var title = dialog.querySelector("h3").textContent; 379 var title = dialog.querySelector("h3").textContent;
359 var url = dialog.querySelector(".url").textContent; 380 var url = dialog.querySelector(".url").textContent;
360 addEnableSubscription(url, title); 381 addEnableSubscription(url, title);
361 closeDialog(); 382 closeDialog();
362 break; 383 break;
363 case "cancel-custom-filters": 384 case "cancel-custom-filters":
364 E("custom-filters").classList.remove("mode-edit"); 385 E("custom-filters").classList.remove("mode-edit");
365 break; 386 break;
366 case "cancel-domain-exception": 387 case "cancel-domain-exception":
367 E("whitelisting-textbox").value = ""; 388 E("whitelisting-textbox").value = "";
389 document.querySelector("#whitelisting .controls").classList.remove("mo de-edit");
368 break; 390 break;
369 case "close-dialog": 391 case "close-dialog":
370 closeDialog(); 392 closeDialog();
371 break; 393 break;
372 case "edit-custom-filters": 394 case "edit-custom-filters":
373 E("custom-filters").classList.add("mode-edit"); 395 E("custom-filters").classList.add("mode-edit");
374 editCustomFilters(); 396 editCustomFilters();
375 break; 397 break;
398 case "edit-domain-exception":
399 document.querySelector("#whitelisting .controls").classList.add("mode- edit");
400 E("whitelisting-textbox").focus();
401 break;
376 case "import-subscription": 402 case "import-subscription":
377 var url = E("blockingList-textbox").value; 403 var url = E("blockingList-textbox").value;
378 addEnableSubscription(url); 404 addEnableSubscription(url);
379 closeDialog(); 405 closeDialog();
380 break; 406 break;
381 case "open-dialog": 407 case "open-dialog":
382 openDialog(element.getAttribute("data-dialog")); 408 openDialog(element.getAttribute("data-dialog"));
383 break; 409 break;
384 case "save-custom-filters": 410 case "save-custom-filters":
385 ext.backgroundPage.sendMessage( 411 ext.backgroundPage.sendMessage(
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (domain.value) 622 if (domain.value)
597 { 623 {
598 ext.backgroundPage.sendMessage( 624 ext.backgroundPage.sendMessage(
599 { 625 {
600 type: "filters.add", 626 type: "filters.add",
601 text: "@@||" + domain.value.toLowerCase() + "^$document" 627 text: "@@||" + domain.value.toLowerCase() + "^$document"
602 }); 628 });
603 } 629 }
604 630
605 domain.value = ""; 631 domain.value = "";
632 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t");
606 } 633 }
607 634
608 function editCustomFilters() 635 function editCustomFilters()
609 { 636 {
610 var customFilterItems = collections.customFilters.items; 637 var customFilterItems = collections.customFilters.items;
611 var filterTexts = []; 638 var filterTexts = [];
612 for (var i = 0; i < customFilterItems.length; i++) 639 for (var i = 0; i < customFilterItems.length; i++)
613 filterTexts.push(customFilterItems[i].text); 640 filterTexts.push(customFilterItems[i].text);
614 E("custom-filters-raw").value = filterTexts.join("\n"); 641 E("custom-filters-raw").value = filterTexts.join("\n");
615 } 642 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 filter: ["added", "loaded", "removed"] 819 filter: ["added", "loaded", "removed"]
793 }); 820 });
794 ext.backgroundPage.sendMessage( 821 ext.backgroundPage.sendMessage(
795 { 822 {
796 type: "subscriptions.listen", 823 type: "subscriptions.listen",
797 filter: ["added", "disabled", "homepage", "removed", "title"] 824 filter: ["added", "disabled", "homepage", "removed", "title"]
798 }); 825 });
799 826
800 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 827 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
801 })(); 828 })();
OLDNEW
« options.html ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld