nw-category-select.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. angular.module('NoteWrangler')
  2. .directive('nwCategorySelect', function(Category) {
  3. return {
  4. replace: true,
  5. restrict: "E",
  6. scope: {
  7. activeCategory: "=",
  8. notes: "="
  9. },
  10. controller: function($scope) {
  11. this.getActiveCategory = function(){
  12. return $scope.activeCategory
  13. }
  14. this.setActiveCategory = function(category) {
  15. $scope.activeCategory = category && category.name;
  16. }
  17. this.getNotesCountForCategory = function(category) {
  18. if(!$scope.notes) {
  19. return 0;
  20. }
  21. var count = 0;
  22. for(var i=0, l = $scope.notes.length; i < l; i++ ) {
  23. if($scope.notes[i].category.id === category.id) {
  24. count++;
  25. }
  26. }
  27. return count;
  28. }
  29. },
  30. templateUrl: '/templates/directives/nw-category-select.html',
  31. link: function(scope, element, attrs) {
  32. // Initially fetch the categories to use within the sorting menu
  33. Category.all().then(function(categoryData) {
  34. scope.categories = categoryData;
  35. });
  36. }
  37. };
  38. });
  39. //simple version
  40. // angular.module('NoteWrangler')
  41. // .directive('nwCategorySelect', function(Category) {
  42. // return {
  43. // replace: true,
  44. // restrict: "E",
  45. // scope:{activeCategory: '='},
  46. // controller: function($scope) {
  47. // this.getActiveCategory = function(){
  48. // // return $scope.activeCategory
  49. // return $scope.activeCategory
  50. //
  51. // }
  52. //
  53. // this.setActiveCategory = function(category) {
  54. // // $scope.activeCategory = category.name;
  55. // $scope.activeCategory = category && category.name;
  56. // }
  57. //
  58. // return this;
  59. // },
  60. // templateUrl: '/templates/directives/nw-category-select.html',
  61. // link: function(scope, element, attrs) {
  62. //
  63. // // Initially fetch the categories to use within the sorting menu
  64. // Category.all().then(function(categoryData) {
  65. // scope.categories = categoryData;
  66. // });
  67. // }
  68. // };
  69. // });