123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /**
- * Created by robin on 11/2/15.
- */
-
- angular.module('luticate')
- .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data', '$q', 'dialogs', 'luticateAuthCache',
- function($scope, luticateAuthUsers, data, $q, dialogs, luticateAuthCache) {
- if (data != null) {
- $scope.user = data;
- $scope.permission = "LU_USER_EDIT";
- $scope.permissionPassword = "LU_USER_SET_PASSWORD";
- }
- else {
- $scope.user = {
- Username: "",
- Email: "",
- Firstname: "",
- Lastname: ""
- };
- $scope.permission = "LU_USER_ADD";
- $scope.permissionPassword = "LU_USER_ADD";
- }
- $scope.userPassword = {
- value: "",
- confirm: ""
- };
- $scope.passwordValidation = {
- length: '$value.length >= 5 || $value.length == 0'
- };
- $scope.password2Validation = {
- same_passwords: 'userPassword.value==$value'
- };
-
- $scope.submitForm = function()
- {
- if ($scope.user.Id != null) {
- var promiseEditUser = {
- id: "promiseEditUser",
- loaderGroups: ["modal"]
- };
- var defer = $q.defer();
- if (luticateAuthCache.hasEffectivePermission("LU_USER_EDIT")) {
- luticateAuthUsers.edit({
- user_id: $scope.user.Id,
- email: $scope.user.Email,
- firstname: $scope.user.Firstname,
- lastname: $scope.user.Lastname
- }, promiseEditUser)
- .then(function(data)
- {
- $scope.mayEditPassword(defer);
- }, defer.reject);
- }
- else {
- $scope.mayEditPassword(defer);
- }
- return defer.promise;
- }
- else {
- var promiseAddUser = {
- id: "promiseAddUser",
- loaderGroups: ["modal"]
- };
- var user = {
- username: $scope.user.Username,
- email: $scope.user.Email,
- firstname: $scope.user.Firstname,
- lastname: $scope.user.Lastname,
- password: $scope.userPassword.value
- };
- return luticateAuthUsers.add(user, promiseAddUser);
- }
- };
-
- $scope.mayEditPassword = function(defer)
- {
- var promiseSetPassword = {
- id: "promiseSetPassword",
- loaderGroups: ["modal"]
- };
- if ($scope.userPassword.value != ""
- && luticateAuthCache.hasEffectivePermission("LU_USER_SET_PASSWORD")) {
- luticateAuthUsers.setPassword({
- user_id: $scope.user.Id,
- password: $scope.userPassword.value
- }, promiseSetPassword)
- .then(defer.resolve, defer.reject);
- }
- else {
- defer.resolve(data);
- }
- };
-
- $scope.editPermissions = function(user)
- {
- dialogs.create('views/modals/userpermissions.html', 'UserPermissionsController', user);
- };
-
- $scope.showEffectivePermissions = function(user)
- {
- dialogs.create('views/modals/usereffectivepermissions.html', 'UserEffectivePermissionsController', user);
- };
-
- $scope.editSettings = function(user)
- {
- dialogs.create('views/modals/usersettings.html', 'UserSettingsController', user);
- };
-
- $scope.showEffectiveSettings = function(user)
- {
- dialogs.create('views/modals/usereffectivesettings.html', 'UserEffectiveSettingsController', user);
- };
- }]);
|