nw-category-item.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. angular.module('NoteWrangler')
  2. .directive('nwCategoryItem', function() {
  3. return {
  4. restrict: "E",
  5. require: "^nwCategorySelect",
  6. scope: {
  7. category: "="
  8. },
  9. templateUrl: '/templates/directives/nw-category-item.html',
  10. link: function(scope, element, attrs, nwCategorySelectCtrl) {
  11. scope.isActive = function() {
  12. return nwCategorySelectCtrl.getActiveCategory() === scope.category.name;
  13. }
  14. scope.makeActive = function(){
  15. nwCategorySelectCtrl.setActiveCategory(scope.category);
  16. }
  17. scope.categoryCount = function() {
  18. return nwCategorySelectCtrl.getNotesCountForCategory(scope.category);
  19. }
  20. scope.makeInactive = function(evt){
  21. // Required to stop the makeActive click handler from firing on the parent element
  22. evt.stopPropagation();
  23. nwCategorySelectCtrl.setActiveCategory(false)
  24. }
  25. }
  26. };
  27. });
  28. //simple version
  29. // angular.module('NoteWrangler')
  30. // .directive('nwCategoryItem', function() {
  31. // return {
  32. // restrict: "E",
  33. // require: "^nwCategorySelect",
  34. // scope: {
  35. // category: "="
  36. // },
  37. // templateUrl: '/templates/directives/nw-category-item.html',
  38. // link: function(scope, element, attrs, nwCategorySelectCtrl) {
  39. // scope.categoryActive = function() {
  40. // return nwCategorySelectCtrl.getActiveCategory() === scope.category.name;
  41. // }
  42. //
  43. // scope.makeActive = function(){
  44. // nwCategorySelectCtrl.setActiveCategory(scope.category);
  45. // }
  46. // }
  47. // };
  48. // });