Added client side for generating preferences for new user

This commit is contained in:
Kenneth Jao 2016-08-30 23:29:27 -04:00
parent 30c024a884
commit 21435b5866
4 changed files with 21 additions and 11 deletions

View File

@ -22,15 +22,6 @@ var workColors = {
"other": "#852E6D" "other": "#852E6D"
}; };
// Sets defaults for new users
var defaults = {
"theme":"light",
"mode":"classes",
"timeHide":1,
"done": true
};
//Creates variables for due dates //Creates variables for due dates
var ref = { var ref = {
@ -56,10 +47,12 @@ Session.set("classDispHover",null); // Stores current hovered filter.
Session.set("commentRestrict",null); // Stores text for comment character restriction. Session.set("commentRestrict",null); // Stores text for comment character restriction.
Template.registerHelper('divColor', (div) => { // Reactive color changing based on preferences. Colors stored in themeColors. Template.registerHelper('divColor', (div) => { // Reactive color changing based on preferences. Colors stored in themeColors.
if(Meteor.user().profile.preferences === undefined) return;
return themeColors[Meteor.user().profile.preferences.theme][div]; return themeColors[Meteor.user().profile.preferences.theme][div];
}); });
Template.registerHelper('textColor', () => { // Reactive color for text. Template.registerHelper('textColor', () => { // Reactive color for text.
if(Meteor.user().profile.preferences === undefined) return;
document.getElementsByTagName("body")[0].style.color = themeColors[Meteor.user().profile.preferences.theme].text; document.getElementsByTagName("body")[0].style.color = themeColors[Meteor.user().profile.preferences.theme].text;
return; return;
}); });
@ -153,6 +146,7 @@ Template.registerHelper('myClasses', () => { // Gets all classes and respective
}); });
Template.registerHelper('pref', (val) => { // Obtains all user preferences. Template.registerHelper('pref', (val) => { // Obtains all user preferences.
if(Meteor.user().profile.preferences === undefined) return;
if(Object.keys(Meteor.user().profile.preferences).length !== Object.keys(defaults).length) { // Invalid preference checking. if(Object.keys(Meteor.user().profile.preferences).length !== Object.keys(defaults).length) { // Invalid preference checking.
var array = Meteor.user().profile; var array = Meteor.user().profile;
array.preferences = defaults; array.preferences = defaults;

View File

@ -1,5 +1,5 @@
<template name="profile"> <template name="profile">
<div id="profPage" style="background-color:{{divColor 'header'}};height:{{mainHeight}};{{textColor}}"> <div id="profPage" style="background-color:{{divColor 'header'}};height:{{mainHeight}};{{textColor}}{{loadNew}}">
<div id="mainpage" onclick="window.location='/'"><h2>Main Page</h2></div> <div id="mainpage" onclick="window.location='/'"><h2>Main Page</h2></div>
<div id="profMainContainer" style="{{mainCenter}}"> <div id="profMainContainer" style="{{mainCenter}}">
<div id="profBanner" style="{{banner}};"></div> <div id="profBanner" style="{{banner}};"></div>

View File

@ -58,6 +58,15 @@ Template.profile.helpers({
}] }]
}; };
}, },
loadNew() {
if(Meteor.user().profile.preferences === undefined) {
var profile = Meteor.user().profile;
profile.preferences = defaults;
serverData = profile;
sendData("editProfile");
}
return;
},
mainCenter() { // Centers main div container. mainCenter() { // Centers main div container.
var width = window.innerWidth * 1600 / 1920 + 10; var width = window.innerWidth * 1600 / 1920 + 10;
return "width:" + width.toString() + "px;margin-left:" + -0.5 * width.toString() + "px"; return "width:" + width.toString() + "px;margin-left:" + -0.5 * width.toString() + "px";

View File

@ -26,4 +26,11 @@ themeColors = {
} }
}; };
defaults = {
"theme":"light",
"mode":"classes",
"timeHide":1,
"done": true
};
serverData = null; serverData = null;