basicFoodEditor.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. angular.module('basicFoodEditor', ['ndbDatabase', 'ngResource', 'Food'])
  2. // TODO: Only ever used with editBasicFood template. See if can auto link.
  3. .controller('BasicFoodEditorController',
  4. ['$scope', '$uibModalInstance', 'NDBList', 'BasicFood', 'foodData', 'ndbKey',
  5. function($scope, $uibModalInstance, NDBList, BasicFood, foodData, ndbKey) {
  6. if (foodData == null)
  7. {
  8. console.error("No food data to edit!");
  9. return;
  10. }
  11. $scope.catagories = NDBList.get({
  12. key: ndbKey,
  13. type: "g"
  14. });
  15. $scope.food = foodData;
  16. $scope.submit = function(food) {
  17. food.$save($scope.close, function (err) {
  18. // TODO: Proper error handling
  19. console.error(err);
  20. });
  21. };
  22. $scope.delete = function(food) {
  23. food.$delete($scope.close, function (err) {
  24. // TODO: Proper error handling
  25. console.error(err);
  26. });
  27. };
  28. $scope.submit = function(food) {
  29. food.$save($scope.close, function (err) {
  30. // TODO: Proper error handling
  31. console.error(err);
  32. });
  33. };
  34. // TODO:
  35. // Will this controller ever be used non-modally?
  36. // Will it even work as a non-modal?
  37. $scope.close = $uibModalInstance != null?
  38. $uibModalInstance.close : null;
  39. $scope.dismiss = $uibModalInstance != null?
  40. $uibModalInstance.dismiss : null;
  41. }]);