2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('comment_form')].helpers({
|
2015-01-05 16:32:26 +09:00
|
|
|
reason: function () {
|
|
|
|
return !!Meteor.user() ? i18n.t('sorry_you_do_not_have_the_rights_to_comments'): i18n.t('please_log_in_to_comment');
|
2014-06-27 19:42:33 +09:00
|
|
|
}
|
2014-09-16 15:18:27 -04:00
|
|
|
});
|
2014-06-27 19:42:33 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('comment_form')].events({
|
2013-04-26 17:28:09 +09:00
|
|
|
'submit form': function(e, instance){
|
2014-12-24 10:13:48 +09:00
|
|
|
|
2012-09-25 09:20:49 +09:00
|
|
|
e.preventDefault();
|
2012-10-01 18:48:46 +09:00
|
|
|
$(e.target).addClass('disabled');
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.clearSeen();
|
2014-12-24 10:13:48 +09:00
|
|
|
|
|
|
|
var comment = {};
|
|
|
|
var $commentForm = instance.$('#comment');
|
2014-12-27 18:34:01 +09:00
|
|
|
var $submitButton = instance.$('.btn-submit');
|
2014-12-24 10:13:48 +09:00
|
|
|
var body = $commentForm.val();
|
|
|
|
|
2014-12-28 11:45:35 +09:00
|
|
|
// now that the form is latency compensated, we don't actually need to show this
|
|
|
|
// $commentForm.prop('disabled', true);
|
|
|
|
// $submitButton.addClass('loading');
|
|
|
|
|
2015-01-20 12:35:09 +09:00
|
|
|
// context can be either post, or comment property
|
|
|
|
var postId = !!this._id ? this._id: this.comment.postId;
|
|
|
|
var post = Posts.findOne(postId);
|
2014-12-27 18:34:01 +09:00
|
|
|
|
2014-12-28 12:13:13 +09:00
|
|
|
comment = {
|
|
|
|
postId: post._id,
|
|
|
|
body: body
|
|
|
|
}
|
2015-01-07 08:22:46 +01:00
|
|
|
|
2014-12-28 12:13:13 +09:00
|
|
|
// child comment
|
|
|
|
if (getCurrentTemplate() == 'comment_reply') {
|
|
|
|
comment.parentCommentId = this.comment._id;
|
|
|
|
}
|
2012-10-04 14:54:26 +09:00
|
|
|
|
2014-12-28 12:13:13 +09:00
|
|
|
Meteor.call('submitComment', comment, function(error, newComment){
|
|
|
|
// $commentForm.prop('disabled', false);
|
|
|
|
// $submitButton.removeClass('loading');
|
|
|
|
if(error){
|
|
|
|
console.log(error);
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(error.reason, "error");
|
2014-12-28 12:13:13 +09:00
|
|
|
}else{
|
|
|
|
trackEvent("newComment", newComment);
|
2015-03-26 12:05:25 +09:00
|
|
|
$commentForm.val('');
|
2014-12-24 10:13:48 +09:00
|
|
|
}
|
2014-12-28 12:13:13 +09:00
|
|
|
});
|
2015-01-07 08:22:46 +01:00
|
|
|
|
2012-09-25 09:20:49 +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
|
|
|
});
|