2014-06-17 11:43:42 +00:00
|
|
|
define [
|
|
|
|
"base"
|
2014-07-08 11:32:50 +00:00
|
|
|
"libs/algolia-2.5.2"
|
2014-06-17 11:43:42 +00:00
|
|
|
], (App, algolia)->
|
2014-07-18 10:35:55 +00:00
|
|
|
App.factory "Institutions", ->
|
2014-06-17 11:25:49 +00:00
|
|
|
new AlgoliaSearch(window.algolia.institutions.app_id, window.algolia.institutions.api_key).initIndex("institutions")
|
2014-06-11 16:45:09 +00:00
|
|
|
|
2014-07-07 13:58:12 +00:00
|
|
|
App.controller "UserProfileController", ($scope, $modal, $http)->
|
2014-06-16 13:49:35 +00:00
|
|
|
$scope.institutions = []
|
2014-06-12 16:15:54 +00:00
|
|
|
$http.get("/user/personal_info").success (data)->
|
2014-06-16 15:14:58 +00:00
|
|
|
$scope.userInfoForm =
|
2014-06-17 13:36:17 +00:00
|
|
|
first_name: data.first_name || ""
|
|
|
|
last_name: data.last_name || ""
|
|
|
|
role: data.role || ""
|
|
|
|
institution: data.institution || ""
|
2014-06-12 16:15:54 +00:00
|
|
|
_csrf : window.csrfToken
|
2014-06-11 16:45:09 +00:00
|
|
|
|
2014-06-16 15:14:58 +00:00
|
|
|
$scope.showForm = ->
|
2016-03-02 15:29:52 +00:00
|
|
|
GrooveWidget.toggle()
|
2014-06-16 15:14:58 +00:00
|
|
|
$scope.formVisable = true
|
|
|
|
|
2014-07-07 13:58:12 +00:00
|
|
|
$scope.getPercentComplete = ->
|
|
|
|
results = _.filter $scope.userInfoForm, (value)-> !value? or value?.length != 0
|
|
|
|
results.length * 20
|
|
|
|
|
|
|
|
$scope.$watch "userInfoForm", (value) ->
|
|
|
|
if value?
|
|
|
|
$scope.percentComplete = $scope.getPercentComplete()
|
|
|
|
, true
|
|
|
|
|
|
|
|
$scope.openUserProfileModal = () ->
|
|
|
|
$modal.open {
|
|
|
|
templateUrl: "userProfileModalTemplate"
|
|
|
|
controller: "UserProfileModalController"
|
|
|
|
scope: $scope
|
|
|
|
}
|
|
|
|
|
|
|
|
App.controller "UserProfileModalController", ($scope, $modalInstance, $http, Institutions) ->
|
|
|
|
$scope.roles = ["Student", "Post-graduate student", "Post-doctoral researcher", "Lecturer", "Professor"]
|
|
|
|
|
2014-07-18 13:08:53 +00:00
|
|
|
$modalInstance.result.finally ->
|
|
|
|
sendUpdate()
|
|
|
|
|
|
|
|
sendUpdate = ->
|
2014-06-20 10:15:25 +00:00
|
|
|
request = $http.post "/user/settings", $scope.userInfoForm
|
2014-06-12 16:15:54 +00:00
|
|
|
request.success (data, status)->
|
|
|
|
request.error (data, status)->
|
|
|
|
console.log "the request failed"
|
2014-06-12 14:50:00 +00:00
|
|
|
|
2014-06-17 10:27:45 +00:00
|
|
|
$scope.updateInstitutionsList = (inputVal)->
|
|
|
|
|
2014-07-17 10:21:25 +00:00
|
|
|
query = $scope.userInfoForm.institution
|
|
|
|
if query?.length <= 3
|
2014-07-18 13:08:53 +00:00
|
|
|
return #saves us algolia searches
|
2014-06-17 10:27:45 +00:00
|
|
|
|
2014-06-13 16:17:58 +00:00
|
|
|
Institutions.search $scope.userInfoForm.institution, (err, response)->
|
2014-06-16 17:41:44 +00:00
|
|
|
$scope.institutions = _.map response.hits, (institution)->
|
2014-06-17 13:44:24 +00:00
|
|
|
"#{institution.name} (#{institution.domain})"
|
2014-06-13 16:17:58 +00:00
|
|
|
|
2014-07-07 13:58:12 +00:00
|
|
|
$scope.done = () ->
|
|
|
|
$modalInstance.close()
|