-
- Hide
+ {{#if isDisabled}}Unhide{{else}}Hide{{/if}}
Modify
diff --git a/client/views/helpers/chunks/question_div/question_div.js b/client/views/helpers/chunks/question_div/question_div.js
index 86c14be5..144f819c 100644
--- a/client/views/helpers/chunks/question_div/question_div.js
+++ b/client/views/helpers/chunks/question_div/question_div.js
@@ -9,4 +9,10 @@ Template.question_div.helpers({
return 150;
}
},
-})
\ No newline at end of file
+ isDisabled: function() {
+ if(Questions.findOne({ _id: this._id}).state === "disabled") {
+ return true;
+ }
+ return false;
+ }
+});
\ No newline at end of file
diff --git a/client/views/helpers/navlogin/navlogin.html b/client/views/helpers/navlogin/navlogin.html
index 708f4107..b9d72af3 100644
--- a/client/views/helpers/navlogin/navlogin.html
+++ b/client/views/helpers/navlogin/navlogin.html
@@ -18,9 +18,13 @@
{{/if}}
-
+ {{#if admin}}
+
+
+ Admin
+
+
+ {{/if}}
{{#if currentUser}}
diff --git a/client/views/helpers/navlogin/navlogin.js b/client/views/helpers/navlogin/navlogin.js
index d72cfa2f..207d0080 100644
--- a/client/views/helpers/navlogin/navlogin.js
+++ b/client/views/helpers/navlogin/navlogin.js
@@ -16,6 +16,14 @@ Template.userInfo.events({
var parentNode = document.getElementById("banner");
popoverTemplate = Blaze.render(Template.register, parentNode);
},
+ "click #navAdmin": function(event, template) {
+ if( $(".admincontainer").css('display') == 'none') {
+ $(".admincontainer").slideDown();
+ }
+ else {
+ $(".admincontainer").slideUp();
+ }
+ },
"click #navHome": function(event, template) {
document.getElementById("searchbar").value = "";
Session.set("search", "");
@@ -29,6 +37,12 @@ Template.userInfo.events({
}
});
+Template.userInfo.helpers({
+ admin: function() {
+ return Session.get("admin");
+ }
+});
+
function showError(reason, parentElement, nextElement) {
if(typeof currentError != "undefined") {
Blaze.remove(currentError);
diff --git a/client/views/list/list.css b/client/views/list/list.css
index dbee5ada..ac30f2d9 100644
--- a/client/views/list/list.css
+++ b/client/views/list/list.css
@@ -147,6 +147,7 @@ div#recent {
padding:1.5% 2% 1.5% 2%;
border-radius:5px;
padding-bottom:50px;
+ display: none;
}
.modcontainer {
diff --git a/client/views/list/list.js b/client/views/list/list.js
index 38dae455..13887f4e 100644
--- a/client/views/list/list.js
+++ b/client/views/list/list.js
@@ -13,6 +13,7 @@ Template.list.onCreated(function () {
Session.set("search", "all");
Session.set("tablename", Template.instance().data.tablename);
Session.set("id", Template.instance().data._id);
+ Session.set("slug", Template.instance().data.slug);
Session.set("description", Template.instance().data.description);
if(typeof Template.instance().data.anonymous !== 'undefined') {
Session.set("anonymous", Template.instance().data.anonymous);
@@ -69,12 +70,12 @@ Template.list.helpers({
if(Session.get("search") == "all") {
//console.log(Session.get("tablename"));
var questions = Questions.find({
- tablename: Session.get("tablename")
+ instanceid: Session.get("id")
}).fetch();
} else {
var re = new RegExp(Session.get("search"), "i");
var questions = Questions.find({
- tablename: Session.get("tablename"),
+ instanceid: Session.get("id"),
"$or": [{
text: {
$regex: re
@@ -112,7 +113,7 @@ Template.list.helpers({
});
// Loops through the retrieved questions and sets properties
for(var i = 0; i < questions.length; i++) {
- if(questions[i].state != "disabled") {
+ if(questions[i].state != "disabled" || Session.get("admin") || Session.get("mod")) {
var urlRegex = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g;
questions[i].text = questions[i].text.replace(urlRegex, function(url) {
if(url.charAt(url.length-1) == ")") {
@@ -187,6 +188,7 @@ Template.list.helpers({
if(a > 2) {
questions[i].answer[a].isHidden = true;
}
+ questions[i].answer[a].text = questions[i].answer[a].text.replace(/\B(@\S+)/g, "$1 ");
var urlRegex = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g;
questions[i].answer[a].text = questions[i].answer[a].text.replace(urlRegex, function(url) {
if(url.charAt(url.length-1) == ")") {
@@ -219,7 +221,7 @@ Template.list.helpers({
}
} else if(questions[i].state == "disabled") {
// If the question is disabled, don't display
- questions[i].disabled = true;
+ //questions[i].disabled = true;
}
}
questions.sort(function(a, b) {
@@ -283,7 +285,7 @@ Template.list.events({
var ip = result;
if (!error) {
// Calls server-side "vote" method to update the Questions and Vote DBs
- Meteor.call('vote', event.currentTarget.id, ip, Session.get("tablename"), function(error, result) {
+ Meteor.call('vote', event.currentTarget.id, ip, Session.get("id"), function(error, result) {
// If the result is an object, there was an error
if(typeof result === 'object') {
// Store an object of the error names and codes
@@ -304,12 +306,17 @@ Template.list.events({
// When the admin hide button is clicked...
"click .adminquestionhide": function(event, template) {
// Call the server-side hide method to hide the question
- Meteor.call('hide', event.currentTarget.id);
+ if(Questions.findOne({ _id: event.currentTarget.id}).state === "disabled") {
+ Meteor.call('unhideThis', event.currentTarget.id);
+ }
+ else {
+ Meteor.call('hide', event.currentTarget.id);
+ }
},
// When the admin unhide button is clicked...
"click #unhidebutton": function(event, template) {
// Call the server-side unhide method to unhide all questions
- Meteor.call('unhide', Session.get("tablename"));
+ Meteor.call('unhide', Session.get("id"));
},
"click .deletebutton": function(event, template) {
var check = confirm("Are you sure you would like to delete the instance?");
@@ -361,6 +368,28 @@ Template.list.events({
$("#down" + theID).slideUp();
}
},
+ "click .checkbox": function(event, template) {
+ var checked = event.target.firstElementChild;
+ if(checked.style.display == "none" || !checked.style.display) {
+ checked.style.display = "block";
+ if(Meteor.user()) {
+ $(".replyname").val("Anonymous");
+ $(".replyemail").val("");
+ }
+ }
+ },
+ "click .checked": function(event, template) {
+ //console.log(event);
+ //return false;
+ var checked = event.target;
+ if(checked.style.display == "block") {
+ if(Meteor.user()) {
+ $(".replyname").val(Meteor.user().profile.name);
+ $(".replyemail").val(Meteor.user().emails[0].address);
+ }
+ checked.style.display = "none";
+ }
+ },
"click .replybottombutton": function(event, template) {
// Retrieves data from form
var theID = event.target.id;
@@ -398,7 +427,7 @@ Template.list.events({
posterName = "Anonymous";
}
// Calls a server-side method to answer a question and update DBs
- Meteor.call('answer', Session.get("tablename"), answer, posterName, email, result, theID, function (error, result) {
+ Meteor.call('answer', Session.get("id"), answer, posterName, email, result, theID, function (error, result) {
// If the result is an object, there was an error
if(typeof result === 'object') {
// Store an object of the error names and codes
@@ -407,7 +436,7 @@ Template.list.events({
"poster": "Please enter a valid name.",
"email": "Please enter a valid email address.",
"ip": "There was an error with your IP address. Try again.",
- "tablename": "There was an error with the table name. Try again.",
+ "instanceid": "There was an error with the instance id. Try again.",
"qid": "There was an error with the question ID."
}
// Alert the error
@@ -468,7 +497,7 @@ Template.list.events({
Session.set("replyCount", total);
},
"click .facebookbutton": function(event, template) {
- popupwindow("https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(window.location.origin + "/list/" + Session.get("tablename")), "Share Question Tool!", 600, 400);
+ popupwindow("https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(window.location.origin + "/list/" + Session.get("slug")), "Share Question Tool!", 600, 400);
},
"click .twitterbutton": function(event, template) {
var questionDiv = event.target.parentElement.parentElement;
@@ -476,7 +505,7 @@ Template.list.events({
if(questionText.length > 35) {
questionText = questionText.substring(0, 34);
}
- var tweetText = 'Check out this question: "' + questionText + '..." on Question Tool by @berkmancenter ' + window.location.origin + "/list/" + Session.get("tablename");
+ var tweetText = 'Check out this question: "' + questionText + '..." on Question Tool by @berkmancenter ' + window.location.origin + "/list/" + Session.get("slug");
popupwindow("https://twitter.com/intent/tweet?text=" + encodeURIComponent(tweetText), "Share Question Tool!", 600, 400);
},
"click #modbutton": function(event, template) {
@@ -614,7 +643,7 @@ function timeSince(date) {
};
function enableDragging() {
- Meteor.call('adminCheck', Session.get("tablename"), function(error, result) {
+ Meteor.call('adminCheck', Session.get("id"), function(error, result) {
// If yes, enable draggable question divs
if(result) {
interact('.question')
diff --git a/client/views/main/main.js b/client/views/main/main.js
index 7f02ceb4..bf054d9b 100644
--- a/client/views/main/main.js
+++ b/client/views/main/main.js
@@ -121,6 +121,14 @@ Template.home.helpers({
instances[i].indexThree = true;
}
}
+ if(instances.length < 1) {
+ showCreateError("Nothing found.");
+ }
+ else {
+ if(typeof currentError != "undefined") {
+ Blaze.remove(currentError);
+ }
+ }
return instances;
}
});
@@ -161,7 +169,7 @@ Template.home.events({
//var selectedInstance = instances.options[instances.selectedIndex].text;
//Cookie.set('tablename', theInstance.tablename);
// Redirects to the list
- window.location.href = "/list/" + theInstance.tablename;
+ window.location.href = "/list/" + theInstance.slug;
//Router.go('/list');
},
"keyup #searchbar": function(event, template) {
@@ -174,7 +182,7 @@ Template.home.events({
},
"click .favoritebutton": function(event, template) {
var style = event.target.currentStyle || window.getComputedStyle(event.target, false),
- bi = style.backgroundImage.slice(4, -1);
+ bi = style.backgroundImage.slice(4, -1).replace(/['"]+/g, '');
event.stopPropagation();
if(bi == (event.target.baseURI + "heart_empty.png")) {
event.target.style.backgroundImage = "url('" + event.target.baseURI + "heart_filled.png')";
@@ -276,13 +284,13 @@ function timeSince(date) {
}
return interval + ' ' + intervalType;
-};
+}
function showCreateError(reason) {
if(typeof currentError != "undefined") {
Blaze.remove(currentError);
}
- var parentNode = document.getElementById("creatediv");
- var nextNode = document.getElementById("instancetopinputcontainer");
+ var parentNode = document.getElementById("recent");
+ var nextNode = document.getElementById("questionscontainer");
currentError = Blaze.renderWithData(Template.form_error, reason, parentNode, nextNode);
}
\ No newline at end of file
diff --git a/client/views/modify/modify.js b/client/views/modify/modify.js
index 1fb0514d..965060fc 100644
--- a/client/views/modify/modify.js
+++ b/client/views/modify/modify.js
@@ -6,7 +6,7 @@ Template.modify.onCreated(function () {
window.location.href = "/";
} else {
// Checks whether the user has proper admin privileges
- Meteor.call('adminCheck', Session.get("tablename"), function (error, result) {
+ Meteor.call('adminCheck', Session.get("id"), function (error, result) {
if(!result) {
// If not, redirects back to the list page
window.location.href = "/list";
@@ -43,7 +43,7 @@ Template.modify.events({
return false;
}
// Calls the server-side "modify" method to update the DBs
- Meteor.call('modify', question, event.currentTarget.id, Session.get("tablename"), function (error, result) {
+ Meteor.call('modify', question, event.currentTarget.id, Session.get("id"), function (error, result) {
if(result) {
// If successful, redirect back to the list page
//window.location.href = "/list";
diff --git a/client/views/propose/propose.js b/client/views/propose/propose.js
index 882f3372..40f19fca 100644
--- a/client/views/propose/propose.js
+++ b/client/views/propose/propose.js
@@ -50,7 +50,7 @@ Template.propose.events({
checked.style.display = "none";
if(event.target.id == "savebox") {
$("#bottominputcontainer").slideUp();
- $('#topinputcontainer').slideUp()
+ $('#topinputcontainer').slideUp();
document.getElementById("anoncheck").style.display = "block";
} else if(event.target.id == "anonbox") {
if(Meteor.user()) {
@@ -193,7 +193,7 @@ Template.propose.events({
Meteor.call('getIP', function (error, result) {
if (!error) {
// Calls server-side "propose" method to add question to DB
- Meteor.call('propose', Session.get("tablename"), question, posterName, posterEmail, result, function (error, result) {
+ Meteor.call('propose', Session.get("id"), Session.get("tablename"), question, posterName, posterEmail, result, function (error, result) {
// If returns an object, there was an error
if(typeof result === 'object') {
// Store an object of the error names and codes
@@ -213,7 +213,7 @@ Template.propose.events({
return false;
} else {
// If successful, redirect back to the list page
- // Router.go("/list");
+ //Router.go("/list");
if(typeof currentError != "undefined") {
Blaze.remove(currentError);
}
diff --git a/client/views/rename/rename.js b/client/views/rename/rename.js
index d0afe5c2..f50abd36 100644
--- a/client/views/rename/rename.js
+++ b/client/views/rename/rename.js
@@ -11,7 +11,7 @@ Template.rename.helpers({
renameid: function() {
return Template.instance().data.id;
}
-})
+});
Template.rename.events({
// When the submit button is clicked...
@@ -28,7 +28,10 @@ Template.rename.events({
showRenameError("Name is already taken.");
} else {
if(template.data.isList) {
- window.location.href = "/list/" + newName;
+ var instance = Instances.findOne({
+ _id: Session.get("id")
+ });
+ window.location.href = "/list/" + instance.slug;
}
}
});
diff --git a/lib/common.js b/lib/common.js
index c5b1671d..59cd24be 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -1,5 +1,6 @@
// Initializes the Mongo collections
Instances = new Mongo.Collection("instances");
+Instances.friendlySlugs('tablename');
Questions = new Mongo.Collection("questions");
Answers = new Mongo.Collection("answers");
Votes = new Mongo.Collection("votes");
@@ -74,6 +75,11 @@ Schemas.Instance = new SimpleSchema({
});
Schemas.Question = new SimpleSchema({
+ instanceid: {
+ type: String,
+ max: 30
+ },
+
tablename: {
type: String,
regEx: /^[a-zA-Z0-9]{4,30}$/
@@ -135,9 +141,9 @@ Schemas.Answer = new SimpleSchema({
type: String,
regEx: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
},
- tablename: {
+ instanceid: {
type: String,
- regEx: /^[a-zA-Z0-9]{4,30}$/
+ max: 30
},
qid: {
type: String,
@@ -154,10 +160,9 @@ Schemas.Vote = new SimpleSchema({
type: String,
regEx: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
},
- tablename: {
+ instanceid: {
type: String,
- regEx: /^[a-zA-Z0-9]{4,30}$/,
- optional: true
+ max: 30
}
});
diff --git a/lib/routes.js b/lib/routes.js
index 82b509ef..ae44180f 100644
--- a/lib/routes.js
+++ b/lib/routes.js
@@ -89,22 +89,25 @@ Router.route('', {
// When the user visits /list/tablename, set cookie to tablename and display list
Router.route('listlink', {
- path: '/list/:tablename',
+ path: '/list/:slug',
waitOn: function() {
+ var instance = Instances.findOne({
+ slug: this.params.slug
+ });
return [
- Meteor.subscribe('questions', this.params.tablename),
- Meteor.subscribe('answers', this.params.tablename),
- Meteor.subscribe('votes', this.params.tablename)
+ Meteor.subscribe('questions', instance._id),
+ Meteor.subscribe('answers', instance._id),
+ Meteor.subscribe('votes', instance._id)
];
},
onBeforeAction: function() {
var instance = Instances.findOne({
- tablename: this.params.tablename
+ slug: this.params.slug
});
if(instance) {
this.render('list', {
data: function() {
- return instance
+ return instance;
}
});
} else {
@@ -142,17 +145,17 @@ Router.route('/rss/:tablename', {
// Retrieves table and question data for the tablename parameter
var table = Instances.findOne({
- tablename: this.params.tablename
+ _id: this.params._id
});
var questions = Questions.find({
- tablename: this.params.tablename
+ instanceid: this.params._id
}).fetch();
// Creates XML header
var xmlData = ' ';
xmlData += "" + table.tablename + " ";
- xmlData += " http://cyber.law.harvard.edu/questions/list/" + table.tablename + "";
+ xmlData += " http://cyber.law.harvard.edu/questions/list/" + table._id + "";
xmlData += "Questions and answers submitted during class ";
xmlData += "en-US ";
xmlData += "Copyright 2006 The President and Fellows of Harvard College. ";
diff --git a/server/methods.js b/server/methods.js
index 8f08383d..7b8463bb 100644
--- a/server/methods.js
+++ b/server/methods.js
@@ -20,11 +20,9 @@ Meteor.methods({
});
},
// A method that checks whether a table exists with parameter tablename
- listCookieCheck: function(table) {
+ listCookieCheck: function(instanceid) {
var table = Instances.findOne({
- tablename: {
- $regex: new RegExp("^" + table, "i")
- }
+ _id: instanceid
});
if(table == null) {
return false;
@@ -33,14 +31,14 @@ Meteor.methods({
}
},
// A method that checks whether the email matches the admin of the supplied tablename
- adminCheck: function(tablename) {
+ adminCheck: function(instanceid) {
if(Meteor.user()) {
var user = Meteor.user().emails[0].address;
} else {
return false;
}
var table = Instances.findOne({
- tablename: tablename
+ _id: instanceid
});
if(((user == table.admin) || (table.moderators.indexOf(user) != -1)) && (user && table.admin)) {
return true;
@@ -48,8 +46,22 @@ Meteor.methods({
return false;
}
},
+ sendEmail: function (to, from, subject, text) {
+ check([to, from, subject, text], [String]);
+
+ // Let other method calls from the same client start running,
+ // without waiting for the email sending to complete.
+ this.unblock();
+
+ Email.send({
+ to: to,
+ from: from,
+ subject: subject,
+ text: text
+ });
+ },
// A method that adds an answer to the databases
- answer: function(tablename, answer, posterName, email, result, currentURL) {
+ answer: function(instanceid, answer, posterName, email, result, currentURL) {
var keys = "";
answer.replace(/<(?:.|\n)*?>/gm, '');
// Retrieves the current quesetion from the DB (if one exists)
@@ -65,7 +77,7 @@ Meteor.methods({
poster: posterName,
email: email,
ip: result,
- tablename: tablename,
+ instanceid: instanceid,
qid: currentURL
}, function(error, id) {
// If error, set keys to the error object
@@ -84,7 +96,7 @@ Meteor.methods({
return false;
} else {
Instances.update({
- tablename: tablename
+ instanceid: instanceid
}, {
$set: {
lasttouch: new Date().getTime() - 1000
@@ -139,6 +151,7 @@ Meteor.methods({
} else {
// If successful, add the "starter" question to the questions database
Questions.insert({
+ instanceid: id,
tablename: tablename,
text: "Welcome to the live question tool. Feel free to post questions. Vote by clicking on the 'vote' button. To reply, press the button in the bottom-right.",
poster: "the system",
@@ -149,6 +162,7 @@ Meteor.methods({
}, function(error, id) {
// If error, set keys to the error object
if(error) {
+ console.log("Second error " + error);
keys = error.invalidKeys;
}
});
@@ -163,19 +177,19 @@ Meteor.methods({
}
},
// Method that unhides every question in a given table
- unhide: function(table) {
+ unhide: function(instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
return false;
}
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
if(email === instance.admin) {
// Sets state to normal for every question with tablename table
Questions.update({
- tablename: table
+ instanceid: instanceid
}, {
$set: {
state: "normal"
@@ -189,7 +203,38 @@ Meteor.methods({
});
}
},
- addMods: function(mods, table) {
+ unhideThis: function(id) {
+ if(Meteor.user()) {
+ var email = Meteor.user().emails[0].address;
+ } else {
+ return false;
+ }
+ var question = Questions.findOne({
+ _id: id
+ });
+ var table = Instances.findOne({
+ _id: question.instanceid
+ });
+ if(email !== table.admin) {
+ if(table.moderators) {
+ if(table.moderators.indexOf(email) == -1) {
+ return false;
+ }
+ }
+ }
+ Questions.update({
+ _id: id
+ }, {
+ $set: {
+ state: "normal"
+ }
+ }, function(error, count, status) {
+ if(error) {
+ return false;
+ }
+ });
+ },
+ addMods: function(mods, instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
@@ -197,11 +242,11 @@ Meteor.methods({
}
var keys;
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
if(email === instance.admin) {
Instances.update({
- tablename: table
+ _id: instanceid
}, {
$push: {
moderators: {
@@ -222,18 +267,18 @@ Meteor.methods({
return true;
}
},
- removeMods: function(mod, table) {
+ removeMods: function(mod, instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
return false;
}
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
if(email === instance.admin) {
Instances.update({
- tablename: table
+ _id: instanceid
}, {
$pull: {
moderators: mod
@@ -249,7 +294,7 @@ Meteor.methods({
return true;
},
// Method that modifies a question
- modify: function(question, id, table) {
+ modify: function(question, id, instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
@@ -257,7 +302,7 @@ Meteor.methods({
}
// Checks whether the user has the proper admin privileges
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
if(email || instance.admin) {
if(email != instance.admin) {
@@ -284,7 +329,7 @@ Meteor.methods({
return true;
},
// Method that combines two questions and answers
- combine: function(question, id1, id2, table) {
+ combine: function(question, id1, id2, instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
@@ -292,7 +337,7 @@ Meteor.methods({
}
// Checks whether the user has proper admin privileges
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
if(email !== instance.admin) {
if(instance.moderators) {
@@ -337,18 +382,19 @@ Meteor.methods({
});
},
// Method that adds a new question to the database
- propose: function(tablename, question, posterName, posterEmail, ip) {
+ propose: function(instanceid, tablename, question, posterName, posterEmail, ip) {
var keys;
question.replace(/<(?:.|\n)*?>/gm, '');
// Gets the current table
var table = Instances.findOne({
- tablename: tablename
+ _id: instanceid
});
if(table == null) {
return false;
} else {
// Update the lasttouch of the Instance
Questions.insert({
+ instanceid: instanceid,
tablename: tablename,
text: question,
poster: posterName,
@@ -413,7 +459,7 @@ Meteor.methods({
return keys;
},
// Method that removes a table from the database
- remove: function(table) {
+ remove: function(instanceid) {
if(Meteor.user()) {
var email = Meteor.user().emails[0].address;
} else {
@@ -421,28 +467,28 @@ Meteor.methods({
}
// Ensures that the user has proper admin privileges
var instance = Instances.findOne({
- tablename: table
+ _id: instanceid
});
// Removes all questions with the given tablename
if(email !== instance.admin) {
return false;
}
Questions.remove({
- tablename: table
+ instanceid: instanceid
}, function(error) {
if(error) {
alert(error);
} else {
// If successful, removes all answers with the given tablename
Answers.remove({
- tablename: table
+ instanceid: instanceid
}, function(error) {
if(error) {
alert(error);
} else {
// If successful, remove the instance with the given tablename
Instances.remove({
- tablename: table
+ _id: instanceid
}, function(error) {
if(error) {
alert(error);
@@ -464,7 +510,7 @@ Meteor.methods({
}
});
},
- adminRemove: function(id) {
+ adminRemove: function(instanceid) {
// Ensures that the user has proper admin privileges
var result;
var hasAccess = false;
@@ -474,7 +520,7 @@ Meteor.methods({
return false;
}
var table = Instances.findOne({
- _id: id
+ _id: instanceid
});
if(email) {
if(email === table.admin) {
@@ -486,21 +532,21 @@ Meteor.methods({
if(hasAccess) {
//Removes all of the questions with the given table ID
Questions.remove({
- q: table.tablename
+ instanceid: instanceid
}, function(error) {
if(error) {
alert(error);
} else {
// If successful, removes all answers with the given tablename
Answers.remove({
- tablename: table.tablename
+ instanceid: instanceid
}, function(error) {
if(error) {
alert(error);
} else {
// If successful, remove the instance with the given tablename
Instances.remove({
- tablename: table.tablename
+ _id: instanceid
}, function(error) {
if(error) {
alert(error);
@@ -533,12 +579,6 @@ Meteor.methods({
return false;
}
var result;
- var existsInstance = Instances.findOne({
- tablename: name
- });
- if(existsInstance) {
- return 1;
- }
var originalInstance = Instances.findOne({
_id: id
});
@@ -561,41 +601,13 @@ Meteor.methods({
}, function(error, count, status) {
if(!error) {
Questions.update({
- tablename: originalName
+ instanceid: id
}, {
$set: {
tablename: name
}
}, {
multi: true
- }, function(error, count, status) {
- if(!error) {
- Answers.update({
- tablename: originalName
- }, {
- $set: {
- tablename: name
- }
- }, {
- multi: true
- }, function(error, count, status) {
- if(!error) {
- Votes.update({
- tablename: originalName
- }, {
- $set: {
- tablename: name
- }
- }, {
- multi: true
- }, function(error, count, status) {
- if(!error) {
- return 3;
- }
- });
- }
- });
- }
});
}
});
@@ -604,17 +616,17 @@ Meteor.methods({
}
},
// Method that registers a vote on a question
- vote: function(id, ip, tablename) {
+ vote: function(questionid, ip, instanceid) {
var keys = "";
// Ensures that the user hasn't already voted from their IP address
var votes = Votes.find({
- qid: id,
+ qid: questionid,
ip: ip
});
if(votes.fetch().length == 0) {
// If they haven't voted, increment the given quesiton's vote # by 1 and update the lasttouch
Questions.update({
- _id: id
+ _id: questionid
}, {
$set: {
lasttouch: new Date().getTime() - 1000
@@ -629,9 +641,9 @@ Meteor.methods({
} else {
// If successful, insert vote into the votes DB
Votes.insert({
- qid: id,
+ qid: questionid,
ip: ip,
- tablename: tablename,
+ instanceid: instanceid,
}, function(error, id) {
if(error) {
// If error, set keys to the error object
@@ -654,7 +666,7 @@ Meteor.methods({
_id: id
});
var table = Instances.findOne({
- tablename: question.tablename
+ _id: question.instanceid
});
if(email !== table.admin) {
if(table.moderators) {
diff --git a/server/publish.js b/server/publish.js
index 193c59ef..05c5514f 100644
--- a/server/publish.js
+++ b/server/publish.js
@@ -12,31 +12,25 @@ Meteor.publish('instances', function() {
});
// Only publishes to the user the questions that are associated with the selected table and are not disabled
-Meteor.publish('questions', function(table) {
+Meteor.publish('questions', function(instanceid) {
return Questions.find({
- tablename: {
- $regex: new RegExp("^" + table, "i")
- },
- state: {
- $ne : 'disabled'
- }
+ instanceid: instanceid,
+ //state: {
+ // $ne : 'disabled'
+ //}
});
});
// Only publishes to the user the answers that are associated with the selected table
-Meteor.publish('answers', function(table) {
+Meteor.publish('answers', function(instanceid) {
return Answers.find({
- tablename: {
- $regex: new RegExp("^" + table, "i")
- }
+ instanceid: instanceid
});
});
// Only publishes to the user the votes that are associated with the selected table
-Meteor.publish('votes', function(table) {
+Meteor.publish('votes', function(instanceid) {
return Votes.find({
- tablename: {
- $regex: new RegExp("^" + table, "i")
- }
+ instanceid: instanceid
});
});
\ No newline at end of file