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: Created Jan. 19, 2018, 11:46 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (returnElement) 540 if (returnElement)
541 return element; 541 return element;
542 return element.getAttribute("data-" + dataName); 542 return element.getAttribute("data-" + dataName);
543 } 543 }
544 544
545 element = element.parentElement; 545 element = element.parentElement;
546 } 546 }
547 return null; 547 return null;
548 } 548 }
549 549
550 function sendMessageHandleErrors(message, onMessage) 550 function sendMessageHandleErrors(message, callback)
551 { 551 {
552 browser.runtime.sendMessage(message, (errors) => 552 browser.runtime.sendMessage(message, (errors) =>
553 { 553 {
554 if (onMessage) 554 if (callback)
555 { 555 {
556 if (errors.length > 0) onMessage(errors); 556 if (errors.length > 0)
557 else onMessage(); 557 callback(errors);
558 else
559 callback();
558 } 560 }
559 }); 561 });
560 } 562 }
561 563
562 function switchTab(id) 564 function switchTab(id)
563 { 565 {
564 location.hash = id; 566 location.hash = id;
565 } 567 }
566 568
567 function execAction(action, element) 569 function execAction(action, element)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 text: findParentData(element, "access", false) 644 text: findParentData(element, "access", false)
643 }); 645 });
644 break; 646 break;
645 case "remove-subscription": 647 case "remove-subscription":
646 browser.runtime.sendMessage({ 648 browser.runtime.sendMessage({
647 type: "subscriptions.remove", 649 type: "subscriptions.remove",
648 url: findParentData(element, "access", false) 650 url: findParentData(element, "access", false)
649 }); 651 });
650 break; 652 break;
651 case "save-custom-filters": 653 case "save-custom-filters":
652 const filters = E("custom-filters-raw"); 654 const filters = E("custom-filters-raw").value;
653 sendMessageHandleErrors({ 655 sendMessageHandleErrors({
654 type: "filters.importRaw", 656 type: "filters.importRaw",
655 text: filters.value, 657 text: filters,
656 removeExisting: true 658 removeExisting: true
657 }, 659 },
658 (errors) => 660 (errors) =>
659 { 661 {
660 if (errors) 662 if (errors)
661 { 663 {
662 filters.classList.add("warning"); 664 E("custom-filters").classList.add("warning");
663 E("custom-filters-edit-error").classList.add("warning"); 665 const customFiltersError = clearAndGetCustomFiltersError();
664 E("link-filters-on-edit-error").classList.add("visible"); 666
665 const lines = filters.value.split(/\n+/); 667 // The current error does not contain info about the line
666 const info = errors.map(error => lines[error.lineno - 1]); 668 // that generated such error.
667 const editFilters = E("custom-filters-edit-filters"); 669 // Whenever the error object will pass the bad filter
668 editFilters.textContent = info.join("\n"); 670 // within its properties, this split should be removed.
669 if (errors.length > 5) editFilters.classList.add("many"); 671 const lines = filters.split("\n");
672 const messages = errors.map(error => lines[error.lineno - 1]);
673 for (const message of messages)
674 {
675 const li = document.createElement("li");
676 customFiltersError.appendChild(li).textContent = message;
677 }
678 if (errors.length > 5)
679 customFiltersError.classList.add("many");
670 } 680 }
671 else 681 else
672 { 682 {
673 setCustomFiltersView("read"); 683 setCustomFiltersView("read");
674 } 684 }
675 }); 685 });
676 break; 686 break;
677 case "show-more-filters-section": 687 case "show-more-filters-section":
678 E("more-filters").setAttribute("aria-hidden", false); 688 E("more-filters").setAttribute("aria-hidden", false);
679 break; 689 break;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 closeDialog(); 768 closeDialog();
759 } 769 }
760 else 770 else
761 { 771 {
762 form.querySelector(":invalid").focus(); 772 form.querySelector(":invalid").focus();
763 } 773 }
764 break; 774 break;
765 } 775 }
766 } 776 }
767 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
768 function setCustomFiltersView(mode) 786 function setCustomFiltersView(mode)
769 { 787 {
770 let customFiltersElement = E("custom-filters-raw"); 788 let customFiltersElement = E("custom-filters-raw");
771 updateCustomFiltersUi(); 789 updateCustomFiltersUi();
772 if (mode == "read") 790 if (mode == "read")
773 { 791 {
774 E("custom-filters-raw").classList.remove("warning"); 792 E("custom-filters").classList.remove("warning");
775 E("custom-filters-edit-error").classList.remove("warning"); 793 clearAndGetCustomFiltersError();
776 E("link-filters-on-edit-error").classList.remove("visible");
777 const editFilters = E("custom-filters-edit-filters");
778 editFilters.textContent = "";
779 editFilters.classList.remove("many");
780 customFiltersElement.disabled = true; 794 customFiltersElement.disabled = true;
781 if (!customFiltersElement.value) 795 if (!customFiltersElement.value)
782 { 796 {
783 setCustomFiltersView("empty"); 797 setCustomFiltersView("empty");
784 return; 798 return;
785 } 799 }
786 } 800 }
787 else if (mode == "write") 801 else if (mode == "write")
788 { 802 {
789 customFiltersElement.disabled = false; 803 customFiltersElement.disabled = false;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 type: "app.get", 992 type: "app.get",
979 what: "features" 993 what: "features"
980 }, 994 },
981 (features) => 995 (features) =>
982 { 996 {
983 hidePref("show_devtools_panel", !features.devToolsPanel); 997 hidePref("show_devtools_panel", !features.devToolsPanel);
984 }); 998 });
985 999
986 getDocLink("filterdoc", (link) => 1000 getDocLink("filterdoc", (link) =>
987 { 1001 {
988 E("link-filters").setAttribute("href", link); 1002 E("link-filters-1").setAttribute("href", link);
989 E("link-filters-on-edit-error").setAttribute("href", link); 1003 E("link-filters-2").setAttribute("href", link);
990 }); 1004 });
991 1005
992 getDocLink("subscriptions", (link) => 1006 getDocLink("subscriptions", (link) =>
993 { 1007 {
994 E("filter-lists-learn-more").setAttribute("href", link); 1008 E("filter-lists-learn-more").setAttribute("href", link);
995 }); 1009 });
996 1010
997 E("custom-filters-raw").setAttribute("placeholder", 1011 E("custom-filters-raw").setAttribute("placeholder",
998 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); 1012 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"]));
999 1013
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 special: true 1188 special: true
1175 }, 1189 },
1176 (subscriptions) => 1190 (subscriptions) =>
1177 { 1191 {
1178 // Load filters 1192 // Load filters
1179 for (let subscription of subscriptions) 1193 for (let subscription of subscriptions)
1180 { 1194 {
1181 browser.runtime.sendMessage({ 1195 browser.runtime.sendMessage({
1182 type: "filters.get", 1196 type: "filters.get",
1183 subscriptionUrl: subscription.url 1197 subscriptionUrl: subscription.url
1184 }, 1198 }, loadCustomFilters);
1185 (filters) =>
1186 {
1187 loadCustomFilters(filters);
1188 });
1189 } 1199 }
1190 }); 1200 });
1191 loadRecommendations(); 1201 loadRecommendations();
1192 browser.runtime.sendMessage({ 1202 browser.runtime.sendMessage({
1193 type: "prefs.get", 1203 type: "prefs.get",
1194 key: "subscriptions_exceptionsurl" 1204 key: "subscriptions_exceptionsurl"
1195 }, 1205 },
1196 (url) => 1206 (url) =>
1197 { 1207 {
1198 acceptableAdsUrl = url; 1208 acceptableAdsUrl = url;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 }); 1502 });
1493 browser.runtime.sendMessage({ 1503 browser.runtime.sendMessage({
1494 type: "subscriptions.listen", 1504 type: "subscriptions.listen",
1495 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1505 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1496 "title", "downloadStatus", "downloading"] 1506 "title", "downloadStatus", "downloading"]
1497 }); 1507 });
1498 1508
1499 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1509 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1500 window.addEventListener("hashchange", onHashChange, false); 1510 window.addEventListener("hashchange", onHashChange, false);
1501 } 1511 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld