| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- angular.module('basicFoodEditor', ['ndbDatabase', 'ngResource'])
- .factory('BasicFood', ['$resource', '$q', function($resource, $q) {
- return $resource('food/:id', {id: "@id"}, {
- 'get': {method: 'GET'},
- 'query': {
- url: "food/query/:query/",
- method: 'GET',
- isArray: true
- },
- 'save': {method: 'PUT'},
- 'update': {method: 'POST'},
- 'delete': {method: 'DELETE'}
- });
- }])
- // TODO: Only ever used with editBasicFood template. See if can auto link.
- .controller('BasicFoodEditorController',
- ['$scope', '$uibModalInstance', 'NDBList', 'BasicFood', 'foodData',
- function($scope, $uibModalInstance, NDBList, BasicFood, foodData) {
- if (foodData == null)
- {
- console.error("No food data to edit!");
- return;
- }
- // TODO: Replace with properties file key.
- $scope.catagories = NDBList.get({
- key: "CfiHcUnSf0RX0jBuqiWjDK2d2ziOmoZG15CTdhQn",
- type: "g"
- });
-
- $scope.food = new BasicFood(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 submitFnName = foodData.id == null? "$save":"$update";
- $scope.submit = function(food) {
- food[submitFnName]($scope.close, function (err) {
- // TODO: Proper error handling
- console.error(err);
- });
- };
- // 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;
- }]);
|