From 19b57571bf1a42a196cd9adc7f15079824471c5e Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Wed, 4 Jul 2018 16:37:40 +0100 Subject: [PATCH] Basic affiliation change implementation. --- .../views/user/settings/user-affiliations.pug | 43 ++++++++++++++++--- .../components/affiliationForm.coffee | 9 ++-- .../UserAffiliationsController.coffee | 32 +++++++++++--- .../UserAffiliationsDataService.coffee | 10 +++++ 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/services/web/app/views/user/settings/user-affiliations.pug b/services/web/app/views/user/settings/user-affiliations.pug index 22498fb938..3d12c5bfa2 100644 --- a/services/web/app/views/user/settings/user-affiliations.pug +++ b/services/web/app/views/user/settings/user-affiliations.pug @@ -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 diff --git a/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee b/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee index faec7b39c0..1c0c7d6229 100644 --- a/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee +++ b/services/web/public/coffee/main/affiliations/components/affiliationForm.coffee @@ -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 diff --git a/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee b/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee index 3ebf25ab50..f3ceca8e0d 100644 --- a/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee +++ b/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee @@ -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 diff --git a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee index 0b026de0e2..6b689f5441 100644 --- a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee +++ b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee @@ -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