+ {{classInfo 'code'}}
+ {{#if code 'exists'}}
+
Code
-
{{code}}
-
+
{{code 'code'}}
+
-
Copied!
+
Copied!
{{/if}}
diff --git a/hourglass/client/menus/menus.js b/hourglass/client/menus/menus.js
index b6ebe08..4136ec1 100644
--- a/hourglass/client/menus/menus.js
+++ b/hourglass/client/menus/menus.js
@@ -220,15 +220,12 @@ Template.registerHelper("classInfo", (info) => {
_id: (isYou) ? Meteor.userId() : thisClass.admin
});
case "code":
- if (isYou) return {
- exists: false
- };
- return (isYou || Meteor.userId() !== this.admin) ? {
- exists: false
- } : {
- exists: true,
- code: Meteor.call('getCode', thisClass._id)
- };
+ if(isYou || Meteor.userId() !== thisClass.admin) return false;
+ var exist;
+ Meteor.call('getCode', thisClass._id, function(err, result) {
+ Session.set("code", [(result === undefined || result === "") ? false : true, result]);
+ });
+ break;
case "mine":
return (isYou) ? true : Meteor.userId() === thisClass.admin;
case "moderators":
@@ -547,13 +544,14 @@ Template.createClass.events({
return;
}
values.privacy = (values.privacy === "Public") ? false : true;
- values.status = false;
+ values.status = false;
values.category = values.category.toLowerCase();
values.code = "";
serverData = values;
+
if (!teachers.findOne({
name: values.teacher
- })) {
+ }) && values.teacher !== "") {
Meteor.call("createTeacher", values.teacher, values.school, function(error, result) {
if (error !== undefined) {
sAlert.error(error.message, {
@@ -570,6 +568,30 @@ Template.createClass.events({
}
});
+Template.classInfoCode.events({
+ 'click .fa' (event) {
+ document.getElementById("copyHolder").select();
+ document.execCommand("copy");
+ $(event.target.parentNode.childNodes[9]).fadeIn(100, function() {
+ setTimeout(function() {
+ $(event.target.parentNode.childNodes[9]).fadeOut(250);
+ }, 500);
+ });
+ }
+});
+
+Template.classInfoCode.helpers({
+ code(info) {
+ try {
+ if(info === "exists") {
+ return Session.get("code")[0];
+ } else {
+ return Session.get("code")[1];
+ }
+ } catch(err) {}
+ }
+})
+
Template.classInfoUsers.events({
'click .userAdder .fa' (event) {
var type = event.target.getAttribute("user");
@@ -621,18 +643,6 @@ Template.classInfoUsers.events({
}
});
-Template.classInfoCode.events({
- 'click .fa' (event) {
- document.getElementById("copyHolder").select();
- document.execCommand("copy");
- $(event.target.parentNode.childNodes[9]).fadeIn(100, function() {
- setTimeout(function() {
- $(event.target.parentNode.childNodes[9]).fadeOut(250);
- }, 500);
- });
- }
-});
-
toggleToMode = function(mode) {
$("#mainBody").fadeOut(250, function() {
(Session.equals("sidebarMode", "option")) ? Session.set("settingMode", mode): Session.set("mode", mode);
diff --git a/hourglass/server/main.js b/hourglass/server/main.js
index 18ee71c..cc89fed 100644
--- a/hourglass/server/main.js
+++ b/hourglass/server/main.js
@@ -312,7 +312,7 @@ function securityCheck(checklist, input) {
break;
// Incorrect teacher format
case 28:
- if (input.teachername.split(" ").length < 2) error = 20;
+ if (input.teachername.split(" ").length < 2 && teachername !== "") error = 20;
break;
}
results.push(error);
@@ -373,17 +373,17 @@ Meteor.methods({
if (!security) {
input.status = Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']);
input.admin = Meteor.userId();
- Meteor.call('genCode', function(error, result) {
+ Meteor.call('genCode', input.privacy, function(error, result) {
input.code = result;
- });
- if (input.category != "class" && input.category != "club") {
- input.category = "other";
- }
- input.subscribers = [];
- input.moderators = [];
- input.banned = [];
- classes.insert(input, function(err, result) {
- Meteor.call('joinClass', [result, input.code]);
+ if (input.category != "class" && input.category != "club") {
+ input.category = "other";
+ }
+ input.subscribers = [];
+ input.moderators = [];
+ input.banned = [];
+ classes.insert(input, function(err, result) {
+ Meteor.call('joinClass', [result, input.code]);
+ });
});
} else {
throw new Meteor.Error(errors[security]);