电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.1 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. /**
  14. * Controller for profile mgmt
  15. */
  16. flowableApp.controller('IdmProfileMgmtController', ['$rootScope', '$scope', '$modal', 'IdmService', '$translate',
  17. function ($rootScope, $scope, $modal, IdmService, $translate) {
  18. $rootScope.setMainPageById('profile');
  19. $scope.model = {
  20. loading: true
  21. };
  22. $scope.showUploadPictureModal = function() {
  23. _internalCreateModal({
  24. scope: $scope,
  25. template: 'views/popup/idm-profile-picture-upload.html',
  26. show: true
  27. }, $modal, $scope);
  28. };
  29. $scope.emailChanged = function() {
  30. $scope.model.profile.emailErrorMessage = undefined;
  31. if ($scope.model.profile.email !== null
  32. && $scope.model.profile.email !== undefined
  33. && $scope.model.profile.email !== '') {
  34. $scope.model.loading = true;
  35. IdmService.updateProfileDetails($scope.model.profile, function (response) {
  36. $scope.model.editingEmail = false;
  37. $scope.loadProfile(); // reload values from server
  38. }, function (data, status) {
  39. $scope.model.loading = false;
  40. if (status === 409) {
  41. $scope.model.profile.emailErrorMessage = $translate.instant(data.message);
  42. }
  43. });
  44. } else {
  45. // Reset if invalid value
  46. $scope.model.profile.email = $scope.model.originalEmail;
  47. }
  48. };
  49. $scope.firstNameChanged = function() {
  50. $scope.model.loading = true;
  51. IdmService.updateProfileDetails($scope.model.profile, function (response) {
  52. $scope.model.editingFirstName = false;
  53. $scope.model.loading = false;
  54. });
  55. };
  56. $scope.lastNameChanged = function() {
  57. $scope.model.loading = true;
  58. IdmService.updateProfileDetails($scope.model.profile, function () {
  59. $scope.model.editingLastName = false;
  60. $scope.model.loading = false;
  61. });
  62. };
  63. $scope.companyChanged = function() {
  64. $scope.model.loading = true;
  65. IdmService.updateProfileDetails($scope.model.profile, function () {
  66. $scope.model.editingCompany = false;
  67. $scope.model.loading = false;
  68. });
  69. };
  70. $scope.showChangePasswordModal = function() {
  71. $scope.model.changePassword = {};
  72. _internalCreateModal({
  73. scope: $scope,
  74. template: 'views/popup/idm-change-password.html',
  75. show: true
  76. }, $modal, $scope);
  77. };
  78. // To fix cache
  79. $scope.cacheBuster = function(force) {
  80. if (!$scope.model.cacheBuster || force) {
  81. $scope.model.cacheBuster = new Date().getTime();
  82. } else {
  83. return $scope.model.cacheBuster;
  84. }
  85. };
  86. // Fetch profile when page is shown
  87. $scope.loadProfile = function() {
  88. IdmService.getProfile().then(function (profileData) {
  89. $scope.model.originalEmail = profileData.email; // Storing it extra, so we're able to reset
  90. $scope.model.profile = profileData;
  91. $scope.model.loading = false;
  92. });
  93. };
  94. $scope.loadProfile();
  95. }]);
  96. flowableApp.
  97. controller('UploadUserPictureController', ['$rootScope', '$scope', 'Upload', function ($rootScope, $scope, Upload) {
  98. $scope.popup = {
  99. loading: false
  100. };
  101. $scope.onFileSelect = function($files) {
  102. $scope.popup.loading = true;
  103. for (var i = 0; i < $files.length; i++) {
  104. var file = $files[i];
  105. Upload.upload({
  106. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/profile-picture',
  107. method: 'POST',
  108. file: file
  109. }).progress(function(evt) {
  110. $scope.popup.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);
  111. }).success(function(data, status, headers, config) {
  112. $scope.popup.loading = false;
  113. $scope.$hide();
  114. $scope.cacheBuster(true);
  115. $scope.loadProfile();
  116. }).error(function(data, status, headers, config) {
  117. if (data && data.message) {
  118. $scope.popup.errorMessage = data.message;
  119. }
  120. $scope.popup.error = true;
  121. $scope.popup.loading = false;
  122. });
  123. }
  124. };
  125. $scope.cancel = function () {
  126. if(!$scope.popup.loading) {
  127. $scope.$hide();
  128. }
  129. };
  130. }]);
  131. flowableApp.
  132. controller('IdmChangePasswordController', ['$rootScope', '$scope', 'IdmService', function ($rootScope, $scope, IdmService) {
  133. $scope.isConfirmButtonDisabled = function() {
  134. return !$scope.model.changePassword.originalPassword
  135. || $scope.model.changePassword.originalPassword.length == 0
  136. || !$scope.model.changePassword.newPassword
  137. || $scope.model.changePassword.newPassword.length === 0
  138. || !$scope.model.changePassword.newPassword2
  139. || $scope.model.changePassword.newPassword2.length === 0
  140. || $scope.model.changePassword.newPassword !== $scope.model.changePassword.newPassword2;
  141. };
  142. $scope.showPasswordsDontMatch = function() {
  143. return $scope.model.changePassword.originalPassword
  144. && $scope.model.changePassword.originalPassword.length > 0
  145. && $scope.model.changePassword.newPassword
  146. && $scope.model.changePassword.newPassword.length > 0
  147. && $scope.model.changePassword.newPassword2
  148. && $scope.model.changePassword.newPassword2.length > 0
  149. && $scope.model.changePassword.newPassword !== $scope.model.changePassword.newPassword2;
  150. };
  151. $scope.changePassword = function() {
  152. $scope.model.changePassword.error = false;
  153. IdmService.changePassword($scope.model.changePassword.originalPassword, $scope.model.changePassword.newPassword)
  154. .then(function() {
  155. $scope.$hide();
  156. }, function() {
  157. $scope.model.changePassword.error = true
  158. });
  159. };
  160. }]);