From 1394b55c54104c9d53b4c91a22e1344a2623da4e Mon Sep 17 00:00:00 2001 From: Alexei Koshelev Date: Wed, 9 Nov 2022 23:43:45 +0300 Subject: [PATCH] Disable textarea button for comments --- apps/common/main/lib/controller/Comments.js | 4 +- .../lib/template/CommentsPopover.template | 2 +- apps/common/main/lib/view/Comments.js | 39 +++++++++++++++++-- apps/common/main/lib/view/ReviewPopover.js | 25 +++++++++++- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 9ec25f9d0..a5578ebea 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -968,11 +968,11 @@ define([ if (!comment) continue; - if (this.subEditStrings[saveTxtId] && !hint) { + if (this.subEditStrings[saveTxtId] && (comment.get('fullInfoInHint') || !hint)) { comment.set('editTextInPopover', true); text = this.subEditStrings[saveTxtId]; } - else if (this.subEditStrings[saveTxtReplyId] && !hint) { + else if (this.subEditStrings[saveTxtReplyId] && (comment.get('fullInfoInHint') || !hint)) { comment.set('showReplyInPopover', true); text = this.subEditStrings[saveTxtReplyId]; } diff --git a/apps/common/main/lib/template/CommentsPopover.template b/apps/common/main/lib/template/CommentsPopover.template index 3e006d6f5..8cc1e3389 100644 --- a/apps/common/main/lib/template/CommentsPopover.template +++ b/apps/common/main/lib/template/CommentsPopover.template @@ -7,7 +7,7 @@
<%= scope.getEncodedName(parsedName) %>
<%=date%>
- <% if (!editTextInPopover || hint || scope.viewmode) { %> + <% if (!editTextInPopover || (hint && !fullInfoInHint) || scope.viewmode) { %>
<%=scope.pickLink(comment)%>
<% } else { %>
diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index 879779f17..6d2573881 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -98,6 +98,17 @@ define([ var text = $(this.el).find('textarea'); return (text && text.length) ? text.val().trim() : ''; }, + disableTextBoxButton: function(textboxEl) { + var button = $(textboxEl.siblings('#id-comments-change')[0]); + + if(textboxEl.val().length > 0) { + button.removeAttr('disabled'); + button.removeClass('disabled'); + } else { + button.attr('disabled', true); + button.addClass('disabled'); + } + }, autoHeightTextBox: function () { var view = this, textBox = $(this.el).find('textarea'), @@ -127,13 +138,19 @@ define([ view.autoScrollToEditButtons(); } + function onTextareaInput(event) { + updateTextBoxHeight(); + view.disableTextBoxButton($(event.target)); + } + if (textBox && textBox.length) { domTextBox = textBox.get(0); + view.disableTextBoxButton(textBox); if (domTextBox) { lineHeight = parseInt(textBox.css('lineHeight'), 10) * 0.25; updateTextBoxHeight(); - textBox.bind('input propertychange', updateTextBoxHeight) + textBox.bind('input propertychange', onTextareaInput) } } @@ -171,7 +188,7 @@ define([ addCommentHeight: 45, newCommentHeight: 110, - textBoxAutoSizeLocked: undefined, // disable autosize textbox + textBoxAutoSizeLocked: undefined, // disable autoHeightTextBoxsize textbox viewmode: false, _commentsViewOnItemClick: function (picker, item, record, e) { @@ -694,7 +711,17 @@ define([ this.layout.setResizeValue(0, container.height() - this.addCommentHeight); } }, + disableTextBoxButton: function(textboxEl) { + var button = $(textboxEl.parent().siblings('.add')[0]); + if(textboxEl.val().length > 0) { + button.removeAttr('disabled'); + button.removeClass('disabled'); + } else { + button.attr('disabled', true); + button.addClass('disabled'); + } + }, autoHeightTextBox: function () { var me = this, domTextBox = null, lineHeight = 0, minHeight = 44; var textBox = $('#comment-msg-new', this.el); @@ -736,9 +763,15 @@ define([ Math.min(height - contentHeight - textBoxMinHeightIndent, height - me.newCommentHeight))); } + function onTextareaInput(event) { + updateTextBoxHeight(); + me.disableTextBoxButton($(event.target)); + } + + me.disableTextBoxButton(textBox); lineHeight = parseInt(textBox.css('lineHeight'), 10) * 0.25; updateTextBoxHeight(); - textBox.bind('input propertychange', updateTextBoxHeight); + textBox.bind('input propertychange', onTextareaInput); this.textBox = textBox; }, diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 86cb533a5..94a6a6e91 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -173,6 +173,17 @@ define([ var text = $(this.el).find('textarea'); return (text && text.length) ? text.val().trim() : ''; }, + disableTextBoxButton: function(textboxEl) { + var button = $(textboxEl.siblings('#id-comments-change-popover')[0]); + + if(textboxEl.val().length > 0) { + button.removeAttr('disabled'); + button.removeClass('disabled'); + } else { + button.attr('disabled', true); + button.addClass('disabled'); + } + }, autoHeightTextBox: function () { var view = this, textBox = this.$el.find('textarea'), @@ -183,6 +194,7 @@ define([ oldHeight = 0, newHeight = 0; + function updateTextBoxHeight() { scrollPos = parentView.scroller.getScrollTop(); if (domTextBox.scrollHeight > domTextBox.clientHeight) { @@ -211,13 +223,20 @@ define([ parentView.autoScrollToEditButtons(); } + function onTextareaInput(event) { + updateTextBoxHeight(); + view.disableTextBoxButton($(event.target)); + } + + if (textBox && textBox.length && parentView.scroller) { domTextBox = textBox.get(0); + view.disableTextBoxButton(textBox); if (domTextBox) { lineHeight = parseInt(textBox.css('lineHeight'), 10) * 0.25; updateTextBoxHeight(); - textBox.bind('input propertychange', updateTextBoxHeight) + textBox.bind('input propertychange', onTextareaInput) } } @@ -519,8 +538,10 @@ define([ }, 'animate:before': function () { var text = me.$window.find('textarea'); - if (text && text.length) + if (text && text.length){ text.focus(); + me.commentsView.disableTextBoxButton(text); + } } }); }