basicFoodEditor.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. angular.module('basicFoodEditor', ['ngResource'])
  2. .factory('BasicFood', ['$resource', '$q', function($resource, $q) {
  3. return $resource('food/:id', {}, {
  4. 'get': {method: 'GET'},
  5. 'query': {method: 'GET', isArray: true},
  6. 'save': {method: 'PUT'},
  7. 'update': {method: 'POST'},
  8. 'delete': {method: 'DELETE'}
  9. });
  10. }])
  11. // TODO: Only ever used with editBasicFood template. See if can auto link.
  12. .controller('BasicFoodEditorController',
  13. ['$scope', '$uibModalInstance', 'BasicFood', 'foodData',
  14. function($scope, $uibModalInstance, BasicFood, foodData) {
  15. if (foodData == null)
  16. {
  17. console.error("No food data to edit!");
  18. return;
  19. }
  20. $scope.food = new BasicFood(foodData);
  21. $scope.submit = function(food) {
  22. food.$save($scope.close, function (err) {
  23. // TODO: Proper error handling
  24. console.error(err);
  25. });
  26. };
  27. // TODO:
  28. // Will this controller ever be used non-modally?
  29. // Will it even work as a non-modal?
  30. $scope.close = $uibModalInstance != null?
  31. $uibModalInstance.close : null;
  32. }]);