habitica/public/js/controllers/userCtrl.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
habitrpg.controller("UserCtrl", ['$scope', '$location', 'User',
function($scope, $location, User) {
$scope.profile = User.user;
$scope.hideUserAvatar = function() {
$(".userAvatar").hide();
};
$scope.toggleHelm = function(val){
User.log({op:'set', data:{'preferences.showHelm':val}});
}
2013-10-13 18:47:59 +00:00
$scope.$watch('_editing.profile', function(value){
if(value === true) $scope.editingProfile = angular.copy(User.user.profile);
});
$scope.save = function(){
var values = {};
_.each($scope.editingProfile, function(value, key){
// Using toString because we need to compare two arrays (websites)
if($scope.editingProfile[key].toString() !== $scope.profile.profile[key].toString()) values['profile.' + key] = value;
});
User.setMultiple(values);
$scope._editing.profile = false;
}
$scope.addWebsite = function(){
2013-10-13 18:47:59 +00:00
if (!$scope.editingProfile.websites) $scope.editingProfile.websites = [];
$scope.editingProfile.websites.push($scope._newWebsite);
$scope._newWebsite = '';
}
$scope.removeWebsite = function($index){
2013-10-13 18:47:59 +00:00
$scope.editingProfile.websites.splice($index,1);
}
}]);