Просмотр исходного кода

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

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

+ 14 - 13
services/web/app/views/user/settings/user-affiliations.pug

@@ -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"

+ 29 - 5
services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee

@@ -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
+
 	]

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee


Некоторые файлы не были показаны из-за большого количества измененных файлов