aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/src/filesplugin.js
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-02-15 13:50:12 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2019-02-26 09:10:23 +0100
commit41ef3d860cd1a565882cfd84dda72f2d9ad9cef2 (patch)
tree6b88427b1b64274a6d57bb7269f717d27cdbf1a9 /apps/comments/src/filesplugin.js
parentfc105d3bb006c94cc0d88864451252111ce33b16 (diff)
downloadnextcloud-server-41ef3d860cd1a565882cfd84dda72f2d9ad9cef2.tar.gz
nextcloud-server-41ef3d860cd1a565882cfd84dda72f2d9ad9cef2.zip
Move comments to webpack
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/comments/src/filesplugin.js')
-rw-r--r--apps/comments/src/filesplugin.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/apps/comments/src/filesplugin.js b/apps/comments/src/filesplugin.js
new file mode 100644
index 00000000000..939edc8c695
--- /dev/null
+++ b/apps/comments/src/filesplugin.js
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ *
+ */
+
+/* global Handlebars */
+
+(function() {
+
+ _.extend(OC.Files.Client, {
+ PROPERTY_COMMENTS_UNREAD: '{' + OC.Files.Client.NS_OWNCLOUD + '}comments-unread'
+ });
+
+ OCA.Comments = _.extend({}, OCA.Comments);
+ if (!OCA.Comments) {
+ /**
+ * @namespace
+ */
+ OCA.Comments = {};
+ }
+
+ /**
+ * @namespace
+ */
+ OCA.Comments.FilesPlugin = {
+ ignoreLists: [
+ 'files_trashbin',
+ 'files.public'
+ ],
+
+ _formatCommentCount: function(count) {
+ return OCA.Comments.Templates['filesplugin']({
+ count: count,
+ countMessage: n('comments', '%n unread comment', '%n unread comments', count),
+ iconUrl: OC.imagePath('core', 'actions/comment')
+ });
+ },
+
+ attach: function(fileList) {
+ var self = this;
+ if (this.ignoreLists.indexOf(fileList.id) >= 0) {
+ return;
+ }
+
+ fileList.registerTabView(new OCA.Comments.CommentsTabView('commentsTabView'));
+
+ var oldGetWebdavProperties = fileList._getWebdavProperties;
+ fileList._getWebdavProperties = function() {
+ var props = oldGetWebdavProperties.apply(this, arguments);
+ props.push(OC.Files.Client.PROPERTY_COMMENTS_UNREAD);
+ return props;
+ };
+
+ fileList.filesClient.addFileInfoParser(function(response) {
+ var data = {};
+ var props = response.propStat[0].properties;
+ var commentsUnread = props[OC.Files.Client.PROPERTY_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;
+ };
+ }
+ };
+
+})();
+
+OC.Plugins.register('OCA.Files.FileList', OCA.Comments.FilesPlugin);