2016-01-27 20:28:55 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016
|
|
|
|
|
*
|
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
|
* or later.
|
|
|
|
|
*
|
|
|
|
|
* See the COPYING-README file.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-17 17:19:42 +03:00
|
|
|
|
/* global Handlebars, escapeHTML */
|
2016-02-03 20:44:14 +03:00
|
|
|
|
|
2016-02-01 18:37:33 +03:00
|
|
|
|
(function(OC, OCA) {
|
2016-01-27 20:28:55 +03:00
|
|
|
|
var TEMPLATE =
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'<ul class="comments">' +
|
|
|
|
|
'</ul>' +
|
2016-08-03 14:18:09 +03:00
|
|
|
|
'<div class="emptycontent hidden"><div class="icon-comment"></div>' +
|
|
|
|
|
'<p>{{emptyResultLabel}}</p></div>' +
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'<input type="button" class="showMore hidden" value="{{moreLabel}}"' +
|
|
|
|
|
' name="show-more" id="show-more" />' +
|
|
|
|
|
'<div class="loading hidden" style="height: 50px"></div>';
|
|
|
|
|
|
|
|
|
|
var EDIT_COMMENT_TEMPLATE =
|
2018-01-18 22:19:59 +03:00
|
|
|
|
'<{{tag}} class="newCommentRow comment" data-id="{{id}}">' +
|
2016-02-01 18:37:33 +03:00
|
|
|
|
' <div class="authorRow">' +
|
2017-11-23 06:53:50 +03:00
|
|
|
|
' <div class="avatar currentUser" data-username="{{actorId}}"></div>' +
|
|
|
|
|
' <div class="author currentUser">{{actorDisplayName}}</div>' +
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'{{#if isEditMode}}' +
|
2018-01-18 23:40:26 +03:00
|
|
|
|
' <div class="action-container">' +
|
|
|
|
|
' <a href="#" class="action cancel icon icon-close has-tooltip" title="{{cancelText}}"></a>' +
|
|
|
|
|
' </div>' +
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'{{/if}}' +
|
2016-02-01 18:37:33 +03:00
|
|
|
|
' </div>' +
|
|
|
|
|
' <form class="newCommentForm">' +
|
2017-10-18 00:24:01 +03:00
|
|
|
|
' <div contentEditable="true" class="message" data-placeholder="{{newMessagePlaceholder}}">{{message}}</div>' +
|
2018-03-04 09:06:33 +03:00
|
|
|
|
' <input class="submit icon-confirm has-tooltip" type="submit" value="" title="{{submitText}}"/>' +
|
2016-02-02 14:06:12 +03:00
|
|
|
|
' <div class="submitLoading icon-loading-small hidden"></div>'+
|
2016-02-01 18:37:33 +03:00
|
|
|
|
' </form>' +
|
2018-01-18 22:19:59 +03:00
|
|
|
|
'</{{tag}}>';
|
2016-01-27 20:28:55 +03:00
|
|
|
|
|
|
|
|
|
var COMMENT_TEMPLATE =
|
2016-02-04 20:20:16 +03:00
|
|
|
|
'<li class="comment{{#if isUnread}} unread{{/if}}{{#if isLong}} collapsed{{/if}}" data-id="{{id}}">' +
|
2016-02-01 18:37:33 +03:00
|
|
|
|
' <div class="authorRow">' +
|
2017-11-23 06:53:50 +03:00
|
|
|
|
' <div class="avatar{{#if isUserAuthor}} currentUser{{/if}}" {{#if actorId}}data-username="{{actorId}}"{{/if}}> </div>' +
|
|
|
|
|
' <div class="author{{#if isUserAuthor}} currentUser{{/if}}">{{actorDisplayName}}</div>' +
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'{{#if isUserAuthor}}' +
|
2018-02-03 22:45:53 +03:00
|
|
|
|
' <a href="#" class="action more icon icon-more has-tooltip"></a>' +
|
|
|
|
|
' <div class="deleteLoading icon-loading-small hidden"></div>' +
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'{{/if}}' +
|
2016-08-31 18:46:50 +03:00
|
|
|
|
' <div class="date has-tooltip live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</div>' +
|
2016-02-01 18:37:33 +03:00
|
|
|
|
' </div>' +
|
2016-02-01 18:54:27 +03:00
|
|
|
|
' <div class="message">{{{formattedMessage}}}</div>' +
|
2016-02-04 20:20:16 +03:00
|
|
|
|
'{{#if isLong}}' +
|
|
|
|
|
' <div class="message-overlay"></div>' +
|
|
|
|
|
'{{/if}}' +
|
2016-01-27 20:28:55 +03:00
|
|
|
|
'</li>';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @memberof OCA.Comments
|
|
|
|
|
*/
|
|
|
|
|
var CommentsTabView = OCA.Files.DetailTabView.extend(
|
|
|
|
|
/** @lends OCA.Comments.CommentsTabView.prototype */ {
|
|
|
|
|
id: 'commentsTabView',
|
|
|
|
|
className: 'tab commentsTabView',
|
2017-10-23 19:00:39 +03:00
|
|
|
|
_autoCompleteData: undefined,
|
2018-02-03 22:45:53 +03:00
|
|
|
|
_commentsModifyMenu: undefined,
|
2016-01-27 20:28:55 +03:00
|
|
|
|
|
|
|
|
|
events: {
|
2016-01-28 16:24:12 +03:00
|
|
|
|
'submit .newCommentForm': '_onSubmitComment',
|
2016-02-03 20:44:14 +03:00
|
|
|
|
'click .showMore': '_onClickShowMore',
|
2016-02-04 20:20:16 +03:00
|
|
|
|
'click .cancel': '_onClickCloseComment',
|
2017-10-18 00:24:01 +03:00
|
|
|
|
'click .comment': '_onClickComment',
|
|
|
|
|
'keyup div.message': '_onTextChange',
|
|
|
|
|
'change div.message': '_onTextChange',
|
|
|
|
|
'input div.message': '_onTextChange',
|
|
|
|
|
'paste div.message': '_onPaste'
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-02-05 17:45:30 +03:00
|
|
|
|
_commentMaxLength: 1000,
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
initialize: function() {
|
|
|
|
|
OCA.Files.DetailTabView.prototype.initialize.apply(this, arguments);
|
2016-02-02 17:13:45 +03:00
|
|
|
|
this.collection = new OCA.Comments.CommentCollection();
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.collection.on('request', this._onRequest, this);
|
|
|
|
|
this.collection.on('sync', this._onEndRequest, this);
|
|
|
|
|
this.collection.on('add', this._onAddModel, this);
|
2017-10-19 19:15:34 +03:00
|
|
|
|
this.collection.on('change:message', this._onChangeModel, this);
|
2016-02-01 18:37:33 +03:00
|
|
|
|
|
2016-02-05 17:45:30 +03:00
|
|
|
|
this._commentMaxThreshold = this._commentMaxLength * 0.9;
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
// TODO: error handling
|
2017-10-25 19:07:26 +03:00
|
|
|
|
_.bindAll(this, '_onTypeComment', '_initAutoComplete', '_onAutoComplete');
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
template: function(params) {
|
|
|
|
|
if (!this._template) {
|
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
|
}
|
2016-02-01 18:37:33 +03:00
|
|
|
|
var currentUser = OC.getCurrentUser();
|
2016-01-27 20:28:55 +03:00
|
|
|
|
return this._template(_.extend({
|
2016-02-03 20:44:14 +03:00
|
|
|
|
actorId: currentUser.uid,
|
|
|
|
|
actorDisplayName: currentUser.displayName
|
|
|
|
|
}, params));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
editCommentTemplate: function(params) {
|
|
|
|
|
if (!this._editCommentTemplate) {
|
|
|
|
|
this._editCommentTemplate = Handlebars.compile(EDIT_COMMENT_TEMPLATE);
|
|
|
|
|
}
|
|
|
|
|
var currentUser = OC.getCurrentUser();
|
|
|
|
|
return this._editCommentTemplate(_.extend({
|
2016-02-03 22:32:37 +03:00
|
|
|
|
actorId: currentUser.uid,
|
|
|
|
|
actorDisplayName: currentUser.displayName,
|
2016-08-03 14:18:09 +03:00
|
|
|
|
newMessagePlaceholder: t('comments', 'New comment …'),
|
2016-02-03 22:32:37 +03:00
|
|
|
|
submitText: t('comments', 'Post'),
|
2018-01-18 22:19:59 +03:00
|
|
|
|
cancelText: t('comments', 'Cancel'),
|
|
|
|
|
tag: 'li'
|
2016-01-27 20:28:55 +03:00
|
|
|
|
}, params));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
commentTemplate: function(params) {
|
|
|
|
|
if (!this._commentTemplate) {
|
|
|
|
|
this._commentTemplate = Handlebars.compile(COMMENT_TEMPLATE);
|
|
|
|
|
}
|
2016-02-04 13:26:11 +03:00
|
|
|
|
|
|
|
|
|
params = _.extend({
|
2016-02-03 20:44:14 +03:00
|
|
|
|
editTooltip: t('comments', 'Edit comment'),
|
2016-02-04 20:20:16 +03:00
|
|
|
|
isUserAuthor: OC.getCurrentUser().uid === params.actorId,
|
|
|
|
|
isLong: this._isLong(params.message)
|
2016-02-04 13:26:11 +03:00
|
|
|
|
}, params);
|
|
|
|
|
|
|
|
|
|
if (params.actorType === 'deleted_users') {
|
|
|
|
|
// makes the avatar a X
|
|
|
|
|
params.actorId = null;
|
|
|
|
|
params.actorDisplayName = t('comments', '[Deleted user]');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this._commentTemplate(params);
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getLabel: function() {
|
|
|
|
|
return t('comments', 'Comments');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setFileInfo: function(fileInfo) {
|
|
|
|
|
if (fileInfo) {
|
2016-02-03 18:18:14 +03:00
|
|
|
|
this.model = fileInfo;
|
2017-10-17 14:22:57 +03:00
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.render();
|
2017-10-23 19:00:39 +03:00
|
|
|
|
this._initAutoComplete($('#commentsTabView').find('.newCommentForm .message'));
|
|
|
|
|
this.collection.setObjectId(this.model.id);
|
2016-01-27 20:28:55 +03:00
|
|
|
|
// reset to first page
|
|
|
|
|
this.collection.reset([], {silent: true});
|
|
|
|
|
this.nextPage();
|
|
|
|
|
} else {
|
2016-02-03 18:18:14 +03:00
|
|
|
|
this.model = null;
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.render();
|
|
|
|
|
this.collection.reset();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
|
this.$el.html(this.template({
|
2016-08-03 14:18:09 +03:00
|
|
|
|
emptyResultLabel: t('comments', 'No comments yet, start the conversation!'),
|
|
|
|
|
moreLabel: t('comments', 'More comments …')
|
2016-01-27 20:28:55 +03:00
|
|
|
|
}));
|
2018-01-18 22:19:59 +03:00
|
|
|
|
this.$el.find('.comments').before(this.editCommentTemplate({ tag: 'div'}));
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.$el.find('.has-tooltip').tooltip();
|
|
|
|
|
this.$container = this.$el.find('ul.comments');
|
2017-02-14 02:49:05 +03:00
|
|
|
|
this.$el.find('.avatar').avatar(OC.getCurrentUser().uid, 32);
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.delegateEvents();
|
2016-08-03 14:18:09 +03:00
|
|
|
|
this.$el.find('.message').on('keydown input change', this._onTypeComment);
|
2016-09-14 15:20:26 +03:00
|
|
|
|
|
2017-10-18 00:24:01 +03:00
|
|
|
|
autosize(this.$el.find('.newCommentRow .message'))
|
2018-07-21 19:10:41 +03:00
|
|
|
|
this.$el.find('.newCommentForm .message').focus();
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-10-25 19:07:26 +03:00
|
|
|
|
_initAutoComplete: function($target) {
|
2017-10-23 19:00:39 +03:00
|
|
|
|
var s = this;
|
2017-11-01 13:27:04 +03:00
|
|
|
|
var limit = 10;
|
|
|
|
|
if(!_.isUndefined(OC.appConfig.comments)) {
|
|
|
|
|
limit = OC.appConfig.comments.maxAutoCompleteResults;
|
|
|
|
|
}
|
2017-10-23 19:00:39 +03:00
|
|
|
|
$target.atwho({
|
|
|
|
|
at: '@',
|
2017-11-01 13:27:04 +03:00
|
|
|
|
limit: limit,
|
2017-10-25 19:07:26 +03:00
|
|
|
|
callbacks: {
|
2017-10-27 01:23:23 +03:00
|
|
|
|
remoteFilter: s._onAutoComplete,
|
|
|
|
|
highlighter: function (li) {
|
|
|
|
|
// misuse the highlighter callback to instead of
|
|
|
|
|
// highlighting loads the avatars.
|
|
|
|
|
var $li = $(li);
|
|
|
|
|
$li.find('.avatar').avatar(undefined, 32);
|
|
|
|
|
return $li;
|
2017-10-31 15:55:03 +03:00
|
|
|
|
},
|
|
|
|
|
sorter: function (q, items) { return items; }
|
2017-10-25 19:07:26 +03:00
|
|
|
|
},
|
2017-10-27 01:23:23 +03:00
|
|
|
|
displayTpl: '<li>'
|
|
|
|
|
+ '<span class="avatar-name-wrapper">'
|
|
|
|
|
+ '<div class="avatar" '
|
|
|
|
|
+ 'data-username="${id}"' // for avatars
|
|
|
|
|
+ ' data-user="${id}"' // for contactsmenu
|
|
|
|
|
+ ' data-user-display-name="${label}"></div>'
|
|
|
|
|
+ ' <strong>${label}</strong>'
|
|
|
|
|
+ '</span></li>',
|
2017-10-23 19:00:39 +03:00
|
|
|
|
insertTpl: ''
|
|
|
|
|
+ '<span class="avatar-name-wrapper">'
|
|
|
|
|
+ '<div class="avatar" '
|
|
|
|
|
+ 'data-username="${id}"' // for avatars
|
|
|
|
|
+ ' data-user="${id}"' // for contactsmenu
|
|
|
|
|
+ ' data-user-display-name="${label}"></div>'
|
|
|
|
|
+ ' <strong>${label}</strong>'
|
|
|
|
|
+ '</span>',
|
|
|
|
|
searchKey: "label"
|
|
|
|
|
});
|
|
|
|
|
$target.on('inserted.atwho', function (je, $el) {
|
2017-11-27 01:45:35 +03:00
|
|
|
|
var editionMode = true;
|
2017-10-23 19:00:39 +03:00
|
|
|
|
s._postRenderItem(
|
|
|
|
|
// we need to pass the parent of the inserted element
|
|
|
|
|
// passing the whole comments form would re-apply and request
|
|
|
|
|
// avatars from the server
|
|
|
|
|
$(je.target).find(
|
2017-10-31 16:42:21 +03:00
|
|
|
|
'div[data-username="' + $el.find('[data-username]').data('username') + '"]'
|
2017-11-27 01:45:35 +03:00
|
|
|
|
).parent(),
|
|
|
|
|
editionMode
|
2017-10-23 19:00:39 +03:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2017-10-25 19:07:26 +03:00
|
|
|
|
_onAutoComplete: function(query, callback) {
|
|
|
|
|
if(_.isEmpty(query)) {
|
2017-10-23 19:00:39 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var s = this;
|
2017-10-25 19:07:26 +03:00
|
|
|
|
if(!_.isUndefined(this._autoCompleteRequestTimer)) {
|
|
|
|
|
clearTimeout(this._autoCompleteRequestTimer);
|
|
|
|
|
}
|
|
|
|
|
this._autoCompleteRequestTimer = _.delay(function() {
|
|
|
|
|
if(!_.isUndefined(this._autoCompleteRequestCall)) {
|
|
|
|
|
this._autoCompleteRequestCall.abort();
|
|
|
|
|
}
|
2018-03-21 11:46:52 +03:00
|
|
|
|
this._autoCompleteRequestCall = $.ajax({
|
|
|
|
|
url: OC.linkToOCS('core', 2) + 'autocomplete/get',
|
|
|
|
|
data: {
|
2017-10-25 19:07:26 +03:00
|
|
|
|
search: query,
|
2017-10-23 19:00:39 +03:00
|
|
|
|
itemType: 'files',
|
|
|
|
|
itemId: s.model.get('id'),
|
2017-10-30 17:10:21 +03:00
|
|
|
|
sorter: 'commenters|share-recipients',
|
2017-10-27 14:50:38 +03:00
|
|
|
|
limit: OC.appConfig.comments.maxAutoCompleteResults
|
2017-10-23 19:00:39 +03:00
|
|
|
|
},
|
2018-03-21 11:46:52 +03:00
|
|
|
|
beforeSend: function (request) {
|
|
|
|
|
request.setRequestHeader('Accept', 'application/json');
|
|
|
|
|
},
|
|
|
|
|
success: function (result) {
|
|
|
|
|
callback(result.ocs.data);
|
2017-10-23 19:00:39 +03:00
|
|
|
|
}
|
2018-03-21 11:46:52 +03:00
|
|
|
|
});
|
2017-10-27 01:23:23 +03:00
|
|
|
|
}, 400);
|
2017-10-23 19:00:39 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
_formatItem: function(commentModel) {
|
2016-01-28 13:47:23 +03:00
|
|
|
|
var timestamp = new Date(commentModel.get('creationDateTime')).getTime();
|
|
|
|
|
var data = _.extend({
|
2016-08-31 18:46:50 +03:00
|
|
|
|
timestamp: timestamp,
|
2016-01-28 13:47:23 +03:00
|
|
|
|
date: OC.Util.relativeModifiedDate(timestamp),
|
2016-02-01 18:54:27 +03:00
|
|
|
|
altDate: OC.Util.formatDate(timestamp),
|
2016-10-17 15:06:23 +03:00
|
|
|
|
formattedMessage: this._formatMessage(commentModel.get('message'), commentModel.get('mentions'))
|
2016-01-28 13:47:23 +03:00
|
|
|
|
}, commentModel.attributes);
|
|
|
|
|
return data;
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_toggleLoading: function(state) {
|
|
|
|
|
this._loading = state;
|
|
|
|
|
this.$el.find('.loading').toggleClass('hidden', !state);
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 22:32:37 +03:00
|
|
|
|
_onRequest: function(type) {
|
|
|
|
|
if (type === 'REPORT') {
|
|
|
|
|
this._toggleLoading(true);
|
|
|
|
|
this.$el.find('.showMore').addClass('hidden');
|
|
|
|
|
}
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 18:18:14 +03:00
|
|
|
|
_onEndRequest: function(type) {
|
|
|
|
|
var fileInfoModel = this.model;
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this._toggleLoading(false);
|
2016-08-03 14:18:09 +03:00
|
|
|
|
this.$el.find('.emptycontent').toggleClass('hidden', !!this.collection.length);
|
2016-01-27 20:28:55 +03:00
|
|
|
|
this.$el.find('.showMore').toggleClass('hidden', !this.collection.hasMoreResults());
|
2016-02-03 18:18:14 +03:00
|
|
|
|
|
|
|
|
|
if (type !== 'REPORT') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find first unread comment
|
|
|
|
|
var firstUnreadComment = this.collection.findWhere({isUnread: true});
|
|
|
|
|
if (firstUnreadComment) {
|
|
|
|
|
// update read marker
|
|
|
|
|
this.collection.updateReadMarker(
|
|
|
|
|
null,
|
|
|
|
|
{
|
|
|
|
|
success: function() {
|
|
|
|
|
fileInfoModel.set('commentsUnread', 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-07-21 19:10:41 +03:00
|
|
|
|
this.$el.find('.newCommentForm .message').focus();
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* takes care of post-rendering after a new comment was added to the
|
|
|
|
|
* collection
|
|
|
|
|
*
|
|
|
|
|
* @param model
|
|
|
|
|
* @param collection
|
|
|
|
|
* @param options
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2016-01-27 20:28:55 +03:00
|
|
|
|
_onAddModel: function(model, collection, options) {
|
2017-10-23 16:37:36 +03:00
|
|
|
|
// we need to render it immediately, to ensure that the right
|
|
|
|
|
// order of comments is kept on opening comments tab
|
|
|
|
|
var $comment = $(this.commentTemplate(this._formatItem(model)));
|
|
|
|
|
if (!_.isUndefined(options.at) && collection.length > 1) {
|
|
|
|
|
this.$container.find('li').eq(options.at).before($comment);
|
|
|
|
|
} else {
|
|
|
|
|
this.$container.append($comment);
|
|
|
|
|
}
|
|
|
|
|
this._postRenderItem($comment);
|
2017-11-23 16:34:09 +03:00
|
|
|
|
$('#commentsTabView').find('.newCommentForm div.message').text('').prop('contenteditable', true);
|
2017-10-23 16:37:36 +03:00
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
// we need to update the model, because it consists of client data
|
|
|
|
|
// only, but the server might add meta data, e.g. about mentions
|
2017-10-23 16:37:36 +03:00
|
|
|
|
var oldMentions = model.get('mentions');
|
|
|
|
|
var self = this;
|
2017-10-19 19:15:34 +03:00
|
|
|
|
model.fetch({
|
|
|
|
|
success: function (model) {
|
2017-10-23 16:37:36 +03:00
|
|
|
|
if(_.isEqual(oldMentions, model.get('mentions'))) {
|
|
|
|
|
// don't attempt to render if unnecessary, avoids flickering
|
|
|
|
|
return;
|
2017-10-19 19:15:34 +03:00
|
|
|
|
}
|
2017-10-23 16:37:36 +03:00
|
|
|
|
var $updated = $(self.commentTemplate(self._formatItem(model)));
|
|
|
|
|
$comment.html($updated.html());
|
|
|
|
|
self._postRenderItem($comment);
|
2017-10-19 19:15:34 +03:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* takes care of post-rendering after a new comment was edited
|
|
|
|
|
*
|
|
|
|
|
* @param model
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2017-10-23 19:00:39 +03:00
|
|
|
|
_onChangeModel: function (model) {
|
2017-10-19 19:15:34 +03:00
|
|
|
|
if(model.get('message').trim() === model.previous('message').trim()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 13:27:04 +03:00
|
|
|
|
var $form = this.$container.find('.comment[data-id="' + model.id + '"] form');
|
2017-10-19 19:15:34 +03:00
|
|
|
|
var $row = $form.closest('.comment');
|
|
|
|
|
var $target = $row.data('commentEl');
|
|
|
|
|
if(_.isUndefined($target)) {
|
|
|
|
|
// ignore noise – this is only set after editing a comment and hitting post
|
|
|
|
|
return;
|
2016-01-27 20:28:55 +03:00
|
|
|
|
}
|
2017-10-19 19:15:34 +03:00
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
// we need to update the model, because it consists of client data
|
|
|
|
|
// only, but the server might add meta data, e.g. about mentions
|
|
|
|
|
model.fetch({
|
|
|
|
|
success: function (model) {
|
|
|
|
|
$target.removeClass('hidden');
|
|
|
|
|
$row.remove();
|
|
|
|
|
|
|
|
|
|
var $message = $target.find('.message');
|
|
|
|
|
$message
|
|
|
|
|
.html(self._formatMessage(model.get('message'), model.get('mentions')))
|
|
|
|
|
.find('.avatar')
|
|
|
|
|
.each(function () { $(this).avatar(); });
|
|
|
|
|
self._postRenderItem($message);
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-02-01 18:37:33 +03:00
|
|
|
|
},
|
2017-10-19 19:15:34 +03:00
|
|
|
|
|
2017-11-27 01:45:35 +03:00
|
|
|
|
_postRenderItem: function($el, editionMode) {
|
2016-01-28 13:47:23 +03:00
|
|
|
|
$el.find('.has-tooltip').tooltip();
|
2018-07-25 15:26:04 +03:00
|
|
|
|
var inlineAvatars = $el.find('.message .avatar');
|
|
|
|
|
if ($($el.context).hasClass('message')) {
|
|
|
|
|
inlineAvatars = $el.find('.avatar');
|
|
|
|
|
}
|
|
|
|
|
inlineAvatars.each(function () {
|
2018-07-18 21:28:02 +03:00
|
|
|
|
var $this = $(this);
|
|
|
|
|
$this.avatar($this.attr('data-username'), 16);
|
|
|
|
|
});
|
|
|
|
|
$el.find('.authorRow .avatar').each(function () {
|
2017-02-14 02:49:05 +03:00
|
|
|
|
var $this = $(this);
|
|
|
|
|
$this.avatar($this.attr('data-username'), 32);
|
|
|
|
|
});
|
2017-04-24 20:52:45 +03:00
|
|
|
|
|
|
|
|
|
var username = $el.find('.avatar').data('username');
|
|
|
|
|
if (username !== oc_current_user) {
|
|
|
|
|
$el.find('.authorRow .avatar, .authorRow .author').contactsMenu(
|
|
|
|
|
username, 0, $el.find('.authorRow'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 23:00:00 +03:00
|
|
|
|
var $message = $el.find('.message');
|
2017-10-18 16:17:22 +03:00
|
|
|
|
if($message.length === 0) {
|
|
|
|
|
// it is the case when writing a comment and mentioning a person
|
|
|
|
|
$message = $el;
|
|
|
|
|
}
|
2018-02-03 22:45:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!editionMode) {
|
|
|
|
|
var self = this;
|
|
|
|
|
// add the dropdown menu to display the edit and delete option
|
|
|
|
|
var modifyCommentMenu = new OCA.Comments.CommentsModifyMenu();
|
|
|
|
|
$el.find('.authorRow').append(modifyCommentMenu.$el);
|
|
|
|
|
$el.find('.more').on('click', _.bind(modifyCommentMenu.show, modifyCommentMenu));
|
|
|
|
|
|
|
|
|
|
self.listenTo(modifyCommentMenu, 'select:menu-item-clicked', function(ev, action) {
|
|
|
|
|
if (action === 'edit') {
|
|
|
|
|
self._onClickEditComment(ev);
|
|
|
|
|
} else if (action === 'delete') {
|
|
|
|
|
self._onClickDeleteComment(ev);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 01:45:35 +03:00
|
|
|
|
this._postRenderMessage($message, editionMode);
|
2017-05-08 23:00:00 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-11-27 01:45:35 +03:00
|
|
|
|
_postRenderMessage: function($el, editionMode) {
|
|
|
|
|
if (editionMode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 23:00:00 +03:00
|
|
|
|
$el.find('.avatar').each(function() {
|
2017-04-24 20:52:45 +03:00
|
|
|
|
var avatar = $(this);
|
|
|
|
|
var strong = $(this).next();
|
|
|
|
|
var appendTo = $(this).parent();
|
|
|
|
|
|
2017-11-27 02:10:53 +03:00
|
|
|
|
var username = $(this).data('username');
|
|
|
|
|
if (username !== oc_current_user) {
|
|
|
|
|
$.merge(avatar, strong).contactsMenu(avatar.data('user'), 0, appendTo);
|
|
|
|
|
}
|
2017-04-24 20:52:45 +03:00
|
|
|
|
});
|
2016-01-27 20:28:55 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-02-01 18:54:27 +03:00
|
|
|
|
/**
|
|
|
|
|
* Convert a message to be displayed in HTML,
|
|
|
|
|
* converts newlines to <br> tags.
|
|
|
|
|
*/
|
2018-01-02 13:20:15 +03:00
|
|
|
|
_formatMessage: function(message, mentions, editMode) {
|
2016-10-17 15:06:23 +03:00
|
|
|
|
message = escapeHTML(message).replace(/\n/g, '<br/>');
|
|
|
|
|
|
|
|
|
|
for(var i in mentions) {
|
2017-10-23 19:00:39 +03:00
|
|
|
|
if(!mentions.hasOwnProperty(i)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-17 15:06:23 +03:00
|
|
|
|
var mention = '@' + mentions[i].mentionId;
|
2016-10-17 19:19:51 +03:00
|
|
|
|
|
|
|
|
|
// escape possible regex characters in the name
|
2016-10-17 15:06:23 +03:00
|
|
|
|
mention = mention.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
2017-10-18 16:17:22 +03:00
|
|
|
|
|
|
|
|
|
var displayName = this._composeHTMLMention(mentions[i].mentionId, mentions[i].mentionDisplayName);
|
2016-10-17 19:19:51 +03:00
|
|
|
|
|
|
|
|
|
// replace every mention either at the start of the input or after a whitespace
|
|
|
|
|
// followed by a non-word character.
|
2016-10-18 18:05:56 +03:00
|
|
|
|
message = message.replace(new RegExp("(^|\\s)(" + mention + ")\\b", 'g'),
|
2016-10-17 19:19:51 +03:00
|
|
|
|
function(match, p1) {
|
|
|
|
|
// to get number of whitespaces (0 vs 1) right
|
|
|
|
|
return p1+displayName;
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-10-17 15:06:23 +03:00
|
|
|
|
}
|
2018-01-02 13:20:15 +03:00
|
|
|
|
if(editMode !== true) {
|
|
|
|
|
message = OCP.Comments.plainToRich(message);
|
|
|
|
|
}
|
2016-10-17 15:06:23 +03:00
|
|
|
|
return message;
|
2016-02-01 18:54:27 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-10-18 16:17:22 +03:00
|
|
|
|
_composeHTMLMention: function(uid, displayName) {
|
|
|
|
|
var avatar = '<div class="avatar" '
|
|
|
|
|
+ 'data-username="' + _.escape(uid) + '"'
|
2017-10-23 19:00:39 +03:00
|
|
|
|
+ ' data-user="' + _.escape(uid) + '"'
|
|
|
|
|
+ ' data-user-display-name="'
|
2017-10-18 16:17:22 +03:00
|
|
|
|
+ _.escape(displayName) + '"></div>';
|
|
|
|
|
|
2017-11-27 13:53:24 +03:00
|
|
|
|
var isCurrentUser = (uid === OC.getCurrentUser().uid);
|
2017-11-27 02:10:53 +03:00
|
|
|
|
|
2017-10-18 16:17:22 +03:00
|
|
|
|
return ''
|
2017-10-23 19:00:39 +03:00
|
|
|
|
+ '<span class="atwho-inserted" contenteditable="false">'
|
2017-11-27 02:10:53 +03:00
|
|
|
|
+ '<span class="avatar-name-wrapper' + (isCurrentUser ? ' currentUser' : '') + '">'
|
2017-10-18 16:17:22 +03:00
|
|
|
|
+ avatar + ' <strong>'+ _.escape(displayName)+'</strong>'
|
2017-10-23 19:00:39 +03:00
|
|
|
|
+ '</span>'
|
2017-10-18 16:17:22 +03:00
|
|
|
|
+ '</span>';
|
|
|
|
|
},
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
nextPage: function() {
|
|
|
|
|
if (this._loading || !this.collection.hasMoreResults()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.collection.fetchNext();
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 20:44:14 +03:00
|
|
|
|
_onClickEditComment: function(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
var $comment = $(ev.target).closest('.comment');
|
|
|
|
|
var commentId = $comment.data('id');
|
|
|
|
|
var commentToEdit = this.collection.get(commentId);
|
|
|
|
|
var $formRow = $(this.editCommentTemplate(_.extend({
|
|
|
|
|
isEditMode: true,
|
|
|
|
|
submitText: t('comments', 'Save')
|
|
|
|
|
}, commentToEdit.attributes)));
|
|
|
|
|
|
2016-02-04 20:20:16 +03:00
|
|
|
|
$comment.addClass('hidden').removeClass('collapsed');
|
2016-02-03 20:44:14 +03:00
|
|
|
|
// spawn form
|
|
|
|
|
$comment.after($formRow);
|
|
|
|
|
$formRow.data('commentEl', $comment);
|
2017-10-18 00:24:01 +03:00
|
|
|
|
$formRow.find('.message').on('keydown input change', this._onTypeComment);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
|
|
|
|
|
// copy avatar element from original to avoid flickering
|
2016-10-21 23:57:06 +03:00
|
|
|
|
$formRow.find('.avatar:first').replaceWith($comment.find('.avatar:first').clone());
|
2016-02-03 22:32:37 +03:00
|
|
|
|
$formRow.find('.has-tooltip').tooltip();
|
2016-02-03 20:44:14 +03:00
|
|
|
|
|
2017-10-23 19:00:39 +03:00
|
|
|
|
var $message = $formRow.find('.message');
|
|
|
|
|
$message
|
2018-01-02 13:20:15 +03:00
|
|
|
|
.html(this._formatMessage(commentToEdit.get('message'), commentToEdit.get('mentions'), true))
|
2017-10-23 19:00:39 +03:00
|
|
|
|
.find('.avatar')
|
|
|
|
|
.each(function () { $(this).avatar(); });
|
2017-11-27 01:45:35 +03:00
|
|
|
|
var editionMode = true;
|
|
|
|
|
this._postRenderItem($message, editionMode);
|
2017-10-23 19:00:39 +03:00
|
|
|
|
|
2016-09-14 15:20:26 +03:00
|
|
|
|
// Enable autosize
|
2017-10-18 00:24:01 +03:00
|
|
|
|
autosize($formRow.find('.message'));
|
2016-09-14 15:20:26 +03:00
|
|
|
|
|
2017-10-23 19:00:39 +03:00
|
|
|
|
// enable autocomplete
|
|
|
|
|
this._initAutoComplete($formRow.find('.message'));
|
|
|
|
|
|
2016-02-03 20:44:14 +03:00
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-05 17:45:30 +03:00
|
|
|
|
_onTypeComment: function(ev) {
|
|
|
|
|
var $field = $(ev.target);
|
2017-12-29 23:09:19 +03:00
|
|
|
|
var len = $field.text().length;
|
2016-02-05 17:45:30 +03:00
|
|
|
|
var $submitButton = $field.data('submitButtonEl');
|
|
|
|
|
if (!$submitButton) {
|
|
|
|
|
$submitButton = $field.closest('form').find('.submit');
|
|
|
|
|
$field.data('submitButtonEl', $submitButton);
|
|
|
|
|
}
|
|
|
|
|
$field.tooltip('hide');
|
|
|
|
|
if (len > this._commentMaxThreshold) {
|
|
|
|
|
$field.attr('data-original-title', t('comments', 'Allowed characters {count} of {max}', {count: len, max: this._commentMaxLength}));
|
|
|
|
|
$field.tooltip({trigger: 'manual'});
|
|
|
|
|
$field.tooltip('show');
|
|
|
|
|
$field.addClass('error');
|
|
|
|
|
}
|
2016-02-17 17:19:42 +03:00
|
|
|
|
|
2016-02-05 17:45:30 +03:00
|
|
|
|
var limitExceeded = (len > this._commentMaxLength);
|
|
|
|
|
$field.toggleClass('error', limitExceeded);
|
|
|
|
|
$submitButton.prop('disabled', limitExceeded);
|
2016-05-02 20:52:13 +03:00
|
|
|
|
|
2017-12-07 06:59:29 +03:00
|
|
|
|
// Submits form with Enter, but Shift+Enter is a new line. If the
|
|
|
|
|
// autocomplete popover is being shown Enter does not submit the
|
|
|
|
|
// form either; it will be handled by At.js which will add the
|
|
|
|
|
// currently selected item to the message.
|
|
|
|
|
if (ev.keyCode === 13 && !ev.shiftKey && !$field.atwho('isSelecting')) {
|
2016-05-02 20:52:13 +03:00
|
|
|
|
$submitButton.click();
|
2017-11-21 00:14:25 +03:00
|
|
|
|
ev.preventDefault();
|
2016-05-03 13:29:43 +03:00
|
|
|
|
}
|
2016-02-05 17:45:30 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-02-04 20:20:16 +03:00
|
|
|
|
_onClickComment: function(ev) {
|
|
|
|
|
var $row = $(ev.target);
|
|
|
|
|
if (!$row.is('.comment')) {
|
|
|
|
|
$row = $row.closest('.comment');
|
|
|
|
|
}
|
|
|
|
|
$row.removeClass('collapsed');
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 20:44:14 +03:00
|
|
|
|
_onClickCloseComment: function(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
var $row = $(ev.target).closest('.comment');
|
|
|
|
|
$row.data('commentEl').removeClass('hidden');
|
|
|
|
|
$row.remove();
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onClickDeleteComment: function(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
var $comment = $(ev.target).closest('.comment');
|
|
|
|
|
var commentId = $comment.data('id');
|
2017-11-24 16:07:39 +03:00
|
|
|
|
var $loading = $comment.find('.deleteLoading');
|
2018-02-03 22:45:53 +03:00
|
|
|
|
var $moreIcon = $comment.find('.more');
|
2016-02-03 20:44:14 +03:00
|
|
|
|
|
|
|
|
|
$comment.addClass('disabled');
|
2016-02-03 22:32:37 +03:00
|
|
|
|
$loading.removeClass('hidden');
|
2018-02-03 22:45:53 +03:00
|
|
|
|
$moreIcon.addClass('hidden');
|
|
|
|
|
|
|
|
|
|
$comment.data('commentEl', $comment);
|
2017-11-24 15:04:59 +03:00
|
|
|
|
|
2016-02-03 20:44:14 +03:00
|
|
|
|
this.collection.get(commentId).destroy({
|
|
|
|
|
success: function() {
|
2016-02-03 22:32:37 +03:00
|
|
|
|
$comment.data('commentEl').remove();
|
2016-02-03 20:44:14 +03:00
|
|
|
|
$comment.remove();
|
|
|
|
|
},
|
2016-06-24 11:10:10 +03:00
|
|
|
|
error: function() {
|
2016-02-03 22:32:37 +03:00
|
|
|
|
$loading.addClass('hidden');
|
2018-02-03 22:45:53 +03:00
|
|
|
|
$moreIcon.removeClass('hidden');
|
2016-02-03 20:44:14 +03:00
|
|
|
|
$comment.removeClass('disabled');
|
2017-11-24 15:04:59 +03:00
|
|
|
|
|
2018-03-01 22:53:50 +03:00
|
|
|
|
OC.Notification.showTemporary(t('comments', 'Error occurred while retrieving comment with ID {id}', {id: commentId}));
|
2016-02-03 20:44:14 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2016-01-28 16:24:12 +03:00
|
|
|
|
_onClickShowMore: function(ev) {
|
2016-01-27 20:28:55 +03:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
this.nextPage();
|
|
|
|
|
},
|
|
|
|
|
|
2016-10-19 14:56:49 +03:00
|
|
|
|
/**
|
2017-10-19 19:15:34 +03:00
|
|
|
|
* takes care of updating comment element states after submit (either new
|
2016-10-19 14:56:49 +03:00
|
|
|
|
* comment or edit).
|
|
|
|
|
*
|
|
|
|
|
* @param {OC.Backbone.Model} model
|
|
|
|
|
* @param {jQuery} $form
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2017-10-19 19:15:34 +03:00
|
|
|
|
_onSubmitSuccess: function(model, $form) {
|
2016-10-17 15:06:23 +03:00
|
|
|
|
var $submit = $form.find('.submit');
|
|
|
|
|
var $loading = $form.find('.submitLoading');
|
2016-10-19 14:56:49 +03:00
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
$submit.removeClass('hidden');
|
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
|
},
|
2016-10-19 13:47:53 +03:00
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
_commentBodyHTML2Plain: function($el) {
|
|
|
|
|
var $comment = $el.clone();
|
2017-05-08 23:00:00 +03:00
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
$comment.find('.avatar-name-wrapper').each(function () {
|
|
|
|
|
var $this = $(this);
|
|
|
|
|
var $inserted = $this.parent();
|
|
|
|
|
$inserted.html('@' + $this.find('.avatar').data('username'));
|
2016-10-17 15:06:23 +03:00
|
|
|
|
});
|
2017-10-19 19:15:34 +03:00
|
|
|
|
|
2018-01-02 13:20:15 +03:00
|
|
|
|
$comment.html(OCP.Comments.richToPlain($comment.html()));
|
|
|
|
|
|
2017-10-30 13:10:04 +03:00
|
|
|
|
var oldHtml;
|
|
|
|
|
var html = $comment.html();
|
|
|
|
|
do {
|
|
|
|
|
// replace works one by one
|
|
|
|
|
oldHtml = html;
|
|
|
|
|
html = oldHtml.replace("<br>", "\n"); // preserve line breaks
|
|
|
|
|
} while(oldHtml !== html);
|
|
|
|
|
$comment.html(html);
|
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
return $comment.text();
|
2016-10-17 15:06:23 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
|
_onSubmitComment: function(e) {
|
2016-02-03 20:44:14 +03:00
|
|
|
|
var self = this;
|
2016-02-02 14:06:12 +03:00
|
|
|
|
var $form = $(e.target);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
var commentId = $form.closest('.comment').data('id');
|
2016-02-01 18:37:33 +03:00
|
|
|
|
var currentUser = OC.getCurrentUser();
|
2016-02-02 14:06:12 +03:00
|
|
|
|
var $submit = $form.find('.submit');
|
|
|
|
|
var $loading = $form.find('.submitLoading');
|
2017-10-18 00:24:01 +03:00
|
|
|
|
var $commentField = $form.find('.message');
|
|
|
|
|
var message = $commentField.text().trim();
|
2016-01-27 20:28:55 +03:00
|
|
|
|
e.preventDefault();
|
2016-02-02 14:06:12 +03:00
|
|
|
|
|
2016-02-05 17:45:30 +03:00
|
|
|
|
if (!message.length || message.length > this._commentMaxLength) {
|
2016-02-02 14:06:12 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 16:34:09 +03:00
|
|
|
|
$commentField.prop('contenteditable', false);
|
2016-02-02 14:06:12 +03:00
|
|
|
|
$submit.addClass('hidden');
|
|
|
|
|
$loading.removeClass('hidden');
|
|
|
|
|
|
2017-10-19 19:15:34 +03:00
|
|
|
|
message = this._commentBodyHTML2Plain($commentField);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
if (commentId) {
|
|
|
|
|
// edit mode
|
|
|
|
|
var comment = this.collection.get(commentId);
|
|
|
|
|
comment.save({
|
2017-10-19 19:15:34 +03:00
|
|
|
|
message: message
|
2016-02-03 20:44:14 +03:00
|
|
|
|
}, {
|
|
|
|
|
success: function(model) {
|
2017-10-23 19:00:39 +03:00
|
|
|
|
self._onSubmitSuccess(model, $form);
|
2018-01-18 22:14:58 +03:00
|
|
|
|
if(model.get('message').trim() === model.previous('message').trim()) {
|
|
|
|
|
// model change event doesn't trigger, manually remove the row.
|
|
|
|
|
var $row = $form.closest('.comment');
|
|
|
|
|
$row.data('commentEl').removeClass('hidden');
|
|
|
|
|
$row.remove();
|
|
|
|
|
}
|
2016-02-03 20:44:14 +03:00
|
|
|
|
},
|
2016-06-24 11:10:10 +03:00
|
|
|
|
error: function() {
|
2016-10-19 14:56:49 +03:00
|
|
|
|
self._onSubmitError($form, commentId);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.collection.create({
|
|
|
|
|
actorId: currentUser.uid,
|
|
|
|
|
actorDisplayName: currentUser.displayName,
|
|
|
|
|
actorType: 'users',
|
|
|
|
|
verb: 'comment',
|
2017-10-19 19:15:34 +03:00
|
|
|
|
message: message,
|
2016-02-03 20:44:14 +03:00
|
|
|
|
creationDateTime: (new Date()).toUTCString()
|
|
|
|
|
}, {
|
|
|
|
|
at: 0,
|
|
|
|
|
// wait for real creation before adding
|
|
|
|
|
wait: true,
|
2016-10-17 15:06:23 +03:00
|
|
|
|
success: function(model) {
|
2017-10-23 19:00:39 +03:00
|
|
|
|
self._onSubmitSuccess(model, $form);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
},
|
2016-06-24 11:10:10 +03:00
|
|
|
|
error: function() {
|
2017-10-19 19:15:34 +03:00
|
|
|
|
self._onSubmitError($form, undefined);
|
2016-02-03 20:44:14 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-01-27 20:28:55 +03:00
|
|
|
|
|
|
|
|
|
return false;
|
2016-02-04 20:20:16 +03:00
|
|
|
|
},
|
|
|
|
|
|
2016-10-19 14:56:49 +03:00
|
|
|
|
/**
|
|
|
|
|
* takes care of updating the UI after an error on submit (either new
|
|
|
|
|
* comment or edit).
|
|
|
|
|
*
|
|
|
|
|
* @param {jQuery} $form
|
|
|
|
|
* @param {string|undefined} commentId
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_onSubmitError: function($form, commentId) {
|
|
|
|
|
$form.find('.submit').removeClass('hidden');
|
|
|
|
|
$form.find('.submitLoading').addClass('hidden');
|
2017-11-23 16:34:09 +03:00
|
|
|
|
$form.find('.message').prop('contenteditable', true);
|
2016-10-19 14:56:49 +03:00
|
|
|
|
|
|
|
|
|
if(!_.isUndefined(commentId)) {
|
2017-02-14 23:26:00 +03:00
|
|
|
|
OC.Notification.show(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}), {type: 'error'});
|
2016-10-19 14:56:49 +03:00
|
|
|
|
} else {
|
2017-02-14 23:26:00 +03:00
|
|
|
|
OC.Notification.show(t('comments', 'Error occurred while posting comment'), {type: 'error'});
|
2016-10-19 14:56:49 +03:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-10-18 00:24:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* ensures the contenteditable div is really empty, when user removed
|
|
|
|
|
* all input, so that the placeholder will be shown again
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_onTextChange: function() {
|
2017-10-19 19:15:34 +03:00
|
|
|
|
var $message = $('#commentsTabView').find('.newCommentForm div.message');
|
2017-10-18 00:24:01 +03:00
|
|
|
|
if(!$message.text().trim().length) {
|
|
|
|
|
$message.empty();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Limit pasting to plain text
|
|
|
|
|
*
|
|
|
|
|
* @param e
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_onPaste: function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
var text = e.originalEvent.clipboardData.getData("text/plain");
|
|
|
|
|
document.execCommand('insertText', false, text);
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-04 20:20:16 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether the given message is long and needs
|
|
|
|
|
* collapsing
|
|
|
|
|
*/
|
|
|
|
|
_isLong: function(message) {
|
|
|
|
|
return message.length > 250 || (message.match(/\n/g) || []).length > 1;
|
2016-01-27 20:28:55 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
OCA.Comments.CommentsTabView = CommentsTabView;
|
2016-02-01 18:37:33 +03:00
|
|
|
|
})(OC, OCA);
|