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

Side by Side Diff: options.js

Issue 29338983: issue 3741 - Add "remove" option to list items in new options page (Closed)
Patch Set: Created March 23, 2016, 4:17 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
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 { 295 {
296 id: "recommend-list-table", 296 id: "recommend-list-table",
297 onClick: toggleRemoveSubscription 297 onClick: toggleRemoveSubscription
298 } 298 }
299 ]); 299 ]);
300 collections.langs = new Collection( 300 collections.langs = new Collection(
301 [ 301 [
302 { 302 {
303 id: "blocking-languages-table", 303 id: "blocking-languages-table",
304 emptyText: "options_dialog_language_added_empty", 304 emptyText: "options_dialog_language_added_empty",
305 onClick: toggleRemoveSubscription 305 onClick: toggleDisableSubscription
saroyanm 2016/03/23 16:34:38 I think we do not need this listeners being specif
Thomas Greiner 2016/05/23 12:43:25 I'd be fine with either but if it's not too much e
saroyanm 2016/06/08 15:21:06 Done.
306 }, 306 },
307 { 307 {
308 id: "blocking-languages-dialog-table", 308 id: "blocking-languages-dialog-table",
309 emptyText: "options_dialog_language_added_empty" 309 emptyText: "options_dialog_language_added_empty"
310 } 310 }
311 ]); 311 ]);
312 collections.allLangs = new Collection( 312 collections.allLangs = new Collection(
313 [ 313 [
314 { 314 {
315 id: "all-lang-table", 315 id: "all-lang-table",
316 emptyText: "options_dialog_language_other_empty", 316 emptyText: "options_dialog_language_other_empty",
317 onClick: onAddLanguageSubscriptionClick 317 onClick: onAddLanguageSubscriptionClick
318 } 318 }
319 ]); 319 ]);
320 collections.acceptableAds = new Collection( 320 collections.acceptableAds = new Collection(
321 [ 321 [
322 { 322 {
323 id: "acceptableads-table", 323 id: "acceptableads-table",
324 onClick: toggleRemoveSubscription 324 onClick: toggleRemoveSubscription
325 } 325 }
326 ]); 326 ]);
327 collections.custom = new Collection( 327 collections.custom = new Collection(
328 [ 328 [
329 { 329 {
330 id: "custom-list-table", 330 id: "custom-list-table",
331 onClick: toggleRemoveSubscription 331 onClick: toggleDisableSubscription
332 } 332 }
333 ]); 333 ]);
334 collections.whitelist = new Collection( 334 collections.whitelist = new Collection(
335 [ 335 [
336 { 336 {
337 id: "whitelisting-table", 337 id: "whitelisting-table",
338 emptyText: "options_whitelisted_empty", 338 emptyText: "options_whitelisted_empty",
339 onClick: onRemoveFilterClick 339 onClick: onRemoveFilterClick
340 } 340 }
341 ]); 341 ]);
(...skipping 11 matching lines...) Expand all
353 onClick: toggleDisableSubscription 353 onClick: toggleDisableSubscription
354 } 354 }
355 ]); 355 ]);
356 356
357 function observeSubscription(subscription) 357 function observeSubscription(subscription)
358 { 358 {
359 function onObjectChanged(change) 359 function onObjectChanged(change)
360 { 360 {
361 for (var i = 0; i < change.length; i++) 361 for (var i = 0; i < change.length; i++)
362 { 362 {
363 if (change[i].name == "disabled")
saroyanm 2016/03/23 16:34:38 This implementation doesn't belong to here as well
saroyanm 2016/05/10 14:26:16 Please ignore this change as well, as specified be
364 {
365 var recommendation = recommendationsMap[subscription.url];
366 if (recommendation && recommendation.type == "ads")
367 {
368 if (subscription.disabled == false)
369 {
370 collections.allLangs.removeItem(subscription);
371 collections.langs.addItems(subscription);
372 }
373 else
374 {
375 collections.allLangs.addItems(subscription);
376 collections.langs.removeItem(subscription);
377 }
378 }
379 }
380 for (var i in collections) 363 for (var i in collections)
381 collections[i].updateItem(subscription); 364 collections[i].updateItem(subscription);
382 } 365 }
383 } 366 }
384 367
385 if (!Object.observe) 368 if (!Object.observe)
386 { 369 {
387 ["disabled", "lastDownload"].forEach(function(property) 370 ["disabled", "lastDownload"].forEach(function(property)
388 { 371 {
389 subscription["$" + property] = subscription[property]; 372 subscription["$" + property] = subscription[property];
(...skipping 26 matching lines...) Expand all
416 function updateSubscription(subscription) 399 function updateSubscription(subscription)
417 { 400 {
418 var subscriptionUrl = subscription.url; 401 var subscriptionUrl = subscription.url;
419 var knownSubscription = subscriptionsMap[subscriptionUrl]; 402 var knownSubscription = subscriptionsMap[subscriptionUrl];
420 if (knownSubscription) 403 if (knownSubscription)
421 { 404 {
422 for (var property in subscription) 405 for (var property in subscription)
423 if (property != "title") 406 if (property != "title")
424 knownSubscription[property] = subscription[property]; 407 knownSubscription[property] = subscription[property];
425 } 408 }
426 else
427 {
saroyanm 2016/03/23 16:34:38 This doesn't have anything to do with updateSubscr
saroyanm 2016/05/10 14:26:16 The implementation was changed, I decided to intro
428 observeSubscription(subscription);
429 getAcceptableAdsURL(function(acceptableAdsUrl)
430 {
431 var collection = null;
432 if (subscriptionUrl in recommendationsMap)
433 {
434 var recommendation = recommendationsMap[subscriptionUrl];
435 if (recommendation.type != "ads")
436 collection = collections.popular;
437 else if (subscription.disabled == false)
438 collection = collections.langs;
439 else
440 collection = collections.allLangs;
441 }
442 else if (subscriptionUrl == acceptableAdsUrl)
443 collection = collections.acceptableAds;
444 else
445 collection = collections.custom;
446
447 collection.addItems(subscription);
448 subscriptionsMap[subscriptionUrl] = subscription;
449 });
450 }
451 } 409 }
452 410
453 function updateFilter(filter) 411 function updateFilter(filter)
454 { 412 {
455 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 413 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
456 if (match && !filtersMap[filter.text]) 414 if (match && !filtersMap[filter.text])
457 { 415 {
458 filter.title = match[1]; 416 filter.title = match[1];
459 collections.whitelist.addItems(filter); 417 collections.whitelist.addItems(filter);
460 } 418 }
(...skipping 14 matching lines...) Expand all
475 { 433 {
476 var list = document.getElementById("subscriptionSelector"); 434 var list = document.getElementById("subscriptionSelector");
477 var doc = new DOMParser().parseFromString(text, "application/xml"); 435 var doc = new DOMParser().parseFromString(text, "application/xml");
478 var elements = doc.documentElement.getElementsByTagName("subscription"); 436 var elements = doc.documentElement.getElementsByTagName("subscription");
479 for (var i = 0; i < elements.length; i++) 437 for (var i = 0; i < elements.length; i++)
480 { 438 {
481 var element = elements[i]; 439 var element = elements[i];
482 var subscription = Object.create(null); 440 var subscription = Object.create(null);
483 subscription.title = element.getAttribute("title"); 441 subscription.title = element.getAttribute("title");
484 subscription.url = element.getAttribute("url"); 442 subscription.url = element.getAttribute("url");
485 subscription.disabled = null; 443 subscription.disabled = true;
486 subscription.downloadStatus = null; 444 subscription.downloadStatus = null;
487 subscription.homepage = null; 445 subscription.homepage = null;
488 var recommendation = Object.create(null); 446 var recommendation = Object.create(null);
489 recommendation.type = element.getAttribute("type"); 447 recommendation.type = element.getAttribute("type");
490 var prefix = element.getAttribute("prefixes"); 448 var prefix = element.getAttribute("prefixes");
491 if (prefix) 449 if (prefix)
492 { 450 {
493 prefix = prefix.replace(/\W/g, "_"); 451 prefix = prefix.replace(/\W/g, "_");
494 subscription.title = getMessage("options_language_" + prefix); 452 subscription.title = getMessage("options_language_" + prefix);
495 } 453 }
496 else 454 else
497 { 455 {
498 var type = recommendation.type.replace(/\W/g, "_"); 456 var type = recommendation.type.replace(/\W/g, "_");
499 subscription.title = getMessage("common_feature_" + type + "_title") ; 457 subscription.title = getMessage("common_feature_" + type + "_title") ;
500 } 458 }
501 459
460 var collection = null;
461 if (recommendation.type != "ads")
462 collection = collections.popular;
463 else
464 collection = collections.allLangs;
465
466 collection.addItems(subscription);
502 recommendationsMap[subscription.url] = recommendation; 467 recommendationsMap[subscription.url] = recommendation;
503 updateSubscription(subscription); 468 subscriptionsMap[subscription.url] = subscription;
469 observeSubscription(subscription);
504 } 470 }
505 }); 471 });
506 } 472 }
507 473
508 function findParentData(element, dataName, returnElement) 474 function findParentData(element, dataName, returnElement)
509 { 475 {
510 while (element) 476 while (element)
511 { 477 {
512 if (element.hasAttribute("data-" + dataName)) 478 if (element.hasAttribute("data-" + dataName))
513 return returnElement ? element : element.getAttribute("data-" + dataName ); 479 return returnElement ? element : element.getAttribute("data-" + dataName );
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 }); 793 });
828 } 794 }
829 }); 795 });
830 loadRecommendations(); 796 loadRecommendations();
831 getAcceptableAdsURL(function(acceptableAdsUrl) 797 getAcceptableAdsURL(function(acceptableAdsUrl)
832 { 798 {
833 var subscription = Object.create(null); 799 var subscription = Object.create(null);
834 subscription.url = acceptableAdsUrl; 800 subscription.url = acceptableAdsUrl;
835 subscription.disabled = true; 801 subscription.disabled = true;
836 subscription.title = getMessage("options_acceptableAds_description"); 802 subscription.title = getMessage("options_acceptableAds_description");
837 updateSubscription(subscription); 803 collections.acceptableAds.addItems(subscription);
804 subscriptionsMap[subscription.url] = subscription;
805 observeSubscription(subscription);
838 806
839 // Load user subscriptions 807 // Load user subscriptions
840 ext.backgroundPage.sendMessage( 808 ext.backgroundPage.sendMessage(
841 { 809 {
842 type: "subscriptions.get", 810 type: "subscriptions.get",
843 downloadable: true 811 downloadable: true
844 }, 812 },
845 function(subscriptions) 813 function(subscriptions)
846 { 814 {
847 for (var i = 0; i < subscriptions.length; i++) 815 for (var i = 0; i < subscriptions.length; i++)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 updateShareLink(); 895 updateShareLink();
928 break; 896 break;
929 } 897 }
930 } 898 }
931 899
932 function onSubscriptionMessage(action, subscription) 900 function onSubscriptionMessage(action, subscription)
933 { 901 {
934 switch (action) 902 switch (action)
935 { 903 {
936 case "added": 904 case "added":
937 updateSubscription(subscription); 905 getAcceptableAdsURL(function(acceptableAdsUrl)
938 updateShareLink(); 906 {
907 updateSubscription(subscription);
908 if (subscriptionsMap[subscription.url])
909 subscription = subscriptionsMap[subscription.url];
910 else
911 subscriptionsMap[subscription.url] = subscription;
939 912
940 var knownSubscription = subscriptionsMap[subscription.url]; 913 var recommendation = recommendationsMap[subscription.url];
941 if (knownSubscription) 914 if (recommendation)
942 collections.filterLists.addItems(knownSubscription); 915 {
943 else 916 if (recommendation.type == "ads")
917 {
918 collections.langs.addItems(subscription);
919 collections.allLangs.removeItem(subscription);
920 }
921 }
922 else if (subscription.url != acceptableAdsUrl)
923 {
924 collections.custom.addItems(subscription);
925 observeSubscription(subscription);
926 }
944 collections.filterLists.addItems(subscription); 927 collections.filterLists.addItems(subscription);
928 updateShareLink();
929 });
945 break; 930 break;
946 case "disabled": 931 case "disabled":
947 updateSubscription(subscription); 932 updateSubscription(subscription);
948 updateShareLink(); 933 updateShareLink();
949 break; 934 break;
950 case "lastDownload": 935 case "lastDownload":
951 updateSubscription(subscription); 936 updateSubscription(subscription);
952 break; 937 break;
953 case "homepage": 938 case "homepage":
954 // TODO: NYI 939 // TODO: NYI
955 break; 940 break;
956 case "removed": 941 case "removed":
957 var knownSubscription = subscriptionsMap[subscription.url]; 942 subscription = subscriptionsMap[subscription.url];
958 getAcceptableAdsURL(function(acceptableAdsUrl) 943 getAcceptableAdsURL(function(acceptableAdsUrl)
959 { 944 {
945 collections.filterLists.removeItem(subscription);
960 if (subscription.url == acceptableAdsUrl) 946 if (subscription.url == acceptableAdsUrl)
961 { 947 {
962 subscription.disabled = true; 948 subscription.disabled = true;
963 updateSubscription(subscription);
964 } 949 }
965 else 950 else
966 { 951 {
967 if (subscription.url in recommendationsMap) 952 var recommendation = recommendationsMap[subscription.url];
968 knownSubscription.disabled = true; 953 if (recommendation && recommendation.type == "ads")
954 {
955 collections.allLangs.addItems(subscription);
956 collections.langs.removeItem(subscription);
957 }
958 else if (recommendation)
959 subscription.disabled = true;
969 else 960 else
970 { 961 {
971 collections.custom.removeItem(knownSubscription); 962 collections.custom.removeItem(subscription);
972 delete subscriptionsMap[subscription.url]; 963 delete subscriptionsMap[subscription.url];
973 } 964 }
974 } 965 }
975 updateShareLink(); 966 updateShareLink();
976 collections.filterLists.removeItem(knownSubscription);
977 }); 967 });
978 break; 968 break;
979 case "title": 969 case "title":
980 // TODO: NYI 970 // TODO: NYI
981 break; 971 break;
982 } 972 }
983 } 973 }
984 974
985 function hidePref(key, value) 975 function hidePref(key, value)
986 { 976 {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 }); 1110 });
1121 ext.backgroundPage.sendMessage( 1111 ext.backgroundPage.sendMessage(
1122 { 1112 {
1123 type: "subscriptions.listen", 1113 type: "subscriptions.listen",
1124 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1114 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1125 "title"] 1115 "title"]
1126 }); 1116 });
1127 1117
1128 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1118 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1129 })(); 1119 })();
OLDNEW
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld