| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- angular.module('basicFoodEditor', ['ndbDatabase', 'ngResource', 'Food'])
- // TODO: Only ever used with editBasicFood template. See if can auto link.
- .controller('BasicFoodEditorController',
- ['$scope', '$uibModalInstance', 'NDBList', 'BasicFood', 'foodData', 'ndbKey',
- function($scope, $uibModalInstance, NDBList, BasicFood, foodData, ndbKey) {
- if (foodData == null)
- {
- console.error("No food data to edit!");
- return;
- }
- $scope.catagories = NDBList.get({
- key: ndbKey,
- type: "g"
- });
-
- $scope.food = foodData;
- $scope.submit = function(food) {
- food.$save($scope.close, function (err) {
- // TODO: Proper error handling
- console.error(err);
- });
- };
- $scope.delete = function(food) {
- food.$delete($scope.close, function (err) {
- // TODO: Proper error handling
- console.error(err);
- });
- };
- var initSubmit = function() {
- var submitFnName = foodData.id == null? "$save":"$update";
- $scope.submit = function(food) {
- food[submitFnName]($scope.close, function (err) {
- // TODO: Proper error handling
- console.error(err);
- });
- };
- };
-
- if (foodData.$promise) {
- foodData.$promise.then(initSubmit);
- }
- else {
- initSubmit();
- }
- // TODO:
- // Will this controller ever be used non-modally?
- // Will it even work as a non-modal?
- $scope.close = $uibModalInstance != null?
- $uibModalInstance.close : null;
- $scope.dismiss = $uibModalInstance != null?
- $uibModalInstance.dismiss : null;
- }]);
|