From 073db86deb7795646acb4ca8f88fc087325b5ae0 Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sun, 28 Aug 2016 14:36:26 -0400 Subject: [PATCH] Added preferences to profile --- hourglass/client/main/main.js | 29 +++++++------- hourglass/client/profile/profile.css | 10 +++++ hourglass/client/profile/profile.html | 56 +++++++++++++++++++++++---- hourglass/client/profile/profile.js | 40 +++++++++---------- 4 files changed, 93 insertions(+), 42 deletions(-) diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index 2cf438b..0a20f58 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -169,6 +169,21 @@ Template.registerHelper('myClasses', () => { } }); +Template.registerHelper('pref', (val) => { + if(Object.keys(Meteor.user().profile.preferences).length !== Object.keys(defaults).length) { + var array = Meteor.user().profile; + array.preferences = defaults; + Session.set("serverData",array); + sendData("editProfile"); + if(val === 'timeHide') return defaults[val]; + return defaults[val].charAt(0).toUpperCase() + defaults[val].slice(1); + } else { + var preferences = Meteor.user().profile.preferences; + if(val === 'timeHide') return preferences[val]; + return preferences[val].charAt(0).toUpperCase() + preferences[val].slice(1); + } +}); + Template.main.helpers({ schoolName() { return " - " + Meteor.user().profile.school; @@ -401,20 +416,6 @@ Template.main.helpers({ currClass.banned.indexOf(Meteor.userId()) !== -1 ) return true; } - }, - pref(val) { - if(Object.keys(Meteor.user().profile.preferences).length !== Object.keys(defaults).length) { - var array = Meteor.user().profile; - array.preferences = defaults; - Session.set("serverData",array); - sendData("editProfile"); - if(val === 'timeHide') return defaults[val]; - return defaults[val].charAt(0).toUpperCase() + defaults[val].slice(1); - } else { - var preferences = Meteor.user().profile.preferences; - if(val === 'timeHide') return preferences[val]; - return preferences[val].charAt(0).toUpperCase() + preferences[val].slice(1); - } } }); diff --git a/hourglass/client/profile/profile.css b/hourglass/client/profile/profile.css index 2c42106..86f04d8 100644 --- a/hourglass/client/profile/profile.css +++ b/hourglass/client/profile/profile.css @@ -660,4 +660,14 @@ #privSubmit:hover { background-color: rgba(0,0,0,0.1); +} + +#profPreferences { + width: 30%; + float: left; + border-top: 5px solid #409333; +} + +#preferences { + padding: 5%; } \ No newline at end of file diff --git a/hourglass/client/profile/profile.html b/hourglass/client/profile/profile.html index c2bf901..6ff6fec 100644 --- a/hourglass/client/profile/profile.html +++ b/hourglass/client/profile/profile.html @@ -19,7 +19,7 @@

Grade:

- {{grade}} + {{grade}}

9th

@@ -117,19 +117,19 @@

Privacy:

- +
-

Public

-

Private

+

Public

+

Private

Category:

- +
-

Class

-

Club

-

Other

+

Class

+

Club

+

Other

@@ -139,6 +139,46 @@ +
+

Preferences

+
+
+
+

Theme:

+ {{pref 'theme'}} +
+
+

Light

+

Dark

+
+
+
+
+
+

Default Mode:

+ {{pref 'mode'}} +
+
+

Classes

+

Calendar

+
+
+
+
+
+

Hide Homework:

+ {{pref 'timeHide'}} +
+
+

1 Day

+

2 Days

+

1 Week

+

1 Month

+

Never

+
+
+
+
diff --git a/hourglass/client/profile/profile.js b/hourglass/client/profile/profile.js index 328a7ea..e44b731 100644 --- a/hourglass/client/profile/profile.js +++ b/hourglass/client/profile/profile.js @@ -7,7 +7,6 @@ Session.set("profInputOpen", null); Session.set("profClassTab", "manClass"); Session.set("modifying", null); -Session.set("radioDiv", null); Session.set("notsearching", true); Session.set("confirm", null); Session.set("serverData", null); @@ -268,17 +267,13 @@ Template.profile.events({ closeInput(sessval); } if (!event.target.className.includes("radio") && - !Session.equals("radioDiv", null) && !event.target.parentNode.className.includes("profOptions") && - event.target.readOnly !== true) { - var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString(); + event.target.readOnly !== true) { for (var i = 0; i < document.getElementsByClassName("profOptions").length; i++) { try { closeDivFade(document.getElementsByClassName("profOptions")[i]); } catch (err) {} } - Session.set("radioDiv", null); - Session.set("radioOffset", null); } if(!document.getElementById("createdClasses").contains(event.target) && Session.get("code") !== null && @@ -328,23 +323,30 @@ Template.profile.events({ }, 'click .radio' (event) { // Click on an input that has a drop-down menu var op = event.target; - Session.set("radioDiv", op.getAttribute("op")); - Session.set("radioOffset", op.getAttribute("opc")); try { for (var i = 0; i < document.getElementsByClassName("profOptions").length; i++) { var curr = document.getElementsByClassName("profOptions")[i]; - if (Session.get("radioDiv") !== i.toString()) { + if (curr.childNodes[1] !== op.nextSibling.nextSibling.childNodes[1] + && curr.childNodes[1] !== op.parentNode.parentNode.childNodes[3].childNodes[1]) { closeDivFade(document.getElementsByClassName("profOptions")[i]); } } } catch (err) {} - openDivFade(document.getElementsByClassName("profOptions")[op.getAttribute("op")]); + + if(event.target.className.includes("op")) { + openDivFade(op.nextSibling.nextSibling); + } else { + openDivFade(op.parentNode.parentNode.childNodes[3]); + } }, 'click .profOptionText' (event) { // When someone selects "drop-down item" var sessval = Session.get("modifying"); var p = event.target; - var opnum = parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset")); - var input = document.getElementsByClassName("op")[opnum]; + if(p.className.includes("cre")) { + var input = p.parentNode.parentNode.childNodes[3] + } else { + var input = p.parentNode.parentNode.childNodes[1].childNodes[5]; + } input.value = p.childNodes[0].nodeValue; try { closeInput(sessval); @@ -352,8 +354,6 @@ Template.profile.events({ closeDivFade(p.parentNode); input.focus(); - Session.set("radioDiv", null); - Session.set("radioOffset", null); }, 'click .addClass' () {         var functionHolder = document.getElementById("profClassInfoHolder"); @@ -568,11 +568,7 @@ Template.profile.events({ }); function openDivFade(div) { - if (div.className === "profOptions") { - div.style.display = "inline-block"; - } else { - div.style.display = "block"; - } + div.style.display = "block"; div.style.opacity = "0"; setTimeout(function() { div.style.opacity = "1"; @@ -617,7 +613,11 @@ function getProfileData() { profile.grade = parseInt(gradein.substring(gradein.length - 2, gradein)); profile.avatar = document.getElementById("profAvatar").style.backgroundImage.replace(")", "").replace("url(", "").replace("\"", "").replace("\"", ""); profile.banner = document.getElementById("profBanner").style.backgroundImage.replace(")", "").replace("url(", "").replace("\"", "").replace("\"", ""); - profile.preferences = Meteor.user().profile.preferences; + profile.preferences = { + "theme":document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(), + "mode":document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(), + "timeHide":document.getElementById("prefHide").childNodes[0].nodeValue + }; return profile; }