Update calendar on change
This commit is contained in:
parent
bca216cf65
commit
93bd64c4b4
@ -24,8 +24,8 @@ var themeColors = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var workColors = {
|
var workColors = {
|
||||||
"normal": "#2E4F74",
|
"normal": "#2E4F74",
|
||||||
"quiz": "#409333",
|
"quiz": "#409333",
|
||||||
"test": "#AD3C44",
|
"test": "#AD3C44",
|
||||||
"project": "#E6E619",
|
"project": "#E6E619",
|
||||||
"other": "#852E6D"
|
"other": "#852E6D"
|
||||||
@ -42,6 +42,7 @@ Session.set("radioDiv",null);
|
|||||||
Session.set("radioOffset",null);
|
Session.set("radioOffset",null);
|
||||||
Session.set("serverData",null);
|
Session.set("serverData",null);
|
||||||
Session.set("noclass",null);
|
Session.set("noclass",null);
|
||||||
|
Session.set("updateCalWork",true);
|
||||||
|
|
||||||
Template.registerHelper('divColor', (div) => {
|
Template.registerHelper('divColor', (div) => {
|
||||||
return themeColors[Cookie.get("theme")][div];
|
return themeColors[Cookie.get("theme")][div];
|
||||||
@ -57,22 +58,23 @@ Template.registerHelper('overlayDim', (part) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Template.registerHelper('myClasses', () => {
|
Template.registerHelper('myClasses', () => {
|
||||||
if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) {
|
if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) {
|
||||||
Session.set("noclass",true);
|
Session.set("noclass",true);
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
var array = [];
|
var array = [];
|
||||||
var courses = Meteor.user().profile.classes;
|
var courses = Meteor.user().profile.classes;
|
||||||
for(var i = 0; i < courses.length; i++) {
|
for(var i = 0; i < courses.length; i++) {
|
||||||
found = classes.findOne({_id:courses[i]});
|
found = classes.findOne({_id:courses[i]});
|
||||||
found.subscribers = found.subscribers.length;
|
found.subscribers = found.subscribers.length;
|
||||||
if(found.admin === Meteor.userId()) found.box = " owned";
|
|
||||||
array.push(found);
|
|
||||||
|
|
||||||
var thisWork = work.find({class: courses[i]}).fetch();
|
if(found.admin === Meteor.userId()) found.box = " owned";
|
||||||
|
array.push(found);
|
||||||
|
|
||||||
for(var j = 0; j < thisWork.length; j++) {
|
var thisWork = work.find({class: courses[i]}).fetch();
|
||||||
thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, {
|
|
||||||
|
for(var j = 0; j < thisWork.length; j++) {
|
||||||
|
thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, {
|
||||||
sameDay: '[Today]',
|
sameDay: '[Today]',
|
||||||
nextDay: '[Tomorrow]',
|
nextDay: '[Tomorrow]',
|
||||||
nextWeek: 'dddd',
|
nextWeek: 'dddd',
|
||||||
@ -80,15 +82,14 @@ Template.registerHelper('myClasses', () => {
|
|||||||
lastWeek: '[Last] dddd',
|
lastWeek: '[Last] dddd',
|
||||||
sameElse: 'MMMM Do'
|
sameElse: 'MMMM Do'
|
||||||
});
|
});
|
||||||
thisWork[j].typeColor = workColors[thisWork[j].type];
|
thisWork[j].typeColor = workColors[thisWork[j].type];
|
||||||
}
|
}
|
||||||
array[i].thisClassWork = thisWork;
|
array[i].thisClassWork = thisWork;
|
||||||
}
|
}
|
||||||
Session.set("noclass",false);
|
Session.set("noclass",false);
|
||||||
Session.set("calendarclasses", Meteor.user().profile.classes);
|
Session.set("calendarclasses", Meteor.user().profile.classes);
|
||||||
return array;
|
return array;
|
||||||
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.main.helpers({
|
Template.main.helpers({
|
||||||
@ -142,37 +143,62 @@ Template.main.helpers({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
calendarOptions() {
|
calendarOptions() {
|
||||||
var events = [];
|
|
||||||
var cursor = work.find({class: {$in: Session.get("calendarclasses")}});
|
|
||||||
cursor.forEach(function(current) {
|
|
||||||
backgroundColor = workColors[current.type];
|
|
||||||
title = current.name;
|
|
||||||
duedate = current.dueDate.toISOString().slice(0, 10);
|
|
||||||
events.push({
|
|
||||||
id: current._id,
|
|
||||||
start: duedate,
|
|
||||||
title: title,
|
|
||||||
backgroundColor: backgroundColor,
|
|
||||||
startEditable: true,
|
|
||||||
className: "workevent",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
|
id: "fullcalendar",
|
||||||
height: window.innerHeight * 0.8,
|
height: window.innerHeight * 0.8,
|
||||||
events: events,
|
|
||||||
buttonText: {
|
buttonText: {
|
||||||
today: 'Today',
|
today: 'Today',
|
||||||
month: 'Month',
|
month: 'Month',
|
||||||
week: 'Week',
|
week: 'Week',
|
||||||
day: 'Day'
|
day: 'Day'
|
||||||
},
|
},
|
||||||
|
events: function(start, end, timezone, callback) {
|
||||||
|
var events = [];
|
||||||
|
var cursor = work.find({class: {$in: Session.get("calendarclasses")}});
|
||||||
|
cursor.forEach(function(current) {
|
||||||
|
backgroundColor = workColors[current.type];
|
||||||
|
title = current.name;
|
||||||
|
duedate = current.dueDate.toISOString().slice(0, 10);
|
||||||
|
events.push({
|
||||||
|
id: current._id,
|
||||||
|
start: duedate,
|
||||||
|
title: title,
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
borderColor: "#444",
|
||||||
|
startEditable: true,
|
||||||
|
className: "workevent",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
callback(events);
|
||||||
|
},
|
||||||
eventDrop: function(event, delta, revertFunc) {
|
eventDrop: function(event, delta, revertFunc) {
|
||||||
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);
|
||||||
Session.set("serverData",current);
|
Session.set("serverData",current);
|
||||||
sendData("editWork");
|
sendData("editWork");
|
||||||
}
|
},
|
||||||
|
eventClick: function(event, jsEvent, view) {
|
||||||
|
var thisWork = work.findOne({_id:event.id})
|
||||||
|
Session.set("currentWork",thisWork);
|
||||||
|
var thisReadWork = formReadable(thisWork);
|
||||||
|
Session.set("currentReadableWork",thisReadWork);
|
||||||
|
openDivFade(document.getElementsByClassName("overlay")[0]);
|
||||||
|
},
|
||||||
|
/*dayClick: function(date, jsEvent, view) {
|
||||||
|
//Make user select class
|
||||||
|
Session.set("newWork", true);
|
||||||
|
Session.set("currentReadableWork",
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
}*/
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
calCenter() {
|
calCenter() {
|
||||||
@ -191,31 +217,31 @@ Template.main.helpers({
|
|||||||
},
|
},
|
||||||
work(value) {
|
work(value) {
|
||||||
if(Session.get("currentWork") === null) return;
|
if(Session.get("currentWork") === null) return;
|
||||||
return Session.get("currentReadableWork")[value];
|
return Session.get("currentReadableWork")[value];
|
||||||
},
|
},
|
||||||
workType() {
|
workType() {
|
||||||
if(Session.get("currentWork") === null) return;
|
if(Session.get("currentWork") === null) 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];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
newWork() {
|
newWork() {
|
||||||
return Session.get("newWork");
|
return Session.get("newWork");
|
||||||
},
|
},
|
||||||
inRole() {
|
inRole() {
|
||||||
if(Session.get("newWork")) {
|
if(Session.get("newWork")) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if(Meteor.userId() === Session.get("currentWork").creator ||
|
if(Meteor.userId() === Session.get("currentWork").creator ||
|
||||||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
||||||
classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1||
|
classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1||
|
||||||
classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 ||
|
classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 ||
|
||||||
classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1
|
classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1
|
||||||
) return true;
|
) return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -331,8 +357,8 @@ Template.main.events({
|
|||||||
classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1
|
classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1
|
||||||
)) return;
|
)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ele = event.target;
|
var ele = event.target;
|
||||||
var sessval = Session.get("modifying");
|
var sessval = Session.get("modifying");
|
||||||
if (ele.id !== sessval && sessval !== null) closeInput(sessval);
|
if (ele.id !== sessval && sessval !== null) closeInput(sessval);
|
||||||
|
|
||||||
@ -347,11 +373,11 @@ Template.main.events({
|
|||||||
input.style.height = 3 * dim.height.toString() + "px";
|
input.style.height = 3 * dim.height.toString() + "px";
|
||||||
input.rows = "4";
|
input.rows = "4";
|
||||||
} else if (typ !== null) {
|
} else if (typ !== null) {
|
||||||
input.type = typ;
|
input.type = typ;
|
||||||
input.style.height = 0.9 * dim.height.toString() + "px";
|
input.style.height = 0.9 * dim.height.toString() + "px";
|
||||||
} else {
|
} else {
|
||||||
input.typ = "text";
|
input.typ = "text";
|
||||||
input.style.height = 0.9 * dim.height.toString() + "px";
|
input.style.height = 0.9 * dim.height.toString() + "px";
|
||||||
}
|
}
|
||||||
input.value = ele.childNodes[0].nodeValue;
|
input.value = ele.childNodes[0].nodeValue;
|
||||||
input.className = "changeInput";
|
input.className = "changeInput";
|
||||||
@ -369,7 +395,7 @@ Template.main.events({
|
|||||||
input.select();
|
input.select();
|
||||||
}
|
}
|
||||||
if(ele.id === "workDate") {
|
if(ele.id === "workDate") {
|
||||||
input.className += " form-control";
|
input.className += " form-control";
|
||||||
}
|
}
|
||||||
input.focus();
|
input.focus();
|
||||||
if (ele.getAttribute("restrict") !== null) {
|
if (ele.getAttribute("restrict") !== null) {
|
||||||
@ -442,38 +468,37 @@ Template.main.events({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'click #workSubmit' () {
|
'click #workSubmit' () {
|
||||||
if(getHomeworkFormData() === null) return;
|
if(getHomeworkFormData() === null) return;
|
||||||
Session.set("serverData",Session.get("currentWork"));
|
Session.set("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]);
|
||||||
},
|
},
|
||||||
'focus .op' (event) {
|
'focus .op' (event) {
|
||||||
event.target.click();
|
event.target.click();
|
||||||
},
|
},
|
||||||
'click .workCard' (event) {
|
'click .workCard' (event) {
|
||||||
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({_id:workid});
|
||||||
Session.set("currentWork",thisWork);
|
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]);
|
||||||
},
|
},
|
||||||
'focus #workDatea' () {
|
'focus #workDatea' () {
|
||||||
$('#workDatea').datepicker({
|
$('#workDatea').datepicker({
|
||||||
format: 'DD, MM d, yyyy',
|
format: 'DD, MM d, yyyy',
|
||||||
startDate: (new Date(Date.now())).toISOString().slice(0,10),
|
startDate: (new Date(Date.now())).toISOString().slice(0,10),
|
||||||
todayHighlight: true,
|
todayHighlight: true,
|
||||||
autoclose: true
|
autoclose: true
|
||||||
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -494,6 +519,9 @@ function closeDivFade(div) {
|
|||||||
|
|
||||||
function sendData(funcName) {
|
function sendData(funcName) {
|
||||||
Meteor.call(funcName, Session.get("serverData"));
|
Meteor.call(funcName, Session.get("serverData"));
|
||||||
|
if(funcName.includes("Work") && Session.get("mode") === "calendar") {
|
||||||
|
$("#fullcalendar").fullCalendar( 'refetchEvents' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeInput(sessval) {
|
function closeInput(sessval) {
|
||||||
@ -513,59 +541,59 @@ function closeInput(sessval) {
|
|||||||
span.style.display = "initial";
|
span.style.display = "initial";
|
||||||
Session.set("modifying", null);
|
Session.set("modifying", null);
|
||||||
if(!Session.get("newWork")) {
|
if(!Session.get("newWork")) {
|
||||||
if(getHomeworkFormData() === null) return;
|
if(getHomeworkFormData() === null) return;
|
||||||
Session.set("serverData",Session.get("currentWork"));
|
Session.set("serverData",Session.get("currentWork"));
|
||||||
sendData("editWork");
|
sendData("editWork");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHomeworkFormData() {
|
function getHomeworkFormData() {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var desc = document.getElementById("workDesc");
|
var desc = document.getElementById("workDesc");
|
||||||
if(desc.childNodes[0].nodeValue.includes("Click here to edit")) {
|
if(desc.childNodes[0].nodeValue.includes("Click here to edit")) {
|
||||||
desc.childNodes[0].nodeValue = "Missing field";
|
desc.childNodes[0].nodeValue = "Missing field";
|
||||||
desc.style.color = "#FF1A1A";
|
desc.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;
|
||||||
data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue);
|
data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue);
|
||||||
data.description = document.getElementById("workDesc").childNodes[0].nodeValue;
|
data.description = document.getElementById("workDesc").childNodes[0].nodeValue;
|
||||||
data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase();
|
data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase();
|
||||||
|
|
||||||
Session.set("currentWork", data);
|
Session.set("currentWork", data);
|
||||||
var readableData = formReadable(data);
|
var readableData = formReadable(data);
|
||||||
Session.set("currentReadableWork", readableData);
|
Session.set("currentReadableWork", readableData);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
function getReadableDate(date) {
|
||||||
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) {
|
function toDate(date) {
|
||||||
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) {
|
function formReadable(input) {
|
||||||
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);
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user