angular.module('CarbonFootprint') .config(function ($routeProvider, CONSTANTS) { $routeProvider.when('/Management/EditSupplier/:Id', { templateUrl: CONSTANTS.PB + 'Management-EditSupplier', controller: 'ManagementEditSupplierCtrl' }); }) .controller('ManagementEditSupplierCtrl', ['$scope', '$timeout', '$http', '$routeParams', 'Redirect', 'Survey_Data_Service', 'MultiLanguageService', function ($scope, $timeout, $http, $routeParams, Redirect, Survey_Data_Service, MultiLanguageService) { var redirect = new Redirect(); var supplierId = Number($routeParams.Id); $scope.supplier = {}; // set $scope.baseUrl var baseUrl = $scope.baseUrl; if (typeof (baseUrl) === 'undefined' || baseUrl == null) { var arr = window.location.href.split("/"); if (arr[3].indexOf('app') == 0) baseUrl = ''; else baseUrl = '/' + arr[3]; $scope.baseUrl = baseUrl; } $http.get($scope.baseUrl+"/api/Supplier/GetByMyCompany") .then(function (response) { $scope.supplier = $scope.getSelectedSupplier(response.data, supplierId); //console.log('Supplier/GetByMyCompany', $scope.supplier); }, function (error) { console.log(error); }); $scope.delete = function () { $http.delete($scope.baseUrl+"/api/Supplier/" + $scope.ID) .then(function (response) { console.log('delete response', response); }, function (error) { console.log('delete error', error); }); }; $scope.save = function () { Save(Survey_Data_Service.API, $scope.supplier, 'Supplier', 'Save') .then(function (response) { if (mergeNumber(response) !== -1) { redirect.backToSupplier(); } else { } }, function (error) { console.log(error); }); }; MultiLanguageService.getResourceAsync().then(function (resource) { $scope.delete = function () { if (confirm(resource['DeleteItemMsg'])) { $http.delete($scope.baseUrl+"/api/Supplier/" + $routeParams.Id) .then(function () { redirect.backToSupplier(); }) } }; }); $scope.getSelectedSupplier = function (suppliers, id) { for (var i = 0; i < suppliers.length; i++) { if (suppliers[i].ID === id) { return suppliers[i]; } } return {}; }; }]);