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

View file

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