Merge pull request #20355 from nextcloud/fix/comments/clear-input/19585

Clear comment on successful post
This commit is contained in:
John Molakvoæ 2020-04-09 13:46:20 +02:00 committed by GitHub
commit 66b743385e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/* eslint-disable */ /* eslint-disable */
/* /**
* Copyright (c) 2016 * Copyright (c) 2016
* *
* This file is licensed under the Affero General Public License version 3 * This file is licensed under the Affero General Public License version 3
@ -264,14 +264,14 @@
}, },
/** /**
* takes care of post-rendering after a new comment was added to the * takes care of post-rendering after a new comment was added to the
* collection * collection
* *
* @param model * @param model
* @param collection * @param collection
* @param options * @param options
* @private * @private
*/ */
_onAddModel: function(model, collection, options) { _onAddModel: function(model, collection, options) {
// we need to render it immediately, to ensure that the right // we need to render it immediately, to ensure that the right
// order of comments is kept on opening comments tab // order of comments is kept on opening comments tab
@ -303,11 +303,11 @@
}, },
/** /**
* takes care of post-rendering after a new comment was edited * takes care of post-rendering after a new comment was edited
* *
* @param model * @param model
* @private * @private
*/ */
_onChangeModel: function(model) { _onChangeModel: function(model) {
if (model.get('message').trim() === model.previous('message').trim()) { if (model.get('message').trim() === model.previous('message').trim()) {
return return
@ -402,9 +402,9 @@
}, },
/** /**
* Convert a message to be displayed in HTML, * Convert a message to be displayed in HTML,
* converts newlines to <br> tags. * converts newlines to <br> tags.
*/ */
_formatMessage: function(message, mentions, editMode) { _formatMessage: function(message, mentions, editMode) {
message = escapeHTML(message).replace(/\n/g, '<br/>') message = escapeHTML(message).replace(/\n/g, '<br/>')
@ -597,9 +597,12 @@
_onSubmitSuccess: function(model, $form) { _onSubmitSuccess: function(model, $form) {
var $submit = $form.find('.submit') var $submit = $form.find('.submit')
var $loading = $form.find('.submitLoading') var $loading = $form.find('.submitLoading')
var $message = $form.find('.message')
$submit.removeClass('hidden') $submit.removeClass('hidden')
$loading.addClass('hidden') $loading.addClass('hidden')
$message.prop('contenteditable', true)
$message.text('')
}, },
_commentBodyHTML2Plain: function($el) { _commentBodyHTML2Plain: function($el) {
@ -651,7 +654,7 @@
message = this._commentBodyHTML2Plain($commentField) message = this._commentBodyHTML2Plain($commentField)
if (commentId) { if (commentId) {
// edit mode // edit mode
var comment = this.collection.get(commentId) var comment = this.collection.get(commentId)
comment.save({ comment.save({
message: message message: message
@ -659,7 +662,7 @@
success: function(model) { success: function(model) {
self._onSubmitSuccess(model, $form) self._onSubmitSuccess(model, $form)
if (model.get('message').trim() === model.previous('message').trim()) { if (model.get('message').trim() === model.previous('message').trim()) {
// model change event doesn't trigger, manually remove the row. // model change event doesn't trigger, manually remove the row.
var $row = $form.closest('.comment') var $row = $form.closest('.comment')
$row.data('commentEl').removeClass('hidden') $row.data('commentEl').removeClass('hidden')
$row.remove() $row.remove()