1038 lines
40 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-10-09 22:57:04 -04:00
modifyingInput = null;
dropOpen = null;
2016-08-09 01:33:14 -04:00
var openValues = {
2016-09-12 09:18:58 -04:00
"menu": "-270px",
"options": "-300px",
2016-09-11 23:22:50 -04:00
"requests": "-235px"
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
};
var defaultWork = {
name: "Name | Click here to edit...",
dueDate: "Click here to edit...",
description: "Click here to edit...",
type: "Click here to edit..."
2016-09-14 06:37:32 -04:00
};
2016-08-20 23:37:04 -04:00
// Reactive variables.
2016-10-03 23:13:05 -04:00
Session.set("user", {}); // Stores user preferences.
2016-09-07 15:33:13 -04:00
Session.set("calendarClasses", []); // Stores calendar classes.
2016-09-11 23:22:50 -04:00
Session.set("sidebar", null); // Status of sidebar.
2016-10-03 23:13:05 -04:00
Session.set("requests", false); // Status of requests.
2016-09-04 20:13:31 -04:00
Session.set("newWork", null); // If user creating new work.
2016-09-15 10:25:10 -04:00
Session.set("currentWorkId",null); // Stores current work Id.
2016-10-09 22:57:04 -04:00
Session.set("currentWork",null);
2016-09-04 20:13:31 -04:00
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.
2016-09-15 08:30:24 -04:00
Session.set("typeFilter", []); // Stores type filters for classes.
2016-10-03 23:13:05 -04:00
Session.set("typeFilterHover", null); // Stores current hovered type filter.
2016-09-15 10:25:10 -04:00
Session.set("classDispHover", null); // Stores current hovered class filter.
2016-09-04 20:13:31 -04:00
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-16 16:48:39 -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);
2016-09-16 18:08:56 -04:00
setTimeout(startDragula, 300);
2016-09-09 02:17:32 -04:00
};
Template.profile.rendered = function() {
Accounts._loginButtonsSession.set('dropdownVisible', true);
};
2016-09-05 15:45:21 -04:00
Template.registerHelper('userProfile', () => {
2016-10-03 23:13:05 -04:00
if (Meteor.user() === undefined || Meteor.user() === null) return;
2016-09-05 14:51:40 -04:00
Session.set("user", Meteor.user().profile);
return;
});
Template.registerHelper('adminPage', () => {
return window.location.pathname.includes("/");
});
2016-09-12 11:12:06 -04:00
Template.registerHelper('screen', (multiplier, fraction) => {
2016-10-03 23:13:05 -04:00
if (typeof multiplier !== "string") return screen.width.toString() + "px";
if (typeof fraction !== "string") return (screen.width * parseFloat(multiplier)).toString() + "px";
return ((screen.width) * parseFloat(multiplier) / parseFloat(fraction)).toString() + "px";
2016-09-12 11:12:06 -04:00
});
2016-08-29 21:02:02 -04:00
Template.registerHelper('divColor', (div) => { // Reactive color changing based on preferences. Colors stored in themeColors.
2016-09-29 23:39:34 -04:00
return Session.get("user").preferences.theme[div];
2016-08-22 23:44:48 -04:00
});
Template.registerHelper('textColor', () => { // Reactive color for text.
2016-09-29 23:39:34 -04:00
document.getElementsByTagName("body")[0].style.color = Session.get("user").preferences.theme.textColor;
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;";
2016-09-29 23:39:34 -04:00
var bg = "background-color:" + 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-10-03 23:13:05 -04:00
if (Session.get("user").classes.length === 0) { // Null checking.
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 refetch = true;
var courses = Session.get("user").classes;
2016-08-30 18:49:33 -04:00
var classDisp = Session.get("classDisp"); // Get sidebar class filter.
2016-09-15 09:19:54 -04:00
var sideFilter = Session.get("typeFilter"); // Get sidebar type 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.
2016-09-11 18:47:50 -04:00
if (courses[i] === Meteor.userId()) {
found = {
_id: courses[i],
name: "Personal",
subscribers: 1,
mine: false,
box: " owned"
};
} else {
found = classes.findOne({
_id: courses[i]
});
found.subscribers = found.subscribers.length;
found.mine = true;
if (found.admin === Meteor.userId()) { // If user owns this class.
found.box = " owned";
found.mine = false;
}
2016-09-11 18:58:57 -04:00
}
2016-09-16 08:43:07 -04:00
if (classDisp.indexOf(courses[i]) !== -1) found.selected = true; // Filter selected.
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";
2016-08-26 23:50:46 -04:00
}
}
2016-09-05 00:16:26 -04:00
2016-09-15 09:19:54 -04:00
if (thisWork[j] !== "no" && Session.get("user").preferences.done) { // If done filter is true
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";
}
}
2016-09-04 20:10:58 -04:00
2016-09-15 09:19:54 -04:00
if (thisWork[j] !== "no" && sideFilter.length !== 0 && !_.contains(sideFilter, thisWork[j].type)) {
2016-09-16 17:25:15 -04:00
thisWork[j] = "no";
2016-09-16 09:10:56 -04:00
}
2016-10-03 23:13:05 -04:00
if (thisWork[j] !== "no" && Session.get("user").preferences.hideReport && (thisWork[j].confirmations.length / thisWork[j].reports.length) <= 0.9) {
2016-09-15 09:19:54 -04:00
thisWork[j] = "no";
}
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-09-10 02:26:11 -04:00
thisWork[j].classid = courses[i];
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-10 14:13:00 -04:00
2016-10-03 23:13:05 -04:00
thisWork[j].creator = Meteor.users.findOne({
_id: thisWork[j].creator
}).profile.name;
var conf = thisWork[j].confirmations.length;
var repo = thisWork[j].reports.length;
var ratio = conf / repo;
2016-09-29 23:39:34 -04:00
var normalColor = Session.get("user").preferences.theme["text"];
if (Math.abs(conf - repo)) {
2016-10-03 23:13:05 -04:00
if ((conf + repo) <= 1) {
thisWork[j].doneRatio = normalColor;
} else {
thisWork[j].doneRatio = "#F9F906";
2016-09-16 17:25:15 -04:00
}
} else if (ratio >= 2) {
thisWork[j].doneRatio = "#33DD33";
2016-09-16 17:25:15 -04:00
} else if (ratio <= 0.9) {
thisWork[j].doneRatio = "#FF1A1A";
}
2016-08-18 23:59:38 -04:00
}
2016-09-16 08:43:07 -04:00
array[i].thisClassWork = thisWork.sort(function(a, b) {
2016-09-16 08:45:20 -04:00
return Date.parse(a.realDate) - Date.parse(b.realDate);
2016-09-16 08:43:07 -04:00
});
2016-08-18 23:59:38 -04:00
}
2016-09-04 20:13:31 -04:00
Session.set("noclass", false);
2016-08-30 18:49:33 -04:00
Session.set("calendarClasses", array);
Session.set("refetchEvents", refetch);
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-10-09 22:57:04 -04:00
return options[val].filter(function(entry) {
return (val === 'theme') ? _.isEqual(preferences[val], themeColors[entry.val]) : preferences[val] === entry.val;
})[0].alias;
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-09-16 18:08:56 -04:00
function startDragula() {
2016-10-03 23:13:05 -04:00
dragula([document.querySelector('#classesMode'), document.querySelector('#nonexistant')], {
2016-10-09 23:00:40 -04:00
moves: function(el, container, handle) {
// return handle.classList.contains("classInfo") || handle.classList.contains("mainClassName");
return _.intersection(["classInfo", "mainClassName", "mainClassHour", "mainClassTeacher"], handle.classList).length > 0;
}
})
2016-10-09 22:57:04 -04:00
.on('out', function(el) {
var els = document.getElementsByClassName("classWrapper");
var final = [];
2016-10-09 23:00:40 -04:00
for (var i = 0; i < els.length; i++) {
2016-10-09 22:57:04 -04:00
var classid = els[i].getElementsByClassName("creWork")[0].getAttribute("classid");
final.push(classid);
}
});
2016-09-16 18:08:56 -04:00
}
2016-08-09 01:33:14 -04:00
Template.main.helpers({
2016-09-29 23:39:34 -04:00
themeName() {
var vals = _.values(themeColors);
var curtheme = Session.get("user").preferences.theme;
2016-10-03 23:13:05 -04:00
for (var i = 0; i < vals.length; i++) {
2016-09-29 23:39:34 -04:00
if (_.isEqual(vals[i], curtheme)) {
var name = _.keys(themeColors)[i];
return name.charAt(0).toUpperCase() + name.slice(1);
2016-10-09 22:57:04 -04:00
}
2016-09-29 23:39:34 -04:00
}
return "Custom";
},
2016-08-30 18:49:33 -04:00
schoolName() { // Finds the name of the user's school.
2016-10-03 23:13:05 -04:00
if (Session.get("user").school === undefined || Session.get("user").school === null) 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-10-03 23:13:05 -04:00
if (Session.equals("sidebar", icon + "Container")) {
2016-09-29 23:39:34 -04:00
return Session.get("user").preferences.theme.statusIcons;
2016-10-03 23:13:05 -04:00
} else if (Session.equals("sidebar", "both")) {
2016-09-29 23:39:34 -04:00
return 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.
2016-09-17 21:35:12 -04:00
return Meteor.user().services.google.picture;
2016-09-07 15:33:13 -04:00
},
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-10-03 23:13:05 -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-10-03 23:13:05 -04:00
return "Backgrounds/" + 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-09-11 23:22:50 -04:00
return "0px";
2016-09-04 20:13:31 -04:00
} else if (Session.equals("sidebar", "both")) {
2016-09-11 23:22:50 -04:00
return "0px";
2016-08-12 12:28:55 -04:00
} 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-09-11 23:22:50 -04:00
return "0px";
2016-09-04 20:13:31 -04:00
} else if (Session.equals("sidebar", "both")) {
2016-09-11 23:22:50 -04:00
return "0px";
2016-08-12 12:28:55 -04:00
} else {
return openValues.options;
}
},
2016-09-11 23:22:50 -04:00
requestStatus() {
if (Session.get("requests")) return "0px";
return openValues.requests;
},
2016-08-30 18:49:33 -04:00
modeStatus(status) { // Color status of display modes.
2016-10-03 23:13:05 -04:00
if (!Session.equals("mode", status)) return;
2016-09-29 23:39:34 -04:00
return Session.get("user").preferences.theme.modeHighlight;
2016-08-12 12:28:55 -04:00
},
2016-08-30 18:49:33 -04:00
currMode(name) { // Status of display mode.
2016-10-03 23:13:05 -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-11 18:51:09 -04:00
if (work.class === Meteor.userId() ||
Meteor.userId() === work.creator ||
2016-09-04 20:13:31 -04:00
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-15 10:25:10 -04:00
className: work.type + " 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);
Session.set("currentWorkId", event.id);
2016-08-18 23:59:38 -04:00
openDivFade(document.getElementsByClassName("overlay")[0]);
},
2016-10-03 23:13:05 -04:00
eventMouseover: function(event, jsEvent, view) {
2016-09-11 18:47:50 -04:00
this.style.boxShadow = "inset 0 0 0 99999px rgba(255,255,255,0.2)";
},
2016-10-03 23:13:05 -04:00
eventMouseout: function(event, jsEvent, view) {
this.style.boxShadow = "";
},
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;";
},
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");
2016-09-15 10:25:10 -04:00
var typeHighlight = Session.get("typeFilterHover");
2016-10-03 23:13:05 -04:00
if (Session.equals("mode", "classes")) {
$(".workCard").toggleClass("scaled", false);
2016-09-11 18:47:50 -04:00
try {
2016-10-03 23:13:05 -04:00
$(".workCard[classid=\'" + hoverHighlight + "\']").toggleClass("scaled", true);
$(".workCard[type=\'" + typeHighlight + "\']").toggleClass("scaled", true);
} catch (err) {}
2016-09-11 18:47:50 -04:00
} else {
2016-10-03 23:13:05 -04:00
$(".workevent").toggleClass("scaled", false);
2016-09-10 02:26:11 -04:00
try {
2016-10-03 23:13:05 -04:00
$("." + hoverHighlight).toggleClass("scaled", true);
$("." + typeHighlight).toggleClass("scaled", true);
} catch (err) {}
}
return;
},
2016-08-30 18:49:33 -04:00
work(value) { // Returns the specified work value.
2016-10-12 01:45:36 -04:00
var thisWork = Session.get("currentWork");
2016-10-09 22:57:04 -04:00
if (Session.equals("currentWork", null)) return;
2016-10-12 01:45:36 -04:00
if (Session.get("newWork") && (thisWork[value] === "Missing field" || thisWork[value] === undefined)) {
2016-10-03 23:13:05 -04:00
return defaultWork[value];
2016-08-18 23:59:38 -04:00
} else {
2016-10-12 01:45:36 -04:00
return formReadable(thisWork,value);
2016-08-18 23:59:38 -04:00
}
2016-08-12 23:10:27 -04:00
},
2016-10-09 22:57:04 -04:00
selectOptions(val) {
return options[val];
},
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-09-15 08:30:24 -04:00
types() {
var types = Object.keys(workColors);
var array = [];
2016-10-03 23:13:05 -04:00
for (var i = 0; i < types.length; i++) {
array.push({
2016-09-15 08:30:24 -04:00
"type": types[i],
"typeName": types[i][0].toUpperCase() + types[i].slice(1),
"selected": _.contains(Session.get("typeFilter"), types[i])
});
}
return array;
},
2016-08-30 18:49:33 -04:00
inRole() { // Checks correct permissions.
var thisWork = work.findOne({
_id: Session.get("currentWorkId")
});
2016-09-04 20:13:31 -04:00
if (Session.get("newWork")) {
2016-08-18 23:59:38 -04:00
return true;
} else {
if (thisWork === undefined) return;
2016-09-04 20:13:31 -04:00
var currClass = classes.findOne({
_id: thisWork["class"]
2016-09-04 20:13:31 -04:00
});
if (Meteor.userId() === thisWork.creator ||
2016-09-04 20:13:31 -04:00
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-10-12 01:45:36 -04:00
if(modifyingInput !== null && event.target !== document.getElementById(modifyingInput)) {
if (!_.contains(e, ["optionHolder", "optionText"])) {
if(document.getElementById(modifyingInput).className.includes("dropdown")) {
$(".optionHolder")
.fadeOut('fast')
.hide('fast');
dropOpen = false;
} else {
closeInput(modifyingInput);
}
modifyingInput = null;
}
}
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")) {
document.getElementById("workComment").value = "";
}
2016-09-04 20:13:31 -04:00
Session.set("newWork", null);
$('.req').css("color", "");
Session.set("commentRestrict", null);
2016-08-12 23:10:27 -04:00
}
2016-10-03 23:13:05 -04:00
if (!document.getElementById("userDropdown").contains(event.target)) closeDivFade(document.getElementById("userDropdown"));
if (!document.getElementById("requests").contains(event.target)) Session.set("requests", false);
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");
}
},
2016-09-11 23:22:50 -04:00
'click #requests .fa-question' () {
2016-10-03 23:13:05 -04:00
Session.set("requests", !Session.get("requests"));
2016-09-11 23:22:50 -04:00
},
2016-08-30 18:49:33 -04:00
'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-16 18:08:56 -04:00
setTimeout(startDragula, 500);
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-10-09 22:57:04 -04:00
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) {
2016-10-03 23:13:05 -04:00
if (document.getElementById("userDropdown").style.display === "block") return;
2016-09-07 15:33:13 -04:00
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-10-09 22:57:04 -04:00
var workid = event.target.getAttribute("workid");
2016-08-30 18:49:33 -04:00
2016-09-04 20:13:31 -04:00
var thisWork = work.findOne({
_id: workid
});
2016-10-09 22:57:04 -04:00
Session.set("newWork", false);
Session.set("currentWork", thisWork);
2016-09-04 20:13:31 -04:00
if (!Session.get("newWork") && !document.getElementById("optionsContainer").contains(event.target)) {
var currClass = classes.findOne({
_id: thisWork["class"]
2016-09-04 20:13:31 -04:00
});
if (!(Meteor.userId() === thisWork.creator || // If user has permission.
2016-09-04 20:13:31 -04:00
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
currClass.moderators.indexOf(Meteor.userId()) !== -1 ||
currClass.banned.indexOf(Meteor.userId()) !== -1)) {
2016-10-09 22:57:04 -04:00
var inputs = $('#editWork .clickModify').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 #requestSubmit' () {
var area = document.getElementById("requestArea");
2016-10-03 23:13:05 -04:00
if (area.value === "") return;
2016-09-08 16:51:22 -04:00
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")
};
2016-10-03 23:13:05 -04:00
Meteor.call("createRequest", array, function(err, result) {
2016-09-08 16:51:22 -04:00
area.value = "Request sent!";
2016-10-03 23:13:05 -04:00
setTimeout(function() {
2016-09-10 00:44:06 -04:00
document.getElementById("requests").style.marginBottom = "-15.5vw";
2016-09-08 16:51:22 -04:00
area.value = "";
2016-10-03 23:13:05 -04:00
Session.set("commentRestrict", null);
}, 750);
2016-09-11 18:47:50 -04:00
});
2016-09-08 16:51:22 -04:00
},
2016-08-30 18:49:33 -04:00
// HANDLING INPUT CHANGING
2016-10-09 22:57:04 -04:00
'click .clickModify' (event) {
2016-10-12 01:45:36 -04:00
if(modifyingInput !== event.target.id) modifyingInput = event.target.id;
},
'focus .clickModify' (event) {
if(modifyingInput !== event.target.id) modifyingInput = event.target.id;
2016-08-12 23:10:27 -04:00
},
2016-10-09 22:57:04 -04:00
'keydown .dropdown' (event) {
console.log("hi");
},
2016-10-12 01:45:36 -04:00
'focus .dropdown' (event) {
if(event.target.id === modifyingInput) return;
2016-10-09 22:57:04 -04:00
event.target.click();
2016-10-12 01:45:36 -04:00
},
'click .dropdown' (event) {
console.log(dropOpen);
console.log(event.target.id === modifyingInput);
2016-10-09 22:57:04 -04:00
if(event.target.id === modifyingInput && dropOpen) {
2016-10-12 01:45:36 -04:00
dropOpen = false;
modifyingInput = null;
2016-10-09 22:57:04 -04:00
$("#" + modifyingInput).next()
.fadeOut(200)
.hide(200);
2016-10-12 01:45:36 -04:00
console.log("hiasdf");
2016-10-09 22:57:04 -04:00
return;
}
2016-10-09 22:57:04 -04:00
dropOpen = true;
$("#" + modifyingInput).next()
2016-10-12 01:45:36 -04:00
.css('opacity',0)
2016-10-09 22:57:04 -04:00
.slideDown(300)
.animate(
{ opacity: 1 },
{ queue: false, duration: 100 }
2016-10-12 01:45:36 -04:00
)
//event.target.focus();
2016-10-09 22:57:04 -04:00
},
'click .optionText' (event) { // Click each preferences setting.
var option = event.target.childNodes[0].nodeValue;
if(modifyingInput[0] === 'w') {
var newSetting = Session.get("currentWork");
newSetting[modifyingInput.charAt(1).toLowerCase() + modifyingInput.slice(2)] = option;
Session.set("currentWork", newSetting);
2016-08-22 23:44:48 -04:00
} else {
2016-10-09 22:57:04 -04:00
var newSetting = Session.get("user");
newSetting.preferences[modifyingInput] = (function() {
var value = options[modifyingInput].filter(function(entry) {
return option === entry.alias;
})[0].val;
return (modifyingInput === 'theme') ? themeColors[value] : value;
})();
Session.set("user", newSetting);
serverData = Session.get("user");
sendData("editProfile");
2016-08-22 23:44:48 -04:00
}
2016-10-09 22:57:04 -04:00
$("#" + modifyingInput).next()
.fadeOut('fast')
.hide('fast');
},
2016-09-05 14:51:40 -04:00
'click #workComment' (event) {
var restrict = event.target.maxLength;
2016-10-03 23:13:05 -04:00
Session.set("commentRestrict", restrict - event.target.value.length.toString() + " characters left");
2016-09-05 14:51:40 -04:00
var text = document.getElementById("commentrestrict");
text.style.display = "initial";
text.style.color = "#7E7E7E";
},
2016-09-23 20:55:15 -04:00
'click #exportDiv' (event) {
2016-09-23 19:53:00 -04:00
var events = [];
2016-09-22 00:36:08 -04:00
var userClasses = Session.get("calendarClasses");
for (var i = 0; i < userClasses.length; i++) {
var works = userClasses[i].thisClassWork;
for (var j = 0; j < works.length; j++) {
var work = works[j];
2016-10-03 23:13:05 -04:00
var workclass = classes.findOne({
_id: work.class
});
2016-09-23 19:37:53 -04:00
if (work.description == defaultWork.description) work.description = "";
if (work.dueDate == defaultWork.dueDate) continue;
if (work.name == defaultWork.name) work.name = "";
2016-10-03 23:13:05 -04:00
if (workclass === undefined) workclass = {
name: "Personal"
};
2016-09-23 19:53:00 -04:00
events.push([
workclass.name + ": " + work.name,
work.realDate.toLocaleDateString(),
work.description,
"True"
]);
2016-09-22 00:36:08 -04:00
}
}
2016-09-23 19:37:53 -04:00
var JSONevents = JSON.stringify(events);
2016-10-03 23:13:05 -04:00
var CSVevents = Papa.unparse({
fields: ["Subject", "Start Date", "Description", "All Day Event"],
data: JSONevents
});
var eventBlob = new Blob([CSVevents], {
type: "data:text/csv;charset=utf-8"
});
2016-09-23 19:53:00 -04:00
saveAs(eventBlob, "hourglass.csv");
2016-09-22 00:36:08 -04:00
},
2016-09-05 14:51:40 -04:00
'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-10-03 23:13:05 -04:00
if (event.target.id === "workComment") {
2016-09-07 21:26:26 -04:00
text = document.getElementById("commentrestrict");
2016-10-03 23:13:05 -04:00
} else if (event.target.id === "requestArea") {
2016-09-08 16:51:22 -04:00
text = document.getElementById("requestrestrict");
2016-09-05 15:49:42 -04:00
} else {
2016-10-03 23:13:05 -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-10-12 01:45:36 -04:00
'focus #wDueDate' () { // Open date picker.
$('#wDueDate').datepicker({
2016-08-30 18:49:33 -04:00
format: 'DD, MM d, yyyy',
2016-10-12 01:45:36 -04:00
clickInput: true,
2016-08-30 18:49:33 -04:00
startDate: 'd',
todayHighlight: true,
todayBtn: true,
2016-10-12 01:45:36 -04:00
onSelect: function(dateText, inst) {
alert("asdf");
closeInput(modifyingInput);
}
2016-08-30 18:49:33 -04:00
});
},
// WORK OVERLAY BUTTONS
'click #commentSubmit' (event) { // Click to submit a comment.
2016-09-14 06:37:32 -04:00
workId = Session.get("currentWorkId");
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-14 06:37:32 -04:00
Meteor.call('addComment', [comment, workId]);
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-10-12 01:45:36 -04:00
serverData = Session.get("currentWork");
sendData("createWork");
2016-09-04 20:13:31 -04:00
Session.set("newWork", null);
closeDivFade(document.getElementsByClassName("overlay")[0]);
},
'click #workDelete' () {
serverData = Session.get("currentWorkId");
sendData("deleteWork");
closeDivFade(document.getElementsByClassName("overlay")[0]);
},
2016-08-30 18:49:33 -04:00
'click #markDone' () { // Click done button.
serverData = [Session.get("currentWorkId"), "done"];
2016-08-30 18:49:33 -04:00
sendData("toggleWork");
},
2016-08-30 18:49:33 -04:00
'click #markConfirm' () { // Click confirm button.
serverData = [Session.get("currentWorkId"), "confirmations"];
2016-08-30 18:49:33 -04:00
sendData("toggleWork");
},
'click #markReport' () { // Click report button.
serverData = [Session.get("currentWorkId"), "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-10-03 23:13:05 -04:00
Session.get("currentWorkId", classid);
2016-09-04 20:13:31 -04:00
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-15 08:30:24 -04:00
'click .sideFilter' (event) {
var div = event.target;
while (div.getAttribute("type") === null) div = div.parentNode;
var type = div.getAttribute("type");
var array = Session.get("typeFilter");
2016-09-15 09:19:54 -04:00
if (array.indexOf(type) !== -1) {
array.splice(array.indexOf(type), 1);
2016-09-15 08:30:24 -04:00
} else {
2016-09-15 09:19:54 -04:00
array.push(type);
2016-09-15 08:30:24 -04:00
}
Session.set("typeFilter", 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-09-15 10:25:10 -04:00
},
'mouseover .sideFilter' (event) {
var div;
if (event.target.className !== "sideFilter") {
div = event.target.parentNode;
} else {
div = event.target;
}
while (div.getAttribute("type") === null) div = div.parentNode;
var type = div.getAttribute("type");
2016-10-03 23:13:05 -04:00
Session.set("typeFilterHover", type);
2016-09-15 10:25:10 -04:00
},
'mouseleave .sideFilter' (event) {
if (event.target.className !== "sideFilter") {
var div = event.target.parentNode;
if (div.contains(event.target)) return;
}
2016-10-03 23:13:05 -04:00
Session.set("typeFilterHover", 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.
Meteor.call(funcName, serverData);
2016-08-12 12:28:55 -04:00
}
2016-08-12 23:10:27 -04:00
2016-10-09 22:57:04 -04:00
function closeInput() { // Close a changeable input and change it back to span.
2016-10-12 01:45:36 -04:00
var data = getHomeworkFormData();
2016-10-09 22:57:04 -04:00
Session.set("currentWork", data);
2016-10-12 01:45:36 -04:00
if(!Session.get("newWork")) {
serverData = Session.get("currentWork");
//sendData("editWork");
}
console.log(serverData);
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-10-12 01:45:36 -04:00
var inputs = ["wName", "wDueDate", "wDescription", "wType"]; // All work fields.
var optional = ["wDescription"]; // Optional work fields.
2016-10-09 22:57:04 -04:00
var data = Session.get("currentWork");
for(var i = 0; i < inputs.length; i++) {
var title = inputs[i].charAt(1).toLowerCase() + inputs[i].slice(2);
2016-10-12 01:45:36 -04:00
var thisData = (title === 'type') ? $("#"+inputs[i]+" span")[0].childNodes[0].nodeValue : $("#"+inputs[i])[0].value;
data[title] = (thisData.includes(defaultWork[title].slice(0,-3)) && !_.contains(optional, title)) ? "Missing field" : thisData;
2016-10-09 22:57:04 -04:00
}
2016-10-12 01:45:36 -04:00
return data;
2016-08-22 23:44:48 -04:00
}
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);
}
function formReadable(input, val) { // Makes work information readable by users.
2016-10-03 23:13:05 -04:00
switch (val) {
case "typeColor":
return input.typeColor = workColors[input.type];
case "name":
return input.name;
case "dueDate":
return getReadableDate(input.dueDate);
case "description":
return input.description;
case "type":
return input.type[0].toUpperCase() + input.type.slice(1);
case "comments":
var comments = input.comments;
var resort = [];
if (Session.get("newWork")) return []; // Don't display comments if user is creating work.
2016-09-04 20:13:31 -04:00
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,
2016-10-03 23:13:05 -04:00
"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-17 21:35:12 -04:00
resort[re].avatar = user.services.google.picture;
2016-09-05 16:41:22 -04:00
resort[re].email = user.services.google.email;
2016-08-28 23:25:43 -04:00
}
return resort;
case "done":
if (Session.get("newWork")) return [];
for (var i = 0; i < input.done.length; i++) { // Display users who marked as done.
var user = Meteor.users.findOne({
_id: input.done[i]
});
input.done[i] = {
"user": user.profile.name,
2016-09-17 21:39:51 -04:00
"avatar": user.services.google.picture,
"email": user.services.google.email
};
}
return input.done;
case "doneCol":
if (Session.get("newWork")) return "";
2016-10-03 23:13:05 -04:00
if (!_.contains(input.done, Meteor.userId())) return "";
return "#27A127";
case "doneText":
if (Session.get("newWork")) return "";
2016-10-03 23:13:05 -04:00
if (!_.contains(input.done, Meteor.userId())) return "Mark done";
return "Done!";
case "userConfirm":
2016-10-03 23:13:05 -04:00
if (!_.contains(input.confirmations, Meteor.userId())) return "";
return "#27A127";
case "confirmations":
return input.confirmations.length;
case "userReport":
2016-10-03 23:13:05 -04:00
if (!_.contains(input.reports, Meteor.userId())) return "";
return "#FF1A1A";
case "reports":
return input.reports.length;
case "email":
return Meteor.users.findOne({
_id: input.creator
}).services.google.email;
case "avatar":
return Meteor.users.findOne({
_id: input.creator
2016-09-17 21:35:12 -04:00
}).services.google.picture;
case "creator":
return Meteor.users.findOne({
_id: input.creator
}).profile.name;
}
2016-08-14 07:52:27 -04:00
}