Files
habitica/public/js/controllers/userCtrl.js
2013-11-19 11:22:41 +11:00

30 lines
910 B
JavaScript

"use strict";
habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http',
function($rootScope, $scope, $location, User, $http) {
$scope.profile = User.user;
$scope.hideUserAvatar = function() {
$(".userAvatar").hide();
};
$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)
var curVal = $scope.profile.profile[key];
if(!curVal || $scope.editingProfile[key].toString() !== curVal.toString())
values['profile.' + key] = value;
});
User.setMultiple(values);
$scope._editing.profile = false;
}
$scope.unlock = User.unlock;
}
]);