run filter on profile.js

This commit is contained in:
Yaman Qalieh 2016-10-23 15:49:43 -04:00
parent 5cf986e7e1
commit d2dbdb0cd3

View File

@ -25,7 +25,7 @@ Session.set("noclass", null); // If user doesn't have classes.
Session.set("notfound", null); // If no results for autocomplete. Session.set("notfound", null); // If no results for autocomplete.
Template.profile.helpers({ Template.profile.helpers({
/* themeName() { /* themeName() {
var vals = _.values(themeColors); var vals = _.values(themeColors);
var curtheme = Session.get("user").preferences.theme; var curtheme = Session.get("user").preferences.theme;
for (var i = 0; i < vals.length; i++) { for (var i = 0; i < vals.length; i++) {
@ -50,7 +50,15 @@ Template.profile.helpers({
}, },
selector: (match) => { selector: (match) => {
regex = new RegExp(match, 'i'); regex = new RegExp(match, 'i');
return {$or: [{'name': regex}, {'teacher': regex}, {'hour': regex}]}; return {
$or: [{
'name': regex
}, {
'teacher': regex
}, {
'hour': regex
}]
};
} }
}] }]
}; };
@ -182,17 +190,17 @@ Template.profile.helpers({
Template.profile.events({ Template.profile.events({
'click' (event) { // Whenever a click happens' 'click' (event) { // Whenever a click happens'
var e = event.target.className; var e = event.target.className;
if(modifyingInput !== null && event.target !== document.getElementById(modifyingInput)) { if (modifyingInput !== null && event.target !== document.getElementById(modifyingInput)) {
if (!(e.includes("optionHolder") || e.includes("optionText"))) { if (!(e.includes("optionHolder") || e.includes("optionText"))) {
if(document.getElementById(modifyingInput).className.includes("dropdown")) { if (document.getElementById(modifyingInput).className.includes("dropdown")) {
$(".optionHolder") $(".optionHolder")
.fadeOut(250, "linear"); .fadeOut(250, "linear");
$(".selectedOption").removeClass("selectedOption"); $(".selectedOption").removeClass("selectedOption");
} else { } else {
if(modifyingInput === "description") { if (modifyingInput === "description") {
Session.set("restrictText", {}); Session.set("restrictText", {});
$("#"+modifyingInput).css('cursor','pointer'); $("#" + modifyingInput).css('cursor', 'pointer');
var newSetting = Session.get("user"); var newSetting = Session.get("user");
newSetting[modifyingInput] = document.getElementById(modifyingInput).value; newSetting[modifyingInput] = document.getElementById(modifyingInput).value;
serverData = newSetting; serverData = newSetting;
@ -225,7 +233,10 @@ Template.profile.events({
'click #mainpage' () { 'click #mainpage' () {
if (!Meteor.userId() || _.contains([null, undefined, ""], Meteor.user().profile.school)) { if (!Meteor.userId() || _.contains([null, undefined, ""], Meteor.user().profile.school)) {
sAlert.closeAll(); sAlert.closeAll();
sAlert.error('Please fill in your profile!', {effect: 'stackslide', position: 'top'}); sAlert.error('Please fill in your profile!', {
effect: 'stackslide',
position: 'top'
});
} else { } else {
window.location = '/'; window.location = '/';
} }
@ -242,7 +253,7 @@ Template.profile.events({
openDivFade(functionHolder);         openDivFade(functionHolder);        
}, 400); }, 400);
}, },
    'click .manageClass' () {      'click .manageClass' () { 
if (Session.equals("profClassTab", "manClass")) return;       if (Session.equals("profClassTab", "manClass")) return;      
var functionHolder = document.getElementById("profClassInfoHolder"); var functionHolder = document.getElementById("profClassInfoHolder");
closeDivFade(functionHolder); closeDivFade(functionHolder);
@ -254,7 +265,7 @@ Template.profile.events({
openDivFade(functionHolder);         openDivFade(functionHolder);        
}, 400); }, 400);
}, },
    'click .createClass' () {     'click .createClass' () {
if (Session.equals("profClassTab", "creClass")) return; if (Session.equals("profClassTab", "creClass")) return;
var functionHolder = document.getElementById("profClassInfoHolder");         var functionHolder = document.getElementById("profClassInfoHolder");        
closeDivFade(functionHolder); closeDivFade(functionHolder);
@ -293,7 +304,7 @@ Template.profile.events({
} else { } else {
var attribute = event.target.getAttribute("classid"); var attribute = event.target.getAttribute("classid");
} }
if(attribute === Meteor.userId()) return; if (attribute === Meteor.userId()) return;
Session.set("selectedClass", null); Session.set("selectedClass", null);
var usertype = ["moderators", "banned"]; var usertype = ["moderators", "banned"];
var array = classes.findOne({ var array = classes.findOne({
@ -463,19 +474,19 @@ Template.profile.events({
$(".optionHolder") $(".optionHolder")
.fadeOut(250, "linear"); .fadeOut(250, "linear");
if(modifyingInput !== null) { if (modifyingInput !== null) {
if(!$("#"+modifyingInput)[0].className.includes("dropdown")) closeInput(modifyingInput); if (!$("#" + modifyingInput)[0].className.includes("dropdown")) closeInput(modifyingInput);
} }
modifyingInput = event.target.id; modifyingInput = event.target.id;
if(!$("#"+modifyingInput)[0].className.includes("dropdown")) { if (!$("#" + modifyingInput)[0].className.includes("dropdown")) {
event.target.select(); event.target.select();
event.target.style.cursor = "text"; event.target.style.cursor = "text";
} }
}, },
'keydown .dropdown' (event) { 'keydown .dropdown' (event) {
event.preventDefault(); event.preventDefault();
var first = $("#"+modifyingInput).next().children("p:first-child"); var first = $("#" + modifyingInput).next().children("p:first-child");
var last = $("#"+modifyingInput).next().children("p:last-child"); var last = $("#" + modifyingInput).next().children("p:last-child");
var next = $(".selectedOption").next(); var next = $(".selectedOption").next();
var prev = $(".selectedOption").prev(); var prev = $(".selectedOption").prev();
var lastSel = $(".selectedOption"); var lastSel = $(".selectedOption");
@ -515,19 +526,21 @@ Template.profile.events({
$(".selectedOption").removeClass("selectedOption"); $(".selectedOption").removeClass("selectedOption");
$("#" + modifyingInput).next() $("#" + modifyingInput).next()
.css('opacity',0) .css('opacity', 0)
.slideDown(300) .slideDown(300)
.animate( .animate({
{ opacity: 1 }, opacity: 1
{ queue: false, duration: 100 } }, {
); queue: false,
duration: 100
});
}, },
'click .optionText' (event) { // Click each preferences setting. 'click .optionText' (event) { // Click each preferences setting.
var option = event.target.childNodes[0].nodeValue; var option = event.target.childNodes[0].nodeValue;
var userSettings = ["description","school","grade"]; var userSettings = ["description", "school", "grade"];
var newSetting = Session.get("user"); var newSetting = Session.get("user");
if(modifyingInput === "privacy" || modifyingInput === "category") { if (modifyingInput === "privacy" || modifyingInput === "category") {
document.getElementById(modifyingInput).value = option; document.getElementById(modifyingInput).value = option;
$("#" + modifyingInput).next() $("#" + modifyingInput).next()
.fadeOut(250, "linear"); .fadeOut(250, "linear");
@ -535,7 +548,7 @@ Template.profile.events({
return; return;
} }
if(_.contains(userSettings, modifyingInput)) { if (_.contains(userSettings, modifyingInput)) {
newSetting[modifyingInput] = (modifyingInput === "grade") ? parseInt(option) : option; newSetting[modifyingInput] = (modifyingInput === "grade") ? parseInt(option) : option;
} else { } else {
newSetting.preferences[modifyingInput] = (function() { newSetting.preferences[modifyingInput] = (function() {
@ -585,11 +598,13 @@ Template.profile.events({
name: item.childNodes[1].childNodes[0].nodeValue, name: item.childNodes[1].childNodes[0].nodeValue,
teacher: item.childNodes[3].childNodes[0].nodeValue, teacher: item.childNodes[3].childNodes[0].nodeValue,
hour: item.childNodes[5].childNodes[0].nodeValue, hour: item.childNodes[5].childNodes[0].nodeValue,
subscribers: Math.floor(item.childNodes[7].childNodes[0].nodeValue.replace(",","").length / 17), subscribers: Math.floor(item.childNodes[7].childNodes[0].nodeValue.replace(",", "").length / 17),
_id: item.getAttribute("classid") _id: item.getAttribute("classid")
}); });
} }
Session.set("autocompleteDivs", divs.sort(function(a,b){return b.subscribers-a.subscribers})); Session.set("autocompleteDivs", divs.sort(function(a, b) {
return b.subscribers - a.subscribers
}));
} catch (err) {} } catch (err) {}
} }
}); });