Integrate e-mails table with backend.

This commit is contained in:
Paulo Reis 2018-06-20 14:22:06 +01:00
parent 917776aede
commit 147d74d92a
3 changed files with 37 additions and 26 deletions

View file

@ -234,13 +234,11 @@ block content
th Institution and role
th
tbody
tr
td paulojreis@ua.pt
td Universidade de Aveiro
td Remove
tr
td paulojreis@fe.up.pt
td Universidade do Porto
tr(
ng-repeat="userEmail in userEmails"
)
td {{ userEmail.email + (userEmail.default ? ' (default)' : '') }}
td {{ userEmail.institution }}
td Remove

View file

@ -2,6 +2,7 @@ define [
"base"
], (App) ->
App.controller "UserAffiliationsController", ["$scope", "UserAffiliationsDataService", "$q", ($scope, UserAffiliationsDataService, $q) ->
$scope.userEmails = []
$scope.countries = []
$scope.universities = []
$scope.newAffiliation =
@ -24,8 +25,6 @@ define [
else
{ local: null, domain: null }
UserAffiliationsDataService.getUserEmails()
$scope.addUniversityToSelection = (universityName) ->
{ name: universityName, isUserSuggested: true }
@ -66,23 +65,34 @@ define [
$scope.handleAffiliationFormSubmit = () ->
if !$scope.newAffiliation.university?
UserAffiliationsDataService.addUserEmail $scope.newAffiliation.email
addEmailPromise = UserAffiliationsDataService
.addUserEmail $scope.newAffiliation.email
else
if $scope.newAffiliation.university.isUserSuggested
UserAffiliationsDataService.addUserAffiliationWithUnknownUniversity(
$scope.newAffiliation.email,
$scope.newAffiliation.university.name,
$scope.newAffiliation.country.code,
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
addEmailPromise = UserAffiliationsDataService
.addUserAffiliationWithUnknownUniversity(
$scope.newAffiliation.email,
$scope.newAffiliation.university.name,
$scope.newAffiliation.country.code,
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
else
UserAffiliationsDataService.addUserAffiliation(
$scope.newAffiliation.email,
$scope.newAffiliation.university.id
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
addEmailPromise = UserAffiliationsDataService
.addUserAffiliation(
$scope.newAffiliation.email,
$scope.newAffiliation.university.id
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
addEmailPromise.then () -> getUserEmails()
# Populates the emails table
getUserEmails = () ->
UserAffiliationsDataService
.getUserEmails()
.then (emails) -> $scope.userEmails = emails
getUserEmails()
# Populates the countries dropdown
UserAffiliationsDataService

View file

@ -47,7 +47,8 @@ define [
addUserEmail = (email) ->
$http.post "/user/emails", {
email
email,
_csrf: window.csrfToken
}
addUserAffiliationWithUnknownUniversity = (email, unknownUniversityName, unknownUniversityCountryCode, role, department) ->
@ -57,7 +58,8 @@ define [
name: unknownUniversityName
country_code: unknownUniversityCountryCode
role,
department
department,
_csrf: window.csrfToken
}
addUserAffiliation = (email, universityId, role, department) ->
@ -66,7 +68,8 @@ define [
university:
id: universityId
role,
department
department,
_csrf: window.csrfToken
}
isDomainBlacklisted = (domain) ->