Add role hints and deparment hints (when not provided by the uni).

This commit is contained in:
Paulo Reis 2018-06-28 16:37:36 +01:00
parent 270c67df5f
commit d021cd8e3f
3 changed files with 55 additions and 20 deletions

View file

@ -124,25 +124,26 @@ form.row(
.affiliations-form-group(
ng-if="ui.isValidEmail && newAffiliation.university"
)
input.form-control(
type="text"
id="affiliations-role"
placeholder="Role"
ui-select(
ng-model="newAffiliation.role"
tagging
tagging-label="false"
)
ui-select-match(
placeholder="Role"
) {{ $select.selected }}
ui-select-choices(
repeat="role in roles | filter: $select.search"
)
span(
ng-bind="role"
)
.affiliations-form-group(
ng-if="ui.isValidEmail && newAffiliation.university"
)
input.form-control(
type="text"
id="affiliations-department"
placeholder="Department"
ng-model="newAffiliation.department"
ng-if="!newAffiliation.university.departments || newAffiliation.university.departments.length === 0"
)
ui-select(
ng-model="newAffiliation.department"
ng-if="newAffiliation.university.departments.length > 0"
tagging
tagging-label="false"
)
@ -150,7 +151,7 @@ form.row(
placeholder="Department"
) {{ $select.selected }}
ui-select-choices(
repeat="department in getUniqueUniversityDepartments() | filter: $select.search"
repeat="department in departments | filter: $select.search"
)
span(
ng-bind="department"

View file

@ -5,6 +5,10 @@ define [
$scope.userEmails = []
$scope.countries = []
$scope.universities = []
$scope.roles = []
$scope.departments = []
_defaultDepartments = []
LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
EMAIL_REGEX = /^([A-Za-z0-9_\-\.]+)@([^\.]+)\.([A-Za-z0-9_\-\.]+)([^\.])$/
@ -45,9 +49,6 @@ define [
$scope.newAffiliation.department = null
$q.reject null
$scope.handleEmailInputBlur = () ->
# if $scope.newAffiliation.autoDetectMode and !$scope.newAffiliation.university and $scope.newAffiliation.email?.match EMAIL_REGEX
# $scope.newAffiliation.autoDetectMode = false
$scope.selectUniversityManually = () ->
$scope.newAffiliation.university = null
@ -96,8 +97,11 @@ define [
.removeUserEmail email
.then () -> _getUserEmails()
$scope.getUniqueUniversityDepartments = () ->
_.uniq $scope.newAffiliation.university.departments
$scope.getDepartments = () ->
if $scope.newAffiliation.university?.departments.length > 0
_.uniq $scope.newAffiliation.university.departments
else
UserAffiliationsDataService.getDefaultDepartmentHints()
_reset = () ->
$scope.newAffiliation =
@ -130,6 +134,17 @@ define [
.getCountries()
.then (countries) -> $scope.countries = countries
# Populates the roles dropdown
UserAffiliationsDataService
.getDefaultRoleHints()
.then (roles) -> $scope.roles = roles
# Fetches the default department hints
UserAffiliationsDataService
.getDefaultDepartmentHints()
.then (departments) ->
_defaultDepartments = departments
# Populates the universities dropdown (after selecting a country)
$scope.$watch "newAffiliation.country", (newSelectedCountry, prevSelectedCountry) ->
if newSelectedCountry? and newSelectedCountry != prevSelectedCountry
@ -139,4 +154,13 @@ define [
UserAffiliationsDataService
.getUniversitiesFromCountry(newSelectedCountry)
.then (universities) -> $scope.universities = universities
# Populates the departments dropdown (after selecting a university)
$scope.$watch "newAffiliation.university", (newSelectedUniversity, prevSelectedUniversity) ->
if newSelectedUniversity? and newSelectedUniversity != prevSelectedUniversity
if newSelectedUniversity.departments?.length > 0
$scope.departments = _.uniq newSelectedUniversity.departments
else
$scope.departments = _defaultDepartments
]

File diff suppressed because one or more lines are too long