1033 lines
41 KiB
JavaScript
Raw Normal View History

2016-09-04 20:10:58 -04:00
/* jshint esversion: 6 */
2016-08-12 12:28:55 -04:00
import {
Template
} from 'meteor/templating';
2016-08-09 01:33:14 -04:00
import './main.html';
var load = true;
2016-09-02 00:15:29 -04:00
var calWorkOpen = null;
var calWorkDate = null;
2016-08-09 01:33:14 -04:00
var openValues = {
2016-08-12 12:28:55 -04:00
"menu": "-25%",
"options": "-20%"
2016-08-09 01:33:14 -04:00
};
2016-09-04 20:10:58 -04:00
// Sets colors for different assignment statuses
2016-08-12 23:10:27 -04:00
var workColors = {
2016-08-18 23:59:38 -04:00
"normal": "#2E4F74",
"quiz": "#409333",
"test": "#AD3C44",
2016-09-02 00:15:29 -04:00
"project": "#D8831A",
"other": "#852E6D"
2016-08-12 12:28:55 -04:00
};
2016-09-04 20:10:58 -04:00
// Creates variables for due dates
2016-08-27 00:54:12 -04:00
var ref = {
2016-09-04 20:13:31 -04:00
"1 Day": 1,
"2 Days": 2,
"1 Week": 7,
"1 Month": 30,
"Never": 0,
"Yes": true,
"No": false
2016-08-28 20:09:16 -04:00
};
2016-08-28 18:41:35 -04:00
2016-08-20 23:37:04 -04:00
// Reactive variables.
2016-09-06 00:27:43 -04:00
Session.set("user",{}); // Stores user preferences.
2016-09-07 15:33:13 -04:00
Session.set("calendarClasses", []); // Stores calendar classes.
Session.set("sidebar", null); // Status of sidebar
2016-09-04 20:13:31 -04:00
Session.set("newWork", null); // If user creating new work.
Session.set("currentWork", null); // Stores current selected work info.
Session.set("currentReadableWork", null); // Stores readable selected work info.
Session.set("modifying", null); // Stores current open input.
Session.set("noclass", null); // If user does not have classes.
Session.set("calCreWork", null); // If user is creating a work from calendar.
Session.set("classDisp", []); // Stores current filter for classes.
Session.set("classDispHover", null); // Stores current hovered filter.
Session.set("refetchEvents", null); // Stores whether to get calendar events again.
2016-09-05 14:51:40 -04:00
Session.set("commentRestrict", ""); // Stores text for comment character restriction.
2016-08-09 01:33:14 -04:00
2016-09-09 02:17:32 -04:00
Template.login.rendered = function() {
Accounts._loginButtonsSession.set('dropdownVisible', true);
};
Template.main.rendered = function() {
Accounts._loginButtonsSession.set('dropdownVisible', true);
};
Template.profile.rendered = function() {
Accounts._loginButtonsSession.set('dropdownVisible', true);
};
2016-09-05 15:45:21 -04:00
Template.registerHelper('userProfile', () => {
2016-09-05 14:51:40 -04:00
if(Meteor.user() === undefined || Meteor.user() === null) return;
Session.set("user", Meteor.user().profile);
return;
});
2016-08-29 21:02:02 -04:00
Template.registerHelper('divColor', (div) => { // Reactive color changing based on preferences. Colors stored in themeColors.
return themeColors[Session.get("user").preferences.theme][div];
2016-08-22 23:44:48 -04:00
});
Template.registerHelper('textColor', () => { // Reactive color for text.
document.getElementsByTagName("body")[0].style.color = themeColors[Session.get("user").preferences.theme].text;
2016-08-28 23:25:43 -04:00
return;
2016-08-12 12:28:55 -04:00
});
2016-08-09 17:07:11 -04:00
2016-08-28 23:25:43 -04:00
Template.registerHelper('overlayDim', (part) => { // Gets size of the overlay container.
var dim = [window.innerWidth * 0.25, window.innerHeight * 0.2];
2016-08-12 12:28:55 -04:00
var width = "width:" + dim[0].toString() + "px;";
var height = "height:" + dim[1].toString() + "px;";
var margin = "margin-left:" + (-dim[0] / 2).toString() + "px;";
var bg = "background-color:" + themeColors[Session.get("user").preferences.theme].header + ";";
2016-08-12 12:28:55 -04:00
return width + height + margin + bg;
});
2016-08-30 18:49:33 -04:00
Template.registerHelper('myClasses', () => { // Gets all classes and respective works.
2016-09-07 21:26:26 -04:00
if(Session.get("user").classes.length === 0) { // Null checking.
2016-08-30 18:49:33 -04:00
Session.set("noclass",true); // Makes sure to display nothing.
2016-08-18 23:59:38 -04:00
return [];
2016-08-14 07:52:27 -04:00
} else {
2016-08-18 23:59:38 -04:00
var array = [];
var courses = Session.get("user").classes;
2016-08-30 18:49:33 -04:00
var classDisp = Session.get("classDisp"); // Get sidebar class filter.
var hide = Session.get("user").preferences.timeHide;
2016-08-30 18:49:33 -04:00
2016-09-04 20:13:31 -04:00
for (var i = 0; i < courses.length; i++) { // For each user class.
found = classes.findOne({
_id: courses[i]
});
found.subscribers = found.subscribers.length;
2016-08-21 22:50:23 -04:00
found.mine = true;
2016-09-04 20:13:31 -04:00
if (found.admin === Meteor.userId()) { // If user owns this class.
2016-08-23 22:09:07 -04:00
found.box = " owned";
found.mine = false;
}
2016-09-04 20:13:31 -04:00
if (classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected.
2016-08-18 23:59:38 -04:00
array.push(found);
2016-09-04 20:13:31 -04:00
var thisWork = work.find({
class: courses[i]
}).fetch();
2016-08-18 23:59:38 -04:00
2016-09-04 20:13:31 -04:00
if (classDisp.length !== 0 && classDisp.indexOf(found._id) === -1) { // Filter classes based on filter.
array[i].thisClassWork = [];
continue;
}
2016-09-04 20:10:58 -04:00
2016-09-04 20:13:31 -04:00
for (var j = 0; j < thisWork.length; j++) { // For each work in class.
if (hide !== 0) { // Time to hide isn't never.
2016-09-04 20:10:58 -04:00
var due = (moment(thisWork[j].dueDate))._d;
2016-09-04 20:13:31 -04:00
var offset = (moment().subtract(hide, 'days'))._d;
if (offset > due) { // If due is before hide days before today
2016-08-27 00:54:12 -04:00
thisWork[j] = "no";
j = 0;
2016-08-26 23:50:46 -04:00
}
}
2016-09-05 00:16:26 -04:00
if(thisWork[j] !== "no" && Session.get("user").preferences.done) { // If done filter is true
2016-08-30 18:49:33 -04:00
if(thisWork[j].done.indexOf(Meteor.userId()) !== -1) { // If user marked this work done.
2016-08-28 18:41:35 -04:00
thisWork[j] = "no";
j = 0;
}
}
2016-09-04 20:10:58 -04:00
2016-08-27 00:54:12 -04:00
}
2016-09-04 20:13:31 -04:00
while (thisWork.indexOf("no") !== -1) thisWork.splice(thisWork.indexOf("no"), 1); // Splice all filtered works.
2016-08-27 00:54:12 -04:00
2016-09-04 20:13:31 -04:00
for (j = 0; j < thisWork.length; j++) {
2016-08-30 18:49:33 -04:00
thisWork[j].realDate = thisWork[j].dueDate;
2016-08-18 23:59:38 -04:00
thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, {
2016-08-18 18:11:45 -04:00
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'MMMM Do'
});
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
if (thisWork[j].dueDate === "Today") { // Font weight based on date proximity.
thisWork[j].cardDate = "600";
2016-09-04 20:13:31 -04:00
} else if (thisWork[j].dueDate === "Tomorrow") {
thisWork[j].cardDate = "400";
}
2016-08-18 23:59:38 -04:00
thisWork[j].typeColor = workColors[thisWork[j].type];
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
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;
2016-09-04 20:10:58 -04:00
2016-08-30 18:49:33 -04:00
var hoverHighlight = Session.get("classDispHover"); // Highlight/scale related class works on hover.
2016-09-10 00:39:28 -04:00
if (hoverHighlight !== null && hoverHighlight === found._id && Session.equals("mode","classes")) {
thisWork[j].scale = "-ms-transform: scale(1.12)-webkit-transform: scale(1.12);transform: scale(1.12)";
} else {
thisWork[j].scale = "";
}
2016-08-18 23:59:38 -04:00
}
array[i].thisClassWork = thisWork;
}
2016-09-04 20:13:31 -04:00
Session.set("noclass", false);
2016-08-30 18:49:33 -04:00
Session.set("calendarClasses", array);
2016-09-04 20:13:31 -04:00
Session.set("refetchEvents", true);
2016-08-18 23:59:38 -04:00
return array;
}
2016-08-14 07:52:27 -04:00
});
2016-08-30 18:49:33 -04:00
Template.registerHelper('pref', (val) => { // Obtains all user preferences.
var preferences = Session.get("user").preferences;
2016-08-31 23:09:21 -04:00
if(val === 'timeHide' || val === 'done') {
var invert = _.invert(ref);
return invert[preferences[val]];
2016-08-28 14:36:26 -04:00
}
2016-08-31 23:09:21 -04:00
return preferences[val].charAt(0).toUpperCase() + preferences[val].slice(1);
2016-08-28 14:36:26 -04:00
});
2016-09-05 14:51:40 -04:00
Template.registerHelper('commentLength', () => { // Returns characters left for comment length.
return Session.get("commentRestrict");
2016-09-07 21:26:26 -04:00
});
2016-09-05 14:51:40 -04:00
2016-08-09 01:33:14 -04:00
Template.main.helpers({
2016-08-30 18:49:33 -04:00
schoolName() { // Finds the name of the user's school.
if(Session.get("user").school === undefined) return;
return " - " + Session.get("user").school;
2016-08-12 12:28:55 -04:00
},
2016-08-30 18:49:33 -04:00
iconColor(icon) { // Sidebar status color
2016-09-02 01:00:52 -04:00
if (Session.equals("sidebar",icon + "Container")) {
return themeColors[Session.get("user").preferences.theme].statusIcons;
2016-09-02 01:00:52 -04:00
} else if (Session.equals("sidebar","both")) {
return themeColors[Session.get("user").preferences.theme].statusIcons;
2016-08-12 12:28:55 -04:00
} else {
return;
}
},
2016-09-07 15:33:13 -04:00
avatar() { // Returns avatar.
return Session.get("user").avatar;
},
username() { // Returns user name.
return Session.get("user").name;
},
2016-08-30 18:49:33 -04:00
defaultMode() { //Loads the default display mode for user.
2016-09-05 14:51:40 -04:00
if(load) Session.set("mode",Session.get("user").preferences.mode);
2016-09-10 00:39:28 -04:00
load = false;
2016-08-23 00:11:57 -04:00
return;
},
bgSrc() { // Returns background.
2016-09-05 00:16:26 -04:00
return "Backgrounds/"+ themeColors[Session.get("user").preferences.theme].background;
2016-08-12 12:28:55 -04:00
},
2016-08-30 18:49:33 -04:00
menuStatus() { // Status of of menu sidebar.
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "menuContainer")) {
2016-08-12 12:28:55 -04:00
return "0%";
2016-09-04 20:13:31 -04:00
} else if (Session.equals("sidebar", "both")) {
2016-08-12 12:28:55 -04:00
return "0%";
} else {
return openValues.menu;
}
},
2016-08-30 18:49:33 -04:00
optionsStatus() { // Status of options sidebar.
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "optionsContainer")) {
2016-08-12 12:28:55 -04:00
return "0%";
2016-09-04 20:13:31 -04:00
} else if (Session.equals("sidebar", "both")) {
2016-08-12 12:28:55 -04:00
return "0%";
} else {
return openValues.options;
}
},
2016-08-30 18:49:33 -04:00
modeStatus(status) { // Color status of display modes.
2016-09-05 00:16:26 -04:00
if (!Session.equals("mode",status)) return;
return themeColors[Session.get("user").preferences.theme].highlightText;
2016-08-12 12:28:55 -04:00
},
2016-08-30 18:49:33 -04:00
currMode(name) { // Status of display mode.
2016-09-05 14:51:40 -04:00
return Session.equals("mode",name);
2016-08-12 12:28:55 -04:00
},
2016-08-30 18:49:33 -04:00
calendarOptions() { // Settings for the calendar, including work displaying.
2016-08-12 12:28:55 -04:00
return {
2016-08-18 23:59:38 -04:00
id: "fullcalendar",
2016-08-15 20:55:21 -04:00
height: window.innerHeight * 0.8,
2016-08-12 12:28:55 -04:00
buttonText: {
today: 'Today',
month: 'Month',
week: 'Week',
day: 'Day'
},
2016-09-02 00:15:29 -04:00
eventLimit: 3,
2016-08-18 23:59:38 -04:00
events: function(start, end, timezone, callback) {
var events = [];
2016-08-30 18:49:33 -04:00
var userClasses = Session.get("calendarClasses");
2016-08-27 00:54:12 -04:00
2016-09-04 20:13:31 -04:00
for (var i = 0; i < userClasses.length; i++) {
2016-08-30 18:49:33 -04:00
var works = userClasses[i].thisClassWork;
2016-09-04 20:13:31 -04:00
for (var j = 0; j < works.length; j++) {
2016-08-30 18:49:33 -04:00
var work = works[j];
2016-09-04 20:13:31 -04:00
var currClass = classes.findOne({
_id: work.class
});
2016-08-30 18:49:33 -04:00
var inRole = false;
2016-09-04 20:13:31 -04:00
if (Meteor.userId() === work.creator ||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
2016-08-30 18:49:33 -04:00
) inRole = true;
events.push({
2016-08-30 18:49:33 -04:00
id: work._id,
start: work.realDate.toISOString().slice(0, 10),
title: work.name,
backgroundColor: workColors[work.type],
borderColor: "#444",
startEditable: inRole,
2016-09-07 21:26:26 -04:00
className: "workevent " + work.class
2016-09-04 20:10:58 -04:00
});
}
2016-08-30 18:49:33 -04:00
}
2016-08-18 23:59:38 -04:00
callback(events);
},
2016-08-30 18:49:33 -04:00
eventDrop: function(event, delta, revertFunc) { // When user drops from click-dragging.
2016-09-04 20:13:31 -04:00
var current = work.findOne({
_id: event.id
});
var date = event.start.format().split("-");
2016-09-04 20:13:31 -04:00
current.dueDate = new Date(date[0], parseInt(date[1]) - 1, date[2], 11, 59, 59);
2016-08-29 21:02:02 -04:00
serverData = current;
sendData("editWork");
2016-08-18 23:59:38 -04:00
},
2016-08-30 18:49:33 -04:00
eventClick: function(event, jsEvent, view) { // On-click for work.
2016-09-04 20:13:31 -04:00
Session.set("newWork", false);
var thisWork = work.findOne({
_id: event.id
});
Session.set("currentWork", thisWork);
2016-08-18 23:59:38 -04:00
var thisReadWork = formReadable(thisWork);
2016-09-04 20:13:31 -04:00
Session.set("currentReadableWork", thisReadWork);
2016-08-18 23:59:38 -04:00
openDivFade(document.getElementsByClassName("overlay")[0]);
},
2016-08-30 18:49:33 -04:00
dayClick: function(date, jsEvent, view) { // On-click for each day.
2016-09-08 16:51:22 -04:00
if (jsEvent.target.className.includes("fc-past") || Session.get("noclass")) return;
2016-09-02 00:15:29 -04:00
Session.set("calCreWork", true);
calWorkDate = date.format();
2016-09-02 00:15:29 -04:00
calWorkOpen = true;
2016-09-01 00:23:22 -04:00
Session.set("newWork", true);
2016-09-04 20:13:31 -04:00
Session.set("sidebar", "menuContainer");
2016-08-19 22:04:32 -04:00
}
2016-08-12 12:28:55 -04:00
};
},
calCenter() { // Centers the calendar
2016-08-12 12:28:55 -04:00
var width = window.innerWidth * 0.85;
2016-08-23 00:11:57 -04:00
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
return "color:"+themeColors[Session.get("user").preferences.theme].calendar;
2016-09-07 21:26:26 -04:00
},
2016-08-30 18:49:33 -04:00
calCreWork() { // Display instructions for creating a work.
2016-09-04 20:13:31 -04:00
if (Session.get("calCreWork")) return true;
2016-09-02 00:53:12 -04:00
return false;
},
filterOn() {
2016-09-04 20:13:31 -04:00
if (Session.get("classDisp").length !== 0) return true;
2016-09-02 00:53:12 -04:00
return false;
},
2016-08-30 18:49:33 -04:00
highlight() { // Calendar highlight/scale option.
var hoverHighlight = Session.get("classDispHover");
var works = document.getElementsByClassName("workevent");
var work = $('.workevent');
2016-09-04 20:13:31 -04:00
if (hoverHighlight === null) {
work.css('-webkit-transform', '');
work.css('-ms-transform', '');
work.css('transform', '');
return;
}
2016-09-04 20:13:31 -04:00
for (var i = 0; i < works.length; i++) {
var id = works[i].className;
var index = id.indexOf("workevent");
2016-09-04 20:13:31 -04:00
id = id.substring(index + 10, index + 27);
2016-09-10 00:39:28 -04:00
console.log(id);
2016-09-04 20:13:31 -04:00
if (id === hoverHighlight) {
works[i].style.webkitTransform = 'scale(1.12)';
works[i].style.msTransform = 'scale(1.12)';
works[i].style.transform = 'scale(1.12)';
} else {
works[i].style.webkitTransform = '';
works[i].style.msTransform = '';
works[i].style.transform = '';
2016-09-04 20:10:58 -04:00
}
}
return;
},
2016-08-30 18:49:33 -04:00
workCenter() { // Centers work overlay.
2016-08-15 20:55:21 -04:00
var w = window.innerWidth * 0.3;
2016-08-12 23:10:27 -04:00
var h = window.innerHeight * 0.7;
2016-09-04 20:13:31 -04:00
return "width:" + w.toString() + "px;height:" + h.toString() + "px;margin-left:" + -0.5 * w.toString() + "px;margin-top:" + -0.5 * h.toString() + "px";
2016-08-12 23:10:27 -04:00
},
2016-08-30 18:49:33 -04:00
work(value) { // Returns the specified work value.
2016-09-04 20:13:31 -04:00
if (Session.equals("currentWork", null)) return;
2016-08-18 23:59:38 -04:00
return Session.get("currentReadableWork")[value];
2016-08-12 23:10:27 -04:00
},
2016-08-30 18:49:33 -04:00
workType() { // Returns color for respective work type.
2016-09-04 20:13:31 -04:00
if (Session.equals("currentWork", null)) return;
if (Session.get("currentWork").type === undefined) return;
2016-08-18 23:59:38 -04:00
type = Session.get("currentWork").type;
2016-09-04 20:13:31 -04:00
if (type.includes("edit")) {
2016-08-18 23:59:38 -04:00
return;
} else {
return workColors[type];
}
2016-08-12 23:10:27 -04:00
},
2016-08-30 18:49:33 -04:00
newWork() { // If user is creating a new work.
2016-08-18 23:59:38 -04:00
return Session.get("newWork");
},
2016-08-30 18:49:33 -04:00
inRole() { // Checks correct permissions.
2016-09-04 20:13:31 -04:00
if (Session.equals("currentWork", null)) return;
if (Session.get("newWork")) {
2016-08-18 23:59:38 -04:00
return true;
} else {
2016-09-04 20:13:31 -04:00
var currClass = classes.findOne({
_id: Session.get("currentWork")["class"]
});
if (Meteor.userId() === Session.get("currentWork").creator ||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
) return true;
2016-08-18 23:59:38 -04:00
}
2016-09-02 00:15:29 -04:00
},
2016-09-07 15:33:13 -04:00
admin() {
return Roles.userIsInRole(Meteor.userId(), ['admin', 'superadmin']);
},
2016-09-02 00:15:29 -04:00
refetchEvents() {
2016-09-04 20:13:31 -04:00
if (Session.get("refetchEvents")) {
$("#fullcalendar").fullCalendar('refetchEvents');
Session.set("refetchEvents", null);
}
}
2016-08-09 01:33:14 -04:00
});
Template.main.events({
2016-08-30 18:49:33 -04:00
'click' (event) { // Closes respective divs when clicking outside of them. Order matters.
2016-08-12 12:28:55 -04:00
var e = event.target.className;
2016-08-30 18:49:33 -04:00
var modifyingInput = Session.get("modifying");
2016-08-30 18:49:33 -04:00
if (event.target.id !== modifyingInput && // Input for dropdown closing.
event.target.id !== modifyingInput + "a" &&
!Session.equals("modifying", null) &&
!event.target.parentNode.className.includes("workOptions") &&
!event.target.parentNode.className.includes("prefOptions")) {
2016-08-30 18:49:33 -04:00
closeInput(modifyingInput);
}
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
if (!Session.equals("sidebar", e) && // Sidebar closing.
!e.includes("fa-cog") &&
!e.includes("fa-bars") &&
!document.getElementById("menuContainer").contains(event.target) &&
!document.getElementById("optionsContainer").contains(event.target)) {
if (Session.get("calCreWork")) {
if (!calWorkOpen) {
Session.set("calCreWork", false);
Session.set("sidebar", null);
2016-09-02 00:15:29 -04:00
}
calWorkOpen = false;
} else {
2016-09-04 20:13:31 -04:00
Session.set("sidebar", null);
2016-09-04 20:10:58 -04:00
}
2016-08-12 12:28:55 -04:00
}
2016-09-04 20:13:31 -04:00
if (e === "overlay") { // Overlay closing.
closeDivFade(document.getElementsByClassName("overlay")[0]);
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork")) {
if (getHomeworkFormData() === null) return;
2016-08-29 21:02:02 -04:00
serverData = Session.get("currentWork");
sendData("editWork");
document.getElementById("workComment").value = "";
}
2016-09-04 20:13:31 -04:00
Session.set("newWork", null);
Session.set("currentWork", null);
Session.set("currentReadableWork", null);
$('.req').css("color", "");
Session.set("commentRestrict", null);
2016-08-12 23:10:27 -04:00
}
2016-08-30 18:49:33 -04:00
if (!event.target.className.includes("radio") && // Dropdown closing.
2016-08-18 17:35:40 -04:00
!event.target.parentNode.className.includes("workOptions") &&
2016-08-22 23:44:48 -04:00
!event.target.parentNode.className.includes("prefOptions") &&
2016-08-18 17:35:40 -04:00
event.target.readOnly !== true) {
2016-09-04 20:10:58 -04:00
var radio;
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
2016-09-04 20:10:58 -04:00
radio = "prefOptions";
2016-08-22 23:44:48 -04:00
} else {
2016-09-04 20:10:58 -04:00
radio = "workOptions";
2016-08-22 23:44:48 -04:00
}
for (var i = 0; i < document.getElementsByClassName(radio).length; i++) {
2016-08-12 23:10:27 -04:00
try {
2016-08-22 23:44:48 -04:00
closeDivFade(document.getElementsByClassName(radio)[i]);
2016-08-12 23:10:27 -04:00
} catch (err) {}
}
}
2016-09-07 15:33:13 -04:00
if(!document.getElementById("userDropdown").contains(event.target)) closeDivFade(document.getElementById("userDropdown"));
2016-09-09 08:20:51 -04:00
if(!document.getElementById("requests").contains(event.target)) document.getElementById("requests").style.marginBottom = "-15.3vw";
2016-08-12 23:10:27 -04:00
},
2016-08-30 18:49:33 -04:00
// MAIN MENU BUTTONS
'click .fa-bars' () { // Click menu button.
var side = Session.get("sidebar");
if (side === "menuContainer") {
Session.set("sidebar", null);
} else if (side === "optionsContainer") {
Session.set("sidebar", "both");
} else if (side === "both") {
Session.set("sidebar", "optionsContainer");
} else {
Session.set("sidebar", "menuContainer");
}
},
'click .fa-cog' () { // Click settings button.
var side = Session.get("sidebar");
if (side === "optionsContainer") {
Session.set("sidebar", null);
} else if (side === "menuContainer") {
Session.set("sidebar", "both");
} else if (side === "both") {
Session.set("sidebar", "menuContainer");
} else {
Session.set("sidebar", "optionsContainer");
}
},
'click .classes' () { // Click classes mode button.
2016-09-04 20:13:31 -04:00
if (Session.equals("mode", "classes")) return;
2016-08-30 18:49:33 -04:00
var modeHolder = document.getElementById("mainBody");
closeDivFade(modeHolder);
setTimeout(function() {
Session.set("mode", "classes");
openDivFade(modeHolder);
}, 300);
2016-09-04 20:13:31 -04:00
Session.set("sidebar", null); // Closes all sidebars.
2016-09-09 01:41:07 -04:00
Session.set("calCreWork", null);
2016-08-30 18:49:33 -04:00
},
'click .calendar' () { // Click calendar mode button.
2016-09-04 20:13:31 -04:00
if (Session.equals("mode", "calendar")) return;
2016-08-30 18:49:33 -04:00
var modeHolder = document.getElementById("mainBody");
closeDivFade(modeHolder);
setTimeout(function() {
Session.set("mode", "calendar");
openDivFade(modeHolder);
}, 300);
2016-09-04 20:13:31 -04:00
Session.set("sidebar", null); // Closes all sidebars.
2016-09-09 01:41:07 -04:00
Session.set("calCreWork", null);
2016-08-30 18:49:33 -04:00
},
'click .creWork' (event) { // Cick add work button.
2016-09-04 20:10:58 -04:00
var attr;
2016-09-04 20:13:31 -04:00
if (event.target.className !== "creWork") {
2016-09-04 20:10:58 -04:00
attr = event.target.parentNode.getAttribute("classid");
} else {
2016-09-04 20:10:58 -04:00
attr = event.target.getAttribute("classid");
}
2016-08-12 23:10:27 -04:00
Session.set("newWork", true);
2016-08-30 18:49:33 -04:00
Session.set("currentReadableWork", // Default readable work.
2016-09-04 20:13:31 -04:00
{
name: "Name | Click here to edit...",
class: attr,
dueDate: "Click here to edit...",
description: "Click here to edit...",
type: "Click here to edit..."
});
Session.set("currentWork", {
class: attr
});
openDivFade(document.getElementsByClassName("overlay")[0]);
2016-09-04 20:10:58 -04:00
},
2016-09-07 15:33:13 -04:00
'click #dropdown' (event) {
if(document.getElementById("userDropdown").style.display === "block") return;
setTimeout(function() {
openDivFade(document.getElementById("userDropdown"));
}, 300);
},
2016-08-30 18:49:33 -04:00
'click .workCard' (event) { // Display work information on work card click.
var dom = event.target;
2016-09-04 20:13:31 -04:00
while (event.target.className !== "workCard") event.target = event.target.parentNode;
2016-08-30 18:49:33 -04:00
workid = event.target.getAttribute("workid");
2016-09-04 20:13:31 -04:00
Session.set("newWork", false);
var thisWork = work.findOne({
_id: workid
});
Session.set("currentWork", thisWork);
2016-08-30 18:49:33 -04:00
var thisReadWork = formReadable(thisWork);
2016-09-04 20:13:31 -04:00
Session.set("currentReadableWork", thisReadWork);
if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({
_id: Session.get("currentWork")["class"]
});
if (!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission.
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1)) {
var inputs = $('#editWork .change').css("cursor", "default");
2016-09-04 20:10:58 -04:00
}
2016-08-30 18:49:33 -04:00
}
openDivFade(document.getElementsByClassName("overlay")[0]);
2016-08-12 23:10:27 -04:00
},
2016-09-08 16:51:22 -04:00
'click #requests .fa-question' () {
document.getElementById("requests").style.marginBottom = "0";
},
'click #requestSubmit' () {
var area = document.getElementById("requestArea");
if(area.value === "") return;
var array = {};
array.content = area.value;
array.info = {
2016-09-09 08:20:51 -04:00
"users": Meteor.users.find().fetch(),
2016-09-08 16:51:22 -04:00
"userInfo": Meteor.user(),
"userClasses": Session.get("calendarClasses")
};
Meteor.call("createRequest", array, function(err,result) {
area.value = "Request sent!";
setTimeout(function(){
2016-09-09 08:20:51 -04:00
document.getElementById("requests").style.marginBottom = "-15.3vw";
2016-09-08 16:51:22 -04:00
area.value = "";
2016-09-09 08:20:51 -04:00
Session.set("commentRestrict",null);
},750);
2016-09-08 16:51:22 -04:00
})
},
2016-08-30 18:49:33 -04:00
// HANDLING INPUT CHANGING
'click .change' (event) { // Click changable inputs. Creates an input where the span is.
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({
_id: Session.get("currentWork")["class"]
});
if (!(Meteor.userId() === Session.get("currentWork").creator || // If user has permission.
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
)) return;
2016-08-18 18:47:03 -04:00
}
2016-08-30 18:49:33 -04:00
// CSS and DOM manipulation.
2016-08-18 23:59:38 -04:00
var ele = event.target;
2016-08-30 18:49:33 -04:00
var modifyingInput = Session.get("modifying");
if (ele.id !== modifyingInput && modifyingInput !== null) closeInput(modifyingInput);
2016-08-12 23:10:27 -04:00
Session.set("modifying", ele.id);
var dim = ele.getBoundingClientRect();
ele.style.display = "none";
var input = document.createElement("input");
2016-08-15 20:55:21 -04:00
var typ = ele.getAttribute("type");
if (typ === "textarea") {
input = document.createElement("textarea");
input.style.height = 3 * dim.height.toString() + "px";
input.rows = "4";
} else if (typ !== null) {
2016-08-18 23:59:38 -04:00
input.type = typ;
input.style.height = 0.9 * dim.height.toString() + "px";
2016-08-12 23:10:27 -04:00
} else {
2016-08-18 23:59:38 -04:00
input.typ = "text";
input.style.height = 0.9 * dim.height.toString() + "px";
2016-08-12 23:10:27 -04:00
}
2016-09-04 20:13:31 -04:00
if (event.target.id !== "workDate") input.value = ele.childNodes[0].nodeValue;
2016-08-12 23:10:27 -04:00
input.className = "changeInput";
2016-08-14 07:52:27 -04:00
2016-09-10 00:39:28 -04:00
2016-08-12 23:10:27 -04:00
input.style.padding = "0.1%";
input.id = ele.id + "a";
ele.parentNode.appendChild(input);
if (ele.getAttribute("re") == "readonly") {
input.readOnly = true;
input.className += " op";
input.style.cursor = "pointer";
} else {
input.select();
}
2016-09-04 20:13:31 -04:00
if (ele.id === "workDate") {
2016-08-18 23:59:38 -04:00
input.className += " form-control";
}
2016-08-12 23:10:27 -04:00
input.focus();
2016-09-05 14:51:40 -04:00
var restrict = ele.getAttribute("restrict");
if (restrict !== null) {
input.maxLength = restrict;
input.className += " restrict";
Session.set("commentRestrict",restrict-input.value.length.toString() + " characters left");
var text = document.getElementById(Session.get("modifying")+"restrict");
text.style.display = "initial";
text.style.color = "#7E7E7E";
2016-08-12 23:10:27 -04:00
}
},
2016-08-30 18:49:33 -04:00
'click .radio' (event) { // Click dropdown input. Opens the dropdown menu.
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({
_id: Session.get("currentWork")["class"]
});
if (!(Meteor.userId() === Session.get("currentWork").creator ||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1
)) return;
}
var op = event.target;
2016-09-04 20:10:58 -04:00
var radio;
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
2016-09-04 20:10:58 -04:00
radio = "prefOptions";
2016-08-22 23:44:48 -04:00
} else {
2016-09-04 20:10:58 -04:00
radio = "workOptions";
2016-08-22 23:44:48 -04:00
}
try {
2016-08-30 18:49:33 -04:00
for (var i = 0; i < document.getElementsByClassName(radio).length; i++) { // Close any previously open menus.
2016-08-22 23:44:48 -04:00
var curr = document.getElementsByClassName(radio)[i];
2016-09-04 20:13:31 -04:00
if (curr.childNodes[1] !== op.parentNode.parentNode.childNodes[3].childNodes[1]) {
2016-08-22 23:44:48 -04:00
closeDivFade(document.getElementsByClassName(radio)[i]);
}
}
} catch (err) {}
openDivFade(op.parentNode.parentNode.childNodes[3]);
},
2016-08-30 18:49:33 -04:00
'click .workOptionText' (event) { // Click each work setting
var modifyingInput = Session.get("modifying");
var p = event.target;
var input = p.parentNode.parentNode.childNodes[1].childNodes[5];
2016-08-22 23:44:48 -04:00
input.value = p.childNodes[0].nodeValue;
2016-09-07 20:04:51 -04:00
closeDivFade(p.parentNode);
2016-08-22 23:44:48 -04:00
try {
2016-08-30 18:49:33 -04:00
closeInput(modifyingInput);
2016-08-22 23:44:48 -04:00
} catch (err) {}
input.focus();
},
2016-08-30 18:49:33 -04:00
'click .prefOptionText' (event) { // Click each preferences setting.
var modifyingInput = Session.get("modifying");
2016-08-22 23:44:48 -04:00
var p = event.target;
var input = p.parentNode.parentNode.childNodes[1].childNodes[5];
input.value = p.childNodes[0].nodeValue;
2016-09-07 20:04:51 -04:00
closeDivFade(p.parentNode);
try {
2016-08-30 18:49:33 -04:00
closeInput(modifyingInput);
} catch (err) {}
input.focus();
},
2016-09-05 14:51:40 -04:00
'click #workComment' (event) {
var restrict = event.target.maxLength;
Session.set("commentRestrict",restrict-event.target.value.length.toString() + " characters left");
var text = document.getElementById("commentrestrict");
text.style.display = "initial";
text.style.color = "#7E7E7E";
},
'keydown input' (event) { // Enter to close input.
2016-08-30 18:49:33 -04:00
var modifyingInput = Session.get("modifying");
if (event.keyCode == 13 && modifyingInput != "workDesc") {
2016-08-12 23:10:27 -04:00
try {
2016-08-30 18:49:33 -04:00
closeInput(modifyingInput);
2016-08-12 23:10:27 -04:00
} 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-09-07 21:26:26 -04:00
var text;
2016-09-05 15:49:42 -04:00
if(event.target.id === "workComment") {
2016-09-07 21:26:26 -04:00
text = document.getElementById("commentrestrict");
2016-09-08 16:51:22 -04:00
} else if(event.target.id === "requestArea") {
text = document.getElementById("requestrestrict");
2016-09-05 15:49:42 -04:00
} else {
2016-09-08 16:51:22 -04:00
text = document.getElementById(Session.get("modifying")+"restrict");
2016-09-05 15:49:42 -04:00
}
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.
}
Session.set("commentRestrict", chars.toString() + " characters left");
},
2016-08-30 18:49:33 -04:00
'focus #workDatea' () { // Open date picker.
$('#workDatea').datepicker({
format: 'DD, MM d, yyyy',
startDate: 'd',
todayHighlight: true,
todayBtn: true,
autoclose: true
});
},
// WORK OVERLAY BUTTONS
'click #commentSubmit' (event) { // Click to submit a comment.
2016-08-22 16:52:04 -04:00
workId = Session.get("currentWork")._id;
var input = document.getElementById('workComment');
comment = input.value;
input.value = "";
2016-09-04 20:13:31 -04:00
Session.set("commentRestrict", null);
2016-08-22 16:52:04 -04:00
if (comment !== "") {
document.getElementById('workComment').value = "";
2016-09-04 20:13:31 -04:00
Meteor.call('addComment', [comment, workId], function(err, result) {
var thisWork = work.findOne({
_id: workId
});
Session.set("currentWork", thisWork);
2016-08-27 21:38:42 -04:00
var thisReadWork = formReadable(thisWork);
2016-09-04 20:13:31 -04:00
Session.set("currentReadableWork", thisReadWork);
2016-08-27 21:38:42 -04:00
});
2016-08-22 16:52:04 -04:00
}
},
2016-08-30 18:49:33 -04:00
'click #workSubmit' () { // Click submit work to create a work.
2016-09-04 20:13:31 -04:00
if (getHomeworkFormData() === null) return; // Makes sure to check valid homework.
2016-08-29 21:02:02 -04:00
serverData = Session.get("currentWork");
2016-09-04 20:13:31 -04:00
if (Session.get("newWork")) {
2016-08-18 23:59:38 -04:00
sendData("createWork");
} else {
sendData("editWork");
}
2016-09-04 20:13:31 -04:00
Session.set("newWork", null);
closeDivFade(document.getElementsByClassName("overlay")[0]);
},
'click #workDelete' () {
serverData = Session.get("currentWork")._id;
sendData("deleteWork");
closeDivFade(document.getElementsByClassName("overlay")[0]);
},
2016-08-30 18:49:33 -04:00
'click #markDone' () { // Click done button.
2016-09-04 20:10:58 -04:00
serverData = [Session.get("currentWork")._id, "done"];
2016-08-30 18:49:33 -04:00
sendData("toggleWork");
},
2016-08-30 18:49:33 -04:00
'click #markConfirm' () { // Click confirm button.
2016-09-04 20:10:58 -04:00
serverData = [Session.get("currentWork")._id, "confirmations"];
2016-08-30 18:49:33 -04:00
sendData("toggleWork");
},
'click #markReport' () { // Click report button.
2016-09-04 20:10:58 -04:00
serverData = [Session.get("currentWork")._id, "reports"];
2016-08-30 18:49:33 -04:00
sendData("toggleWork");
},
2016-08-30 18:49:33 -04:00
// CLASS FILTERS
'click .sideClass' (event) { // Click class list in sidebar.
2016-08-22 23:44:48 -04:00
var div = event.target;
2016-09-04 20:13:31 -04:00
while (div.getAttribute("classid") === null) div = div.parentNode;
var classid = div.getAttribute("classid");
2016-09-04 20:13:31 -04:00
if (Session.get("calCreWork")) { // If creating work from calendar.
Session.get("calCreWork", null);
Session.set("sidebar", null);
var date = calWorkDate.split("-");
2016-09-04 20:13:31 -04:00
date = new Date(date[0], parseInt(date[1]) - 1, date[2], 11, 59, 59);
Session.set("newWork", true);
2016-09-04 20:13:31 -04:00
Session.set("currentReadableWork", {
name: "Name | Click here to edit...",
class: classid,
dueDate: getReadableDate(date),
description: "Click here to edit...",
type: "Click here to edit..."
});
2016-09-04 20:13:31 -04:00
Session.set("currentWork", {
class: classid,
dueDate: date
});
openDivFade(document.getElementsByClassName("overlay")[0]);
2016-08-30 18:49:33 -04:00
} else { // Normal clicking turns on filter.
var array = Session.get("classDisp");
2016-09-04 20:13:31 -04:00
if (array.indexOf(classid) !== -1) {
array.splice(array.indexOf(classid), 1);
} else {
array.push(classid);
2016-08-29 21:02:02 -04:00
}
2016-09-04 20:13:31 -04:00
Session.set("classDisp", array);
}
},
2016-09-02 00:53:12 -04:00
'click #disableFilter' () {
2016-09-04 20:13:31 -04:00
Session.set("classDisp", []);
2016-09-02 00:53:12 -04:00
},
2016-08-30 18:49:33 -04:00
'mouseover .sideClass' (event) { // Highlight/scale filter on-hover.
2016-09-04 20:10:58 -04:00
var div;
2016-09-04 20:13:31 -04:00
if (event.target.className !== "sideClass") {
2016-09-04 20:10:58 -04:00
div = event.target.parentNode;
} else {
2016-09-04 20:10:58 -04:00
div = event.target;
}
2016-09-04 20:13:31 -04:00
while (div.getAttribute("classid") === null) div = div.parentNode;
var classid = div.getAttribute("classid");
2016-09-04 20:13:31 -04:00
Session.set("classDispHover", classid);
},
2016-08-30 18:49:33 -04:00
'mouseleave .sideClass' (event) { // Turn off highlight/scale filter on-leave.
2016-09-04 20:13:31 -04:00
if (event.target.className !== "sideClass") {
var div = event.target.parentNode;
2016-09-04 20:13:31 -04:00
if (div.contains(event.target)) return;
}
2016-09-04 20:13:31 -04:00
Session.set("classDispHover", null);
}
2016-08-09 01:33:14 -04:00
});
function openDivFade(div) {
2016-08-12 12:28:55 -04:00
div.style.display = "block";
div.style.opacity = "0";
setTimeout(function() {
div.style.opacity = "1";
}, 100);
2016-08-09 01:33:14 -04:00
}
function closeDivFade(div) {
2016-08-12 12:28:55 -04:00
div.style.opacity = "0";
setTimeout(function() {
2016-09-07 21:26:26 -04:00
div.style.display = "none";
2016-08-12 12:28:55 -04:00
}, 100);
2016-08-09 01:33:14 -04:00
}
2016-08-30 18:49:33 -04:00
function sendData(funcName) { // Call Meteor function, and do actions after function is completed depending on function.
2016-09-04 20:13:31 -04:00
Meteor.call(funcName, serverData, function(err, result) {
if (funcName === "toggleWork") {
2016-08-28 18:41:35 -04:00
var workId = Session.get("currentWork")._id;
2016-09-04 20:13:31 -04:00
var thisWork = work.findOne({
_id: workId
});
Session.set("currentWork", thisWork);
2016-08-28 18:41:35 -04:00
var thisReadWork = formReadable(thisWork);
2016-09-04 20:13:31 -04:00
Session.set("currentReadableWork", thisReadWork);
2016-08-28 18:41:35 -04:00
}
2016-08-29 21:02:02 -04:00
});
2016-08-12 12:28:55 -04:00
}
2016-08-12 23:10:27 -04:00
2016-08-30 18:49:33 -04:00
function closeInput(modifyingInput) { // Close a changeable input and change it back to span.
var input = document.getElementById(modifyingInput + "a");
var span = document.getElementById(modifyingInput);
2016-09-04 20:10:58 -04:00
var color;
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) {
2016-09-04 20:10:58 -04:00
color = "#000";
2016-08-22 23:44:48 -04:00
} else {
2016-09-04 20:10:58 -04:00
color = "#8C8C8C";
2016-08-22 23:44:48 -04:00
}
span.style.color = color;
2016-09-05 14:51:40 -04:00
Session.set("commentRestrict","");
2016-08-12 23:10:27 -04:00
try {
2016-09-05 14:51:40 -04:00
input.parentNode.removeChild(input);
document.getElementById(modifyingInput+"restrict").style.display = "none";
2016-08-12 23:10:27 -04:00
} catch (err) {}
2016-08-30 18:49:33 -04:00
if (input.value === "") { // If input has nothing.
2016-08-12 23:10:27 -04:00
span.childNodes[0].nodeValue = "Click here to edit...";
} else {
span.childNodes[0].nodeValue = input.value;
}
2016-08-22 23:44:48 -04:00
span.style.display = "initial";
2016-08-12 23:10:27 -04:00
Session.set("modifying", null);
2016-08-23 00:11:57 -04:00
2016-09-04 20:13:31 -04:00
if (Session.equals("sidebar", "optionsContainer") || Session.equals("sidebar", "both")) { // Close depending on work or preferences.
2016-08-29 21:02:02 -04:00
serverData = getPreferencesData();
2016-08-23 00:11:57 -04:00
sendData("editProfile");
2016-09-04 20:13:31 -04:00
} else if (!Session.get("newWork")) {
if (getHomeworkFormData() === null) return;
2016-08-29 21:02:02 -04:00
serverData = Session.get("currentWork");
2016-08-18 23:59:38 -04:00
sendData("editWork");
2016-08-28 23:25:43 -04:00
}
2016-08-12 23:10:27 -04:00
}
2016-08-30 18:49:33 -04:00
function getHomeworkFormData() { // Get all data relating to work creation.
2016-08-18 23:59:38 -04:00
var inputs = document.getElementsByClassName("req");
var stop;
2016-09-04 20:13:31 -04:00
for (var i = 0; i < inputs.length; i++) {
2016-08-18 23:59:38 -04:00
var value = inputs[i].childNodes[0].nodeValue;
2016-09-04 20:13:31 -04:00
if (value.includes("Click here to edit")) {
2016-08-18 23:59:38 -04:00
inputs[i].childNodes[0].nodeValue = "Missing field";
inputs[i].style.color = "#FF1A1A";
stop = true;
}
}
2016-09-04 20:13:31 -04:00
if (stop) return null;
2016-08-18 23:59:38 -04:00
var data = Session.get("currentWork");
data.name = document.getElementById("workName").childNodes[0].nodeValue;
data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue);
data.description = document.getElementById("workDesc").childNodes[0].nodeValue;
data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase();
Session.set("currentWork", data);
var readableData = formReadable(data);
Session.set("currentReadableWork", readableData);
2016-08-13 17:33:12 -04:00
}
2016-08-30 18:49:33 -04:00
function getPreferencesData() { // Get all data relating to preferences.
var profile = Session.get("user");
2016-08-22 23:44:48 -04:00
var options = {
2016-09-04 20:13:31 -04:00
"theme": document.getElementById("prefTheme").childNodes[0].nodeValue.toLowerCase(),
"mode": document.getElementById("prefMode").childNodes[0].nodeValue.toLowerCase(),
"timeHide": ref[document.getElementById("prefHide").childNodes[0].nodeValue],
"done": ref[document.getElementById("prefDone").childNodes[0].nodeValue]
2016-08-22 23:44:48 -04:00
};
profile.preferences = options;
return profile;
}
2016-09-04 20:13:31 -04:00
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
2016-08-30 18:49:33 -04:00
function getReadableDate(date) { // Get readable date from Date constructor.
2016-09-04 20:13:31 -04:00
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();
2016-08-13 20:22:54 -04:00
}
2016-08-30 18:49:33 -04:00
function toDate(date) { // Turns formatted date back to Date constructor.
2016-09-04 20:13:31 -04:00
date = date.substring(date.search(",") + 2, date.length);
month = months.indexOf(date.substring(0, date.search(" ")));
day = date.substring(date.search(" ") + 1, date.search(","));
year = date.substring(date.search(",") + 2, date.length);
return new Date(year, month, day, 11, 59, 59);
}
2016-08-30 18:49:33 -04:00
function formReadable(input) { // Makes work information readable by users.
2016-08-18 23:59:38 -04:00
input.dueDate = getReadableDate(input.dueDate);
input.type = input.type[0].toUpperCase() + input.type.slice(1);
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork")) {
if (input.done.indexOf(Meteor.userId()) !== -1) { // If user marked as done.
2016-08-28 23:25:43 -04:00
input.doneCol = "#27A127";
input.doneText = "Done!";
} else {
input.doneCol = "";
input.doneText = "Mark done";
}
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
for (var i = 0; i < input.done.length; i++) { // Display users who marked as done.
2016-09-05 16:41:22 -04:00
var user = Meteor.users.findOne({
_id: input.done[i]
});
2016-09-04 20:13:31 -04:00
input.done[i] = {
2016-09-05 16:41:22 -04:00
"user": user.profile.name,
"avatar": user.profile.avatar,
"email": user.services.google.email
2016-09-04 20:13:31 -04:00
};
2016-08-28 23:25:43 -04:00
}
2016-08-28 18:55:10 -04:00
2016-09-04 20:13:31 -04:00
if (input.confirmations.indexOf(Meteor.userId()) !== -1) { // If user confirmed.
input.userConfirm = "#27A127";
2016-08-28 23:25:43 -04:00
} else {
input.userConfirm = "";
}
2016-08-28 18:41:35 -04:00
2016-09-04 20:13:31 -04:00
if (input.reports.indexOf(Meteor.userId()) !== -1) { // If user reported.
2016-08-28 23:25:43 -04:00
input.userReport = "#FF1A1A";
} else {
input.userReport = "";
}
2016-08-28 18:41:35 -04:00
input.confirmations = input.confirmations.length;
input.reports = input.reports.length;
2016-08-28 18:41:35 -04:00
2016-08-28 23:25:43 -04:00
var comments = input.comments;
var resort = [];
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork")) { // Don't display comments if user is creating work.
for (var k = 0; k < comments.length; k++) {
var re = comments.length - k - 1;
resort[re] = {
"comment": comments[k].comment,
"date": null,
2016-09-05 16:41:22 -04:00
"user": null,
"avatar": null,
"email":null
2016-09-04 20:13:31 -04:00
};
2016-09-05 16:41:22 -04:00
var user = Meteor.users.findOne({
2016-09-04 20:13:31 -04:00
_id: comments[k].user
2016-09-05 16:41:22 -04:00
});
resort[re].user = user.profile.name;
2016-09-04 20:13:31 -04:00
resort[re].date = moment(comments[k].date).fromNow();
2016-09-05 16:41:22 -04:00
resort[re].avatar = user.profile.avatar;
resort[re].email = user.services.google.email;
2016-08-28 23:25:43 -04:00
}
input.comments = resort;
}
}
2016-08-18 23:59:38 -04:00
return input;
2016-08-14 07:52:27 -04:00
}