+
{{selectedClass 'name'}}
-
Code: {{selectedClass 'code'}}
+
Code:
+
+ {{#if code}}
+
Copy Code
+ {{/if}}
-
Moderators:
+ Moderators:
+
- {{#each selectedClass 'moderators'}}
- {{> userDisplay}}
- {{/each}}
+
+ {{#each selectedClass 'moderators'}}
+ {{> userDisplay}}
+ {{/each}}
+
-
+
+
+ {{#each selectedClass 'banned'}}
+ {{> userDisplay}}
+ {{/each}}
+
+
+ Change Owner
+
Delete Class
@@ -180,6 +193,7 @@
{{email}}
{{name}}
+
diff --git a/hourglass/client/profile/profile.js b/hourglass/client/profile/profile.js
index cb3a590..9ab182b 100644
--- a/hourglass/client/profile/profile.js
+++ b/hourglass/client/profile/profile.js
@@ -17,7 +17,8 @@ Session.set("serverData", null);
Session.set("autocompleteDivs", null);
Session.set("confirmText", null);
Session.set("selectedClass",null);
-Session.set("adding",null);
+Session.set("selectClassId",null);
+Session.set("code",null);
var themeColors = {
"light": {
@@ -144,9 +145,9 @@ Template.profile.helpers({
privacy: {$eq: false},
_id: {$nin: Meteor.user().profile.classes}
},
- {sort: {subscribers: -1 }},
- {limit: 20}
- ).fetch();
+ {sort: {subscribers: -1 }},
+ {limit: 20}
+ ).fetch();
},
profClassHeight() {
return 0.6 * window.innerHeight.toString() + "px";
@@ -181,7 +182,36 @@ Template.profile.helpers({
return Session.get("confirmText");
},
selectedClass(val) {
- return Session.get("selectedClass")[val];
+ var usertype = ["moderators","banned"];
+ var attribute = Session.get("selectClassId");
+ var array = classes.findOne({_id:attribute});
+
+ if(array.code === "") {
+ array.code = "None";
+ Session.set("code", false);
+ } else {
+ Session.set("code", true);
+ }
+
+ for(var i = 0; i < usertype.length; i++) {
+ var users = array[usertype[i]];
+ array[usertype[i]] = [];
+ for(var j = 0; j < users.length; j++) {
+ var detailusers = {};
+ var user = Meteor.users.findOne({_id:users[j]});
+ detailusers._id = user._id;
+ detailusers.email = user.services.google.email;
+ detailusers.name = user.profile.name;
+ array[usertype[i]].push(detailusers);
+ }
+ }
+ return array[val];
+ },
+ code() {
+ return Session.get("code");
+ },
+ userHolder() {
+ return 0.15 * window.innerHeight.toString() + "px";
}
});
@@ -257,21 +287,19 @@ Template.profile.events({
Session.set("radioDiv", null);
Session.set("radioOffset", null);
}
- if(event.target.className !== "userAddInput" &&
- Session.get("adding")) {
- var inputs = document.getElementsByClassName("userAddInput");
- for(var i = 0; i < inputs.length; i++) {
- try {
- inputs[i].parentNode.removeChild(inputs[i]);
- } catch(err) {}
- }
- Session.set("adding",false);
- }
- if(!document.getElementById("createdClasses").contains(event.target) &&
- Session.get("selectedClass") !== null) {
- document.getElementById("createdClasses").style.marginRight = "-40%";
- setTimeout(function() { Session.set("selectedClass", null); }, 300);
- }
+ if(!document.getElementById("createdClasses").contains(event.target) &&
+ Session.get("code") !== null &&
+ !event.target.className.includes("fa-times-circle-o")) {
+ document.getElementById("createdClasses").style.marginRight = "-40%";
+ setTimeout(function() { Session.set("selectedClass", null); }, 300);
+ }
+ if(Session.get("changeAdmin") &&
+ !document.getElementById("changeAdmin").contains(event.target)) {
+ Session.set("changeAdmin",false);
+ var div = document.getElementById("changeAdmin");
+ div.removeChild(div.childNodes[3]);
+ div.removeChild(div.childNodes[3]);
+ }
},
'keydown' (event) {
var sessval = Session.get("modifying");
@@ -338,20 +366,20 @@ Template.profile.events({
}, 300);
},
'click .manageClass' () {
- var functionHolder = document.getElementById("profClassInfoHolder");
- closeDivFade(functionHolder);
- setTimeout(function() {
- Session.set("profClassTab", "manClass");
- openDivFade(functionHolder);
- }, 300);
+ var functionHolder = document.getElementById("profClassInfoHolder");
+ closeDivFade(functionHolder);
+ setTimeout(function() {
+ Session.set("profClassTab", "manClass");
+ openDivFade(functionHolder);
+ }, 300);
},
'click .createClass' () {
- var functionHolder = document.getElementById("profClassInfoHolder");
- closeDivFade(functionHolder);
- setTimeout(function() {
- Session.set("profClassTab", "creClass");
- openDivFade(functionHolder);
- }, 300);
+ var functionHolder = document.getElementById("profClassInfoHolder");
+ closeDivFade(functionHolder);
+ setTimeout(function() {
+ Session.set("profClassTab", "creClass");
+ openDivFade(functionHolder);
+ }, 300);
},
'click .fa-search' () {
Session.set("searching", true);
@@ -409,8 +437,8 @@ Template.profile.events({
sendData(Session.get("confirm"));
closeDivFade(document.getElementsByClassName("overlay")[0]);
if(Session.get("confirm") === "createClass") {
- var form = document.getElementById("create");
- for(var i = 0; i < form.length; i++) form[i].value = "";
+ var form = document.getElementById("create");
+ for(var i = 0; i < form.length; i++) form[i].value = "";
}
Session.set("serverData", null);
Session.set("confirm", null);
@@ -420,16 +448,6 @@ Template.profile.events({
Session.set("serverData", null);
Session.set("confirm", null);
},
- 'click #save' () {
- Session.set("serverData", getProfileData());
- Session.set("confirm", "editProfile");
- Session.set("confirmText", "Save new profile settings?");
-
- openDivFade(document.getElementsByClassName("overlay")[0]);
- setTimeout(function() {
- document.getElementsByClassName("overlay")[0].style.opacity = "1";
- }, 200);
- },
'click #creSubmit' () {
var data = getCreateFormData();
if (data === null) return;
@@ -438,44 +456,82 @@ Template.profile.events({
Session.set("confirmText", "Submit request?");
openDivFade(document.getElementsByClassName("overlay")[0]);
- setTimeout(function() {
- document.getElementsByClassName("overlay")[0].style.opacity = "1";
- }, 200);
},
'focus .op' (event) {
event.target.click();
},
'click .owned' (event) {
- if (event.target.id === "label") return;
+ if (event.target.id === "label") return;
if (!event.target.className.includes("owned")) {
var attribute = event.target.parentNode.getAttribute("classid");
} else {
var attribute = event.target.getAttribute("classid");
}
- var usertype = ["moderators","banned","blockEdit"];
- var array = classes.findOne({_id:attribute});
-
- if(array.code === "") array.code = "None";
- for(var i = 0; i < usertype.length; i++) {
- var users = array[usertype[i]];
- for(var j = 0; j < users.length; j++) {
- var detailusers = {};
- var user = Meteor.users.findOne({_id:users[j]});
- detailusers._id = user._id;
- detailusers.email = user.name + "hi";
- detailusers.name = user.name;
- array[usertype[i]] = detailusers;
- }
- }
- document.getElementById("createdClasses").style.marginRight = "0";
- Session.set("selectedClass",array);
+ Session.set("selectClassId",attribute);
+ document.getElementById("createdClasses").style.marginRight = "0";
},
'click .userAdder .fa-plus' (event) {
- if(Session.get("adding")) return;
- var input = document.createElement("input");
- input.className = "userAddInput";
- event.target.parentNode.appendChild(input);
- Session.set("adding", true);
+ var input = event.target.parentNode.childNodes[3];
+ input.placeholder = "1234@abc.xyz";
+ input.className.replace(" formInvalid","");
+ var value = input.value;
+ input.value = "";
+ if(checkUser(value)) {
+ input.className += " formInvalid";
+ input.placeholder = "Not a valid user";
+ return;
+ }
+ var user = Meteor.users.findOne({"services.google.email":input.value});
+ Session.set("serverData", [
+ user._id,
+ document.getElementById("createdClasses").getAttribute("classid"),
+ event.target.parentNode.childNodes[1].childNodes[0].nodeValue.replace(":","").toLowerCase()
+ ]);
+ sendData("trackUserInClass");
+
+ },
+ 'click .userBox .fa-times' (event) {
+ var box = event.target.parentNode;
+ Session.set("serverData", [
+ box.getAttribute("userid"),
+ document.getElementById("createdClasses").getAttribute("classid"),
+ box.parentNode.parentNode.childNodes[1].childNodes[1].childNodes[0].nodeValue.replace(":","").toLowerCase()
+ ])
+ sendData("untrackUserInClass");
+ },
+ 'click #copy' () {
+ if(document.getElementById("code").value === "None") return;
+ document.getElementById("code").select();
+ document.execCommand("copy");
+ },
+ 'click #deleteClass' () {
+ Session.set("serverData",document.getElementById("createdClasses").getAttribute("classid"));
+ Session.set("confirm", "deleteClass");
+ Session.set("confirmText", "Delete this class?");
+ openDivFade(document.getElementsByClassName("overlay")[0]);
+ },
+ 'click #changeAdmin span' (event) {
+ if(Session.get("changeAdmin")) return;
+ Session.set("changeAdmin",true);
+ var input = document.createElement("input");
+ input.placeholder = "1234@abc.xyz";
+ var i = document.createElement("i");
+ i.className = "fa fa-exchange";
+ i.setAttribute("aria-hidden","true");
+ event.target.parentNode.appendChild(input);
+ event.target.parentNode.appendChild(i);
+ },
+ 'click .fa-exchange' (event) {
+ var input = event.target.parentNode.childNodes[3];
+ input.placeholder = "1234@abc.xyz";
+ input.className.replace(" formInvalid","");
+ var value = input.value;
+ input.value = "";
+ if(checkUser(value)) {
+ input.className += " formInvalid";
+ input.placeholder = "Not a valid user";
+ return;
+ }
}
});
@@ -542,7 +598,7 @@ function getCreateFormData() {
var stop;
var form = document.getElementsByClassName("creInput");
for (var i = 0; i < form.length; i++) {
- if(i === 1 || i === 2) continue;
+ if(i === 1 || i === 2) continue;
if (form[i].value === "") {
form[i].focus();
form[i].placeholder = "Missing field";
@@ -575,3 +631,12 @@ function getCreateFormData() {
code: ""
};
}
+
+function checkUser(email) {
+ var user = Meteor.users.findOne({"services.google.email":email});
+ if(user === undefined) {
+ return true;
+ } else {
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/hourglass/collections/main.js b/hourglass/collections/main.js
index 7359ffd..073e80c 100644
--- a/hourglass/collections/main.js
+++ b/hourglass/collections/main.js
@@ -20,7 +20,7 @@ classes.schema = new SimpleSchema({
privacy: {type: Boolean},
category: {type: String},
moderators: {type: [String], optional: true},
- blockEdit: {type: [String], optional: true},
+ banned: {type: [String], optional: true},
subscribers: {type: [String], optional: true}
});
diff --git a/hourglass/server/main.js b/hourglass/server/main.js
index 33799fe..267c81f 100644
--- a/hourglass/server/main.js
+++ b/hourglass/server/main.js
@@ -16,7 +16,7 @@ superadmins = [
];
worktype = ["test", "quiz", "project", "normal"];
-var possiblelist = ["moderators","blockEdit"];
+var possiblelist = ["moderators","banned"];
for (var i = 0; i < superadmins.length; i++) {
var superadmin = superadmins[i];
@@ -57,7 +57,7 @@ Meteor.publish('classes', function() {
privacy: 1,
category: 1,
moderators: 1,
- blockEdit: 1,
+ banned: 1,
subscribers: 1
}
});
@@ -148,7 +148,7 @@ Meteor.methods({
input.category = "other";
}
input.moderators = [];
- input.blockEdit = [];
+ input.banned = [];
classes.insert(input);
Meteor.call('joinClass', classes.findOne(input)._id, input.code, function(error, result) {});
return 1;
@@ -162,14 +162,14 @@ Meteor.methods({
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
classes.update({_id: input[1]}, {$set: {admin: input[0]}});
} else if (found && foundclass && foundclass.admin == Meteor.userId() &&
- foundclass.blockEdit.indexOf(input[0]) != -1) {
+ foundclass.banned.indexOf(input[0]) != -1) {
classes.update({_id: input[1]}, {$set: {admin: input[0]}});
} else {
throw "Unauthorized";
}
},
'trackUserInClass': function(input) {
- var foundclass = Meteor.findOne({_id: input[1]});
+ var foundclass = classes.findOne({_id: input[1]});
var userlist = input[2];
var index = possiblelist.indexOf(input[2]);
var set = {};
@@ -183,11 +183,13 @@ Meteor.methods({
}
},
'untrackUserInClass': function(input) {
- var foundclass = Meteor.findOne({_id: input[1]});
+ var foundclass = classes.findOne({_id: input[1]});
var userlist = input[2];
var index = possiblelist.indexOf(input[2]);
var set = {};
- set[userlist] = foundclass[userlist].splice(foundclass[userlist].indexOf(input[0]), 1);
+ foundclass[userlist].splice(foundclass[userlist].indexOf(input[0]), 1);
+ set[userlist] = foundclass[userlist];
+
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
classes.update({_id: input[1]}, {$set: set});
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
@@ -227,7 +229,7 @@ Meteor.methods({
if (Meteor.user() !== null &&
found !== null &&
Meteor.user().profile.classes.indexOf(input.class) !== -1 &&
- found.blockEdit.indexOf(Meteor.userId()) === -1 &&
+ found.banned.indexOf(Meteor.userId()) === -1 &&
input.dueDate instanceof Date && input.dueDate.getTime() >= ref &&
worktype.indexOf(input.type) != -1 &&
input.name.length <= 50 && input.description.length <= 150) {
@@ -303,7 +305,7 @@ Meteor.methods({
var user = Meteor.userId();
if (typeof comment === "string" && comment.length <= 200 &&
currentclass.subscribers.indexOf(Meteor.userId()) != -1 &&
- currentclass.blockEdit.indexOf(Meteor.userId()) === -1) {
+ currentclass.banned.indexOf(Meteor.userId()) === -1) {
var comments = workobject.comments.concat(comment);
work.update({
_id: input[1]