fix(i18n): signup, clone default tasks

This commit is contained in:
Matteo Pagliazzi 2014-05-14 20:01:31 +02:00
parent 35ef88c6c0
commit a38f2354f5

View file

@ -355,22 +355,21 @@ UserSchema.pre('save', function(next) {
var self = this;
_.each(['habits', 'dailys', 'todos', 'rewards', 'tags'], function(taskType){
self[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
var newTask = task;
var newTask = _.cloneDeep(task);
// Render task's text and notes in user's language
if(taskType === 'tags'){
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
newTask.id = shared.uuid();
newTask.name = task.name(self.preferences.language);
newTask.name = newTask.name(self.preferences.language);
}else{
newTask.text = task.text(self.preferences.language);
newTask.notes = task.notes(self.preferences.language);
newTask.text = newTask.text(self.preferences.language);
newTask.notes = newTask.notes(self.preferences.language);
if(newTask.checklist){
newTask.checklist = _.map(newTask.checklist, function(checklistItem){
var newChecklistItem = checklistItem;
newChecklistItem.text = checklistItem.text(self.preferences.language);
return newChecklistItem;
checklistItem.text = checklistItem.text(self.preferences.language);
return checklistItem;
});
}
}