2015-04-11 14:35:51 +09:00
|
|
|
var editComment = function(instance) {
|
|
|
|
var comment = instance.data.comment;
|
|
|
|
var content = instance.$('#body').val();
|
2013-10-09 12:39:05 +09:00
|
|
|
|
|
|
|
|
2015-04-11 14:35:51 +09:00
|
|
|
if(!Meteor.user())
|
|
|
|
throw i18n.t('you_must_be_logged_in');
|
|
|
|
|
|
|
|
Comments.update(comment._id, {
|
|
|
|
$set: {
|
|
|
|
body: content
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
trackEvent("edit comment", {'postId': comment.postId, 'commentId': comment._id});
|
|
|
|
Router.go('post_page_comment', {_id: comment.postId, commentId: comment._id});
|
|
|
|
};
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2015-04-11 14:35:51 +09:00
|
|
|
Template[getTemplate('comment_edit')].onRendered(function() {
|
|
|
|
var self = this;
|
2015-04-12 21:19:30 +09:00
|
|
|
this.$("#comment").keydown(function (e) {
|
|
|
|
if(((e.metaKey || e.ctrlKey) && e.keyCode == 13) || (e.ctrlKey && e.keyCode == 13)){
|
|
|
|
editComment(self);
|
|
|
|
}
|
2015-04-11 14:35:51 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Template[getTemplate('comment_edit')].events({
|
|
|
|
'click input[type=submit]': function(e, instance){
|
|
|
|
e.preventDefault();
|
|
|
|
editComment(instance);
|
2013-10-09 12:39:05 +09:00
|
|
|
},
|
|
|
|
'click .delete-link': function(e){
|
|
|
|
var comment = this;
|
|
|
|
|
|
|
|
e.preventDefault();
|
2014-12-03 00:06:00 -08:00
|
|
|
|
2014-11-19 00:00:09 +08:00
|
|
|
if(confirm(i18n.t("are_you_sure"))){
|
2013-10-09 12:39:05 +09:00
|
|
|
Meteor.call('removeComment', comment._id);
|
2014-12-03 00:06:00 -08:00
|
|
|
Router.go('post_page', {_id: comment.postId});
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash("Your comment has been deleted.", "success");
|
2013-10-09 12:39:05 +09:00
|
|
|
}
|
|
|
|
}
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
});
|