2014-06-16 09:49:35 -04:00
|
|
|
define ["libs/algolia", "libs/angular", "libs/angular-autocomplete/angular-autocomplete"], (algolia)->
|
2014-06-11 12:45:09 -04:00
|
|
|
|
2014-06-16 09:49:35 -04:00
|
|
|
app = angular.module("userProfileInformationApp", ["autocomplete"])
|
2014-06-11 12:45:09 -04:00
|
|
|
|
2014-06-13 12:17:58 -04:00
|
|
|
app.factory "Institutions", ->
|
|
|
|
new AlgoliaSearch("SK53GL4JLY", "75dc5e65794cd47eb7f725e6bb5075be").initIndex("institutions")
|
2014-06-11 12:45:09 -04:00
|
|
|
|
2014-06-16 11:22:45 -04:00
|
|
|
app.directive "focusInput", ($timeout) ->
|
|
|
|
return (scope, element, attr) ->
|
|
|
|
scope.$watch attr.focusInput, (value) ->
|
|
|
|
if value
|
|
|
|
$timeout ->
|
|
|
|
element.select()
|
|
|
|
|
2014-06-13 12:17:58 -04:00
|
|
|
app.controller "UpdateForm", ($scope, $http, Institutions)->
|
2014-06-16 09:49:35 -04:00
|
|
|
$scope.institutions = []
|
2014-06-16 11:14:58 -04:00
|
|
|
$scope.formVisable = false
|
2014-06-12 12:15:54 -04:00
|
|
|
$scope.hidePersonalInfoSection = true
|
2014-06-16 11:14:58 -04:00
|
|
|
$scope.roles = ["Student", "Post-graduate student", "Post-doctoral researcher", "Lecturer", "Proffessor"]
|
2014-06-11 12:45:09 -04:00
|
|
|
|
2014-06-12 12:15:54 -04:00
|
|
|
$http.get("/user/personal_info").success (data)->
|
2014-06-16 11:14:58 -04:00
|
|
|
$scope.userInfoForm =
|
2014-06-12 12:15:54 -04:00
|
|
|
first_name: data.first_name
|
|
|
|
last_name: data.last_name
|
|
|
|
role: data.role
|
|
|
|
institution: data.institution
|
|
|
|
_csrf : window.csrfToken
|
2014-06-11 12:45:09 -04:00
|
|
|
|
2014-06-12 12:15:54 -04:00
|
|
|
if getPercentComplete() != 100
|
2014-06-12 10:50:00 -04:00
|
|
|
$scope.percentComplete = getPercentComplete()
|
2014-06-12 12:15:54 -04:00
|
|
|
$scope.hidePersonalInfoSection = false
|
|
|
|
|
2014-06-16 11:14:58 -04:00
|
|
|
$scope.showForm = ->
|
|
|
|
$scope.formVisable = true
|
|
|
|
|
2014-06-12 12:15:54 -04:00
|
|
|
$scope.sendUpdate = ->
|
|
|
|
request = $http.post "/user/personal_info", $scope.userInfoForm
|
|
|
|
request.success (data, status)->
|
|
|
|
request.error (data, status)->
|
|
|
|
console.log "the request failed"
|
|
|
|
$scope.percentComplete = getPercentComplete()
|
2014-06-12 05:23:42 -04:00
|
|
|
|
2014-06-12 12:15:54 -04:00
|
|
|
getPercentComplete = ->
|
|
|
|
results = _.filter $scope.userInfoForm, (value)-> value? and value?.length != 0
|
|
|
|
results.length * 20
|
2014-06-12 10:50:00 -04:00
|
|
|
|
2014-06-16 09:49:35 -04:00
|
|
|
$scope.updateInstitutionsList = (a)->
|
2014-06-13 12:17:58 -04:00
|
|
|
Institutions.search $scope.userInfoForm.institution, (err, response)->
|
2014-06-16 09:49:35 -04:00
|
|
|
$scope.institutions = _.pluck response.hits, "name"
|
2014-06-13 12:17:58 -04:00
|
|
|
|
2014-06-16 11:14:58 -04:00
|
|
|
|
|
|
|
|
2014-06-12 12:15:54 -04:00
|
|
|
angular.bootstrap(document.getElementById("userProfileInformation"), ['userProfileInformationApp'])
|
2014-06-12 05:23:42 -04:00
|
|
|
|