{"size": 824, "ext": "js", "max_stars_repo_path": "advanced-directives/exercises/01/app/catalog/catalog-directive.js", "max_stars_repo_name": "JeffJin/ng-conf2015", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "advanced-directives/exercises/01/app/catalog/catalog-directive.js", "max_issues_repo_name": "JeffJin/ng-conf2015", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "advanced-directives/exercises/01/app/catalog/catalog-directive.js", "max_forks_repo_name": "JeffJin/ng-conf2015", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.75, "max_line_length": 95, "alphanum_fraction": 0.6699029126}
/*
Move catalogController into the catalog directive

Implement a 25% discount on any items with a calcPrice over $100

Bonus: set the on sale items' onSale property to true, we'll use this later
 */

angular.module('APP')
.controller('catalogController', ['$scope', 'CatalogService', function($scope, catalogService){
  this.catalog = catalogService.getCatalog();;
  this.calcPrice = function(item){
    var tempCost = item.cost*2 //if this is over 100 reduce by 25%
    if(tempCost > 100){
      tempCost = tempCost * 0.75;
      item.onSale = true
    }
    else{
      item.onSale = false;
    }
    return tempCost;
  }
}])
.directive('catalog', function(){
   return {
    controller: 'catalogController',
    restrict: 'E',
    controllerAs: 'ctrl',
    templateUrl: 'app/catalog/catalog-directive.tpl.html'
  };
});
