web-beautify filter

This commit is contained in:
Yaman Qalieh 2016-09-04 20:13:31 -04:00
parent b98f229c0b
commit 8eaaff37f4

View File

@ -26,36 +26,36 @@ var workColors = {
// Creates variables for due dates // Creates variables for due dates
var ref = { var ref = {
"1 Day":1, "1 Day": 1,
"2 Days":2, "2 Days": 2,
"1 Week":7, "1 Week": 7,
"1 Month":30, "1 Month": 30,
"Never":0, "Never": 0,
"Yes":true, "Yes": true,
"No":false "No": false
}; };
// Reactive variables. // Reactive variables.
Session.set("calendarClasses", null); Session.set("calendarClasses", null);
Session.set("sidebar", null); // Status of sidebar Session.set("sidebar", null); // Status of sidebar
Session.set("newWork",null); // If user creating new work. Session.set("newWork", null); // If user creating new work.
Session.set("currentWork",null); // Stores current selected work info. Session.set("currentWork", null); // Stores current selected work info.
Session.set("currentReadableWork",null); // Stores readable selected work info. Session.set("currentReadableWork", null); // Stores readable selected work info.
Session.set("modifying",null); // Stores current open input. Session.set("modifying", null); // Stores current open input.
Session.set("noclass",null); // If user does not have classes. Session.set("noclass", null); // If user does not have classes.
Session.set("calCreWork",null); // If user is creating a work from calendar. Session.set("calCreWork", null); // If user is creating a work from calendar.
Session.set("classDisp",[]); // Stores current filter for classes. Session.set("classDisp", []); // Stores current filter for classes.
Session.set("classDispHover",null); // Stores current hovered filter. Session.set("classDispHover", null); // Stores current hovered filter.
Session.set("refetchEvents",null); // Stores whether to get calendar events again. Session.set("refetchEvents", null); // Stores whether to get calendar events again.
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() === undefined) return; if (Meteor.user() === 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() === undefined) return; if (Meteor.user() === 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;
}); });
@ -71,8 +71,8 @@ Template.registerHelper('overlayDim', (part) => { // Gets size of the overlay co
}); });
Template.registerHelper('myClasses', () => { // Gets all classes and respective works. Template.registerHelper('myClasses', () => { // Gets all classes and respective works.
if(Meteor.user() === undefined) { // Null checking. if (Meteor.user() === undefined) { // Null checking.
Session.set("noclass",true); // Makes sure to display nothing. Session.set("noclass", true); // Makes sure to display nothing.
return []; return [];
} else { } else {
var array = []; var array = [];
@ -80,44 +80,48 @@ Template.registerHelper('myClasses', () => { // Gets all classes and respective
var classDisp = Session.get("classDisp"); // Get sidebar class filter. var classDisp = Session.get("classDisp"); // Get sidebar class filter.
var hide = Meteor.user().profile.preferences.timeHide; var hide = Meteor.user().profile.preferences.timeHide;
for(var i = 0; i < courses.length; i++) { // For each user class. for (var i = 0; i < courses.length; i++) { // For each user class.
found = classes.findOne({_id:courses[i]}); found = classes.findOne({
_id: courses[i]
});
found.subscribers = found.subscribers.length; found.subscribers = found.subscribers.length;
found.mine = true; found.mine = true;
if(found.admin === Meteor.userId()) { // If user owns this class. if (found.admin === Meteor.userId()) { // If user owns this class.
found.box = " owned"; found.box = " owned";
found.mine = false; found.mine = false;
} }
if(classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected. if (classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected.
array.push(found); array.push(found);
var thisWork = work.find({class: courses[i]}).fetch(); var thisWork = work.find({
class: courses[i]
}).fetch();
if(classDisp.length !== 0 && classDisp.indexOf(found._id) === -1) { // Filter classes based on filter. if (classDisp.length !== 0 && classDisp.indexOf(found._id) === -1) { // Filter classes based on filter.
array[i].thisClassWork = []; array[i].thisClassWork = [];
continue; continue;
} }
for(var j = 0; j < thisWork.length; j++) { // For each work in class. for (var j = 0; j < thisWork.length; j++) { // For each work in class.
if(hide !== 0) { // Time to hide isn't never. if (hide !== 0) { // Time to hide isn't never.
var due = (moment(thisWork[j].dueDate))._d; var due = (moment(thisWork[j].dueDate))._d;
var offset = (moment().subtract(hide,'days'))._d; var offset = (moment().subtract(hide, 'days'))._d;
if(offset > due) { // If due is before hide days before today if (offset > due) { // If due is before hide days before today
thisWork[j] = "no"; thisWork[j] = "no";
j = 0; j = 0;
} }
} }
if(thisWork[j] !== "no" && Meteor.user().profile.preferences.done) { // If done filter is true if (thisWork[j] !== "no" && Meteor.user().profile.preferences.done) { // If done filter is true
if(thisWork[j].done.indexOf(Meteor.userId()) !== -1) { // If user marked this work done. if (thisWork[j].done.indexOf(Meteor.userId()) !== -1) { // If user marked this work done.
thisWork[j] = "no"; thisWork[j] = "no";
j = 0; j = 0;
} }
} }
} }
while(thisWork.indexOf("no") !== -1) thisWork.splice(thisWork.indexOf("no"),1); // Splice all filtered works. while (thisWork.indexOf("no") !== -1) thisWork.splice(thisWork.indexOf("no"), 1); // Splice all filtered works.
for(j = 0; j < thisWork.length; j++) { for (j = 0; j < thisWork.length; j++) {
thisWork[j].realDate = thisWork[j].dueDate; thisWork[j].realDate = thisWork[j].dueDate;
thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, { thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, {
sameDay: '[Today]', sameDay: '[Today]',
@ -128,18 +132,18 @@ Template.registerHelper('myClasses', () => { // Gets all classes and respective
sameElse: 'MMMM Do' sameElse: 'MMMM Do'
}); });
if(thisWork[j].dueDate === "Today") { // Font weight based on date proximity. if (thisWork[j].dueDate === "Today") { // Font weight based on date proximity.
thisWork[j].cardDate = "600"; thisWork[j].cardDate = "600";
} else if(thisWork[j].dueDate === "Tomorrow") { } else if (thisWork[j].dueDate === "Tomorrow") {
thisWork[j].cardDate = "400"; thisWork[j].cardDate = "400";
} }
thisWork[j].typeColor = workColors[thisWork[j].type]; thisWork[j].typeColor = workColors[thisWork[j].type];
thisWork[j].confirmationLength = thisWork[j].confirmations.length; // Counts the number of confirmations and reports for a particular work. thisWork[j].confirmationLength = thisWork[j].confirmations.length; // Counts the number of confirmations and reports for a particular work.
thisWork[j].reportLength = thisWork[j].reports.length; thisWork[j].reportLength = thisWork[j].reports.length;
var hoverHighlight = Session.get("classDispHover"); // Highlight/scale related class works on hover. var hoverHighlight = Session.get("classDispHover"); // Highlight/scale related class works on hover.
if(hoverHighlight !== null && hoverHighlight === found._id) { if (hoverHighlight !== null && hoverHighlight === found._id) {
thisWork[j].scale = "-ms-transform: scale(1.12)-webkit-transform: scale(1.12);transform: scale(1.12)"; thisWork[j].scale = "-ms-transform: scale(1.12)-webkit-transform: scale(1.12);transform: scale(1.12)";
} else { } else {
thisWork[j].scale = ""; thisWork[j].scale = "";
@ -147,17 +151,17 @@ Template.registerHelper('myClasses', () => { // Gets all classes and respective
} }
array[i].thisClassWork = thisWork; array[i].thisClassWork = thisWork;
} }
Session.set("noclass",false); Session.set("noclass", false);
Session.set("calendarClasses", array); Session.set("calendarClasses", array);
Session.set("refetchEvents",true); Session.set("refetchEvents", true);
return array; return array;
} }
}); });
Template.registerHelper('pref', (val) => { // Obtains all user preferences. Template.registerHelper('pref', (val) => { // Obtains all user preferences.
if(Meteor.user() === undefined) return; if (Meteor.user() === undefined) return;
var preferences = Meteor.user().profile.preferences; var preferences = Meteor.user().profile.preferences;
if(val === 'timeHide' || val === 'done') { if (val === 'timeHide' || val === 'done') {
var invert = _.invert(ref); var invert = _.invert(ref);
return invert[preferences[val]]; return invert[preferences[val]];
} }
@ -166,50 +170,50 @@ Template.registerHelper('pref', (val) => { // Obtains all user preferences.
Template.main.helpers({ Template.main.helpers({
schoolName() { // Finds the name of the user's school. schoolName() { // Finds the name of the user's school.
if(Meteor.user().profile.school === undefined) return; if (Meteor.user().profile.school === undefined) return;
return " - " + Meteor.user().profile.school; return " - " + Meteor.user().profile.school;
}, },
iconColor(icon) { // Sidebar status color iconColor(icon) { // Sidebar status color
if (Session.equals("sidebar",icon + "Container")) { if (Session.equals("sidebar", icon + "Container")) {
return themeColors[Meteor.user().profile.preferences.theme].statusIcons; return themeColors[Meteor.user().profile.preferences.theme].statusIcons;
} else if (Session.equals("sidebar","both")) { } else if (Session.equals("sidebar", "both")) {
return themeColors[Meteor.user().profile.preferences.theme].statusIcons; return themeColors[Meteor.user().profile.preferences.theme].statusIcons;
} else { } else {
return; return;
} }
}, },
defaultMode() { //Loads the default display mode for user. defaultMode() { //Loads the default display mode for user.
if(load) { if (load) {
Session.set("mode",Meteor.user().profile.preferences.mode); Session.set("mode", Meteor.user().profile.preferences.mode);
load = false; load = false;
} }
return; return;
}, },
bgSrc() { // Adjusts for different, larger screen sizes. bgSrc() { // Adjusts for different, larger screen sizes.
var dim = [window.innerWidth, window.innerHeight]; var dim = [window.innerWidth, window.innerHeight];
var pic = "Backgrounds/"+themeColors[Meteor.user().profile.preferences.theme].background; var pic = "Backgrounds/" + themeColors[Meteor.user().profile.preferences.theme].background;
return pic; return pic;
}, },
menuStatus() { // Status of of menu sidebar. menuStatus() { // Status of of menu sidebar.
if (Session.equals("sidebar","menuContainer")) { if (Session.equals("sidebar", "menuContainer")) {
return "0%"; return "0%";
} else if (Session.equals("sidebar","both")) { } else if (Session.equals("sidebar", "both")) {
return "0%"; return "0%";
} else { } else {
return openValues.menu; return openValues.menu;
} }
}, },
optionsStatus() { // Status of options sidebar. optionsStatus() { // Status of options sidebar.
if (Session.equals("sidebar","optionsContainer")) { if (Session.equals("sidebar", "optionsContainer")) {
return "0%"; return "0%";
} else if (Session.equals("sidebar","both")) { } else if (Session.equals("sidebar", "both")) {
return "0%"; return "0%";
} else { } else {
return openValues.options; return openValues.options;
} }
}, },
modeStatus(status) { // Color status of display modes. modeStatus(status) { // Color status of display modes.
if (Session.equals("mode",status)) { if (Session.equals("mode", status)) {
return themeColors[Meteor.user().profile.preferences.theme].highlightText; return themeColors[Meteor.user().profile.preferences.theme].highlightText;
} else { } else {
return; return;
@ -238,17 +242,19 @@ Template.main.helpers({
var events = []; var events = [];
var userClasses = Session.get("calendarClasses"); var userClasses = Session.get("calendarClasses");
for(var i = 0; i < userClasses.length; i++) { for (var i = 0; i < userClasses.length; i++) {
var works = userClasses[i].thisClassWork; var works = userClasses[i].thisClassWork;
for(var j = 0; j < works.length; j++) { for (var j = 0; j < works.length; j++) {
var work = works[j]; var work = works[j];
var currClass = classes.findOne({_id: work.class}); var currClass = classes.findOne({
_id: work.class
});
var inRole = false; var inRole = false;
if(Meteor.userId() === work.creator || if (Meteor.userId() === work.creator ||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 || currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1 currClass.banned.indexOf(Meteor.userId()) !== -1
) inRole = true; ) inRole = true;
events.push({ events.push({
@ -258,34 +264,38 @@ Template.main.helpers({
backgroundColor: workColors[work.type], backgroundColor: workColors[work.type],
borderColor: "#444", borderColor: "#444",
startEditable: inRole, startEditable: inRole,
className: "workevent "+work.class, className: "workevent " + work.class,
}); });
} }
} }
callback(events); callback(events);
}, },
eventDrop: function(event, delta, revertFunc) { // When user drops from click-dragging. eventDrop: function(event, delta, revertFunc) { // When user drops from click-dragging.
var current = work.findOne({_id:event.id}); var current = work.findOne({
_id: event.id
});
var date = event.start.format().split("-"); var date = event.start.format().split("-");
current.dueDate = new Date(date[0],parseInt(date[1])-1,date[2],11,59,59); current.dueDate = new Date(date[0], parseInt(date[1]) - 1, date[2], 11, 59, 59);
serverData = current; serverData = current;
sendData("editWork"); sendData("editWork");
}, },
eventClick: function(event, jsEvent, view) { // On-click for work. eventClick: function(event, jsEvent, view) { // On-click for work.
Session.set("newWork",false); Session.set("newWork", false);
var thisWork = work.findOne({_id:event.id}); var thisWork = work.findOne({
Session.set("currentWork",thisWork); _id: event.id
});
Session.set("currentWork", thisWork);
var thisReadWork = formReadable(thisWork); var thisReadWork = formReadable(thisWork);
Session.set("currentReadableWork",thisReadWork); Session.set("currentReadableWork", thisReadWork);
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
dayClick: function(date, jsEvent, view) { // On-click for each day. dayClick: function(date, jsEvent, view) { // On-click for each day.
if(jsEvent.target.className.includes("fc-past")) return; if (jsEvent.target.className.includes("fc-past")) return;
Session.set("calCreWork", true); Session.set("calCreWork", true);
calWorkDate = date.format(); calWorkDate = date.format();
calWorkOpen = true; calWorkOpen = true;
Session.set("newWork", true); Session.set("newWork", true);
Session.set("sidebar","menuContainer"); Session.set("sidebar", "menuContainer");
} }
}; };
}, },
@ -294,7 +304,7 @@ Template.main.helpers({
return "width:" + width.toString() + "px;margin-left:" + (0.5 * window.innerWidth - 0.5 * width).toString() + "px;"; return "width:" + width.toString() + "px;margin-left:" + (0.5 * window.innerWidth - 0.5 * width).toString() + "px;";
}, },
calColor() { // Sets the color of the calendar according to theme calColor() { // Sets the color of the calendar according to theme
return "color:"+themeColors[Meteor.user().profile.preferences.theme].calendar; return "color:" + themeColors[Meteor.user().profile.preferences.theme].calendar;
}, },
calbg() { //Sets size of the calendar calbg() { //Sets size of the calendar
var width = window.innerWidth * 0.865; var width = window.innerWidth * 0.865;
@ -302,29 +312,29 @@ Template.main.helpers({
return "width:" + width.toString() + "px;height:" + height.toString() + "px;margin-left:" + (0.5 * window.innerWidth - 0.5 * width).toString() + "px;margin-top:" + (0.47 * window.innerHeight - 0.5 * height).toString() + "px"; return "width:" + width.toString() + "px;height:" + height.toString() + "px;margin-left:" + (0.5 * window.innerWidth - 0.5 * width).toString() + "px;margin-top:" + (0.47 * window.innerHeight - 0.5 * height).toString() + "px";
}, },
calCreWork() { // Display instructions for creating a work. calCreWork() { // Display instructions for creating a work.
if(Session.get("calCreWork")) return true; if (Session.get("calCreWork")) return true;
return false; return false;
}, },
filterOn() { filterOn() {
if(Session.get("classDisp").length !== 0) return true; if (Session.get("classDisp").length !== 0) return true;
return false; return false;
}, },
highlight() { // Calendar highlight/scale option. highlight() { // Calendar highlight/scale option.
var hoverHighlight = Session.get("classDispHover"); var hoverHighlight = Session.get("classDispHover");
var works = document.getElementsByClassName("workevent"); var works = document.getElementsByClassName("workevent");
var work = $('.workevent'); var work = $('.workevent');
if(hoverHighlight === null) { if (hoverHighlight === null) {
work.css('-webkit-transform',''); work.css('-webkit-transform', '');
work.css('-ms-transform',''); work.css('-ms-transform', '');
work.css('transform',''); work.css('transform', '');
return; return;
} }
for(var i = 0; i < works.length; i++) { for (var i = 0; i < works.length; i++) {
var id = works[i].className; var id = works[i].className;
var index = id.indexOf("workevent"); var index = id.indexOf("workevent");
id = id.substring(index+10,index+27); id = id.substring(index + 10, index + 27);
if(id === hoverHighlight) { if (id === hoverHighlight) {
works[i].style.webkitTransform = 'scale(1.12)'; works[i].style.webkitTransform = 'scale(1.12)';
works[i].style.msTransform = 'scale(1.12)'; works[i].style.msTransform = 'scale(1.12)';
works[i].style.transform = 'scale(1.12)'; works[i].style.transform = 'scale(1.12)';
@ -339,23 +349,23 @@ Template.main.helpers({
workCenter() { // Centers work overlay. workCenter() { // Centers work overlay.
var w = window.innerWidth * 0.3; var w = window.innerWidth * 0.3;
var h = window.innerHeight * 0.7; var h = window.innerHeight * 0.7;
return "width:"+w.toString()+"px;height:"+h.toString()+"px;margin-left:"+-0.5*w.toString()+"px;margin-top:"+-0.5*h.toString()+"px"; return "width:" + w.toString() + "px;height:" + h.toString() + "px;margin-left:" + -0.5 * w.toString() + "px;margin-top:" + -0.5 * h.toString() + "px";
}, },
commentDim() { // Dimensions of comment container. commentDim() { // Dimensions of comment container.
var work = Session.get("currentWork"); var work = Session.get("currentWork");
if(Session.equals("newWork",null) || work === null) return; if (Session.equals("newWork", null) || work === null) return;
if(Session.get("newWork") || work.comments.length <= 3) return; if (Session.get("newWork") || work.comments.length <= 3) return;
return 0.23 * window.innerHeight.toString() + "px"; return 0.23 * window.innerHeight.toString() + "px";
}, },
work(value) { // Returns the specified work value. work(value) { // Returns the specified work value.
if(Session.equals("currentWork",null)) return; if (Session.equals("currentWork", null)) return;
return Session.get("currentReadableWork")[value]; return Session.get("currentReadableWork")[value];
}, },
workType() { // Returns color for respective work type. workType() { // Returns color for respective work type.
if(Session.equals("currentWork",null)) return; if (Session.equals("currentWork", null)) return;
if(Session.get("currentWork").type === undefined) return; if (Session.get("currentWork").type === undefined) return;
type = Session.get("currentWork").type; type = Session.get("currentWork").type;
if(type.includes("edit")) { if (type.includes("edit")) {
return; return;
} else { } else {
return workColors[type]; return workColors[type];
@ -368,23 +378,26 @@ Template.main.helpers({
return Session.get("newWork"); return Session.get("newWork");
}, },
inRole() { // Checks correct permissions. inRole() { // Checks correct permissions.
if(Session.equals("currentWork",null)) return; if (Session.equals("currentWork", null)) return;
if(Session.get("newWork")) { if (Session.get("newWork")) {
return true; return true;
} else { } else {
var currClass = classes.findOne({_id: Session.get("currentWork")["class"]}); var currClass = classes.findOne({
if(Meteor.userId() === Session.get("currentWork").creator || _id: Session.get("currentWork")["class"]
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || });
currClass.moderators.indexOf(Meteor.userId()) !== -1 || if (Meteor.userId() === Session.get("currentWork").creator ||
currClass.banned.indexOf(Meteor.userId()) !== -1 Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
) return true; currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
) return true;
} }
}, },
refetchEvents() { refetchEvents() {
if(Session.get("refetchEvents")) { if (Session.get("refetchEvents")) {
$("#fullcalendar").fullCalendar( 'refetchEvents' ); $("#fullcalendar").fullCalendar('refetchEvents');
Session.set("refetchEvents",null); Session.set("refetchEvents", null);
} } }
}
}); });
Template.main.events({ Template.main.events({
@ -400,35 +413,35 @@ Template.main.events({
closeInput(modifyingInput); closeInput(modifyingInput);
} }
if (!Session.equals("sidebar",e) && // Sidebar closing. if (!Session.equals("sidebar", e) && // Sidebar closing.
!e.includes("fa-cog") && !e.includes("fa-cog") &&
!e.includes("fa-bars") && !e.includes("fa-bars") &&
!document.getElementById("menuContainer").contains(event.target) && !document.getElementById("menuContainer").contains(event.target) &&
!document.getElementById("optionsContainer").contains(event.target)) { !document.getElementById("optionsContainer").contains(event.target)) {
if(Session.get("calCreWork")) { if (Session.get("calCreWork")) {
if(!calWorkOpen) { if (!calWorkOpen) {
Session.set("calCreWork",false); Session.set("calCreWork", false);
Session.set("sidebar",null); Session.set("sidebar", null);
} }
calWorkOpen = false; calWorkOpen = false;
} else { } else {
Session.set("sidebar",null); Session.set("sidebar", null);
} }
} }
if(e === "overlay") { // Overlay closing. if (e === "overlay") { // Overlay closing.
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
if(!Session.get("newWork")) { if (!Session.get("newWork")) {
if(getHomeworkFormData() === null) return; if (getHomeworkFormData() === null) return;
serverData = Session.get("currentWork"); serverData = Session.get("currentWork");
sendData("editWork"); sendData("editWork");
document.getElementById("workComment").value = ""; document.getElementById("workComment").value = "";
} }
Session.set("newWork",null); Session.set("newWork", null);
Session.set("currentWork",null); Session.set("currentWork", null);
Session.set("currentReadableWork",null); Session.set("currentReadableWork", null);
$('.req').css("color",""); $('.req').css("color", "");
Session.set("commentRestrict",null); Session.set("commentRestrict", null);
} }
if (!event.target.className.includes("radio") && // Dropdown closing. if (!event.target.className.includes("radio") && // Dropdown closing.
@ -436,7 +449,7 @@ Template.main.events({
!event.target.parentNode.className.includes("prefOptions") && !event.target.parentNode.className.includes("prefOptions") &&
event.target.readOnly !== true) { event.target.readOnly !== true) {
var radio; var radio;
if(Session.equals("sidebar","optionsContainer") || Session.equals("sidebar","both")) { if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
radio = "prefOptions"; radio = "prefOptions";
} else { } else {
radio = "workOptions"; radio = "workOptions";
@ -474,75 +487,83 @@ Template.main.events({
} }
}, },
'click .classes' () { // Click classes mode button. 'click .classes' () { // Click classes mode button.
if (Session.equals("mode","classes")) return; if (Session.equals("mode", "classes")) return;
var modeHolder = document.getElementById("mainBody"); var modeHolder = document.getElementById("mainBody");
closeDivFade(modeHolder); closeDivFade(modeHolder);
setTimeout(function() { setTimeout(function() {
Session.set("mode", "classes"); Session.set("mode", "classes");
openDivFade(modeHolder); openDivFade(modeHolder);
}, 300); }, 300);
Session.set("sidebar",null); // Closes all sidebars. Session.set("sidebar", null); // Closes all sidebars.
}, },
'click .calendar' () { // Click calendar mode button. 'click .calendar' () { // Click calendar mode button.
if (Session.equals("mode","calendar")) return; if (Session.equals("mode", "calendar")) return;
var modeHolder = document.getElementById("mainBody"); var modeHolder = document.getElementById("mainBody");
closeDivFade(modeHolder); closeDivFade(modeHolder);
setTimeout(function() { setTimeout(function() {
Session.set("mode", "calendar"); Session.set("mode", "calendar");
openDivFade(modeHolder); openDivFade(modeHolder);
}, 300); }, 300);
Session.set("sidebar",null); // Closes all sidebars. Session.set("sidebar", null); // Closes all sidebars.
}, },
'click .creWork' (event) { // Cick add work button. 'click .creWork' (event) { // Cick add work button.
var attr; var attr;
if(event.target.className !== "creWork") { if (event.target.className !== "creWork") {
attr = event.target.parentNode.getAttribute("classid"); attr = event.target.parentNode.getAttribute("classid");
} else { } else {
attr = event.target.getAttribute("classid"); attr = event.target.getAttribute("classid");
} }
Session.set("newWork", true); Session.set("newWork", true);
Session.set("currentReadableWork", // Default readable work. Session.set("currentReadableWork", // Default readable work.
{ {
name:"Name | Click here to edit...", name: "Name | Click here to edit...",
class:attr, class: attr,
dueDate:"Click here to edit...", dueDate: "Click here to edit...",
description:"Click here to edit...", description: "Click here to edit...",
type:"Click here to edit..." type: "Click here to edit..."
});
Session.set("currentWork", {
class: attr
}); });
Session.set("currentWork",{class:attr});
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'click .workCard' (event) { // Display work information on work card click. 'click .workCard' (event) { // Display work information on work card click.
var dom = event.target; var dom = event.target;
while(event.target.className !== "workCard") event.target = event.target.parentNode; while (event.target.className !== "workCard") event.target = event.target.parentNode;
workid = event.target.getAttribute("workid"); workid = event.target.getAttribute("workid");
Session.set("newWork",false); Session.set("newWork", false);
var thisWork = work.findOne({_id:workid}); var thisWork = work.findOne({
Session.set("currentWork",thisWork); _id: workid
});
Session.set("currentWork", thisWork);
var thisReadWork = formReadable(thisWork); var thisReadWork = formReadable(thisWork);
Session.set("currentReadableWork",thisReadWork); Session.set("currentReadableWork", thisReadWork);
if(!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) { if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({_id: Session.get("currentWork")["class"]}); var currClass = classes.findOne({
if(!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission. _id: Session.get("currentWork")["class"]
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || });
currClass.moderators.indexOf(Meteor.userId()) !== -1 || if (!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission.
currClass.banned.indexOf(Meteor.userId()) !== -1)) { Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
var inputs = $('#editWork .change').css("cursor","default"); currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1)) {
var inputs = $('#editWork .change').css("cursor", "default");
} }
} }
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
// HANDLING INPUT CHANGING // HANDLING INPUT CHANGING
'click .change' (event) { // Click changable inputs. Creates an input where the span is. 'click .change' (event) { // Click changable inputs. Creates an input where the span is.
if(!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) { if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({_id: Session.get("currentWork")["class"]}); var currClass = classes.findOne({
if(!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission. _id: Session.get("currentWork")["class"]
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || });
currClass.moderators.indexOf(Meteor.userId()) !== -1 || if (!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission.
currClass.banned.indexOf(Meteor.userId()) !== -1 Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
)) return; currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
)) return;
} }
// CSS and DOM manipulation. // CSS and DOM manipulation.
var ele = event.target; var ele = event.target;
@ -566,7 +587,7 @@ Template.main.events({
input.typ = "text"; input.typ = "text";
input.style.height = 0.9 * dim.height.toString() + "px"; input.style.height = 0.9 * dim.height.toString() + "px";
} }
if(event.target.id !== "workDate") input.value = ele.childNodes[0].nodeValue; if (event.target.id !== "workDate") input.value = ele.childNodes[0].nodeValue;
input.className = "changeInput"; input.className = "changeInput";
input.style.width = "70%"; input.style.width = "70%";
@ -580,7 +601,7 @@ Template.main.events({
} else { } else {
input.select(); input.select();
} }
if(ele.id === "workDate") { if (ele.id === "workDate") {
input.className += " form-control"; input.className += " form-control";
} }
input.focus(); input.focus();
@ -597,18 +618,20 @@ Template.main.events({
} }
}, },
'click .radio' (event) { // Click dropdown input. Opens the dropdown menu. 'click .radio' (event) { // Click dropdown input. Opens the dropdown menu.
if(!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) { if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({_id: Session.get("currentWork")["class"]}); var currClass = classes.findOne({
if(!(Meteor.userId() === Session.get("currentWork").creator || _id: Session.get("currentWork")["class"]
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || });
currClass.moderators.indexOf(Meteor.userId()) !== -1 || if (!(Meteor.userId() === Session.get("currentWork").creator ||
currClass.banned.indexOf(Meteor.userId()) !== -1 Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
)) return; currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
)) return;
} }
var op = event.target; var op = event.target;
var radio; var radio;
if(Session.equals("sidebar","optionsContainer") || Session.equals("sidebar","both")) { if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
radio = "prefOptions"; radio = "prefOptions";
} else { } else {
radio = "workOptions"; radio = "workOptions";
@ -616,7 +639,7 @@ Template.main.events({
try { try {
for (var i = 0; i < document.getElementsByClassName(radio).length; i++) { // Close any previously open menus. for (var i = 0; i < document.getElementsByClassName(radio).length; i++) { // Close any previously open menus.
var curr = document.getElementsByClassName(radio)[i]; var curr = document.getElementsByClassName(radio)[i];
if(curr.childNodes[1] !== op.parentNode.parentNode.childNodes[3].childNodes[1]) { if (curr.childNodes[1] !== op.parentNode.parentNode.childNodes[3].childNodes[1]) {
closeDivFade(document.getElementsByClassName(radio)[i]); closeDivFade(document.getElementsByClassName(radio)[i]);
} }
} }
@ -670,26 +693,28 @@ Template.main.events({
var input = document.getElementById('workComment'); var input = document.getElementById('workComment');
comment = input.value; comment = input.value;
input.value = ""; input.value = "";
Session.set("commentRestrict",null); Session.set("commentRestrict", null);
if (comment !== "") { if (comment !== "") {
document.getElementById('workComment').value = ""; document.getElementById('workComment').value = "";
Meteor.call('addComment', [comment, workId], function(err,result) { Meteor.call('addComment', [comment, workId], function(err, result) {
var thisWork = work.findOne({_id:workId}); var thisWork = work.findOne({
Session.set("currentWork",thisWork); _id: workId
});
Session.set("currentWork", thisWork);
var thisReadWork = formReadable(thisWork); var thisReadWork = formReadable(thisWork);
Session.set("currentReadableWork",thisReadWork); Session.set("currentReadableWork", thisReadWork);
}); });
} }
}, },
'click #workSubmit' () { // Click submit work to create a work. 'click #workSubmit' () { // Click submit work to create a work.
if(getHomeworkFormData() === null) return; // Makes sure to check valid homework. if (getHomeworkFormData() === null) return; // Makes sure to check valid homework.
serverData = Session.get("currentWork"); serverData = Session.get("currentWork");
if(Session.get("newWork")) { if (Session.get("newWork")) {
sendData("createWork"); sendData("createWork");
} else { } else {
sendData("editWork"); sendData("editWork");
} }
Session.set("newWork",null); Session.set("newWork", null);
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'click #workDelete' () { 'click #workDelete' () {
@ -698,15 +723,15 @@ Template.main.events({
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'input #workComment' (event) { // Restrict length on comment. 'input #workComment' (event) { // Restrict length on comment.
var chars = 200-event.target.value.length; var chars = 200 - event.target.value.length;
document.getElementById("commentRestrict").style.color = "#7E7E7E"; document.getElementById("commentRestrict").style.color = "#7E7E7E";
if(chars === 200) { // Don't display if nothing in comment. if (chars === 200) { // Don't display if nothing in comment.
Session.set("commentRestrict",""); Session.set("commentRestrict", "");
return; return;
} else if(chars === 0) { } else if (chars === 0) {
document.getElementById("commentRestrict").style.color = "#FF1A1A"; // Make text red if 0 characters left. document.getElementById("commentRestrict").style.color = "#FF1A1A"; // Make text red if 0 characters left.
} }
Session.set("commentRestrict",chars.toString() + " characters left"); Session.set("commentRestrict", chars.toString() + " characters left");
}, },
'click #markDone' () { // Click done button. 'click #markDone' () { // Click done button.
serverData = [Session.get("currentWork")._id, "done"]; serverData = [Session.get("currentWork")._id, "done"];
@ -723,56 +748,58 @@ Template.main.events({
// CLASS FILTERS // CLASS FILTERS
'click .sideClass' (event) { // Click class list in sidebar. 'click .sideClass' (event) { // Click class list in sidebar.
var div = event.target; var div = event.target;
while(div.getAttribute("classid") === null) div = div.parentNode; while (div.getAttribute("classid") === null) div = div.parentNode;
var classid = div.getAttribute("classid"); var classid = div.getAttribute("classid");
if(Session.get("calCreWork")) { // If creating work from calendar. if (Session.get("calCreWork")) { // If creating work from calendar.
Session.get("calCreWork",null); Session.get("calCreWork", null);
Session.set("sidebar",null); Session.set("sidebar", null);
var date = calWorkDate.split("-"); var date = calWorkDate.split("-");
date = new Date(date[0],parseInt(date[1])-1,date[2],11,59,59); date = new Date(date[0], parseInt(date[1]) - 1, date[2], 11, 59, 59);
Session.set("newWork", true); Session.set("newWork", true);
Session.set("currentReadableWork", Session.set("currentReadableWork", {
{ name: "Name | Click here to edit...",
name:"Name | Click here to edit...", class: classid,
class:classid, dueDate: getReadableDate(date),
dueDate:getReadableDate(date), description: "Click here to edit...",
description:"Click here to edit...", type: "Click here to edit..."
type:"Click here to edit..." });
Session.set("currentWork", {
class: classid,
dueDate: date
}); });
Session.set("currentWork",{class:classid,dueDate:date});
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
} else { // Normal clicking turns on filter. } else { // Normal clicking turns on filter.
var array = Session.get("classDisp"); var array = Session.get("classDisp");
if(array.indexOf(classid) !== -1) { if (array.indexOf(classid) !== -1) {
array.splice(array.indexOf(classid),1); array.splice(array.indexOf(classid), 1);
} else { } else {
array.push(classid); array.push(classid);
} }
Session.set("classDisp",array); Session.set("classDisp", array);
} }
}, },
'click #disableFilter' () { 'click #disableFilter' () {
Session.set("classDisp",[]); Session.set("classDisp", []);
}, },
'mouseover .sideClass' (event) { // Highlight/scale filter on-hover. 'mouseover .sideClass' (event) { // Highlight/scale filter on-hover.
var div; var div;
if(event.target.className !== "sideClass") { if (event.target.className !== "sideClass") {
div = event.target.parentNode; div = event.target.parentNode;
} else { } else {
div = event.target; div = event.target;
} }
while(div.getAttribute("classid") === null) div = div.parentNode; while (div.getAttribute("classid") === null) div = div.parentNode;
var classid = div.getAttribute("classid"); var classid = div.getAttribute("classid");
Session.set("classDispHover",classid); Session.set("classDispHover", classid);
}, },
'mouseleave .sideClass' (event) { // Turn off highlight/scale filter on-leave. 'mouseleave .sideClass' (event) { // Turn off highlight/scale filter on-leave.
if(event.target.className !== "sideClass") { if (event.target.className !== "sideClass") {
var div = event.target.parentNode; var div = event.target.parentNode;
if(div.contains(event.target)) return; if (div.contains(event.target)) return;
} }
Session.set("classDispHover",null); Session.set("classDispHover", null);
} }
}); });
@ -792,13 +819,15 @@ function closeDivFade(div) {
} }
function sendData(funcName) { // Call Meteor function, and do actions after function is completed depending on function. function sendData(funcName) { // Call Meteor function, and do actions after function is completed depending on function.
Meteor.call(funcName, serverData , function(err,result) { Meteor.call(funcName, serverData, function(err, result) {
if(funcName === "toggleWork") { if (funcName === "toggleWork") {
var workId = Session.get("currentWork")._id; var workId = Session.get("currentWork")._id;
var thisWork = work.findOne({_id:workId}); var thisWork = work.findOne({
Session.set("currentWork",thisWork); _id: workId
});
Session.set("currentWork", thisWork);
var thisReadWork = formReadable(thisWork); var thisReadWork = formReadable(thisWork);
Session.set("currentReadableWork",thisReadWork); Session.set("currentReadableWork", thisReadWork);
} }
}); });
} }
@ -807,7 +836,7 @@ function closeInput(modifyingInput) { // Close a changeable input and change it
var input = document.getElementById(modifyingInput + "a"); var input = document.getElementById(modifyingInput + "a");
var span = document.getElementById(modifyingInput); var span = document.getElementById(modifyingInput);
var color; var color;
if(Session.equals("sidebar","optionsContainer") || Session.equals("sidebar","both")) { if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
color = "#000"; color = "#000";
} else { } else {
color = "#8C8C8C"; color = "#8C8C8C";
@ -826,11 +855,11 @@ function closeInput(modifyingInput) { // Close a changeable input and change it
span.style.display = "initial"; span.style.display = "initial";
Session.set("modifying", null); Session.set("modifying", null);
if(Session.equals("sidebar","optionsContainer") || Session.equals("sidebar","both")) { // Close depending on work or preferences. if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) { // Close depending on work or preferences.
serverData = getPreferencesData(); serverData = getPreferencesData();
sendData("editProfile"); sendData("editProfile");
} else if(!Session.get("newWork")) { } else if (!Session.get("newWork")) {
if(getHomeworkFormData() === null) return; if (getHomeworkFormData() === null) return;
serverData = Session.get("currentWork"); serverData = Session.get("currentWork");
sendData("editWork"); sendData("editWork");
} }
@ -839,15 +868,15 @@ function closeInput(modifyingInput) { // Close a changeable input and change it
function getHomeworkFormData() { // Get all data relating to work creation. function getHomeworkFormData() { // Get all data relating to work creation.
var inputs = document.getElementsByClassName("req"); var inputs = document.getElementsByClassName("req");
var stop; var stop;
for(var i = 0; i < inputs.length; i++) { for (var i = 0; i < inputs.length; i++) {
var value = inputs[i].childNodes[0].nodeValue; var value = inputs[i].childNodes[0].nodeValue;
if(value.includes("Click here to edit")) { if (value.includes("Click here to edit")) {
inputs[i].childNodes[0].nodeValue = "Missing field"; inputs[i].childNodes[0].nodeValue = "Missing field";
inputs[i].style.color = "#FF1A1A"; inputs[i].style.color = "#FF1A1A";
stop = true; stop = true;
} }
} }
if(stop) return null; if (stop) return null;
var data = Session.get("currentWork"); var data = Session.get("currentWork");
data.name = document.getElementById("workName").childNodes[0].nodeValue; data.name = document.getElementById("workName").childNodes[0].nodeValue;
@ -863,36 +892,36 @@ function getHomeworkFormData() { // Get all data relating to work creation.
function getPreferencesData() { // Get all data relating to preferences. function getPreferencesData() { // Get all data relating to preferences.
var profile = Meteor.user().profile; var profile = Meteor.user().profile;
var options = { var options = {
"theme":document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(), "theme": document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(),
"mode":document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(), "mode": document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(),
"timeHide":ref[document.getElementById("prefHide").childNodes[0].nodeValue], "timeHide": ref[document.getElementById("prefHide").childNodes[0].nodeValue],
"done":ref[document.getElementById("prefDone").childNodes[0].nodeValue] "done": ref[document.getElementById("prefDone").childNodes[0].nodeValue]
}; };
profile.preferences = options; profile.preferences = options;
return profile; return profile;
} }
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
function getReadableDate(date) { // Get readable date from Date constructor. function getReadableDate(date) { // Get readable date from Date constructor.
return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate()+", "+date.getFullYear(); return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();
} }
function toDate(date) { // Turns formatted date back to Date constructor. function toDate(date) { // Turns formatted date back to Date constructor.
date = date.substring(date.search(",")+2,date.length); date = date.substring(date.search(",") + 2, date.length);
month = months.indexOf(date.substring(0,date.search(" "))); month = months.indexOf(date.substring(0, date.search(" ")));
day = date.substring(date.search(" ")+1,date.search(",")); day = date.substring(date.search(" ") + 1, date.search(","));
year = date.substring(date.search(",")+2,date.length); year = date.substring(date.search(",") + 2, date.length);
return new Date(year,month,day,11,59,59); return new Date(year, month, day, 11, 59, 59);
} }
function formReadable(input) { // Makes work information readable by users. function formReadable(input) { // Makes work information readable by users.
input.dueDate = getReadableDate(input.dueDate); input.dueDate = getReadableDate(input.dueDate);
input.type = input.type[0].toUpperCase() + input.type.slice(1); input.type = input.type[0].toUpperCase() + input.type.slice(1);
if(!Session.get("newWork")) { if (!Session.get("newWork")) {
if(input.done.indexOf(Meteor.userId()) !== -1) { // If user marked as done. if (input.done.indexOf(Meteor.userId()) !== -1) { // If user marked as done.
input.doneCol = "#27A127"; input.doneCol = "#27A127";
input.doneText = "Done!"; input.doneText = "Done!";
} else { } else {
@ -900,17 +929,21 @@ function formReadable(input) { // Makes work information readable by users.
input.doneText = "Mark done"; input.doneText = "Mark done";
} }
for(var i = 0; i < input.done.length; i++) { // Display users who marked as done. for (var i = 0; i < input.done.length; i++) { // Display users who marked as done.
input.done[i] = {"user":Meteor.users.findOne({_id:input.done[i]}).profile.name}; input.done[i] = {
"user": Meteor.users.findOne({
_id: input.done[i]
}).profile.name
};
} }
if(input.confirmations.indexOf(Meteor.userId()) !== -1) { // If user confirmed. if (input.confirmations.indexOf(Meteor.userId()) !== -1) { // If user confirmed.
input.userConfirm = "#27A127"; input.userConfirm = "#27A127";
} else { } else {
input.userConfirm = ""; input.userConfirm = "";
} }
if(input.reports.indexOf(Meteor.userId()) !== -1) { // If user reported. if (input.reports.indexOf(Meteor.userId()) !== -1) { // If user reported.
input.userReport = "#FF1A1A"; input.userReport = "#FF1A1A";
} else { } else {
input.userReport = ""; input.userReport = "";
@ -921,12 +954,18 @@ function formReadable(input) { // Makes work information readable by users.
var comments = input.comments; var comments = input.comments;
var resort = []; var resort = [];
if(!Session.get("newWork")) { // Don't display comments if user is creating work. if (!Session.get("newWork")) { // Don't display comments if user is creating work.
for(var k = 0; k < comments.length; k++) { for (var k = 0; k < comments.length; k++) {
var re = comments.length-k-1; var re = comments.length - k - 1;
resort[re] = {"comment":comments[k].comment,"date":null,"user":null}; resort[re] = {
resort[re].user = Meteor.users.findOne({_id:comments[k].user}).profile.name; "comment": comments[k].comment,
resort[re].date = moment(comments[k].date).fromNow(); "date": null,
"user": null
};
resort[re].user = Meteor.users.findOne({
_id: comments[k].user
}).profile.name;
resort[re].date = moment(comments[k].date).fromNow();
} }
input.comments = resort; input.comments = resort;
} }