Merge branch 'MrRenter-commentEditTwoEleven'
This commit is contained in:
5
app.js
Normal file → Executable file
5
app.js
Normal file → Executable file
@ -470,6 +470,11 @@ app.post(
|
|||||||
storyController.commentOnCommentSubmit
|
storyController.commentOnCommentSubmit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.put(
|
||||||
|
'/stories/comment/:id/edit',
|
||||||
|
storyController.commentEdit
|
||||||
|
);
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
'/stories/submit',
|
'/stories/submit',
|
||||||
storyController.submitNew
|
storyController.submitNew
|
||||||
|
37
controllers/story.js
Normal file → Executable file
37
controllers/story.js
Normal file → Executable file
@ -441,6 +441,43 @@ exports.commentOnCommentSubmit = function(req, res, next) {
|
|||||||
commentSave(comment, Comment, res, next);
|
commentSave(comment, Comment, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.commentEdit = function(req, res, next) {
|
||||||
|
|
||||||
|
Comment.find({'_id': req.params.id}, function(err, cmt) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
cmt = cmt.pop();
|
||||||
|
|
||||||
|
if (!req.user && cmt.author.userId !== req.user._id) {
|
||||||
|
return next(new Error('Not authorized'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var sanitizedBody = sanitizeHtml(req.body.body, {
|
||||||
|
allowedTags: [],
|
||||||
|
allowedAttributes: []
|
||||||
|
}).replace(/"/g, '"');
|
||||||
|
if (req.body.body !== sanitizedBody) {
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: 'HTML is not allowed'
|
||||||
|
});
|
||||||
|
return res.send(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmt.body = sanitizedBody;
|
||||||
|
cmt.commentOn = Date.now();
|
||||||
|
cmt.save(function (err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
res.send(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
function commentSave(comment, Context, res, next) {
|
function commentSave(comment, Context, res, next) {
|
||||||
comment.save(function(err, data) {
|
comment.save(function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -298,7 +298,6 @@ $(document).ready(function() {
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
associatedPost: storyId,
|
associatedPost: storyId,
|
||||||
originalStoryLink: originalStoryLink,
|
|
||||||
body: data
|
body: data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -314,7 +313,7 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var profileValidation = angular.module('profileValidation',
|
var profileValidation = angular.module('profileValidation',
|
||||||
['ui.bootstrap', 'ngLodash']);
|
['ui.bootstrap']);
|
||||||
profileValidation.controller('profileValidationController', ['$scope', '$http',
|
profileValidation.controller('profileValidationController', ['$scope', '$http',
|
||||||
function($scope, $http) {
|
function($scope, $http) {
|
||||||
$http.get('/account/api').success(function(data) {
|
$http.get('/account/api').success(function(data) {
|
||||||
@ -393,12 +392,12 @@ profileValidation.directive('uniqueUsername', ['$http', function($http) {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
profileValidation.directive('existingUsername',
|
profileValidation.directive('existingUsername',
|
||||||
['$http', 'lodash', function($http, lodash) {
|
['$http', function($http) {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function (scope, element, attrs, ngModel) {
|
link: function (scope, element, attrs, ngModel) {
|
||||||
element.bind("keyup", function (event) {
|
element.bind('keyup', function (event) {
|
||||||
if (element.val().length > 0) {
|
if (element.val().length > 0) {
|
||||||
ngModel.$setValidity('exists', false);
|
ngModel.$setValidity('exists', false);
|
||||||
} else {
|
} else {
|
||||||
@ -406,14 +405,11 @@ profileValidation.directive('existingUsername',
|
|||||||
ngModel.$setPristine();
|
ngModel.$setPristine();
|
||||||
}
|
}
|
||||||
if (element.val()) {
|
if (element.val()) {
|
||||||
var debo = lodash.debounce(function() {
|
$http
|
||||||
$http
|
.get('/api/checkExistingUsername/' + element.val())
|
||||||
.get('/api/checkExistingUsername/' + element.val())
|
.success(function (data) {
|
||||||
.success(function (data) {
|
ngModel.$setValidity('exists', data);
|
||||||
ngModel.$setValidity('exists', data);
|
});
|
||||||
});
|
|
||||||
}, 2000);
|
|
||||||
debo();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
44
views/stories/comments.jade
Normal file → Executable file
44
views/stories/comments.jade
Normal file → Executable file
@ -21,7 +21,13 @@
|
|||||||
success: function (data, textStatus, xhr) {
|
success: function (data, textStatus, xhr) {
|
||||||
commentDetails = data;
|
commentDetails = data;
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
|
var editButton = "";
|
||||||
|
// todo
|
||||||
|
if (commentDetails.author.username === DF105CFA89562196E702912B3818C6A5B46E80D262442FDF29976621E5AF0D23) {
|
||||||
|
if ((Date.now() - commentDetails.commentOn) < 600000){
|
||||||
|
editButton = "<a class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost edit-btn' id='" + commentDetails._id + "'>Edit</a> · ";
|
||||||
|
}
|
||||||
|
}
|
||||||
$(div)
|
$(div)
|
||||||
.html(
|
.html(
|
||||||
'<div class="media media-news">' +
|
'<div class="media media-news">' +
|
||||||
@ -36,6 +42,7 @@
|
|||||||
'<h6>' +
|
'<h6>' +
|
||||||
'<div class="clearfix comment-a-comment negative-15">' +
|
'<div class="clearfix comment-a-comment negative-15">' +
|
||||||
"<a class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost' id='" + commentDetails._id + "'>Reply</a> · " +
|
"<a class='btn btn-no-shadow btn-primary btn-xs btn-primary-ghost' id='" + commentDetails._id + "'>Reply</a> · " +
|
||||||
|
editButton +
|
||||||
"commented " + moment(commentDetails.commentOn).fromNow() + " by " +
|
"commented " + moment(commentDetails.commentOn).fromNow() + " by " +
|
||||||
"<a href='/" + commentDetails.author.username + "'>@" + commentDetails.author.username + "</a>" +
|
"<a href='/" + commentDetails.author.username + "'>@" + commentDetails.author.username + "</a>" +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
@ -55,10 +62,13 @@
|
|||||||
complete: function () {
|
complete: function () {
|
||||||
sentinel--;
|
sentinel--;
|
||||||
if (!sentinel) {
|
if (!sentinel) {
|
||||||
$('.comment-a-comment').on('click', 'a', function () {
|
$('.comment-a-comment').on('click', 'a', function() {
|
||||||
|
var editOrComment = 'comment';
|
||||||
|
if ($(this).hasClass("edit-btn")){
|
||||||
|
editOrComment = 'edit';
|
||||||
|
}
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
console.log('not logged in');
|
window.location.href = '/signin';
|
||||||
//window.location.href = '/signin';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$(this).unbind('click');
|
$(this).unbind('click');
|
||||||
@ -72,7 +82,7 @@
|
|||||||
"<div class='input-group'>" +
|
"<div class='input-group'>" +
|
||||||
"<input class='form-control big-text-field field-responsive' id='comment-to-comment-textinput' type='text' maxlength='140' autofocus />" +
|
"<input class='form-control big-text-field field-responsive' id='comment-to-comment-textinput' type='text' maxlength='140' autofocus />" +
|
||||||
"<span class='input-group-btn'>" +
|
"<span class='input-group-btn'>" +
|
||||||
"<button id='submit-comment-to-comment' class='btn btn-big btn-primary btn-responsive'>Send</button>" +
|
"<button id='submit-comment-to-" + editOrComment + "' class='btn btn-big btn-primary btn-responsive'>Send</button>" +
|
||||||
"</span>" +
|
"</span>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
@ -109,9 +119,31 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
// todo
|
||||||
|
var submitCommentForEditToCommentHandler = function submitCommentForEditToCommentHandler() {
|
||||||
|
$('#submit-comment-to-edit').unbind('click');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "PUT",
|
||||||
|
url: '/stories/comment/' + commentId + '/edit',
|
||||||
|
data: {
|
||||||
|
associatedPost: commentId,
|
||||||
|
originalStoryLink: originalStoryLink,
|
||||||
|
body: $('#comment-to-comment-textinput').val()
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
success: function (msg) {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
error: function (err){
|
||||||
|
$('#submit-comment-to-edit').bind('click', submitCommentForEditToCommentHandler);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$('#submit-comment-to-edit').on('click', submitCommentForEditToCommentHandler)
|
||||||
$('#submit-comment-to-comment').on('click', submitCommentToCommentHandler);
|
$('#submit-comment-to-comment').on('click', submitCommentToCommentHandler);
|
||||||
});//
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,8 @@ block content
|
|||||||
if (user)
|
if (user)
|
||||||
script.
|
script.
|
||||||
var isLoggedIn = true;
|
var isLoggedIn = true;
|
||||||
var B3BA669EC5C1DD70FB478221E067A7E1B686929C569F5E73561B69C8F42129B = !{JSON.stringify(user._id)}
|
var B3BA669EC5C1DD70FB478221E067A7E1B686929C569F5E73561B69C8F42129B = !{JSON.stringify(user._id)};
|
||||||
|
var DF105CFA89562196E702912B3818C6A5B46E80D262442FDF29976621E5AF0D23 = !{JSON.stringify(user.profile.username)};
|
||||||
else
|
else
|
||||||
script.
|
script.
|
||||||
var isLoggedIn = false;
|
var isLoggedIn = false;
|
||||||
|
Reference in New Issue
Block a user