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

Delta Between Two Patch Sets: desktop-options.js

Issue 29674584: Issue 5549 - Implement missing error handlings for custom filter lists (Closed)
Left Patch Set: removed filterError flag + added better way to check invalid filters Created Jan. 30, 2018, 1:11 p.m.
Right Patch Set: changed custom-filters-edit-area to custom-filters-control as suggested Created Feb. 5, 2018, 9:05 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « desktop-options.html ('k') | locale/en_US/desktop-options.json » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 sendMessageHandleErrors({ 655 sendMessageHandleErrors({
656 type: "filters.importRaw", 656 type: "filters.importRaw",
657 text: filters, 657 text: filters,
658 removeExisting: true 658 removeExisting: true
659 }, 659 },
660 (errors) => 660 (errors) =>
661 { 661 {
662 if (errors) 662 if (errors)
663 { 663 {
664 E("custom-filters").classList.add("warning"); 664 E("custom-filters").classList.add("warning");
665 const editFilters = E("custom-filters-error"); 665 const customFiltersError = clearAndGetCustomFiltersError();
666 editFilters.textContent = "";
667 666
668 // The current error does not contain info about the line 667 // The current error does not contain info about the line
669 // that generated such error. 668 // that generated such error.
670 // Whenever the error object will pass the bad filter 669 // Whenever the error object will pass the bad filter
671 // within its properties, this split should be removed. 670 // within its properties, this split should be removed.
672 const lines = filters.split("\n"); 671 const lines = filters.split("\n");
673 const messages = errors.map(error => lines[error.lineno - 1]); 672 const messages = errors.map(error => lines[error.lineno - 1]);
674 for (const message of messages) 673 for (const message of messages)
675 { 674 {
676 const li = document.createElement("li"); 675 const li = document.createElement("li");
677 editFilters.appendChild(li).textContent = message; 676 customFiltersError.appendChild(li).textContent = message;
678 } 677 }
679 if (errors.length > 5) 678 if (errors.length > 5)
680 editFilters.classList.add("many"); 679 customFiltersError.classList.add("many");
681 } 680 }
682 else 681 else
683 { 682 {
684 setCustomFiltersView("read"); 683 setCustomFiltersView("read");
685 } 684 }
686 }); 685 });
687 break; 686 break;
688 case "show-more-filters-section": 687 case "show-more-filters-section":
689 E("more-filters").setAttribute("aria-hidden", false); 688 E("more-filters").setAttribute("aria-hidden", false);
690 break; 689 break;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 closeDialog(); 768 closeDialog();
770 } 769 }
771 else 770 else
772 { 771 {
773 form.querySelector(":invalid").focus(); 772 form.querySelector(":invalid").focus();
774 } 773 }
775 break; 774 break;
776 } 775 }
777 } 776 }
778 777
778 function clearAndGetCustomFiltersError()
779 {
780 const customFiltersError = E("custom-filters-error");
781 customFiltersError.textContent = "";
782 customFiltersError.classList.remove("many");
783 return customFiltersError;
784 }
785
779 function setCustomFiltersView(mode) 786 function setCustomFiltersView(mode)
780 { 787 {
781 let customFiltersElement = E("custom-filters-raw"); 788 let customFiltersElement = E("custom-filters-raw");
782 updateCustomFiltersUi(); 789 updateCustomFiltersUi();
783 if (mode == "read") 790 if (mode == "read")
784 { 791 {
785 E("custom-filters").classList.remove("warning"); 792 E("custom-filters").classList.remove("warning");
786 const editFilters = E("custom-filters-error"); 793 clearAndGetCustomFiltersError();
787 editFilters.textContent = "";
788 editFilters.classList.remove("many");
789 customFiltersElement.disabled = true; 794 customFiltersElement.disabled = true;
790 if (!customFiltersElement.value) 795 if (!customFiltersElement.value)
791 { 796 {
792 setCustomFiltersView("empty"); 797 setCustomFiltersView("empty");
793 return; 798 return;
794 } 799 }
795 } 800 }
796 else if (mode == "write") 801 else if (mode == "write")
797 { 802 {
798 customFiltersElement.disabled = false; 803 customFiltersElement.disabled = false;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 special: true 1188 special: true
1184 }, 1189 },
1185 (subscriptions) => 1190 (subscriptions) =>
1186 { 1191 {
1187 // Load filters 1192 // Load filters
1188 for (let subscription of subscriptions) 1193 for (let subscription of subscriptions)
1189 { 1194 {
1190 browser.runtime.sendMessage({ 1195 browser.runtime.sendMessage({
1191 type: "filters.get", 1196 type: "filters.get",
1192 subscriptionUrl: subscription.url 1197 subscriptionUrl: subscription.url
1193 }, 1198 }, loadCustomFilters);
1194 loadCustomFilters);
1195 } 1199 }
1196 }); 1200 });
1197 loadRecommendations(); 1201 loadRecommendations();
1198 browser.runtime.sendMessage({ 1202 browser.runtime.sendMessage({
1199 type: "prefs.get", 1203 type: "prefs.get",
1200 key: "subscriptions_exceptionsurl" 1204 key: "subscriptions_exceptionsurl"
1201 }, 1205 },
1202 (url) => 1206 (url) =>
1203 { 1207 {
1204 acceptableAdsUrl = url; 1208 acceptableAdsUrl = url;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 }); 1502 });
1499 browser.runtime.sendMessage({ 1503 browser.runtime.sendMessage({
1500 type: "subscriptions.listen", 1504 type: "subscriptions.listen",
1501 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1505 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1502 "title", "downloadStatus", "downloading"] 1506 "title", "downloadStatus", "downloading"]
1503 }); 1507 });
1504 1508
1505 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1509 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1506 window.addEventListener("hashchange", onHashChange, false); 1510 window.addEventListener("hashchange", onHashChange, false);
1507 } 1511 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld