Commit d9110f34 authored by Curtis Adam's avatar Curtis Adam

Move the language setting to the user page and save it inside the database

parent c24a944b
......@@ -305,7 +305,8 @@
"delete": "Benutzerkonto löschen",
"deleteText": "Falls du sicher bist, dass du THMcards nicht weiter verwenden möchtest, kannst du hier dein Benutzerkonto löschen.",
"appearance": "Erscheinungsbild",
"theme": "Farbauswahl"
"theme": "Farbauswahl",
"language": "Sprache"
}
},
"profil-header": {
......@@ -1045,5 +1046,9 @@
"language": "Wähle eine Sprache",
"info": "Über THMcards",
"connection": "Verbindungsstatus"
},
"language": {
"german": "Deutsch",
"english": "Englisch"
}
}
......@@ -316,7 +316,8 @@
"delete": "Delete user profile",
"deleteText": "If you do not think you will use THMcards again, you can delete here your user profile.",
"appearance": "Appearance",
"theme": "Color theme"
"theme": "Color theme",
"language": "Language"
}
},
"profil-header": {
......@@ -1079,5 +1080,9 @@
"language": "Choose a language",
"info": "About THMcards",
"connection": "Connection Status"
},
"language": {
"german": "German",
"english": "English"
}
}
......@@ -25,6 +25,7 @@ if (Meteor.isServer) {
'customerId': 1,
'blockedtext': 1,
"selectedColorTheme": "default",
"selectedLanguage": 1,
"mailNotification": 1,
"webNotification": 1
}
......@@ -53,7 +54,8 @@ if (Meteor.isServer) {
'daysInRow': 1,
'balance': 1,
"mailNotification": 1,
"webNotification": 1
"webNotification": 1,
"selectedLanguage": 1
}
});
} else {
......@@ -339,6 +341,20 @@ Meteor.methods({
Roles.removeUsersFromRoles(Meteor.user()._id, 'firstLogin');
},
/** Function saves the given language to the given user
* @param {string} selectedLanguage - The id of the selected language
* @param {string} id - The id of the user
* */
updateLanguage: function (selectedLanguage, id) {
check(selectedLanguage, String);
check(id, String);
Meteor.users.update(id, {
$set: {
"selectedLanguage": selectedLanguage
}
});
},
/** Function saves the given colorTheme to the given user
* @param {string} selectedColorTheme - The id of the selected color theme
* @param {string} id - The id of the user
......
import {Session} from "meteor/session";
import {Meteor} from "meteor/meteor";
//------------------------ GET LANGUAGE FROM USER
getUserLanguage = function () {
return navigator.language.substr(0, 2);
};
export function getUserLanguage() {
if (Meteor.userId()) {
let language = Meteor.users.findOne(Meteor.userId()).selectedLanguage;
if (language !== undefined) {
return language;
} else {
let navigatorLanguage = navigator.language.substr(0, 2);
switch (navigatorLanguage) {
case "de":
Meteor.call("updateLanguage", "de", Meteor.userId());
return "de";
default:
Meteor.call("updateLanguage", "en", Meteor.userId());
return "en";
}
}
} else {
return navigator.language.substr(0, 2);
}
}
//------------------------ LOADING I18N
......
......@@ -287,6 +287,18 @@
class="btn btn-success btn-raised btn-block col-xs-12 col-sm-3 pull-right">{{_
"profile.save"}}</button>
{{/unless}}
<div class="form-group">
<label for="sel2">{{_ "profile.settings.language"}}:</label>
<select class="form-control" id="languageSelect">
<option {{getSelectedLanguage "en"}} value="en">{{_ "language.english"}}</option>
<option {{getSelectedLanguage "de"}} value="de">{{_ "language.german"}}</option>
</select>
</div>
{{#unless isDisabledSaveLanguage}}
<button id="languageSave" type="button"
class="btn btn-success btn-raised btn-block col-xs-12 col-sm-3 pull-right">{{_
"profile.save"}}</button>
{{/unless}}
</div>
</div>
<div class="panel panel-default">
......@@ -632,7 +644,8 @@
{{#each getInvoices}}
<a href="/cardset/{{cardset_id}}" class="list-group-item">
<h4 class="list-group-item-heading">{{getCardsetName cardset_id}}</h4>
<p class="list-group-item-text">{{_ "billing.purchases.boughtFor"}} {{getPrice amount}} {{_
<p class="list-group-item-text">{{_ "billing.purchases.boughtFor"}} {{getPrice
amount}} {{_
"billing.purchases.at"}} {{getDate}}</p>
</a>
{{/each}}
......
......@@ -107,6 +107,12 @@ Template.profileSettings.helpers({
return "selected";
}
},
/** Function returns "selected" when the value of the selectedLanguage and the input _id are the same */
getSelectedLanguage: function (id) {
if (id === Meteor.users.findOne(Meteor.userId()).selectedLanguage) {
return "selected";
}
},
getMailNotifications: function () {
if (Meteor.users.findOne(Meteor.userId()).mailNotification) {
return "checked";
......@@ -125,6 +131,9 @@ Template.profileSettings.helpers({
},
isDisabledSaveTheme: function () {
return Session.get("themeSettings");
},
isDisabledSaveLanguage: function () {
return Session.get("languageSettings");
}
});
......@@ -132,12 +141,14 @@ Template.profileSettings.helpers({
Template.profileSettings.onDestroyed(function () {
// Go back to last saved Theme
Session.set("theme", Meteor.users.findOne(Meteor.userId()).selectedColorTheme);
Session.set("language", Meteor.users.findOne(Meteor.userId()).selectedLanguage);
});
Template.profileSettings.onCreated(function () {
Session.set("profileSettingsCancel", true);
Session.set("profileSettingsSave", true);
Session.set("themeSettings", true);
Session.set("languageSettings", true);
});
Template.profileSettings.events({
......@@ -231,20 +242,38 @@ Template.profileSettings.events({
},
/** Function evaluates the currently selected color theme of the input box and saves it to the database */
"click #colorThemeSave": function () {
var selected = $('#colorThemeSelect').val();
var user_id = Meteor.userId();
let selected = $('#colorThemeSelect').val();
let user_id = Meteor.userId();
Session.set("themeSettings", true);
Meteor.call("updateColorTheme", selected, user_id);
Bert.alert(TAPi18n.__('profile.saved'), 'success', 'growl-top-left');
},
/** Function evaluates the currently selected language of the input box and saves it to the database */
"click #languageSave": function () {
let selected = $('#languageSelect').val();
let user_id = Meteor.userId();
Session.set("languageSettings", true);
Meteor.call("updateLanguage", selected, user_id);
TAPi18n.setLanguage(selected);
Session.set('activeLanguage', selected);
Bert.alert(TAPi18n.__('profile.saved'), 'success', 'growl-top-left');
},
/** Function changes the temporary color theme when the input box changes its value */
"change #colorThemeSelect": function () {
var selected = $('#colorThemeSelect').val();
let selected = $('#colorThemeSelect').val();
Session.set("themeSettings", false);
// Set session variable. Will be reset to value from mongoDB when template is destroyed
Session.set("theme", selected);
},
/** Function changes the temporary language when the input box changes its value */
"change #languageSelect": function () {
let selected = $('#languageSelect').val();
Session.set("languageSettings", false);
// Set session variable. Will be reset to value from mongoDB when template is destroyed
Session.set("language", selected);
},
"click #profileSave": function () {
// Email validation
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
......
......@@ -4,10 +4,18 @@ import {Meteor} from "meteor/meteor";
import {Template} from "meteor/templating";
import WordCloud from "wordcloud";
import {Cloud} from "../../api/cloud.js";
import {getUserLanguage} from "../../startup/client/i18n";
import "./welcome.html";
import {Session} from "meteor/session";
Meteor.subscribe("wordcloud");
function setActiveLanguage() {
let language = getUserLanguage();
TAPi18n.setLanguage(language);
Session.set('activeLanguage', language);
}
/**
* This method nserts a hover message for the wordcloud content
* @param {Object} item - Array containing data of the wordcloud object (name, description, kind and color)
......@@ -79,6 +87,8 @@ Template.welcome.events({
Meteor.loginWithFacebook({}, function (err) {
if (err) {
throw new Meteor.Error("Facebook login failed");
} else {
setActiveLanguage();
}
});
},
......@@ -87,6 +97,8 @@ Template.welcome.events({
Meteor.loginWithTwitter({}, function (err) {
if (err) {
throw new Meteor.Error("Twitter login failed");
} else {
setActiveLanguage();
}
});
},
......@@ -95,14 +107,18 @@ Template.welcome.events({
Meteor.loginWithGoogle({}, function (err) {
if (err) {
throw new Meteor.Error("Google login failed");
} else {
setActiveLanguage();
}
});
},
'click #cas': function () {
Meteor.loginWithCas({}, function (err) {
Meteor.loginWithCas(function (err) {
if (err) {
throw new Meteor.Error("CAS login failed");
} else {
setActiveLanguage();
}
});
},
......@@ -110,7 +126,11 @@ Template.welcome.events({
// Backdoor for login in acceptance tests
'click #BackdoorLogin': function () {
if (Meteor.settings.public.displayLoginButtons.displayTestingBackdoor) {
Meteor.insecureUserLogin($("#TestingBackdoorUsername").val());
Meteor.insecureUserLogin($("#TestingBackdoorUsername").val(), function (err, result) {
if (result) {
setActiveLanguage();
}
});
}
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment