angular.module('CarbonFootprint') .config(function ($routeProvider, CONSTANTS) { $routeProvider.when('/Management/CreateSupplier', { templateUrl: CONSTANTS.PB + 'Management-CreateSupplier', controller: 'ManagementCreateSupplierCtrl' }); }) .controller('ManagementCreateSupplierCtrl', ['$scope', '$http', 'Redirect', 'Survey_Data_Service', function ($scope, $http, Redirect, Survey_Data_Service) { var redirect = new Redirect(); $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; } $scope.createSupplier = function () { $scope.isCheckOnce = true; $http.post($scope.baseUrl+'/api/Supplier/Check', $scope.supplier) .success(function (data, status, headers, config) { //console.log('success', data); //console.log('success', status); //console.log('success', headers); //console.log('success', config); if (typeof (data) !== 'undefined' && data.err != '') alert(data.err); else { Save(Survey_Data_Service.API, $scope.supplier, 'Supplier', 'Save') .then(function (response) { if (mergeNumber(response) !== -1) { redirect.backToSupplier(); } else { $scope.account_repeat = true; } }, function (error) { if (typeof (error) != 'undefined' && typeof (error.data) != 'undefined' && typeof (error.data.ExceptionMessage) != 'undefined') alert(error.data.ExceptionMessage); //console.log(error); }); } }) .error(function (data, status, headers, config) { //console.log(data.ExceptionMessage); console.log('error', data, status, headers, config); }); }; $scope.usernameBlur = function (UserName) { //console.log('usernameBlur', UserName, $scope.supplier); if (typeof (UserName) === 'undefined' || UserName.length == 0) return; $http.post($scope.baseUrl+'/api/Supplier/Check', $scope.supplier) .success(function (data, status, headers, config) { //console.log('success', data); //console.log('success', status); //console.log('success', headers); //console.log('success', config); if (typeof (data) !== 'undefined' && data.err != '') alert(data.err); else { $scope.supplier.Name = data.Name; $scope.supplier.ContactEmail = data.Email; $scope.supplier.Phone = data.PhoneNumber; $scope.supplier.ContactPhone = data.MobileNumber; } //console.log('success', data, status, headers, config); }) .error(function (data, status, headers, config) { //console.log('error', data, status, headers, config); }); }; $scope.backToManagement = function () { redirect.backToManagement(); }; }]);