demo20230512/Browser_Local/js/Management/ManagementEditUserController.js
2023-05-12 10:20:28 +08:00

76 lines
3.1 KiB
JavaScript

angular.module('CarbonFootprint')
.config(function ($routeProvider, CONSTANTS) {
$routeProvider.when('/Management/EditUser/:Id', {
templateUrl: CONSTANTS.PB + 'Management-EditUser',
controller: 'ManagementEditUserCtrl'
});
})
.controller('ManagementEditUserCtrl', ['$scope', '$timeout', '$routeParams', '$http', 'Survey_Data_Service', 'Redirect',
function ($scope, $timeout, $routeParams, $http, Survey_Data_Service, Redirect) {
var redirect = new Redirect();
$scope.user = {};
// 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/User/GetByUid/" + $routeParams.Id)
.then(function (response) {
var user = response.data;
$scope.user = {
Id: user.Id,
DefaultPassword: user.DefaultPassword,
Department: user.Department,
Email: user.Email,
Job: user.Job,
Name: user.Name,
PhoneNumber: user.PhoneNumber,
UserName: user.UserName,
Password: user.DefaultPassword,
PasswordRepeat: user.DefaultPassword,
};
});
$scope.save = function () {
if ($scope.user.Password.trim() != '') {
$scope.user.DefaultPassword = $scope.user.Password;
}
Save(Survey_Data_Service.API, $scope.user, 'User', 'Save')
.then(function (response) {
if (mergeNumber(response) !== -1) {
redirect.backToManagement();
} else {
}
}, function (error) {
console.log(error);
if (typeof (error) !== 'undefined' &&
typeof (error.data) !== 'undefined' &&
typeof (error.data.ExceptionMessage) !== 'undefined')
alert(error.data.ExceptionMessage);
});
};
$scope.delete = function () {
Save(Survey_Data_Service.API, $scope.user, 'User', 'Delete')
.then(function (response) {
if (mergeNumber(response) !== -1) {
redirect.backToManagement();
} else {
}
}, function (error) {
console.log(error);
});
};
$scope.cancel = function () {
redirect.backToManagement();
};
}]);