fix indenting

This commit is contained in:
Yaman Qalieh 2016-08-18 17:35:40 -04:00
parent f8b57bcfb9
commit 3716d8012a

View File

@ -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"
@ -57,34 +57,34 @@ 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"; if(found.admin === Meteor.userId()) found.box = " owned";
array.push(found); array.push(found);
var thisWork = work.find({class: courses[i]}).fetch(); var thisWork = work.find({class: courses[i]}).fetch();
for(var j = 0; j < thisWork.length; j++) { for(var j = 0; j < thisWork.length; j++) {
thisWork[j].dueDate = getReadableDate(thisWork[j].dueDate); thisWork[j].dueDate = getReadableDate(thisWork[j].dueDate);
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);
return array; return array;
} }
}); });
Template.main.helpers({ Template.main.helpers({
schoolName() { schoolName() {
Session.set("calendarclasses", Meteor.user().profile.classes); Session.set("calendarclasses", Meteor.user().profile.classes);
return " - " + Meteor.user().profile.school; return " - " + Meteor.user().profile.school;
}, },
iconColor(icon) { iconColor(icon) {
@ -174,31 +174,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;
} }
} }
}); });
@ -256,13 +256,13 @@ Template.main.events({
Session.set("sidebar", null); Session.set("sidebar", null);
} }
if(e === "overlay") { if(e === "overlay") {
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
if(!Session.get("newWork")) { if(!Session.get("newWork")) {
if(getHomeworkFormData() === null) return; if(getHomeworkFormData() === null) return;
Session.set("serverData",Session.get("currentWork")); Session.set("serverData",Session.get("currentWork"));
sendData("editWork"); sendData("editWork");
} }
Session.set("newWork",null); Session.set("newWork",null);
} }
if (event.target.id !== sessval && if (event.target.id !== sessval &&
@ -272,9 +272,9 @@ Template.main.events({
closeInput(sessval); closeInput(sessval);
} }
if (!event.target.className.includes("radio") && if (!event.target.className.includes("radio") &&
!Session.equals("radioDiv", null) && !Session.equals("radioDiv", null) &&
!event.target.parentNode.className.includes("workOptions") && !event.target.parentNode.className.includes("workOptions") &&
event.target.readOnly !== true) { event.target.readOnly !== true) {
var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString(); var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString();
for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) { for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) {
try { try {
@ -286,32 +286,32 @@ Template.main.events({
} }
}, },
'click .creWork' (event) { 'click .creWork' (event) {
if(event.target.className !== "creWork") { if(event.target.className !== "creWork") {
var attr = event.target.parentNode.getAttribute("classid"); var attr = event.target.parentNode.getAttribute("classid");
} else { } else {
var attr = event.target.getAttribute("classid"); var attr = event.target.getAttribute("classid");
} }
Session.set("newWork", true); Session.set("newWork", true);
Session.set("currentReadableWork", Session.set("currentReadableWork",
{ {
name:"Name | Click here to edit...", name:"Name | Click here to edit...",
class:attr, class:attr,
dueDate:"Click here to edit...", dueDate:"Click here to edit...",
description:"Click here to edit...", description:"Click here to edit...",
type:"Click here to edit..." type:"Click here to edit..."
}); });
Session.set("currentWork",{class:attr}); Session.set("currentWork",{class:attr});
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'click .change' (event) { 'click .change' (event) {
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; )) 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);
@ -326,11 +326,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";
@ -348,7 +348,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) {
@ -421,38 +421,38 @@ 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: 'd', startDate: 'd',
todayHighlight: true, todayHighlight: true,
autoclose: true autoclose: true
}); });
} }
}); });
@ -492,59 +492,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;
} }