aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments/js')
-rw-r--r--apps/comments/js/app.js20
-rw-r--r--apps/comments/js/commentcollection.js167
-rw-r--r--apps/comments/js/commentmodel.js58
-rw-r--r--apps/comments/js/commentstabview.js435
-rw-r--r--apps/comments/js/commentsummarymodel.js65
-rw-r--r--apps/comments/js/filesplugin.js123
6 files changed, 0 insertions, 868 deletions
diff --git a/apps/comments/js/app.js b/apps/comments/js/app.js
deleted file mode 100644
index 547059393a5..00000000000
--- a/apps/comments/js/app.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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.
- *
- */
-
-(function() {
- if (!OCA.Comments) {
- /**
- * @namespace
- */
- OCA.Comments = {};
- }
-
-})();
-
diff --git a/apps/comments/js/commentcollection.js b/apps/comments/js/commentcollection.js
deleted file mode 100644
index a15039cf484..00000000000
--- a/apps/comments/js/commentcollection.js
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2016
- *
- * This file is licensed under the Affero General Public License version 3
- * or later.
- *
- * See the COPYING-README file.
- *
- */
-
-(function(OC, OCA) {
-
- /**
- * @class OCA.Comments.CommentCollection
- * @classdesc
- *
- * Collection of comments assigned to a file
- *
- */
- var CommentCollection = OC.Backbone.Collection.extend(
- /** @lends OCA.Comments.CommentCollection.prototype */ {
-
- sync: OC.Backbone.davSync,
-
- model: OCA.Comments.CommentModel,
-
- /**
- * Object type
- *
- * @type string
- */
- _objectType: 'files',
-
- /**
- * Object id
- *
- * @type string
- */
- _objectId: null,
-
- /**
- * True if there are no more page results left to fetch
- *
- * @type bool
- */
- _endReached: false,
-
- /**
- * Number of comments to fetch per page
- *
- * @type int
- */
- _limit : 20,
-
- /**
- * Initializes the collection
- *
- * @param {string} [options.objectType] object type
- * @param {string} [options.objectId] object id
- */
- initialize: function(models, options) {
- options = options || {};
- if (options.objectType) {
- this._objectType = options.objectType;
- }
- if (options.objectId) {
- this._objectId = options.objectId;
- }
- },
-
- url: function() {
- return OC.linkToRemote('dav') + '/comments/' +
- encodeURIComponent(this._objectType) + '/' +
- encodeURIComponent(this._objectId) + '/';
- },
-
- setObjectId: function(objectId) {
- this._objectId = objectId;
- },
-
- hasMoreResults: function() {
- return !this._endReached;
- },
-
- reset: function() {
- this._endReached = false;
- this._summaryModel = null;
- return OC.Backbone.Collection.prototype.reset.apply(this, arguments);
- },
-
- /**
- * Fetch the next set of results
- */
- fetchNext: function(options) {
- var self = this;
- if (!this.hasMoreResults()) {
- return null;
- }
-
- var body = '<?xml version="1.0" encoding="utf-8" ?>\n' +
- '<oc:filter-comments xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">\n' +
- // load one more so we know there is more
- ' <oc:limit>' + (this._limit + 1) + '</oc:limit>\n' +
- ' <oc:offset>' + this.length + '</oc:offset>\n' +
- '</oc:filter-comments>\n';
-
- options = options || {};
- var success = options.success;
- options = _.extend({
- remove: false,
- parse: true,
- data: body,
- davProperties: CommentCollection.prototype.model.prototype.davProperties,
- success: function(resp) {
- if (resp.length <= self._limit) {
- // no new entries, end reached
- self._endReached = true;
- } else {
- // remove last entry, for next page load
- resp = _.initial(resp);
- }
- if (!self.set(resp, options)) {
- return false;
- }
- if (success) {
- success.apply(null, arguments);
- }
- self.trigger('sync', 'REPORT', self, options);
- }
- }, options);
-
- return this.sync('REPORT', this, options);
- },
-
- /**
- * Returns the matching summary model
- *
- * @return {OCA.Comments.CommentSummaryModel} summary model
- */
- getSummaryModel: function() {
- if (!this._summaryModel) {
- this._summaryModel = new OCA.Comments.CommentSummaryModel({
- id: this._objectId,
- objectType: this._objectType
- });
- }
- return this._summaryModel;
- },
-
- /**
- * Updates the read marker for this comment thread
- *
- * @param {Date} [date] optional date, defaults to now
- * @param {Object} [options] backbone options
- */
- updateReadMarker: function(date, options) {
- options = options || {};
-
- return this.getSummaryModel().save({
- readMarker: (date || new Date()).toUTCString()
- }, options);
- }
- });
-
- OCA.Comments.CommentCollection = CommentCollection;
-})(OC, OCA);
-
diff --git a/apps/comments/js/commentmodel.js b/apps/comments/js/commentmodel.js
deleted file mode 100644
index 89492707b61..00000000000
--- a/apps/comments/js/commentmodel.js
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2016
- *
- * This file is licensed under the Affero General Public License version 3
- * or later.
- *
- * See the COPYING-README file.
- *
- */
-
-(function(OC, OCA) {
- var NS_OWNCLOUD = 'http://owncloud.org/ns';
- /**
- * @class OCA.Comments.CommentModel
- * @classdesc
- *
- * Comment
- *
- */
- var CommentModel = OC.Backbone.Model.extend(
- /** @lends OCA.Comments.CommentModel.prototype */ {
- sync: OC.Backbone.davSync,
-
- defaults: {
- actorType: 'users',
- objectType: 'files'
- },
-
- davProperties: {
- 'id': '{' + NS_OWNCLOUD + '}id',
- 'message': '{' + NS_OWNCLOUD + '}message',
- 'actorType': '{' + NS_OWNCLOUD + '}actorType',
- 'actorId': '{' + NS_OWNCLOUD + '}actorId',
- 'actorDisplayName': '{' + NS_OWNCLOUD + '}actorDisplayName',
- 'creationDateTime': '{' + NS_OWNCLOUD + '}creationDateTime',
- 'objectType': '{' + NS_OWNCLOUD + '}objectType',
- 'objectId': '{' + NS_OWNCLOUD + '}objectId',
- 'isUnread': '{' + NS_OWNCLOUD + '}isUnread'
- },
-
- parse: function(data) {
- return {
- id: data.id,
- message: data.message,
- actorType: data.actorType,
- actorId: data.actorId,
- actorDisplayName: data.actorDisplayName,
- creationDateTime: data.creationDateTime,
- objectType: data.objectType,
- objectId: data.objectId,
- isUnread: (data.isUnread === 'true')
- };
- }
- });
-
- OCA.Comments.CommentModel = CommentModel;
-})(OC, OCA);
-
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js
deleted file mode 100644
index 415ec2a9be5..00000000000
--- a/apps/comments/js/commentstabview.js
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (c) 2016
- *
- * This file is licensed under the Affero General Public License version 3
- * or later.
- *
- * See the COPYING-README file.
- *
- */
-
-/* global Handlebars, escapeHTML */
-
-(function(OC, OCA) {
- var TEMPLATE =
- '<ul class="comments">' +
- '</ul>' +
- '<div class="empty hidden">{{emptyResultLabel}}</div>' +
- '<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 =
- '<div class="newCommentRow comment" data-id="{{id}}">' +
- ' <div class="authorRow">' +
- ' {{#if avatarEnabled}}' +
- ' <div class="avatar" data-username="{{actorId}}"></div>' +
- ' {{/if}}' +
- ' <div class="author">{{actorDisplayName}}</div>' +
- '{{#if isEditMode}}' +
- ' <a href="#" class="action delete icon icon-delete has-tooltip" title="{{deleteTooltip}}"></a>' +
- '{{/if}}' +
- ' </div>' +
- ' <form class="newCommentForm">' +
- ' <textarea class="message" placeholder="{{newMessagePlaceholder}}">{{{message}}}</textarea>' +
- ' <input class="submit" type="submit" value="{{submitText}}" />' +
- '{{#if isEditMode}}' +
- ' <input class="cancel" type="button" value="{{cancelText}}" />' +
- '{{/if}}' +
- ' <div class="submitLoading icon-loading-small hidden"></div>'+
- ' </form>' +
- '</div>';
-
- var COMMENT_TEMPLATE =
- '<li class="comment{{#if isUnread}} unread{{/if}}{{#if isLong}} collapsed{{/if}}" data-id="{{id}}">' +
- ' <div class="authorRow">' +
- ' {{#if avatarEnabled}}' +
- ' <div class="avatar" {{#if actorId}}data-username="{{actorId}}"{{/if}}> </div>' +
- ' {{/if}}' +
- ' <div class="author">{{actorDisplayName}}</div>' +
- '{{#if isUserAuthor}}' +
- ' <a href="#" class="action edit icon icon-rename has-tooltip" title="{{editTooltip}}"></a>' +
- '{{/if}}' +
- ' <div class="date has-tooltip" title="{{altDate}}">{{date}}</div>' +
- ' </div>' +
- ' <div class="message">{{{formattedMessage}}}</div>' +
- '{{#if isLong}}' +
- ' <div class="message-overlay"></div>' +
- '{{/if}}' +
- '</li>';
-
- /**
- * @memberof OCA.Comments
- */
- var CommentsTabView = OCA.Files.DetailTabView.extend(
- /** @lends OCA.Comments.CommentsTabView.prototype */ {
- id: 'commentsTabView',
- className: 'tab commentsTabView',
-
- events: {
- 'submit .newCommentForm': '_onSubmitComment',
- 'click .showMore': '_onClickShowMore',
- 'click .action.edit': '_onClickEditComment',
- 'click .action.delete': '_onClickDeleteComment',
- 'click .cancel': '_onClickCloseComment',
- 'click .comment': '_onClickComment'
- },
-
- _commentMaxLength: 1000,
-
- initialize: function() {
- OCA.Files.DetailTabView.prototype.initialize.apply(this, arguments);
- this.collection = new OCA.Comments.CommentCollection();
- this.collection.on('request', this._onRequest, this);
- this.collection.on('sync', this._onEndRequest, this);
- this.collection.on('add', this._onAddModel, this);
-
- this._avatarsEnabled = !!OC.config.enable_avatars;
-
- this._commentMaxThreshold = this._commentMaxLength * 0.9;
-
- // TODO: error handling
- _.bindAll(this, '_onTypeComment');
- },
-
- template: function(params) {
- if (!this._template) {
- this._template = Handlebars.compile(TEMPLATE);
- }
- var currentUser = OC.getCurrentUser();
- return this._template(_.extend({
- avatarEnabled: this._avatarsEnabled,
- 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({
- avatarEnabled: this._avatarsEnabled,
- actorId: currentUser.uid,
- actorDisplayName: currentUser.displayName,
- newMessagePlaceholder: t('comments', 'Type in a new comment...'),
- deleteTooltip: t('comments', 'Delete comment'),
- submitText: t('comments', 'Post'),
- cancelText: t('comments', 'Cancel')
- }, params));
- },
-
- commentTemplate: function(params) {
- if (!this._commentTemplate) {
- this._commentTemplate = Handlebars.compile(COMMENT_TEMPLATE);
- }
-
- params = _.extend({
- avatarEnabled: this._avatarsEnabled,
- editTooltip: t('comments', 'Edit comment'),
- isUserAuthor: OC.getCurrentUser().uid === params.actorId,
- isLong: this._isLong(params.message)
- }, params);
-
- if (params.actorType === 'deleted_users') {
- // makes the avatar a X
- params.actorId = null;
- params.actorDisplayName = t('comments', '[Deleted user]');
- }
-
- return this._commentTemplate(params);
- },
-
- getLabel: function() {
- return t('comments', 'Comments');
- },
-
- setFileInfo: function(fileInfo) {
- if (fileInfo) {
- this.model = fileInfo;
- this.render();
- this.collection.setObjectId(fileInfo.id);
- // reset to first page
- this.collection.reset([], {silent: true});
- this.nextPage();
- } else {
- this.model = null;
- this.render();
- this.collection.reset();
- }
- },
-
- render: function() {
- this.$el.html(this.template({
- emptyResultLabel: t('comments', 'No other comments available'),
- moreLabel: t('comments', 'More comments...')
- }));
- this.$el.find('.comments').before(this.editCommentTemplate({}));
- this.$el.find('.has-tooltip').tooltip();
- this.$container = this.$el.find('ul.comments');
- if (this._avatarsEnabled) {
- this.$el.find('.avatar').avatar(OC.getCurrentUser().uid, 28);
- }
- this.delegateEvents();
- this.$el.find('textarea').on('keyup input change', this._onTypeComment);
- },
-
- _formatItem: function(commentModel) {
- var timestamp = new Date(commentModel.get('creationDateTime')).getTime();
- var data = _.extend({
- date: OC.Util.relativeModifiedDate(timestamp),
- altDate: OC.Util.formatDate(timestamp),
- formattedMessage: this._formatMessage(commentModel.get('message'))
- }, commentModel.attributes);
- return data;
- },
-
- _toggleLoading: function(state) {
- this._loading = state;
- this.$el.find('.loading').toggleClass('hidden', !state);
- },
-
- _onRequest: function(type) {
- if (type === 'REPORT') {
- this._toggleLoading(true);
- this.$el.find('.showMore').addClass('hidden');
- }
- },
-
- _onEndRequest: function(type) {
- var fileInfoModel = this.model;
- this._toggleLoading(false);
- this.$el.find('.empty').toggleClass('hidden', !!this.collection.length);
- this.$el.find('.showMore').toggleClass('hidden', !this.collection.hasMoreResults());
-
- 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);
- }
- }
- );
- }
- },
-
- _onAddModel: function(model, collection, options) {
- var $el = $(this.commentTemplate(this._formatItem(model)));
- if (!_.isUndefined(options.at) && collection.length > 1) {
- this.$container.find('li').eq(options.at).before($el);
- } else {
- this.$container.append($el);
- }
-
- this._postRenderItem($el);
- },
-
- _postRenderItem: function($el) {
- $el.find('.has-tooltip').tooltip();
- if(this._avatarsEnabled) {
- $el.find('.avatar').each(function() {
- var $this = $(this);
- $this.avatar($this.attr('data-username'), 28);
- });
- }
- },
-
- /**
- * Convert a message to be displayed in HTML,
- * converts newlines to <br> tags.
- */
- _formatMessage: function(message) {
- return escapeHTML(message).replace(/\n/g, '<br/>');
- },
-
- nextPage: function() {
- if (this._loading || !this.collection.hasMoreResults()) {
- return;
- }
-
- this.collection.fetchNext();
- },
-
- _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)));
-
- $comment.addClass('hidden').removeClass('collapsed');
- // spawn form
- $comment.after($formRow);
- $formRow.data('commentEl', $comment);
- $formRow.find('textarea').on('keyup input change', this._onTypeComment);
-
- // copy avatar element from original to avoid flickering
- $formRow.find('.avatar').replaceWith($comment.find('.avatar').clone());
- $formRow.find('.has-tooltip').tooltip();
-
- return false;
- },
-
- _onTypeComment: function(ev) {
- var $field = $(ev.target);
- var len = $field.val().length;
- 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');
- }
-
- var limitExceeded = (len > this._commentMaxLength);
- $field.toggleClass('error', limitExceeded);
- $submitButton.prop('disabled', limitExceeded);
- },
-
- _onClickComment: function(ev) {
- var $row = $(ev.target);
- if (!$row.is('.comment')) {
- $row = $row.closest('.comment');
- }
- $row.removeClass('collapsed');
- },
-
- _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');
- var $loading = $comment.find('.submitLoading');
-
- $comment.addClass('disabled');
- $loading.removeClass('hidden');
- this.collection.get(commentId).destroy({
- success: function() {
- $comment.data('commentEl').remove();
- $comment.remove();
- },
- error: function(msg) {
- $loading.addClass('hidden');
- $comment.removeClass('disabled');
- OC.Notification.showTemporary(msg);
- }
- });
-
-
- return false;
- },
-
- _onClickShowMore: function(ev) {
- ev.preventDefault();
- this.nextPage();
- },
-
- _onSubmitComment: function(e) {
- var self = this;
- var $form = $(e.target);
- var commentId = $form.closest('.comment').data('id');
- var currentUser = OC.getCurrentUser();
- var $submit = $form.find('.submit');
- var $loading = $form.find('.submitLoading');
- var $textArea = $form.find('textarea');
- var message = $textArea.val().trim();
- e.preventDefault();
-
- if (!message.length || message.length > this._commentMaxLength) {
- return;
- }
-
- $textArea.prop('disabled', true);
- $submit.addClass('hidden');
- $loading.removeClass('hidden');
-
- if (commentId) {
- // edit mode
- var comment = this.collection.get(commentId);
- comment.save({
- message: $textArea.val()
- }, {
- success: function(model) {
- var $row = $form.closest('.comment');
- $submit.removeClass('hidden');
- $loading.addClass('hidden');
- $row.data('commentEl')
- .removeClass('hidden')
- .find('.message')
- .html(self._formatMessage(model.get('message')));
- $row.remove();
- },
- error: function(msg) {
- $submit.removeClass('hidden');
- $loading.addClass('hidden');
- $textArea.prop('disabled', false);
-
- OC.Notification.showTemporary(msg);
- }
- });
- } else {
- this.collection.create({
- actorId: currentUser.uid,
- actorDisplayName: currentUser.displayName,
- actorType: 'users',
- verb: 'comment',
- message: $textArea.val(),
- creationDateTime: (new Date()).toUTCString()
- }, {
- at: 0,
- // wait for real creation before adding
- wait: true,
- success: function() {
- $submit.removeClass('hidden');
- $loading.addClass('hidden');
- $textArea.val('').prop('disabled', false);
- },
- error: function(msg) {
- $submit.removeClass('hidden');
- $loading.addClass('hidden');
- $textArea.prop('disabled', false);
-
- OC.Notification.showTemporary(msg);
- }
- });
- }
-
- return false;
- },
-
- /**
- * Returns whether the given message is long and needs
- * collapsing
- */
- _isLong: function(message) {
- return message.length > 250 || (message.match(/\n/g) || []).length > 1;
- }
- });
-
- OCA.Comments.CommentsTabView = CommentsTabView;
-})(OC, OCA);
-
diff --git a/apps/comments/js/commentsummarymodel.js b/apps/comments/js/commentsummarymodel.js
deleted file mode 100644
index d405315ca1f..00000000000
--- a/apps/comments/js/commentsummarymodel.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2016
- *
- * This file is licensed under the Affero General Public License version 3
- * or later.
- *
- * See the COPYING-README file.
- *
- */
-
-(function(OC, OCA) {
- var NS_OWNCLOUD = 'http://owncloud.org/ns';
- /**
- * @class OCA.Comments.CommentSummaryModel
- * @classdesc
- *
- * Model containing summary information related to comments
- * like the read marker.
- *
- */
- var CommentSummaryModel = OC.Backbone.Model.extend(
- /** @lends OCA.Comments.CommentSummaryModel.prototype */ {
- sync: OC.Backbone.davSync,
-
- /**
- * Object type
- *
- * @type string
- */
- _objectType: 'files',
-
- /**
- * Object id
- *
- * @type string
- */
- _objectId: null,
-
- davProperties: {
- 'readMarker': '{' + NS_OWNCLOUD + '}readMarker'
- },
-
- /**
- * Initializes the summary model
- *
- * @param {string} [options.objectType] object type
- * @param {string} [options.objectId] object id
- */
- initialize: function(attrs, options) {
- options = options || {};
- if (options.objectType) {
- this._objectType = options.objectType;
- }
- },
-
- url: function() {
- return OC.linkToRemote('dav') + '/comments/' +
- encodeURIComponent(this._objectType) + '/' +
- encodeURIComponent(this.id) + '/';
- }
- });
-
- OCA.Comments.CommentSummaryModel = CommentSummaryModel;
-})(OC, OCA);
-
diff --git a/apps/comments/js/filesplugin.js b/apps/comments/js/filesplugin.js
deleted file mode 100644
index ec201d1d3f7..00000000000
--- a/apps/comments/js/filesplugin.js
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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() {
- var TEMPLATE_COMMENTS_UNREAD =
- '<a class="action action-comment permanent" title="{{countMessage}}" href="#">' +
- '<img class="svg" src="{{iconUrl}}"/>' +
- '</a>';
-
- OCA.Comments = _.extend({}, OCA.Comments);
- if (!OCA.Comments) {
- /**
- * @namespace
- */
- OCA.Comments = {};
- }
-
- /**
- * @namespace
- */
- OCA.Comments.FilesPlugin = {
- ignoreLists: [
- 'files_trashbin',
- 'files.public'
- ],
-
- _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.ignoreLists.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;
- };
- }
- };
-
-})();
-
-OC.Plugins.register('OCA.Files.FileList', OCA.Comments.FilesPlugin);