mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 19:50:37 +00:00
profile edits saved only on click
This commit is contained in:
parent
4e56df0e82
commit
68426c7ccb
2 changed files with 23 additions and 10 deletions
|
|
@ -9,14 +9,27 @@ habitrpg.controller("UserCtrl", ['$scope', '$location', 'User',
|
|||
$scope.toggleHelm = function(val){
|
||||
User.log({op:'set', data:{'preferences.showHelm':val}});
|
||||
}
|
||||
|
||||
$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(){
|
||||
if (!User.user.profile.websites) User.user.profile.websites = [];
|
||||
User.user.profile.websites.push($scope._newWebsite);
|
||||
User.set('profile.websites', User.user.profile.websites);
|
||||
if (!$scope.editingProfile.websites) $scope.editingProfile.websites = [];
|
||||
$scope.editingProfile.websites.push($scope._newWebsite);
|
||||
$scope._newWebsite = '';
|
||||
}
|
||||
$scope.removeWebsite = function($index){
|
||||
User.user.profile.websites.splice($index,1);
|
||||
User.set('profile.websites', User.user.profile.websites);
|
||||
$scope.editingProfile.websites.splice($index,1);
|
||||
}
|
||||
}]);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
// ------- Edit -------
|
||||
.span4
|
||||
button.btn.btn-default(ng-click='_editing.profile = true', ng-show='!_editing.profile') Edit
|
||||
button.btn.btn-primary(ng-click='_editing.profile = false', ng-show='_editing.profile') Save
|
||||
button.btn.btn-primary(ng-click='save()', ng-show='_editing.profile') Save
|
||||
div(ng-show='!_editing.profile')
|
||||
h4 Display Name
|
||||
span(ng-show='profile.profile.name') {{profile.profile.name}}
|
||||
|
|
@ -68,13 +68,13 @@
|
|||
// TODO use photo-upload instead: https://groups.google.com/forum/?fromgroups=#!topic/derbyjs/xMmADvxBOak
|
||||
.control-group.option-large
|
||||
label.control-label Display Name
|
||||
input.option-content(type='text', placeholder='Full Name', ng-model='user.profile.name', ng-blur='set("profile.name", user.profile.name)', )
|
||||
input.option-content(type='text', placeholder='Full Name', ng-model='editingProfile.name')
|
||||
.control-group.option-large
|
||||
label.control-label Photo Url
|
||||
input.option-content(type='url', ng-model='user.profile.imageUrl', placeholder='Image Url', ng-blur='set("profile.imageUrl", user.profile.imageUrl)')
|
||||
input.option-content(type='url', ng-model='editingProfile.imageUrl', placeholder='Image Url')
|
||||
.control-group.option-large
|
||||
label.control-label Blurb
|
||||
textarea.option-content(style='height:15em;', placeholder='Blurb', ng-model='user.profile.blurb', ng-blur='set("profile.blurb", user.profile.blurb)')
|
||||
textarea.option-content(style='height:15em;', placeholder='Blurb', ng-model='editingProfile.blurb')
|
||||
include ../shared/formatting-help
|
||||
.control-group.option-large
|
||||
label.control-label Websites
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
input.option-content(type='url', ng-model='_newWebsite', placeholder='Add Website')
|
||||
ul
|
||||
// would prefer if there were and index in #each, instead using data-website to search with indexOf
|
||||
li(ng-repeat='website in user.profile.websites')
|
||||
li(ng-repeat='website in editingProfile.websites')
|
||||
| {{website}}
|
||||
a(ng-click='removeWebsite($index)')
|
||||
i.icon-remove
|
||||
|
|
|
|||
Loading…
Reference in a new issue