2016-01-27 17:28:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-02-03 12:00:55 +00:00
|
|
|
/* global Handlebars */
|
|
|
|
|
2016-01-27 17:28:55 +00:00
|
|
|
(function() {
|
2016-11-21 14:03:45 +00:00
|
|
|
|
|
|
|
_.extend(OC.Files.Client, {
|
|
|
|
PROPERTY_COMMENTS_UNREAD: '{' + OC.Files.Client.NS_OWNCLOUD + '}comments-unread'
|
|
|
|
});
|
|
|
|
|
2016-02-03 12:00:55 +00:00
|
|
|
var TEMPLATE_COMMENTS_UNREAD =
|
|
|
|
'<a class="action action-comment permanent" title="{{countMessage}}" href="#">' +
|
|
|
|
'<img class="svg" src="{{iconUrl}}"/>' +
|
|
|
|
'</a>';
|
2016-02-25 19:48:19 +00:00
|
|
|
|
2016-01-27 17:28:55 +00:00
|
|
|
OCA.Comments = _.extend({}, OCA.Comments);
|
|
|
|
if (!OCA.Comments) {
|
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
OCA.Comments = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
OCA.Comments.FilesPlugin = {
|
2016-02-16 10:24:44 +00:00
|
|
|
ignoreLists: [
|
|
|
|
'files_trashbin',
|
|
|
|
'files.public'
|
2016-01-27 17:28:55 +00:00
|
|
|
],
|
|
|
|
|
2016-02-03 12:00:55 +00:00
|
|
|
_formatCommentCount: function(count) {
|
|
|
|
if (!this._commentsUnreadTemplate) {
|
|
|
|
this._commentsUnreadTemplate = Handlebars.compile(TEMPLATE_COMMENTS_UNREAD);
|
|
|
|
}
|
|
|
|
return this._commentsUnreadTemplate({
|
|
|
|
count: count,
|
2016-09-28 08:54:37 +00:00
|
|
|
countMessage: n('comments', '%n unread comment', '%n unread comments', count),
|
2016-02-03 12:00:55 +00:00
|
|
|
iconUrl: OC.imagePath('core', 'actions/comment')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-27 17:28:55 +00:00
|
|
|
attach: function(fileList) {
|
2016-02-03 12:00:55 +00:00
|
|
|
var self = this;
|
2016-02-16 10:24:44 +00:00
|
|
|
if (this.ignoreLists.indexOf(fileList.id) >= 0) {
|
2016-01-27 17:28:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileList.registerTabView(new OCA.Comments.CommentsTabView('commentsTabView'));
|
2016-02-03 12:00:55 +00:00
|
|
|
|
|
|
|
var oldGetWebdavProperties = fileList._getWebdavProperties;
|
|
|
|
fileList._getWebdavProperties = function() {
|
|
|
|
var props = oldGetWebdavProperties.apply(this, arguments);
|
2016-11-21 14:03:45 +00:00
|
|
|
props.push(OC.Files.Client.PROPERTY_COMMENTS_UNREAD);
|
2016-02-03 12:00:55 +00:00
|
|
|
return props;
|
|
|
|
};
|
|
|
|
|
|
|
|
fileList.filesClient.addFileInfoParser(function(response) {
|
|
|
|
var data = {};
|
|
|
|
var props = response.propStat[0].properties;
|
2016-11-21 14:03:45 +00:00
|
|
|
var commentsUnread = props[OC.Files.Client.PROPERTY_COMMENTS_UNREAD];
|
2016-02-03 12:00:55 +00:00
|
|
|
if (!_.isUndefined(commentsUnread) && commentsUnread !== '') {
|
|
|
|
data.commentsUnread = parseInt(commentsUnread, 10);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
|
|
|
|
fileList.$el.addClass('has-comments');
|
|
|
|
var oldCreateRow = fileList._createRow;
|
|
|
|
fileList._createRow = function(fileData) {
|
|
|
|
var $tr = oldCreateRow.apply(this, arguments);
|
|
|
|
if (fileData.commentsUnread) {
|
|
|
|
$tr.attr('data-comments-unread', fileData.commentsUnread);
|
|
|
|
}
|
|
|
|
return $tr;
|
|
|
|
};
|
|
|
|
|
|
|
|
// register "comment" action for reading comments
|
|
|
|
fileList.fileActions.registerAction({
|
|
|
|
name: 'Comment',
|
|
|
|
displayName: t('comments', 'Comment'),
|
|
|
|
mime: 'all',
|
|
|
|
permissions: OC.PERMISSION_READ,
|
|
|
|
type: OCA.Files.FileActions.TYPE_INLINE,
|
|
|
|
render: function(actionSpec, isDefault, context) {
|
|
|
|
var $file = context.$file;
|
|
|
|
var unreadComments = $file.data('comments-unread');
|
|
|
|
if (unreadComments) {
|
|
|
|
var $actionLink = $(self._formatCommentCount(unreadComments));
|
|
|
|
context.$file.find('a.name>span.fileactions').append($actionLink);
|
|
|
|
return $actionLink;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
actionHandler: function(fileName, context) {
|
|
|
|
context.$file.find('.action-comment').tooltip('hide');
|
|
|
|
// open sidebar in comments section
|
|
|
|
context.fileList.showDetailsView(fileName, 'commentsTabView');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// add attribute to "elementToFile"
|
|
|
|
var oldElementToFile = fileList.elementToFile;
|
|
|
|
fileList.elementToFile = function($el) {
|
|
|
|
var fileInfo = oldElementToFile.apply(this, arguments);
|
|
|
|
var commentsUnread = $el.data('comments-unread');
|
|
|
|
if (commentsUnread) {
|
|
|
|
fileInfo.commentsUnread = commentsUnread;
|
|
|
|
}
|
|
|
|
return fileInfo;
|
|
|
|
};
|
2016-01-27 17:28:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
OC.Plugins.register('OCA.Files.FileList', OCA.Comments.FilesPlugin);
|