Advertisement
Guest User

Untitled

a guest
May 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .filter('checkBoxFilter', function() {
  2.  
  3.   return function(input, roles, universes) {
  4.  
  5.     // if neither has checked
  6.     if(roles.length <= 0 && universes.length <= 0) {
  7.       return input;
  8.     }
  9.  
  10.     // if role and not universe
  11.     if(roles.length > 0 && universes.length <= 0) {
  12.       var tempListRole = input.filter(function(e) {
  13.         var containsRole = false;
  14.         var tempRole = e.attributes.role.toLowerCase();
  15.         containsRole = _.contains(roles, tempRole);
  16.         console.log(containsRole);
  17.         return containsRole;
  18.       });
  19.  
  20.       return tempListRole;
  21.     }
  22.  
  23.     // if universe and not role
  24.     if(roles.length <= 0 && universes.length > 0) {
  25.       var tempListUniverse = input.filter(function(e) {
  26.         var containsUniverse = false;
  27.         var tempUniverse = e.attributes.universe.toLowerCase();
  28.         containsUniverse = _.contains(universes, tempUniverse);
  29.         console.log(containsUniverse);
  30.         return containsUniverse;
  31.       });
  32.  
  33.       return tempListUniverse;
  34.     }
  35.  
  36.     // if both have checked
  37.     if(roles.length > 0 && universes.length > 0) {
  38.  
  39.       var tempList = input.filter(function(e) {
  40.         var containsRole = false;
  41.         var tempRole = e.attributes.role.toLowerCase();
  42.         containsRole = _.contains(roles, tempRole);
  43.         console.log(containsRole);
  44.         return containsRole;
  45.       });
  46.  
  47.       var tempListFinal = tempList.filter(function(e) {
  48.         var containsUniverse = false;
  49.         var tempUniverse = e.attributes.universe.toLowerCase();
  50.         containsUniverse = _.contains(universes, tempUniverse);
  51.         console.log(containsUniverse);
  52.         return containsUniverse;
  53.       });
  54.  
  55.       return tempListFinal;
  56.     }
  57.  
  58.   }
  59.  
  60. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement