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: changes as requested Created Jan. 30, 2018, 9:39 a.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 customFiltersError = clearAndGetCustomFiltersError();
666
665 // The current error does not contain info about the line 667 // The current error does not contain info about the line
666 // that generated such error. 668 // that generated such error.
667 // Whenever the error object will pass the bad filter 669 // Whenever the error object will pass the bad filter
668 // within its properties, this split should be removed. 670 // within its properties, this split should be removed.
669 const lines = filters.split(/\n+|\n\s+\n/); 671 const lines = filters.split("\n");
670 const messages = errors.map(error => lines[error.lineno - 1]); 672 const messages = errors.map(error => lines[error.lineno - 1]);
671 const editFilters = E("custom-filters-error");
672 for (const message of messages) 673 for (const message of messages)
673 { 674 {
674 const li = document.createElement("li"); 675 const li = document.createElement("li");
675 editFilters.appendChild(li).textContent = message; 676 customFiltersError.appendChild(li).textContent = message;
saroyanm 2018/01/30 12:03:44 The Error keep being added to the error container.
676 } 677 }
677 if (errors.length > 5) 678 if (errors.length > 5)
678 editFilters.classList.add("many"); 679 customFiltersError.classList.add("many");
679 } 680 }
680 else 681 else
681 { 682 {
682 setCustomFiltersView("read"); 683 setCustomFiltersView("read");
683 } 684 }
684 }); 685 });
685 break; 686 break;
686 case "show-more-filters-section": 687 case "show-more-filters-section":
687 E("more-filters").setAttribute("aria-hidden", false); 688 E("more-filters").setAttribute("aria-hidden", false);
688 break; 689 break;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 closeDialog(); 768 closeDialog();
768 } 769 }
769 else 770 else
770 { 771 {
771 form.querySelector(":invalid").focus(); 772 form.querySelector(":invalid").focus();
772 } 773 }
773 break; 774 break;
774 } 775 }
775 } 776 }
776 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
777 function setCustomFiltersView(mode) 786 function setCustomFiltersView(mode)
778 { 787 {
779 let customFiltersElement = E("custom-filters-raw"); 788 let customFiltersElement = E("custom-filters-raw");
780 updateCustomFiltersUi(); 789 updateCustomFiltersUi();
781 if (mode == "read") 790 if (mode == "read")
782 { 791 {
783 E("custom-filters").classList.remove("warning"); 792 E("custom-filters").classList.remove("warning");
784 const editFilters = E("custom-filters-error"); 793 clearAndGetCustomFiltersError();
785 editFilters.textContent = "";
786 editFilters.classList.remove("many");
787 customFiltersElement.disabled = true; 794 customFiltersElement.disabled = true;
788 if (!customFiltersElement.value) 795 if (!customFiltersElement.value)
789 { 796 {
790 setCustomFiltersView("empty"); 797 setCustomFiltersView("empty");
791 return; 798 return;
792 } 799 }
793 } 800 }
794 else if (mode == "write") 801 else if (mode == "write")
795 { 802 {
796 customFiltersElement.disabled = false; 803 customFiltersElement.disabled = false;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 special: true 1188 special: true
1182 }, 1189 },
1183 (subscriptions) => 1190 (subscriptions) =>
1184 { 1191 {
1185 // Load filters 1192 // Load filters
1186 for (let subscription of subscriptions) 1193 for (let subscription of subscriptions)
1187 { 1194 {
1188 browser.runtime.sendMessage({ 1195 browser.runtime.sendMessage({
1189 type: "filters.get", 1196 type: "filters.get",
1190 subscriptionUrl: subscription.url 1197 subscriptionUrl: subscription.url
1191 }, 1198 }, loadCustomFilters);
1192 (filters) =>
1193 {
1194 loadCustomFilters(filters);
1195 });
1196 } 1199 }
1197 }); 1200 });
1198 loadRecommendations(); 1201 loadRecommendations();
1199 browser.runtime.sendMessage({ 1202 browser.runtime.sendMessage({
1200 type: "prefs.get", 1203 type: "prefs.get",
1201 key: "subscriptions_exceptionsurl" 1204 key: "subscriptions_exceptionsurl"
1202 }, 1205 },
1203 (url) => 1206 (url) =>
1204 { 1207 {
1205 acceptableAdsUrl = url; 1208 acceptableAdsUrl = url;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 }); 1502 });
1500 browser.runtime.sendMessage({ 1503 browser.runtime.sendMessage({
1501 type: "subscriptions.listen", 1504 type: "subscriptions.listen",
1502 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1505 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1503 "title", "downloadStatus", "downloading"] 1506 "title", "downloadStatus", "downloading"]
1504 }); 1507 });
1505 1508
1506 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1509 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1507 window.addEventListener("hashchange", onHashChange, false); 1510 window.addEventListener("hashchange", onHashChange, false);
1508 } 1511 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld