Paulo Reis 8 лет назад
Родитель
Сommit
4d1b6c6ba8

+ 21 - 2
services/web/app/views/user/settings/user-affiliations.pug

@@ -11,7 +11,9 @@ form.row(
 					th.affiliations-table-email Email
 					th.affiliations-table-institution Institution and role
 					th.affiliations-table-inline-actions
-			tbody
+			tbody(
+				ng-if="!ui.hasError"
+			)
 				tr(
 					ng-repeat="userEmail in userEmails"
 				)
@@ -73,7 +75,6 @@ form.row(
 					td.text-center(colspan="3") 
 						i.fa.fa-fw.fa-spin.fa-refresh
 						|  Loading...
-				
 				tr.affiliations-table-highlighted-row(
 					ng-if="!ui.showAddEmailUI && !ui.isLoadingEmails"
 				)
@@ -139,6 +140,24 @@ form.row(
 							)
 								i.fa.fa-fw.fa-spin.fa-refresh
 								|  Adding...
+			tbody(
+				ng-if="ui.hasError"
+			)
+				tr.affiliations-table-error-row(
+					ng-if="true"
+				)
+					td.text-center(colspan="3") 
+						div
+							i.fa.fa-fw.fa-exclamation-triangle 
+							|  An error has occurred while performing your request.
+						div
+							| Click 
+							a(
+								href
+								ng-click="acknowledgeError();"
+							) here
+							|  to reload your emails and affiliations.
+				
 		hr
 
 script(type="text/ng-template", id="affiliationFormTpl")

+ 19 - 3
services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee

@@ -52,12 +52,15 @@ define [
 			$scope.affiliationToChange.department = userEmail.affiliation.department
 
 		$scope.saveAffiliationChange = () ->
+			$scope.ui.isLoadingEmails = true
 			UserAffiliationsDataService
 				.addRoleAndDepartment(
 					$scope.affiliationToChange.email,
 					$scope.affiliationToChange.role,
 					$scope.affiliationToChange.department
 				)
+				.then () -> _getUserEmails()
+				.catch () -> $scope.ui.hasError = true
 
 		$scope.cancelAffiliationChange = (email) ->
 			$scope.affiliationToChange.email = ""
@@ -93,15 +96,19 @@ define [
 							$scope.newAffiliation.role,
 							$scope.newAffiliation.department
 						)
-			addEmailPromise.then () -> 
-				_reset()
-				_getUserEmails()
+			addEmailPromise
+				.then () -> 
+					_reset()
+					_getUserEmails()
+				.catch () ->
+					$scope.ui.hasError = true
 
 		$scope.setDefaultUserEmail = (userEmail) ->
 			$scope.ui.isLoadingEmails = true
 			UserAffiliationsDataService
 				.setDefaultUserEmail userEmail.email
 				.then () -> _getUserEmails()
+				.catch () -> $scope.ui.hasError = true
 
 		$scope.removeUserEmail = (userEmail) ->
 			$scope.ui.isLoadingEmails = true
@@ -111,6 +118,11 @@ define [
 			UserAffiliationsDataService
 				.removeUserEmail userEmail.email
 				.then () -> _getUserEmails()
+				.catch () -> $scope.ui.hasError = true
+
+		$scope.acknowledgeError = () ->
+			_reset()
+			_getUserEmails()
 
 		_reset = () ->
 			$scope.newAffiliation =
@@ -120,6 +132,7 @@ define [
 				role: null
 				department: null
 			$scope.ui = 
+				hasError: false
 				showChangeAffiliationUI: false
 				showManualUniversitySelectionUI: false
 				isLoadingEmails: false
@@ -141,6 +154,9 @@ define [
 				.then (emails) -> 
 					$scope.userEmails = emails
 					$scope.ui.isLoadingEmails = false
+				.catch () ->
+					$scope.ui.hasError = true
+
 		_getUserEmails()
 
 	]

+ 1 - 2
services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee

@@ -27,7 +27,7 @@ define [
 		getDefaultDepartmentHints = () ->
 			$q.resolve defaultDepartmentHints
 
-		getUserEmails = () ->
+		getUserEmails = () ->			
 			$http.get "/user/emails"
 				.then (response) -> response.data
 
@@ -88,7 +88,6 @@ define [
 				_csrf: window.csrfToken
 			}
 
-
 		setDefaultUserEmail = (email) ->
 			$http.post "/user/emails/default", {
 				email,

+ 12 - 0
services/web/public/stylesheets/app/account-settings.less

@@ -29,6 +29,18 @@
 	.affiliations-table-highlighted-row {
 		background-color: tint(@content-alt-bg-color, 6%);
 	}
+	.affiliations-table-error-row {
+		background-color: @alert-danger-bg;
+		color: @alert-danger-text;
+		a {
+			color: #FFF;
+			font-weight: bold;
+			&:hover,
+			&:focus {
+				color: #FFF;
+			}
+		}
+	}
 
 	.affiliations-form-group {
 		margin-top: @table-cell-padding;