diff options
Diffstat (limited to 'apps/comments/js/commentstabview.js')
-rw-r--r-- | apps/comments/js/commentstabview.js | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index 2ab6349d98a..9b75cb4671e 100644 --- a/apps/comments/js/commentstabview.js +++ b/apps/comments/js/commentstabview.js @@ -23,10 +23,11 @@ var EDIT_COMMENT_TEMPLATE = '<div class="newCommentRow comment" data-id="{{id}}">' + ' <div class="authorRow">' + - ' <div class="avatar" data-username="{{actorId}}"></div>' + - ' <div class="author">{{actorDisplayName}}</div>' + + ' <div class="avatar currentUser" data-username="{{actorId}}"></div>' + + ' <div class="author currentUser">{{actorDisplayName}}</div>' + '{{#if isEditMode}}' + ' <a href="#" class="action delete icon icon-delete has-tooltip" title="{{deleteTooltip}}"></a>' + + ' <div class="deleteLoading icon-loading-small hidden"></div>'+ '{{/if}}' + ' </div>' + ' <form class="newCommentForm">' + @@ -42,8 +43,8 @@ var COMMENT_TEMPLATE = '<li class="comment{{#if isUnread}} unread{{/if}}{{#if isLong}} collapsed{{/if}}" data-id="{{id}}">' + ' <div class="authorRow">' + - ' <div class="avatar" {{#if actorId}}data-username="{{actorId}}"{{/if}}> </div>' + - ' <div class="author">{{actorDisplayName}}</div>' + + ' <div class="avatar{{#if isUserAuthor}} currentUser{{/if}}" {{#if actorId}}data-username="{{actorId}}"{{/if}}> </div>' + + ' <div class="author{{#if isUserAuthor}} currentUser{{/if}}">{{actorDisplayName}}</div>' + '{{#if isUserAuthor}}' + ' <a href="#" class="action edit icon icon-rename has-tooltip" title="{{editTooltip}}"></a>' + '{{/if}}' + @@ -214,13 +215,15 @@ searchKey: "label" }); $target.on('inserted.atwho', function (je, $el) { + var editionMode = true; 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( 'div[data-username="' + $el.find('[data-username]').data('username') + '"]' - ).parent() + ).parent(), + editionMode ); }); }, @@ -320,7 +323,7 @@ this.$container.append($comment); } this._postRenderItem($comment); - $('#commentsTabView').find('.newCommentForm div.message').text('').prop('disabled', false); + $('#commentsTabView').find('.newCommentForm div.message').text('').prop('contenteditable', true); // we need to update the model, because it consists of client data // only, but the server might add meta data, e.g. about mentions @@ -377,7 +380,7 @@ }); }, - _postRenderItem: function($el) { + _postRenderItem: function($el, editionMode) { $el.find('.has-tooltip').tooltip(); $el.find('.avatar').each(function() { var $this = $(this); @@ -395,16 +398,23 @@ // it is the case when writing a comment and mentioning a person $message = $el; } - this._postRenderMessage($message); + this._postRenderMessage($message, editionMode); }, - _postRenderMessage: function($el) { + _postRenderMessage: function($el, editionMode) { + if (editionMode) { + return; + } + $el.find('.avatar').each(function() { var avatar = $(this); var strong = $(this).next(); var appendTo = $(this).parent(); - $.merge(avatar, strong).contactsMenu(avatar.data('user'), 0, appendTo); + var username = $(this).data('username'); + if (username !== oc_current_user) { + $.merge(avatar, strong).contactsMenu(avatar.data('user'), 0, appendTo); + } }); }, @@ -445,9 +455,11 @@ + ' data-user-display-name="' + _.escape(displayName) + '"></div>'; + var isCurrentUser = (uid === OC.getCurrentUser().uid); + return '' + '<span class="atwho-inserted" contenteditable="false">' - + '<span class="avatar-name-wrapper">' + + '<span class="avatar-name-wrapper' + (isCurrentUser ? ' currentUser' : '') + '">' + avatar + ' <strong>'+ _.escape(displayName)+'</strong>' + '</span>' + '</span>'; @@ -486,7 +498,8 @@ .html(this._formatMessage(commentToEdit.get('message'), commentToEdit.get('mentions'))) .find('.avatar') .each(function () { $(this).avatar(); }); - this._postRenderItem($message); + var editionMode = true; + this._postRenderItem($message, editionMode); // Enable autosize autosize($formRow.find('.message')); @@ -547,10 +560,17 @@ ev.preventDefault(); var $comment = $(ev.target).closest('.comment'); var commentId = $comment.data('id'); - var $loading = $comment.find('.submitLoading'); - + var $loading = $comment.find('.deleteLoading'); + var $commentField = $comment.find('.message'); + var $submit = $comment.find('.submit'); + var $cancel = $comment.find('.cancel'); + + $commentField.prop('contenteditable', false); + $submit.prop('disabled', true); + $cancel.prop('disabled', true); $comment.addClass('disabled'); $loading.removeClass('hidden'); + this.collection.get(commentId).destroy({ success: function() { $comment.data('commentEl').remove(); @@ -559,6 +579,10 @@ error: function() { $loading.addClass('hidden'); $comment.removeClass('disabled'); + $commentField.prop('contenteditable', true); + $submit.prop('disabled', false); + $cancel.prop('disabled', false); + OC.Notification.showTemporary(t('comments', 'Error occurred while retrieving comment with id {id}', {id: commentId})); } }); @@ -624,7 +648,7 @@ return; } - $commentField.prop('disabled', true); + $commentField.prop('contenteditable', false); $submit.addClass('hidden'); $loading.removeClass('hidden'); @@ -677,7 +701,7 @@ _onSubmitError: function($form, commentId) { $form.find('.submit').removeClass('hidden'); $form.find('.submitLoading').addClass('hidden'); - $form.find('.message').prop('disabled', false); + $form.find('.message').prop('contenteditable', true); if(!_.isUndefined(commentId)) { OC.Notification.show(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}), {type: 'error'}); |