選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

useredit.controller.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Created by robin on 11/2/15.
  3. */
  4. angular.module('luticate')
  5. .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data', '$q', 'dialogs', 'luticateAuthCache',
  6. function($scope, luticateAuthUsers, data, $q, dialogs, luticateAuthCache) {
  7. if (data != null) {
  8. $scope.user = data;
  9. $scope.permission = "LU_USER_EDIT";
  10. $scope.permissionPassword = "LU_USER_SET_PASSWORD";
  11. }
  12. else {
  13. $scope.user = {
  14. Username: "",
  15. Email: "",
  16. Firstname: "",
  17. Lastname: ""
  18. };
  19. $scope.permission = "LU_USER_ADD";
  20. $scope.permissionPassword = "LU_USER_ADD";
  21. }
  22. $scope.userPassword = {
  23. value: "",
  24. confirm: ""
  25. };
  26. $scope.passwordValidation = {
  27. length: '$value.length >= 5 || $value.length == 0'
  28. };
  29. $scope.password2Validation = {
  30. same_passwords: 'userPassword.value==$value'
  31. };
  32. $scope.submitForm = function()
  33. {
  34. if ($scope.user.Id != null) {
  35. var promiseEditUser = {
  36. id: "promiseEditUser",
  37. loaderGroups: ["modal"]
  38. };
  39. var defer = $q.defer();
  40. if (luticateAuthCache.hasEffectivePermission("LU_USER_EDIT")) {
  41. luticateAuthUsers.edit({
  42. user_id: $scope.user.Id,
  43. email: $scope.user.Email,
  44. firstname: $scope.user.Firstname,
  45. lastname: $scope.user.Lastname
  46. }, promiseEditUser)
  47. .then(function(data)
  48. {
  49. $scope.mayEditPassword(defer);
  50. }, defer.reject);
  51. }
  52. else {
  53. $scope.mayEditPassword(defer);
  54. }
  55. return defer.promise;
  56. }
  57. else {
  58. var promiseAddUser = {
  59. id: "promiseAddUser",
  60. loaderGroups: ["modal"]
  61. };
  62. var user = {
  63. username: $scope.user.Username,
  64. email: $scope.user.Email,
  65. firstname: $scope.user.Firstname,
  66. lastname: $scope.user.Lastname,
  67. password: $scope.userPassword.value
  68. };
  69. return luticateAuthUsers.add(user, promiseAddUser);
  70. }
  71. };
  72. $scope.mayEditPassword = function(defer)
  73. {
  74. var promiseSetPassword = {
  75. id: "promiseSetPassword",
  76. loaderGroups: ["modal"]
  77. };
  78. if ($scope.userPassword.value != ""
  79. && luticateAuthCache.hasEffectivePermission("LU_USER_SET_PASSWORD")) {
  80. luticateAuthUsers.setPassword({
  81. user_id: $scope.user.Id,
  82. password: $scope.userPassword.value
  83. }, promiseSetPassword)
  84. .then(defer.resolve, defer.reject);
  85. }
  86. else {
  87. defer.resolve(data);
  88. }
  89. };
  90. $scope.editPermissions = function(user)
  91. {
  92. dialogs.create('views/modals/userpermissions.html', 'UserPermissionsController', user);
  93. };
  94. $scope.showEffectivePermissions = function(user)
  95. {
  96. dialogs.create('views/modals/usereffectivepermissions.html', 'UserEffectivePermissionsController', user);
  97. };
  98. $scope.editSettings = function(user)
  99. {
  100. dialogs.create('views/modals/usersettings.html', 'UserSettingsController', user);
  101. };
  102. $scope.showEffectiveSettings = function(user)
  103. {
  104. dialogs.create('views/modals/usereffectivesettings.html', 'UserEffectiveSettingsController', user);
  105. };
  106. }]);