725 lines
29 KiB
JavaScript
Raw Normal View History

/* jshint esversion: 6 */
import {
2016-08-12 12:28:55 -04:00
Template
} from 'meteor/templating';
2016-09-12 11:12:06 -04:00
var openValues = {
"owned": "-540px",
"priv": "-160px"
};
confirm = null; // Sets function to execute after confirmation click.
2016-08-25 22:35:44 -04:00
// Sets up global variables
Session.set("profClassTab", "manClass"); // Set default classes card mode to 'Manage Classes.'
2016-10-01 16:09:58 -04:00
Session.set("owned", false); // Status of createdClasses.
Session.set("privClass", false); //Status of joinPrivClass.
Session.set("modifying", null); // Stores current open input.
Session.set("notsearching", true); // If user is searching in search box.
Session.set("autocompleteDivs", null); // Stores returned autocomplete results.
Session.set("confirmText", null); // Stores text for different confirmation functions.
2016-10-01 16:09:58 -04:00
Session.set("selectedClass", null); // Stores selected owned class info.
Session.set("code", null); // If owned class has a code.
Session.set("noclass", null); // If user doesn't have classes.
Session.set("notfound", null); // If no results for autocomplete.
Template.profile.helpers({
2016-09-29 23:39:34 -04:00
themeName() {
var vals = _.values(themeColors);
var curtheme = Session.get("user").preferences.theme;
2016-10-01 16:09:58 -04:00
for (var i = 0; i < vals.length; i++) {
2016-09-29 23:39:34 -04:00
if (_.isEqual(vals[i], curtheme)) {
var name = _.keys(themeColors)[i];
return name.charAt(0).toUpperCase() + name.slice(1);
}
}
return "Custom";
},
classSettings() { // Returns autocomplete array for classes.
2016-08-12 12:28:55 -04:00
return {
position: "bottom",
limit: 10,
rules: [{
token: '',
collection: classes,
field: "name",
template: Template.classDisplay,
filter: {
2016-08-12 16:12:03 -04:00
privacy: false,
2016-08-12 12:28:55 -04:00
status: true
}
}]
};
},
schoolComplete() { // Returns autocomplete array for schools.
2016-08-12 12:28:55 -04:00
return {
position: "bottom",
limit: 6,
rules: [{
token: '',
collection: schools,
field: 'name',
matchAll: true,
2016-09-02 00:53:12 -04:00
template: Template.schoolList
2016-08-12 12:28:55 -04:00
}]
};
},
teacherComplete() { // Returns autocomplete array for teachers.
2016-08-12 12:28:55 -04:00
return {
position: "bottom",
limit: 1,
rules: [{
token: '',
collection: classes,
field: 'teacher',
2016-09-02 00:53:12 -04:00
template: Template.teacherList
2016-08-12 12:28:55 -04:00
}]
};
},
banner() { // Returns banner
return Session.get("user").banner;
2016-08-12 12:28:55 -04:00
},
avatar() { // Returns avatar
2016-09-17 21:35:51 -04:00
return Meteor.user().services.google.picture;
2016-08-12 12:28:55 -04:00
},
2016-10-01 16:09:58 -04:00
username() { //Returns current user's username
return Session.get("user").name;
2016-08-12 12:28:55 -04:00
},
motd() { // Returns the current user's description
2016-09-29 23:39:34 -04:00
if (Session.get("user").description !== undefined && Session.get("user").description !== null && Session.get("user").description !== "") return Session.get("user").description;
2016-09-12 11:12:06 -04:00
return "Say something about yourself!";
2016-08-12 12:28:55 -04:00
},
school() { // Returns the current user's school's name
if (!_.contains([null, undefined, ""], Session.get("user").school)) return Session.get("user").school;
2016-09-12 11:12:06 -04:00
return "Click here to edit...";
2016-08-12 12:28:55 -04:00
},
grade() { // Returns the current user's grade
2016-09-29 23:39:34 -04:00
if (Session.get("user").grade !== undefined && Session.get("user").grade !== null && Session.get("user").grade !== "") return Session.get("user").grade + "th";
2016-09-12 11:12:06 -04:00
return "Click here to edit...";
2016-08-12 12:28:55 -04:00
},
classes() { // Loads all of the possible classes ( Limit of twenty shown ) ( Sorts by class size )
2016-10-01 16:09:58 -04:00
var array = classes.find({
status: {
$eq: true
},
privacy: {
$eq: false
},
_id: {
$nin: Meteor.user().profile.classes
}
}, {
sort: {
subscribers: -1
}
}, {
limit: 20
}).fetch();
2016-10-01 16:09:58 -04:00
for (var i = 0; i < array.length; i++) {
array[i].subscribers = array[i].subscribers.length;
}
2016-10-01 16:09:58 -04:00
if (array.length === 0) {
Session.set("noclass", true);
} else {
2016-10-01 16:09:58 -04:00
Session.set("noclass", false);
}
return array;
2016-08-12 12:28:55 -04:00
},
2016-09-12 11:12:06 -04:00
ownedStatus() { // Status of createdClasses
2016-10-01 16:09:58 -04:00
if (!Session.get("owned")) return openValues.owned;
2016-09-12 11:12:06 -04:00
return "0px";
},
privStatus() {
2016-10-01 16:09:58 -04:00
if (!Session.get("privClass")) return openValues.priv;
2016-09-12 11:12:06 -04:00
return "0px";
},
2016-10-01 16:09:58 -04:00
profClassTabColor(status) {  // Change this [Supposed to show the current mode that's selected via color]    
if (Session.equals("profClassTab", status)) {
return Meteor.user().profile.preferences.theme.modeHighlight;
} else {
return;
}
},
2016-08-25 22:35:44 -04:00
profClassTab(tab) { // Tells current class
2016-10-01 16:09:58 -04:00
if (Session.equals("profClassTab", tab)) {
2016-08-12 12:28:55 -04:00
return true;
} else {
return false;
}
},
2016-08-25 22:35:44 -04:00
notsearching() { // Tells whether user is using the searchbox
2016-08-12 12:28:55 -04:00
return Session.get("notsearching");
},
2016-08-25 22:35:44 -04:00
autocompleteClasses() { // Returns current auto-completes for classes
2016-08-12 12:28:55 -04:00
return Session.get("autocompleteDivs");
},
notfound() { // Returns if autocomplete has no results.
2016-08-12 12:28:55 -04:00
return Session.get("notfound");
},
2016-10-01 16:09:58 -04:00
noclass() { // Returns if user has classes.
return Session.get("noclass");
},
confirmText() { // Returns respective text for different confirm functions.
2016-08-12 12:28:55 -04:00
return Session.get("confirmText");
},
selectedClass(val) { // Returns values for selectedClass
2016-10-01 16:09:58 -04:00
if (Session.equals("selectedClass", null)) return;
2016-09-07 01:12:30 -04:00
return Session.get("selectedClass")[val];
},
code() { // Returns if selected class has code.
return Session.get("code");
2016-08-12 12:28:55 -04:00
}
});
Template.profile.events({
2016-08-25 22:56:10 -04:00
'click' (event) { // Whenever a click happens
var modifyingInput = Session.get("modifying");
if (event.target.id !== modifyingInput &&
2016-10-01 16:09:58 -04:00
event.target.id !== modifyingInput + "a" &&
!Session.equals("modifying", null) &&
!event.target.parentNode.className.includes("profOptions")) {
closeInput(modifyingInput);
2016-08-12 12:28:55 -04:00
}
if (!event.target.className.includes("radio") &&
2016-10-01 16:09:58 -04:00
!event.target.parentNode.className.includes("profOptions") &&
event.target.readOnly !== true) {
2016-08-12 12:28:55 -04:00
for (var i = 0; i < document.getElementsByClassName("profOptions").length; i++) {
try {
closeDivFade(document.getElementsByClassName("profOptions")[i]);
} catch (err) {}
}
}
2016-10-01 16:09:58 -04:00
if (!document.getElementById("createdClasses").contains(event.target) &&
!Session.equals("code", null) &&
!event.target.className.includes("fa-times-circle-o")) {
Session.set("owned", false);
}
2016-10-01 16:09:58 -04:00
if (Session.get("changeAdmin") &&
!document.getElementById("changeAdmin").contains(event.target)) {
Session.set("changeAdmin", false);
var div = document.getElementById("changeAdmin");
div.removeChild(div.childNodes[3]);
div.removeChild(div.childNodes[3]);
}
2016-10-01 16:09:58 -04:00
if (Session.get("privClass") &&
!(event.target.id === "private") &&
!document.getElementById("joinPrivClass").contains(event.target)) {
Session.set("privClass", false);
}
2016-08-12 12:28:55 -04:00
},
// MAIN BUTTONS
2016-10-01 15:56:51 -04:00
'click #mainpage' () {
if (!Meteor.userId() || _.contains([null, undefined, ""], Meteor.user().profile.school)) {
2016-10-01 16:18:48 -04:00
sAlert.closeAll();
sAlert.error('Please fill in your profile!', {effect: 'stackslide', position: 'top'});
2016-10-01 15:56:51 -04:00
} else {
window.location = '/';
}
},
'click .addClass' () { 
2016-10-01 16:09:58 -04:00
if (Session.equals("profClassTab", "addClass")) return;         
var functionHolder = document.getElementById("profClassInfoHolder");
closeDivFade(functionHolder);
var div = document.getElementById("profClasses");
div.style.height = "50%";
setTimeout(function() {            
Session.set("profClassTab", "addClass");
div.style.height = "90%";          
openDivFade(functionHolder);        
}, 400);
},
    'click .manageClass' () { 
if (Session.equals("profClassTab", "manClass")) return;      
var functionHolder = document.getElementById("profClassInfoHolder");
closeDivFade(functionHolder);
var div = document.getElementById("profClasses");
div.style.height = "50%";     
setTimeout(function() {            
Session.set("profClassTab", "manClass"); 
div.style.height = "90%";           
openDivFade(functionHolder);        
}, 400);
},
    'click .createClass' () {
if (Session.equals("profClassTab", "creClass")) return;
var functionHolder = document.getElementById("profClassInfoHolder");        
closeDivFade(functionHolder);
2016-10-01 16:09:58 -04:00
var div = document.getElementById("profClasses");
div.style.height = "50%";
2016-09-06 19:52:37 -04:00
setTimeout(function() {
Session.set("profClassTab", "creClass");
div.style.height = "90%";
2016-09-06 19:52:37 -04:00
openDivFade(functionHolder);
}, 400);
2016-08-12 12:28:55 -04:00
},
2016-10-01 16:09:58 -04:00
'click .classBox' (event) { // When you click on a box that holds class
if (event.target.id === "label" ||
Session.equals("profClassTab", "manClass") ||
2016-08-23 22:09:07 -04:00
event.target.className.includes("fa-times")) return;
2016-08-12 12:28:55 -04:00
if (event.target.className !== "classBox") {
var attribute = event.target.parentNode.getAttribute("classid");
} else {
var attribute = event.target.getAttribute("classid");
}
var data = [attribute, ""];
2016-08-29 21:02:02 -04:00
serverData = data;
confirm = "joinClass";
2016-08-12 12:28:55 -04:00
Session.set("confirmText", "Join class?");
2016-08-12 12:28:55 -04:00
openDivFade(document.getElementsByClassName("overlay")[0]);
setTimeout(function() {
document.getElementsByClassName("overlay")[0].style.opacity = "1";
}, 200);
},
'click .owned' (event) { // When you click your own class
if (event.target.id === "label") return;
if (!event.target.className.includes("owned")) {
var attribute = event.target.parentNode.getAttribute("classid");
} else {
var attribute = event.target.getAttribute("classid");
}
2016-10-01 16:09:58 -04:00
Session.set("selectedClass", null);
var usertype = ["moderators", "banned"];
var array = classes.findOne({
_id: attribute
});
2016-09-07 01:12:30 -04:00
2016-10-01 16:09:58 -04:00
for (var i = 0; i < usertype.length; i++) {
2016-09-07 01:12:30 -04:00
var users = array[usertype[i]];
array[usertype[i]] = [];
2016-10-01 16:09:58 -04:00
for (var j = 0; j < users.length; j++) {
2016-09-07 01:12:30 -04:00
var detailusers = {};
2016-10-01 16:09:58 -04:00
var user = Meteor.users.findOne({
_id: users[j]
});
2016-09-07 01:12:30 -04:00
detailusers._id = user._id;
detailusers.email = user.services.google.email;
detailusers.name = user.profile.name;
array[usertype[i]].push(detailusers);
}
}
2016-10-01 16:09:58 -04:00
Meteor.call('getCode', attribute, function(err, result) {
2016-09-07 01:12:30 -04:00
array.code = result;
2016-10-01 16:09:58 -04:00
if (result === "None") {
2016-09-07 01:12:30 -04:00
Session.set("code", false);
} else {
Session.set("code", true);
}
2016-10-01 16:09:58 -04:00
Session.set("selectedClass", array);
Session.set("owned", true);
2016-09-26 19:31:29 -04:00
});
2016-08-12 12:28:55 -04:00
},
'click .classBox .fa-times' (event) { // Leaves a class
var box = event.target.parentNode;
var classid = box.getAttribute("classid");
serverData = box.getAttribute("classid");
confirm = "leaveClass";
Session.set("confirmText", "Leave this class?");
openDivFade(document.getElementsByClassName("overlay")[0]);
2016-08-12 12:28:55 -04:00
},
2016-08-25 22:56:10 -04:00
'click #creSubmit' () { //Submits form data for class
2016-08-12 12:28:55 -04:00
var data = getCreateFormData();
if (data === null) return;
2016-08-29 21:02:02 -04:00
serverData = data;
confirm = "createClass";
2016-08-12 12:28:55 -04:00
Session.set("confirmText", "Submit request?");
openDivFade(document.getElementsByClassName("overlay")[0]);
},
'click #private' (event) { // Joins private class
2016-10-01 16:09:58 -04:00
if (Session.get("privClass")) return;
var input = document.getElementById("privateCode");
input.className = "";
input.placeholder = "Enter code here...";
2016-10-01 16:09:58 -04:00
Session.set("privClass", true);
},
'click #privSubmit' () { // Submits private class code
var input = document.getElementById("privateCode");
var code = input.value;
input.value = "";
serverData = code;
Meteor.call("joinPrivateClass", code, function(error, result) {
2016-10-01 16:09:58 -04:00
if (result) {
Session.set("privClass", false);
} else {
input.className = "formInvalid";
input.placeholder = "Invalid code.";
}
});
},
// OWNED CLASS BUTTONS
'click #copy' () { // Copies code for private classes.
2016-10-01 16:09:58 -04:00
if (document.getElementById("code").value === "None") return;
document.getElementById("code").select();
document.execCommand("copy");
},
'click .userAdder .fa-plus' (event) { // Gives/Removes user privileges
var input = event.target.parentNode.childNodes[3];
input.placeholder = "1234@abc.xyz";
2016-10-01 16:09:58 -04:00
input.className.replace(" formInvalid", "");
var value = input.value;
var classid = document.getElementById("createdClasses").getAttribute("classid");
input.value = "";
2016-10-01 16:09:58 -04:00
if (checkUser(value, classid)) {
input.className += " formInvalid";
input.placeholder = "Not a valid user";
return;
}
2016-10-01 16:09:58 -04:00
var user = Meteor.users.findOne({
"services.google.email": value
});
2016-08-29 21:02:02 -04:00
serverData = [
user._id,
classid,
2016-10-01 16:09:58 -04:00
event.target.parentNode.childNodes[1].childNodes[0].nodeValue.replace(":", "").toLowerCase(),
true
2016-08-29 21:02:02 -04:00
];
sendData("trackUserInClass");
2016-08-21 22:50:23 -04:00
},
2016-08-25 22:56:10 -04:00
'click .userBox .fa-times' (event) { // Removes user from permissions
var box = event.target.parentNode;
2016-08-29 21:02:02 -04:00
serverData = [
box.getAttribute("userid"),
document.getElementById("createdClasses").getAttribute("classid"),
2016-10-01 16:09:58 -04:00
box.parentNode.parentNode.childNodes[1].childNodes[1].childNodes[0].nodeValue.replace(":", "").toLowerCase(),
false
2016-08-29 21:02:02 -04:00
];
sendData("trackUserInClass");
},
2016-10-01 16:09:58 -04:00
'click #deleteClass' () {
2016-08-29 21:02:02 -04:00
serverData = document.getElementById("createdClasses").getAttribute("classid");
confirm = "deleteClass";
Session.set("confirmText", "Delete this class?");
openDivFade(document.getElementsByClassName("overlay")[0]);
},
'click #changeAdmin span' (event) { // Click to give ownership of class.
2016-10-01 16:09:58 -04:00
if (Session.get("changeAdmin")) return;
Session.set("changeAdmin", true);
var input = document.createElement("input");
input.placeholder = "1234@abc.xyz";
var i = document.createElement("i");
i.className = "fa fa-exchange";
2016-10-01 16:09:58 -04:00
i.setAttribute("aria-hidden", "true");
event.target.parentNode.appendChild(input);
event.target.parentNode.appendChild(i);
},
2016-08-25 22:56:10 -04:00
'click .fa-exchange' (event) { //Changes class admin upon confirmation
var input = event.target.parentNode.childNodes[3];
input.placeholder = "1234@abc.xyz";
2016-10-01 16:09:58 -04:00
input.className.replace(" formInvalid", "");
var value = input.value;
var classid = document.getElementById("createdClasses").getAttribute("classid");
input.value = "";
2016-10-01 16:09:58 -04:00
if (checkUser(value, classid)) {
input.className += " formInvalid";
input.placeholder = "Not a valid user";
return;
}
2016-10-01 16:09:58 -04:00
var user = Meteor.users.findOne({
"services.google.email": value
});
serverData = [user._id, classid];
confirm = "changeAdmin";
Session.set("confirmText", "Are you really sure?");
2016-10-02 23:54:22 -04:00
openDivFade(document.getElementsByClassName("overlay")[0]);
document.getElementById("createdClasses").style.marginRight = "-40%";
},
// OVERLAY BUTTONS
'click .fa-check-circle-o' () { // Confirmation Button
sendData(confirm);
closeDivFade(document.getElementsByClassName("overlay")[0]);
2016-10-01 16:09:58 -04:00
if (confirm === "createClass") {
var form = document.getElementsByClassName("creInput");
2016-10-01 16:09:58 -04:00
for (var i = 0; i < form.length; i++) form[i].value = "";
}
serverData = null;
confirm = null;
},
'click .fa-times-circle-o' () { // Deny Button
closeDivFade(document.getElementsByClassName("overlay")[0]);
serverData = null;
confirm = null;
},
// INPUT HANDLING
'click .change' (event) { // Click changable inputs. Creates an input where the span is.
var ele = event.target;
var modifyingInput = Session.get("modifying");
if (ele.id !== modifyingInput && modifyingInput !== null) closeInput(modifyingInput);
Session.set("modifying", ele.id);
var dim = ele.getBoundingClientRect();
ele.style.display = "none";
var input = document.createElement("input");
if (ele.getAttribute("type") !== null) {
input.type = ele.getAttribute("type");
} else {
input.type = "text";
}
input.value = ele.childNodes[0].nodeValue;
input.className = "changeInput";
input.style.height = 0.9 * dim.height.toString() + "px";
2016-09-10 00:39:28 -04:00
input.style.width = "55%";
input.style.padding = "0.1%";
input.id = ele.id + "a";
input.setAttribute("opc", ele.getAttribute("opc"));
ele.parentNode.appendChild(input);
if (ele.getAttribute("re") == "readonly") {
input.readOnly = true;
input.className += " op";
input.style.cursor = "pointer";
} else {
input.select();
}
input.focus();
2016-09-05 14:51:40 -04:00
var restrict = ele.getAttribute("restrict");
if (restrict !== null) {
input.maxLength = restrict;
input.className += " restrict";
2016-10-01 16:09:58 -04:00
Session.set("commentRestrict", restrict - input.value.length.toString() + " characters left");
var text = document.getElementById(Session.get("modifying") + "restrict");
2016-09-05 14:51:40 -04:00
text.style.display = "inherit";
text.style.color = "#7E7E7E";
}
},
'click .radio' (event) { // Click dropdown input. Opens the dropdown menu.
var op = event.target;
try {
for (var i = 0; i < document.getElementsByClassName("profOptions").length; i++) {
var curr = document.getElementsByClassName("profOptions")[i];
2016-09-26 19:31:29 -04:00
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) {}
2016-10-01 16:09:58 -04:00
if (event.target.className.includes("op")) {
2016-09-26 19:31:29 -04:00
openDivFade(op.nextSibling.nextSibling);
} else {
openDivFade(op.parentNode.parentNode.childNodes[3]);
}
},
2016-09-05 14:51:40 -04:00
'keydown input' (event) { // Restricts characters for certain inputs.
var modifyingInput = Session.get("modifying");
if (event.keyCode == 13) {
try {
closeInput(modifyingInput);
} catch (err) {}
}
2016-09-05 14:51:40 -04:00
},
'input .restrict' (event) {
var restrict = event.target.maxLength;
var chars = restrict - event.target.value.length;
2016-10-01 16:09:58 -04:00
var text = document.getElementById(Session.get("modifying") + "restrict");
2016-09-05 14:51:40 -04:00
text.style.color = "#7E7E7E";
if (chars === restrict) { // Don't display if nothing in comment.
Session.set("commentRestrict", "");
return;
} else if (chars === 0) {
text.style.color = "#FF1A1A"; // Make text red if 0 characters left.
text.style.opacity = "0";
}
2016-09-05 14:51:40 -04:00
Session.set("commentRestrict", chars.toString() + " characters left");
},
'click .profOptionText' (event) { // Click each profile option setting.
var modifyingInput = Session.get("modifying");
var p = event.target;
2016-10-01 16:09:58 -04:00
if (p.className.includes("cre")) {
2016-09-09 22:25:02 -04:00
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(modifyingInput);
} catch (err) {}
closeDivFade(p.parentNode);
input.focus();
},
// AUTOCOMPLETE HANDLING
'keyup #profClassSearch' (event) { // Auto-complete updater
if (event.target.value.length === 0) {
Session.set("notsearching", true);
} else {
Session.set("notsearching", false);
}
Session.set("autocompleteDivs", null);
var divs = [];
try {
var items = document.getElementsByClassName("-autocomplete-container")[0].childNodes[3].childNodes;
if (items.length === 0) { // If no results.
Session.set("notfound", true);
} else {
Session.set("notfound", false);
}
for (var i = 2; i < items.length; i += 3) { // Iterate through autocomplete div.
var item = items[i].childNodes[3];
2016-10-01 16:09:58 -04:00
if (Meteor.user().profile.classes.indexOf(item.getAttribute("classid")) !== -1) continue;
divs.push({
name: item.childNodes[1].childNodes[0].nodeValue,
teacher: item.childNodes[3].childNodes[0].nodeValue,
hour: item.childNodes[5].childNodes[0].nodeValue,
2016-10-01 16:09:58 -04:00
subscribers: item.childNodes[7].childNodes[0].nodeValue.length / 17,
_id: item.getAttribute("classid")
});
Session.set("autocompleteDivs", divs);
}
} catch (err) {}
},
'focus .op' (event) { // Selects input for next tabbing.
event.target.click();
},
2016-08-12 12:28:55 -04:00
});
function openDivFade(div) {
2016-08-28 14:36:26 -04:00
div.style.display = "block";
2016-08-12 12:28:55 -04:00
div.style.opacity = "0";
setTimeout(function() {
div.style.opacity = "1";
}, 100);
}
function closeDivFade(div) {
2016-08-12 12:28:55 -04:00
div.style.opacity = "0";
setTimeout(function() {
div.style.display = "none";
}, 100);
}
function closeInput(modifyingInput) { // Closes current modifying input.
var input = document.getElementById(modifyingInput + "a");
var span = document.getElementById(modifyingInput);
2016-08-12 12:28:55 -04:00
input.parentNode.removeChild(input);
2016-09-05 14:51:40 -04:00
Session.set("commentRestrict", "");
2016-08-12 12:28:55 -04:00
try {
2016-10-01 16:09:58 -04:00
document.getElementById("modifyingInput" + "restrict").style.display = "none";
} catch (err) {}
2016-09-09 22:25:02 -04:00
2016-08-12 12:28:55 -04:00
if (input.value === "") {
span.childNodes[0].nodeValue = "Click here to edit...";
} else {
span.childNodes[0].nodeValue = input.value;
}
span.style.display = "initial";
Session.set("modifying", null);
Session.set("user", getProfileData());
serverData = Session.get("user");
2016-08-12 18:27:03 -04:00
sendData("editProfile");
}
function sendData(funcName) {
Meteor.call(funcName, serverData, function(err, result) {
2016-10-01 16:09:58 -04:00
if (funcName === "trackUserInClass") {
var selectedClass = Session.get("selectedClass");
2016-10-01 16:09:58 -04:00
var array = classes.findOne({
_id: selectedClass._id
});
var usertype = ["moderators", "banned"];
for (var i = 0; i < usertype.length; i++) {
var users = array[usertype[i]];
array[usertype[i]] = [];
2016-10-01 16:09:58 -04:00
for (var j = 0; j < users.length; j++) {
var detailusers = {};
2016-10-01 16:09:58 -04:00
var user = Meteor.users.findOne({
_id: users[j]
});
detailusers._id = user._id;
detailusers.email = user.services.google.email;
detailusers.name = user.profile.name;
array[usertype[i]].push(detailusers);
}
}
selectedClass.moderators = array.moderators;
selectedClass.banned = array.banned;
2016-10-01 16:09:58 -04:00
Session.set("selectedClass", selectedClass);
}
});
2016-08-11 01:53:24 -04:00
}
function getProfileData() { // Gets all data related to profile.
var profile = Session.get("user");
profile.description = document.getElementById("motd").childNodes[0].nodeValue;
2016-10-01 16:09:58 -04:00
if (profile.description.includes("Say something about yourself!")) profile.description = "";
profile.school = document.getElementById("school").childNodes[0].nodeValue;
2016-10-01 16:09:58 -04:00
if (profile.school === "Click here to edit...") profile.school = "";
2016-08-12 12:28:55 -04:00
var gradein = document.getElementById("grade").childNodes[0].nodeValue;
profile.grade = parseInt(gradein.substring(gradein.length - 2, gradein));
2016-10-01 16:09:58 -04:00
if (!profile.grade) profile.grade = "";
profile.avatar = document.getElementById("profAvatar").src;
profile.banner = document.getElementById("profBanner").src;
2016-09-26 19:31:29 -04:00
2016-09-29 23:39:34 -04:00
var themename = document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase();
var themeobj = themeColors[themename];
2016-08-28 14:36:26 -04:00
profile.preferences = {
2016-09-29 23:39:34 -04:00
"theme": themeobj,
2016-10-01 16:09:58 -04:00
"mode": document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(),
"timeHide": ref[document.getElementById("prefHide").childNodes[0].nodeValue],
"done": ref[document.getElementById("prefDone").childNodes[0].nodeValue],
"hideReport": ref[document.getElementById("prefReport").childNodes[0].nodeValue]
2016-08-28 14:36:26 -04:00
};
return profile;
}
function getCreateFormData() { // Gets create class form data, and returns null.
2016-08-12 12:28:55 -04:00
var stop;
var form = document.getElementsByClassName("creInput");
for (var i = 0; i < form.length; i++) { // Checks for missing/invalid fields.
2016-10-01 16:09:58 -04:00
if (i === 1 || i === 2) continue;
2016-08-12 12:28:55 -04:00
if (form[i].value === "") {
form[i].focus();
form[i].placeholder = "Missing field";
form[i].className += " formInvalid";
stop = true;
} else {
form[i].className = form[i].className.replace(" formInvalid", "");
}
}
if (stop) return null;
2016-08-12 12:28:55 -04:00
var school = form[0].value;
var hour = form[1].value;
var teacher = form[2].value;
var name = form[3].value;
2016-08-12 15:55:35 -04:00
if (form[4].value == "Public") {
2016-08-12 12:28:55 -04:00
var privacy = false;
} else {
var privacy = true;
}
2016-08-12 15:55:35 -04:00
var category = form[5].value.toLowerCase();
2016-08-12 12:28:55 -04:00
return {
school: school,
hour: hour,
teacher: teacher,
name: name,
privacy: privacy,
category: category,
status: false,
code: ""
};
}
2016-10-01 16:09:58 -04:00
function checkUser(email, classid) { // Checks if user email exists.
var user = Meteor.users.findOne({
"services.google.email": email
});
if (user === undefined) {
return true;
2016-10-01 16:09:58 -04:00
} else {
if (classes.findOne({
_id: classid
}).subscribers)
return false;
}
2016-08-29 21:02:02 -04:00
}