controllers.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435
  1. angular.module('app.controllers', []).controller('ShipwreckListController', function($scope, $state, popupService, $window, Shipwreck) {
  2. $scope.shipwrecks = Shipwreck.query(); //fetch all shipwrecks. Issues a GET to /api/vi/shipwrecks
  3. $scope.deleteShipwreck = function(shipwreck) { // Delete a Shipwreck. Issues a DELETE to /api/v1/shipwrecks/:id
  4. if (popupService.showPopup('Really delete this?')) {
  5. shipwreck.$delete(function() {
  6. $scope.shipwrecks = Shipwreck.query();
  7. $state.go('shipwrecks');
  8. });
  9. }
  10. };
  11. }).controller('ShipwreckViewController', function($scope, $stateParams, Shipwreck) {
  12. $scope.shipwreck = Shipwreck.get({ id: $stateParams.id }); //Get a single shipwreck.Issues a GET to /api/v1/shipwrecks/:id
  13. }).controller('ShipwreckCreateController', function($scope, $state, $stateParams, Shipwreck) {
  14. $scope.shipwreck = new Shipwreck(); //create new shipwreck instance. Properties will be set via ng-model on UI
  15. $scope.addShipwreck = function() { //create a new shipwreck. Issues a POST to /api/v1/shipwrecks
  16. $scope.shipwreck.$save(function() {
  17. $state.go('shipwrecks'); // on success go back to the list i.e. shipwrecks state.
  18. });
  19. };
  20. }).controller('ShipwreckEditController', function($scope, $state, $stateParams, Shipwreck) {
  21. $scope.updateShipwreck = function() { //Update the edited shipwreck. Issues a PUT to /api/v1/shipwrecks/:id
  22. $scope.shipwreck.$update(function() {
  23. $state.go('shipwrecks'); // on success go back to the list i.e. shipwrecks state.
  24. });
  25. };
  26. $scope.loadShipwreck = function() { //Issues a GET request to /api/v1/shipwrecks/:id to get a shipwreck to update
  27. $scope.shipwreck = Shipwreck.get({ id: $stateParams.id });
  28. };
  29. $scope.loadShipwreck(); // Load a shipwreck which can be edited on UI
  30. });