summaryrefslogtreecommitdiffstats
path: root/apps/comments/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-02-03 13:00:55 +0100
committerVincent Petry <pvince81@owncloud.com>2016-02-03 13:00:55 +0100
commit8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b (patch)
tree9b484c1f7102cebd96995c29efd11fbbad870e64 /apps/comments/js
parent621f54da514af548bf900f7a1c64af046f53b86d (diff)
downloadnextcloud-server-8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b.tar.gz
nextcloud-server-8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b.zip
Add file row indicator for unread comments
Diffstat (limited to 'apps/comments/js')
-rw-r--r--apps/comments/js/filesplugin.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/apps/comments/js/filesplugin.js b/apps/comments/js/filesplugin.js
index c8d91e0ede3..bf6bb05146b 100644
--- a/apps/comments/js/filesplugin.js
+++ b/apps/comments/js/filesplugin.js
@@ -8,7 +8,15 @@
*
*/
+/* global Handlebars */
+
(function() {
+ var TEMPLATE_COMMENTS_UNREAD =
+ '<a class="action action-comment permanent" title="{{countMessage}}" href="#">' +
+ '<img class="svg" src="{{iconUrl}}"/>' +
+ '{{count}}' +
+ '</a>';
+
OCA.Comments = _.extend({}, OCA.Comments);
if (!OCA.Comments) {
/**
@@ -26,12 +34,88 @@
'favorites'
],
+ _formatCommentCount: function(count) {
+ if (!this._commentsUnreadTemplate) {
+ this._commentsUnreadTemplate = Handlebars.compile(TEMPLATE_COMMENTS_UNREAD);
+ }
+ return this._commentsUnreadTemplate({
+ count: count,
+ countMessage: t('comments', '{count} unread comments', {count: count}),
+ iconUrl: OC.imagePath('core', 'actions/comment')
+ });
+ },
+
attach: function(fileList) {
+ var self = this;
if (this.allowedLists.indexOf(fileList.id) < 0) {
return;
}
fileList.registerTabView(new OCA.Comments.CommentsTabView('commentsTabView'));
+
+ var NS_OC = 'http://owncloud.org/ns';
+
+ var oldGetWebdavProperties = fileList._getWebdavProperties;
+ fileList._getWebdavProperties = function() {
+ var props = oldGetWebdavProperties.apply(this, arguments);
+ props.push('{' + NS_OC + '}comments-unread');
+ return props;
+ };
+
+ fileList.filesClient.addFileInfoParser(function(response) {
+ var data = {};
+ var props = response.propStat[0].properties;
+ var commentsUnread = props['{' + NS_OC + '}comments-unread'];
+ 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;
+ };
}
};