2015-04-28 15:54:19 +09:00
|
|
|
Template.comment_edit.helpers({
|
2015-09-08 11:08:02 +09:00
|
|
|
canEdit: function () {
|
|
|
|
var comment = this;
|
|
|
|
return Users.can.edit(Meteor.user(), comment);
|
|
|
|
},
|
2015-04-28 15:54:19 +09:00
|
|
|
commentFields: function () {
|
2015-04-28 17:15:53 +09:00
|
|
|
return Comments.simpleSchema().getEditableFields(Meteor.user());
|
2015-04-28 15:54:19 +09:00
|
|
|
}
|
|
|
|
});
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
AutoForm.hooks({
|
|
|
|
editCommentForm: {
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
before: {
|
2015-05-04 10:19:50 +09:00
|
|
|
"method-update": function() {
|
|
|
|
|
|
|
|
var comment = this.currentDoc;
|
|
|
|
var modifier = this.updateDoc;
|
2015-04-11 14:35:51 +09:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
// ------------------------------ Checks ------------------------------ //
|
2015-04-11 14:35:51 +09:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
if (!Meteor.user()) {
|
|
|
|
Messages.flash(i18n.t('you_must_be_logged_in'), "");
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
|
|
|
|
|
|
|
// run all post edit client callbacks on modifier object successively
|
2015-05-04 12:32:00 +09:00
|
|
|
modifier = Telescope.callbacks.run("commentEditClient", modifier, comment);
|
|
|
|
return modifier;
|
2015-04-28 15:54:19 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-04 12:32:00 +09:00
|
|
|
onSuccess: function(formType, comment) {
|
2015-07-01 15:28:08 +09:00
|
|
|
// TODO: find out why comment is undefined here
|
2015-05-04 12:32:00 +09:00
|
|
|
comment = this.currentDoc;
|
2015-04-28 15:54:19 +09:00
|
|
|
Events.track("edit comment", {'commentId': comment._id});
|
2015-09-18 16:27:59 +09:00
|
|
|
FlowRouter.go("postPage", {_id: comment.postId});
|
2015-04-28 15:54:19 +09:00
|
|
|
},
|
|
|
|
|
2015-05-04 12:32:00 +09:00
|
|
|
onError: function(formType, error) {
|
2015-05-04 10:19:50 +09:00
|
|
|
console.log(error);
|
2015-04-28 15:54:19 +09:00
|
|
|
Messages.flash(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
|
|
|
|
Messages.clearSeen();
|
2015-04-12 21:19:30 +09:00
|
|
|
}
|
2015-04-28 15:54:19 +09:00
|
|
|
|
|
|
|
}
|
2015-04-11 14:35:51 +09:00
|
|
|
});
|
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
// delete link
|
2015-04-13 18:14:12 +09:00
|
|
|
Template.comment_edit.events({
|
2013-10-09 12:39:05 +09:00
|
|
|
'click .delete-link': function(e){
|
2015-04-28 15:54:19 +09:00
|
|
|
var comment = this.comment;
|
2013-10-09 12:39:05 +09:00
|
|
|
|
|
|
|
e.preventDefault();
|
2014-12-03 00:06:00 -08:00
|
|
|
|
2015-04-28 15:54:19 +09:00
|
|
|
if(confirm("Are you sure?")){
|
2015-09-18 16:27:59 +09:00
|
|
|
FlowRouter.go("postsDefault");
|
2015-04-28 15:54:19 +09:00
|
|
|
Meteor.call("deleteCommentById", comment._id, function(error) {
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
Messages.flash(error.reason, 'error');
|
|
|
|
} else {
|
|
|
|
Messages.flash(i18n.t('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
|
|
|
});
|
2015-04-28 15:54:19 +09:00
|
|
|
|
|
|
|
Template.comment_edit.onRendered(function() {
|
|
|
|
var self = this;
|
2015-05-14 11:21:44 +09:00
|
|
|
this.$("textarea").keydown(function (e) {
|
2015-04-28 15:54:19 +09:00
|
|
|
if(((e.metaKey || e.ctrlKey) && e.keyCode == 13) || (e.ctrlKey && e.keyCode == 13)){
|
2015-05-14 11:21:44 +09:00
|
|
|
self.$('#editCommentForm').submit();
|
2015-04-28 15:54:19 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|