2016-08-25 22:35:44 -04:00
|
|
|
|
import {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
Template
|
|
|
|
|
|
} from 'meteor/templating';
|
2016-08-10 00:25:19 -04:00
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirm = null; // Sets function to execute after confirmation click.
|
|
|
|
|
|
|
2016-08-25 22:35:44 -04:00
|
|
|
|
// Sets up global variables
|
|
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
Session.set("profClassTab", "manClass"); // Set default classes card mode to 'Manage Classes.'
|
|
|
|
|
|
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.
|
|
|
|
|
|
Session.set("selectClassId",null); // Stores selected owned class ID.
|
|
|
|
|
|
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.
|
2016-08-10 00:25:19 -04:00
|
|
|
|
|
|
|
|
|
|
Template.profile.helpers({
|
2016-08-30 22:49:02 -04:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
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,
|
|
|
|
|
|
template: Template.schoollist
|
|
|
|
|
|
}]
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -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',
|
|
|
|
|
|
template: Template.teacherlist
|
|
|
|
|
|
}]
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
mainCenter() { // Centers main div container.
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var width = window.innerWidth * 1600 / 1920 + 10;
|
|
|
|
|
|
return "width:" + width.toString() + "px;margin-left:" + -0.5 * width.toString() + "px";
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
mainHeight() { // Returns height of screen for div.
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return window.innerHeight.toString() + "px";
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
banner() { // Styles the banner
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var width = window.innerWidth * 1600 / 1920;
|
|
|
|
|
|
var height = width * 615 / 1600;
|
2016-08-13 20:52:47 -04:00
|
|
|
|
if (Meteor.user().profile.banner !== undefined) {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var banner = Meteor.user().profile.banner;
|
|
|
|
|
|
} else {
|
2016-08-12 18:27:03 -04:00
|
|
|
|
var banner = "Banners/defaultcover.jpg";
|
|
|
|
|
|
currentprofile = Meteor.user().profile;
|
|
|
|
|
|
currentprofile.banner = banner
|
|
|
|
|
|
Meteor.call("editProfile", currentprofile);
|
2016-08-12 12:28:55 -04:00
|
|
|
|
}
|
2016-08-12 18:27:03 -04:00
|
|
|
|
return "width:" + width.toString() + "px;height:" + height.toString() + "px;background-image:url(" + banner + ");background-size:" + width.toString() + "px " + height.toString() + "px";
|
2016-08-12 12:28:55 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
avatar() { // Styles the avatar
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var dim = window.innerWidth * 1600 / 1920 * 0.16;
|
2016-08-16 06:43:46 -04:00
|
|
|
|
var pic = "";
|
|
|
|
|
|
var userprofile = Meteor.user().profile.avatar;
|
|
|
|
|
|
if (userprofile !== undefined && userprofile !== null) {
|
|
|
|
|
|
pic = Meteor.user().profile.avatar;
|
2016-08-12 12:28:55 -04:00
|
|
|
|
} else {
|
2016-08-16 06:43:46 -04:00
|
|
|
|
pic = "Avatars/" + (Math.floor(Math.random() * (11 - 1)) + 1).toString() + ".png";
|
2016-08-12 18:27:03 -04:00
|
|
|
|
currentprofile = Meteor.user().profile;
|
2016-08-16 06:43:46 -04:00
|
|
|
|
currentprofile.avatar = pic;
|
2016-08-12 18:27:03 -04:00
|
|
|
|
Meteor.call("editProfile", currentprofile);
|
2016-08-12 12:28:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
return "background-image:url(" + pic + ");background-size:" + dim.toString() + "px " + dim.toString() + "px";
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
avatarDim() { // Dimensions of the avatar
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var dim = window.innerWidth * 1600 / 1920 * 0.16;
|
|
|
|
|
|
return "height:" + dim.toString() + "px;width:" + dim.toString() + "px;top:" + 0.43 * window.innerHeight.toString() + "px;";
|
|
|
|
|
|
},
|
2016-08-25 22:35:44 -04:00
|
|
|
|
username() { //Returns current user's username
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Meteor.user().profile.name;
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
motd() { // Returns the current user's description
|
2016-08-12 18:27:03 -04:00
|
|
|
|
if (Meteor.user().profile.description) {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Meteor.user().profile.description;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return "Say something about yourself!";
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
school() { // Returns the current user's school's name
|
2016-08-12 18:27:03 -04:00
|
|
|
|
if (Meteor.user().profile.school) {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Meteor.user().profile.school;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return "Click here to edit...";
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
grade() { // Returns the current user's grade
|
2016-08-12 18:27:03 -04:00
|
|
|
|
if (Meteor.user().profile.grade) {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Meteor.user().profile.grade + "th";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return "Click here to edit...";
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
classes() { // Loads all of the possible classes ( Limit of twenty shown ) ( Sorts by class size )
|
2016-08-17 22:33:01 -04:00
|
|
|
|
var array = classes.find(
|
2016-08-12 17:07:12 -04:00
|
|
|
|
{
|
|
|
|
|
|
status: {$eq: true},
|
2016-08-14 15:02:18 -04:00
|
|
|
|
privacy: {$eq: false},
|
|
|
|
|
|
_id: {$nin: Meteor.user().profile.classes}
|
2016-08-12 17:07:12 -04:00
|
|
|
|
},
|
2016-08-16 20:46:38 -04:00
|
|
|
|
{sort: {subscribers: -1 }},
|
|
|
|
|
|
{limit: 20}
|
|
|
|
|
|
).fetch();
|
2016-08-17 22:33:01 -04:00
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < array.length; i++) {
|
|
|
|
|
|
array[i].subscribers = array[i].subscribers.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(array.length === 0) {
|
|
|
|
|
|
Session.set("noclass",true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Session.set("noclass",false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return array;
|
2016-08-12 12:28:55 -04:00
|
|
|
|
},
|
2016-08-25 22:35:44 -04:00
|
|
|
|
profClassHeight() { // Dimensions the class height
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return 0.6 * window.innerHeight.toString() + "px";
|
|
|
|
|
|
},
|
2016-08-25 22:35:44 -04:00
|
|
|
|
classHolderHeight() { // Dimensions the container for the classes
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return 0.26 * window.innerHeight.toString() + "px";
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
profClassTabColor(status) { // Change this [Supposed to show the current mode that's selected via color]
|
2016-08-12 12:28:55 -04:00
|
|
|
|
if (status === Session.get("profClassTab")) {
|
2016-08-27 19:01:14 -04:00
|
|
|
|
return Session.get("themeColors")[Meteor.user().profile.preferences.theme].highlightText;
|
2016-08-12 12:28:55 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2016-08-25 22:35:44 -04:00
|
|
|
|
profClassTab(tab) { // Tells current class
|
2016-08-12 12:28:55 -04:00
|
|
|
|
if (tab === Session.get("profClassTab")) {
|
|
|
|
|
|
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");
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
notfound() { // Returns if autocomplete has no results.
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Session.get("notfound");
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
noclass() { // Returns if user has classes.
|
2016-08-17 22:33:01 -04:00
|
|
|
|
return Session.get("noclass");
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirmText() { // Returns respective text for different confirm functions.
|
2016-08-12 12:28:55 -04:00
|
|
|
|
return Session.get("confirmText");
|
2016-08-15 22:15:07 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
selectedClass(val) { // Returns values for selectedClass
|
2016-08-18 00:44:13 -04:00
|
|
|
|
if(Session.get("selectClassId") === null) return;
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var usertype = ["moderators","banned"];
|
|
|
|
|
|
var attribute = Session.get("selectClassId");
|
|
|
|
|
|
var array = classes.findOne({_id:attribute});
|
2016-08-27 18:57:16 -04:00
|
|
|
|
var code = Meteor.call('getCode',attribute);
|
|
|
|
|
|
if(code === "") {
|
2016-08-16 20:46:38 -04:00
|
|
|
|
array.code = "None";
|
|
|
|
|
|
Session.set("code", false);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Session.set("code", true);
|
2016-08-27 18:57:16 -04:00
|
|
|
|
array.code = code;
|
2016-08-16 20:46:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < usertype.length; i++) {
|
|
|
|
|
|
var users = array[usertype[i]];
|
|
|
|
|
|
array[usertype[i]] = [];
|
|
|
|
|
|
for(var j = 0; j < users.length; j++) {
|
|
|
|
|
|
var detailusers = {};
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return array[val];
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
code() { // Returns if selected class has code.
|
2016-08-16 20:46:38 -04:00
|
|
|
|
return Session.get("code");
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
userHolder() { // Returns height of user holders for moderators/banned.
|
2016-08-16 20:46:38 -04:00
|
|
|
|
return 0.15 * window.innerHeight.toString() + "px";
|
2016-08-12 12:28:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2016-08-10 00:25:19 -04:00
|
|
|
|
|
|
|
|
|
|
Template.profile.events({
|
2016-08-25 22:56:10 -04:00
|
|
|
|
'click' (event) { // Whenever a click happens
|
2016-08-30 22:49:02 -04:00
|
|
|
|
var modifyingInput = Session.get("modifying");
|
|
|
|
|
|
if (event.target.id !== modifyingInput &&
|
|
|
|
|
|
event.target.id !== modifyingInput + "a" &&
|
2016-08-15 22:15:07 -04:00
|
|
|
|
!Session.equals("modifying", null) &&
|
|
|
|
|
|
!event.target.parentNode.className.includes("profOptions")) {
|
2016-08-30 22:49:02 -04:00
|
|
|
|
closeInput(modifyingInput);
|
2016-08-12 12:28:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
if (!event.target.className.includes("radio") &&
|
2016-08-15 22:15:07 -04:00
|
|
|
|
!event.target.parentNode.className.includes("profOptions") &&
|
2016-08-28 14:36:26 -04:00
|
|
|
|
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-08-16 20:46:38 -04:00
|
|
|
|
if(!document.getElementById("createdClasses").contains(event.target) &&
|
|
|
|
|
|
Session.get("code") !== null &&
|
|
|
|
|
|
!event.target.className.includes("fa-times-circle-o")) {
|
|
|
|
|
|
document.getElementById("createdClasses").style.marginRight = "-40%";
|
|
|
|
|
|
}
|
|
|
|
|
|
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-08-18 00:44:13 -04:00
|
|
|
|
if(Session.get("privateClass") &&
|
|
|
|
|
|
!document.getElementById("joinPrivClass").contains(event.target)) {
|
|
|
|
|
|
Session.set("privateClass",false);
|
|
|
|
|
|
document.getElementById("joinPrivClass").style.marginBottom = "-10%";
|
|
|
|
|
|
}
|
2016-08-12 12:28:55 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
// MAIN BUTTONS
|
2016-08-12 12:28:55 -04:00
|
|
|
|
'click .addClass' () {
|
|
|
|
|
|
var functionHolder = document.getElementById("profClassInfoHolder");
|
|
|
|
|
|
closeDivFade(functionHolder);
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
Session.set("profClassTab", "addClass");
|
|
|
|
|
|
openDivFade(functionHolder);
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
},
|
2016-08-12 17:07:12 -04:00
|
|
|
|
'click .manageClass' () {
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var functionHolder = document.getElementById("profClassInfoHolder");
|
|
|
|
|
|
closeDivFade(functionHolder);
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
Session.set("profClassTab", "manClass");
|
|
|
|
|
|
openDivFade(functionHolder);
|
|
|
|
|
|
}, 300);
|
2016-08-12 17:07:12 -04:00
|
|
|
|
},
|
|
|
|
|
|
'click .createClass' () {
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var functionHolder = document.getElementById("profClassInfoHolder");
|
|
|
|
|
|
closeDivFade(functionHolder);
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
Session.set("profClassTab", "creClass");
|
|
|
|
|
|
openDivFade(functionHolder);
|
|
|
|
|
|
}, 300);
|
2016-08-12 12:28:55 -04:00
|
|
|
|
},
|
2016-08-25 22:56:10 -04:00
|
|
|
|
'click .classBox' (event) { // When you click on a box that holds class
|
2016-08-23 22:09:07 -04:00
|
|
|
|
if (event.target.id === "label" ||
|
|
|
|
|
|
Session.get("profClassTab") === "manClass" ||
|
|
|
|
|
|
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;
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirm = "joinClass";
|
2016-08-12 12:28:55 -04:00
|
|
|
|
Session.set("confirmText", "Join class?");
|
2016-08-11 18:28:29 -04:00
|
|
|
|
|
2016-08-12 12:28:55 -04:00
|
|
|
|
openDivFade(document.getElementsByClassName("overlay")[0]);
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
document.getElementsByClassName("overlay")[0].style.opacity = "1";
|
|
|
|
|
|
}, 200);
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
'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-08-12 17:35:29 -04:00
|
|
|
|
}
|
2016-08-30 22:49:02 -04:00
|
|
|
|
Session.set("selectClassId",attribute);
|
|
|
|
|
|
document.getElementById("createdClasses").style.marginRight = "0";
|
2016-08-12 12:28:55 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -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;
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirm = "createClass";
|
2016-08-12 12:28:55 -04:00
|
|
|
|
Session.set("confirmText", "Submit request?");
|
|
|
|
|
|
|
|
|
|
|
|
openDivFade(document.getElementsByClassName("overlay")[0]);
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
'click #private' (event) { // Joins private class
|
|
|
|
|
|
Session.set("privateClass",true);
|
|
|
|
|
|
var input = document.getElementById("privateCode");
|
|
|
|
|
|
input.className = "";
|
|
|
|
|
|
input.placeholder = "Enter code here...";
|
|
|
|
|
|
document.getElementById("joinPrivClass").style.marginBottom = "0";
|
2016-08-15 22:15:07 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
'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) {
|
|
|
|
|
|
if(result) {
|
|
|
|
|
|
document.getElementById("joinPrivClass").style.marginBottom = "-10%";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
input.className = "formInvalid";
|
|
|
|
|
|
input.placeholder = "Invalid code.";
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2016-08-15 22:15:07 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
// OWNED CLASS BUTTONS=
|
|
|
|
|
|
'click #copy' () { // Copies code for private classes.
|
|
|
|
|
|
if(document.getElementById("code").value === "None") return;
|
|
|
|
|
|
document.getElementById("code").select();
|
|
|
|
|
|
document.execCommand("copy");
|
|
|
|
|
|
},
|
|
|
|
|
|
'click .userAdder .fa-plus' (event) { // Gives/Removes user privileges
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var input = event.target.parentNode.childNodes[3];
|
|
|
|
|
|
input.placeholder = "1234@abc.xyz";
|
|
|
|
|
|
input.className.replace(" formInvalid","");
|
|
|
|
|
|
var value = input.value;
|
2016-08-17 22:33:01 -04:00
|
|
|
|
var classid = document.getElementById("createdClasses").getAttribute("classid");
|
2016-08-16 20:46:38 -04:00
|
|
|
|
input.value = "";
|
2016-08-17 22:33:01 -04:00
|
|
|
|
if(checkUser(value,classid)) {
|
2016-08-16 20:46:38 -04:00
|
|
|
|
input.className += " formInvalid";
|
|
|
|
|
|
input.placeholder = "Not a valid user";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-08-17 22:33:01 -04:00
|
|
|
|
var user = Meteor.users.findOne({"services.google.email":value});
|
2016-08-29 21:02:02 -04:00
|
|
|
|
serverData = [
|
2016-08-16 20:46:38 -04:00
|
|
|
|
user._id,
|
2016-08-17 22:33:01 -04:00
|
|
|
|
classid,
|
2016-08-30 22:49:02 -04:00
|
|
|
|
event.target.parentNode.childNodes[1].childNodes[0].nodeValue.replace(":","").toLowerCase(),
|
|
|
|
|
|
true
|
2016-08-29 21:02:02 -04:00
|
|
|
|
];
|
2016-08-16 20:46:38 -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
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var box = event.target.parentNode;
|
2016-08-29 21:02:02 -04:00
|
|
|
|
serverData = [
|
2016-08-16 20:46:38 -04:00
|
|
|
|
box.getAttribute("userid"),
|
|
|
|
|
|
document.getElementById("createdClasses").getAttribute("classid"),
|
2016-08-30 22:49:02 -04:00
|
|
|
|
box.parentNode.parentNode.childNodes[1].childNodes[1].childNodes[0].nodeValue.replace(":","").toLowerCase(),
|
|
|
|
|
|
false
|
2016-08-29 21:02:02 -04:00
|
|
|
|
];
|
2016-08-30 22:49:02 -04:00
|
|
|
|
sendData("trackUserInClass");
|
2016-08-16 20:46:38 -04:00
|
|
|
|
},
|
2016-08-25 22:56:10 -04:00
|
|
|
|
'click #deleteClass' () {
|
2016-08-29 21:02:02 -04:00
|
|
|
|
serverData = document.getElementById("createdClasses").getAttribute("classid");
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirm = "deleteClass";
|
2016-08-16 20:46:38 -04:00
|
|
|
|
Session.set("confirmText", "Delete this class?");
|
|
|
|
|
|
openDivFade(document.getElementsByClassName("overlay")[0]);
|
|
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
'click #changeAdmin span' (event) { // Click to give ownership of class.
|
2016-08-16 20:46:38 -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";
|
|
|
|
|
|
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
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var input = event.target.parentNode.childNodes[3];
|
|
|
|
|
|
input.placeholder = "1234@abc.xyz";
|
|
|
|
|
|
input.className.replace(" formInvalid","");
|
|
|
|
|
|
var value = input.value;
|
2016-08-17 22:33:01 -04:00
|
|
|
|
var classid = document.getElementById("createdClasses").getAttribute("classid");
|
2016-08-16 20:46:38 -04:00
|
|
|
|
input.value = "";
|
2016-08-17 22:33:01 -04:00
|
|
|
|
if(checkUser(value,classid)) {
|
2016-08-16 20:46:38 -04:00
|
|
|
|
input.className += " formInvalid";
|
|
|
|
|
|
input.placeholder = "Not a valid user";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-08-17 22:33:01 -04:00
|
|
|
|
var user = Meteor.users.findOne({"services.google.email":value});
|
2016-08-29 21:02:02 -04:00
|
|
|
|
serverData = [user._id,classid];
|
2016-08-30 22:49:02 -04:00
|
|
|
|
confirm = "changeAdmin";
|
2016-08-17 22:33:01 -04:00
|
|
|
|
Session.set("confirmText", "Are you really sure?");
|
|
|
|
|
|
openDivFade(document.getElementsByClassName("overlay")[0])
|
|
|
|
|
|
document.getElementById("createdClasses").style.marginRight = "-40%";
|
2016-08-18 00:44:13 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
// OVERLAY BUTTONS
|
|
|
|
|
|
'click .fa-check-circle-o' () { // Confirmation Button
|
|
|
|
|
|
sendData(confirm);
|
|
|
|
|
|
closeDivFade(document.getElementsByClassName("overlay")[0]);
|
|
|
|
|
|
if(confirm === "createClass") {
|
|
|
|
|
|
var form = document.getElementById("create");
|
|
|
|
|
|
for(var i = 0; i < form.length; i++) form[i].value = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
serverData = null;
|
|
|
|
|
|
confirm = null;
|
2016-08-18 00:44:13 -04:00
|
|
|
|
},
|
2016-08-30 22:49:02 -04:00
|
|
|
|
'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";
|
|
|
|
|
|
input.style.width = "70%";
|
|
|
|
|
|
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();
|
|
|
|
|
|
if (ele.getAttribute("restrict") !== null) {
|
|
|
|
|
|
var span = document.createElement("span");
|
|
|
|
|
|
span.id = "restrict";
|
|
|
|
|
|
var num = parseInt(ele.getAttribute("restrict")) - input.value.length;
|
|
|
|
|
|
if (num <= 0) {
|
|
|
|
|
|
span.style.setProperty("color", "#FF1A1A", "important");
|
|
|
|
|
|
num = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
span.appendChild(document.createTextNode(num.toString() + " characters left"));
|
|
|
|
|
|
ele.parentNode.appendChild(span);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'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];
|
|
|
|
|
|
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) {}
|
|
|
|
|
|
|
|
|
|
|
|
if(event.target.className.includes("op")) {
|
|
|
|
|
|
openDivFade(op.nextSibling.nextSibling);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openDivFade(op.parentNode.parentNode.childNodes[3]);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'keydown' (event) { // Restricts characters for certain inputs.
|
|
|
|
|
|
var modifyingInput = Session.get("modifying");
|
|
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
closeInput(modifyingInput);
|
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (modifyingInput !== null && event.keyCode !== 13) {
|
|
|
|
|
|
var restrict = document.getElementById(modifyingInput).getAttribute("restrict");
|
|
|
|
|
|
if (restrict !== null) {
|
|
|
|
|
|
var num = parseInt(restrict) - event.target.value.length;
|
|
|
|
|
|
var restext = document.getElementById("restrict");
|
|
|
|
|
|
if (num === 1) {
|
|
|
|
|
|
restext.childNodes[0].nodeValue = num.toString() + " character left";
|
|
|
|
|
|
restext.style.setProperty("color", "#999", "important");
|
|
|
|
|
|
} else if (num <= 0) {
|
|
|
|
|
|
var input = document.getElementById(modifyingInput + "a");
|
|
|
|
|
|
input.value = input.value.substring(0, parseInt(restrict));
|
|
|
|
|
|
restext.childNodes[0].nodeValue = "0 characters left";
|
|
|
|
|
|
restext.style.setProperty("color", "#FF1A1A", "important");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
restext.childNodes[0].nodeValue = num.toString() + " characters left";
|
|
|
|
|
|
restext.style.setProperty("color", "#999", "important");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'click .profOptionText' (event) { // Click each profile option setting.
|
|
|
|
|
|
var modifyingInput = Session.get("modifying");
|
|
|
|
|
|
var p = event.target;
|
|
|
|
|
|
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(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);
|
2016-08-18 00:44:13 -04:00
|
|
|
|
} else {
|
2016-08-30 22:49:02 -04:00
|
|
|
|
Session.set("notfound", false);
|
2016-08-18 00:44:13 -04:00
|
|
|
|
}
|
2016-08-30 22:49:02 -04:00
|
|
|
|
for (var i = 2; i < items.length; i += 3) { // Iterate through autocomplete div.
|
|
|
|
|
|
var item = items[i].childNodes[3];
|
|
|
|
|
|
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,
|
|
|
|
|
|
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
|
|
|
|
});
|
2016-08-10 00:25:19 -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);
|
2016-08-10 00:25:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function closeDivFade(div) {
|
2016-08-12 12:28:55 -04:00
|
|
|
|
div.style.opacity = "0";
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
div.style.display = "none";
|
|
|
|
|
|
}, 100);
|
2016-08-10 00:25:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
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);
|
|
|
|
|
|
try {
|
|
|
|
|
|
var restrict = document.getElementById("restrict");
|
|
|
|
|
|
restrict.parentNode.removeChild(restrict);
|
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
|
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);
|
2016-08-29 21:02:02 -04:00
|
|
|
|
serverData = getProfileData();
|
2016-08-12 18:27:03 -04:00
|
|
|
|
sendData("editProfile");
|
2016-08-10 00:25:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-10 21:56:12 -04:00
|
|
|
|
function sendData(funcName) {
|
2016-08-29 21:02:02 -04:00
|
|
|
|
Meteor.call(funcName, serverData);
|
2016-08-11 01:53:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
function getProfileData() { // Gets all data related to profile.
|
2016-08-28 13:12:41 -04:00
|
|
|
|
var profile = Meteor.user().profile;
|
|
|
|
|
|
profile.description = document.getElementById("motd").childNodes[0].nodeValue;
|
|
|
|
|
|
profile.school = document.getElementById("school").childNodes[0].nodeValue;
|
2016-08-12 12:28:55 -04:00
|
|
|
|
var gradein = document.getElementById("grade").childNodes[0].nodeValue;
|
2016-08-28 13:12:41 -04:00
|
|
|
|
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("\"", "");
|
2016-08-28 14:36:26 -04:00
|
|
|
|
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
|
|
|
|
|
|
};
|
2016-08-11 18:28:29 -04:00
|
|
|
|
|
2016-08-28 13:12:41 -04:00
|
|
|
|
return profile;
|
2016-08-11 18:28:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
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");
|
2016-08-30 22:49:02 -04:00
|
|
|
|
for (var i = 0; i < form.length; i++) { // Checks for missing/invalid fields.
|
2016-08-16 20:46:38 -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-11 18:28:29 -04:00
|
|
|
|
|
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-08-16 20:46:38 -04:00
|
|
|
|
|
2016-08-30 22:49:02 -04:00
|
|
|
|
function checkUser(email,classid) { // Checks if user email exists.
|
2016-08-16 20:46:38 -04:00
|
|
|
|
var user = Meteor.users.findOne({"services.google.email":email});
|
|
|
|
|
|
if(user === undefined) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
2016-08-17 22:33:01 -04:00
|
|
|
|
if(classes.findOne({_id:classid}).subscribers)
|
2016-08-16 20:46:38 -04:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2016-08-29 21:02:02 -04:00
|
|
|
|
}
|