Basic affiliation change implementation.

This commit is contained in:
Paulo Reis 2018-07-04 16:37:40 +01:00 committed by James Allen
parent a64910d409
commit 19b57571bf
4 changed files with 78 additions and 16 deletions

View file

@ -16,12 +16,45 @@ form.row(
ng-repeat="userEmail in userEmails"
)
td {{ userEmail.email + (userEmail.default ? ' (default)' : '') }}
//- td {{ userEmail | json }}
td
div(ng-if="userEmail.affiliation.institution") {{ userEmail.affiliation.institution.name }}
div(ng-if="userEmail.affiliation.role || userEmail.affiliation.department")
span(ng-if="userEmail.affiliation.role") {{ userEmail.affiliation.role }}
span(ng-if="userEmail.affiliation.role && userEmail.affiliation.department") ,
span(ng-if="userEmail.affiliation.department") {{ userEmail.affiliation.department }}
div(ng-if="userEmail.affiliation.institution")
div {{ userEmail.affiliation.institution.name }}
a(
href
ng-if="!isChangingAffiliation(userEmail.email) && !userEmail.affiliation.role && !userEmail.affiliation.department"
ng-click="changeAffiliation(userEmail);"
) Add role and department
div(
ng-if="!isChangingAffiliation(userEmail.email) && (userEmail.affiliation.role || userEmail.affiliation.department)"
)
span(ng-if="userEmail.affiliation.role") {{ userEmail.affiliation.role }}
span(ng-if="userEmail.affiliation.role && userEmail.affiliation.department") ,
span(ng-if="userEmail.affiliation.department") {{ userEmail.affiliation.department }}
| (
a(
href
ng-click="changeAffiliation(userEmail);"
) change
| )
div(
ng-if="isChangingAffiliation(userEmail.email)"
)
affiliation-form(
affiliation-data="affiliationToChange"
show-university-and-country="false"
show-role-and-department="true"
)
.pull-right
a(
href
ng-click="saveAffiliationChange();"
) Save
| or
a(
href
ng-click="cancelAffiliationChange();"
) Cancel
td
a(
href

View file

@ -35,11 +35,10 @@ define [
.then (universities) -> ctrl.universities = universities
# Populates the departments dropdown (after selecting a university)
$scope.$watch "$ctrl.affiliationData.university", (newSelectedUniversity, prevSelectedUniversity) ->
if newSelectedUniversity? and newSelectedUniversity != prevSelectedUniversity
if newSelectedUniversity.departments?.length > 0
ctrl.departments = _.uniq newSelectedUniversity.departments
else
ctrl.departments = _defaultDepartments
if newSelectedUniversity? and newSelectedUniversity != prevSelectedUniversity and newSelectedUniversity.departments?.length > 0
ctrl.departments = _.uniq newSelectedUniversity.departments
else
ctrl.departments = _defaultDepartments
return

View file

@ -46,6 +46,27 @@ define [
$scope.newAffiliation.department = null
$scope.ui.showManualUniversitySelectionUI = true
$scope.changeAffiliation = (userEmail) ->
$scope.affiliationToChange.email = userEmail.email
$scope.affiliationToChange.role = userEmail.affiliation.role
$scope.affiliationToChange.department = userEmail.affiliation.department
$scope.saveAffiliationChange = () ->
UserAffiliationsDataService
.addRoleAndDepartment(
$scope.affiliationToChange.email,
$scope.affiliationToChange.role,
$scope.affiliationToChange.department
)
$scope.cancelAffiliationChange = (email) ->
$scope.affiliationToChange.email = ""
$scope.affiliationToChange.role = null
$scope.affiliationToChange.department = null
$scope.isChangingAffiliation = (email) ->
$scope.affiliationToChange.email == email
$scope.showAddEmailForm = () ->
$scope.ui.showAddEmailUI = true
@ -88,12 +109,6 @@ define [
.removeUserEmail email
.then () -> _getUserEmails()
# $scope.getDepartments = () ->
# if $scope.newAffiliation.university?.departments.length > 0
# _.uniq $scope.newAffiliation.university.departments
# else
# UserAffiliationsDataService.getDefaultDepartmentHints()
_reset = () ->
$scope.newAffiliation =
email: ""
@ -102,12 +117,17 @@ define [
role: null
department: null
$scope.ui =
showChangeAffiliationUI: false
showManualUniversitySelectionUI: false
isLoadingEmails: false
isAddingNewEmail: false
showAddEmailUI: false
isValidEmail: false
isBlacklistedEmail: false
$scope.affiliationToChange =
email: ""
role: null
department: null
_reset()
# Populates the emails table

View file

@ -80,6 +80,15 @@ define [
_csrf: window.csrfToken
}
addRoleAndDepartment = (email, role, department) ->
$http.post "/endorse", {
email,
role,
department,
_csrf: window.csrfToken
}
setDefaultUserEmail = (email) ->
$http.post "/user/emails/default", {
email,
@ -105,6 +114,7 @@ define [
addUserEmail
addUserAffiliationWithUnknownUniversity
addUserAffiliation
addRoleAndDepartment
setDefaultUserEmail
removeUserEmail
isDomainBlacklisted