2013-09-08 16:28:06 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
2013-10-22 19:19:43 +00:00
|
|
|
habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http',
|
|
|
|
|
function($rootScope, $scope, $location, User, $http) {
|
|
|
|
|
$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
|
|
|
|
2013-10-22 19:19:43 +00:00
|
|
|
$scope.$watch('_editing.profile', function(value){
|
|
|
|
|
if(value === true) $scope.editingProfile = angular.copy(User.user.profile);
|
2013-10-13 18:47:59 +00:00
|
|
|
});
|
|
|
|
|
|
2013-10-22 19:19:43 +00:00
|
|
|
$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(){
|
|
|
|
|
if (!$scope.editingProfile.websites) $scope.editingProfile.websites = [];
|
|
|
|
|
$scope.editingProfile.websites.push($scope._newWebsite);
|
|
|
|
|
$scope._newWebsite = '';
|
|
|
|
|
}
|
|
|
|
|
$scope.removeWebsite = function($index){
|
|
|
|
|
$scope.editingProfile.websites.splice($index,1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For gem-unlockable preferences, (a) if owned, select preference (b) else, purchase
|
|
|
|
|
* @param path: User.preferences <-> User.purchased maps like User.preferences.skin=abc <-> User.purchased.skin.abc. Pass in this paramater as "skin.abc"
|
|
|
|
|
*/
|
|
|
|
|
$scope.unlock = function(path){
|
|
|
|
|
if (window.habitrpgShared.helpers.dotGet('purchased.' + path, User.user)) {
|
|
|
|
|
var pref = path.split('.')[0],
|
|
|
|
|
val = path.split('.')[1];
|
|
|
|
|
window.habitrpgShared.helpers.dotSet('preferences.' + pref, val, User.user);
|
|
|
|
|
} else {
|
|
|
|
|
if (confirm("Purchase for 2 Gems?") !== true) return;
|
2013-10-22 20:37:55 +00:00
|
|
|
if (User.user.balance < 0.5) return $rootScope.modals.buyGems = true;
|
2013-10-22 19:19:43 +00:00
|
|
|
User.unlock(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-08 16:28:06 +00:00
|
|
|
}
|
2013-10-22 19:19:43 +00:00
|
|
|
]);
|