From 5766bbfc65e3f6663737da5d15359d68e3f991ff Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Mon, 24 Aug 2015 20:47:27 -0700
Subject: Prevents users from typing more than 4000 characters into any
 'textbox' (posts, comments, and post/comment edits).  Also adds new error
 message for when users hit exactly 4000 characters so they know the limit.

---
 web/react/components/edit_post_modal.jsx | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

(limited to 'web/react/components/edit_post_modal.jsx')

diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx
index 2d865a45d..2dce889f8 100644
--- a/web/react/components/edit_post_modal.jsx
+++ b/web/react/components/edit_post_modal.jsx
@@ -3,6 +3,7 @@
 
 var Client = require('../utils/client.jsx');
 var AsyncClient = require('../utils/async_client.jsx');
+var Constants = require('../utils/constants.jsx');
 var Textbox = require('./textbox.jsx');
 var BrowserStore = require('../stores/browser_store.jsx');
 
@@ -37,7 +38,15 @@ module.exports = React.createClass({
         $(this.state.refocusId).focus();
     },
     handleEditInput: function(editText) {
-        this.setState({ editText: editText });
+        var newError = this.state.error;
+
+        if (!this.state.error && editText.length >= Constants.MAX_POST_LEN) {
+            newError = 'Message length cannot exceed 4000 characters';
+        } else if (this.state.error === 'Message length cannot exceed 4000 characters' && editText.length < Constants.MAX_POST_LEN) {
+            newError = '';
+        }
+
+        this.setState({editText: editText, error: newError});
     },
     handleEditKeyPress: function(e) {
         if (e.which == 13 && !e.shiftKey && !e.altKey) {
@@ -53,7 +62,7 @@ module.exports = React.createClass({
         var self = this;
 
         $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) {
-            self.setState({ editText: "", title: "", channel_id: "", post_id: "", comments: 0, refocusId: "" });
+            self.setState({editText: "", title: "", channel_id: "", post_id: "", comments: 0, refocusId: "", error: ''});
         });
 
         $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) {
@@ -69,7 +78,7 @@ module.exports = React.createClass({
         return { editText: "", title: "", post_id: "", channel_id: "", comments: 0, refocusId: "" };
     },
     render: function() {
-        var error = this.state.error ? <div className='form-group has-error'><label className='control-label'>{ this.state.error }</label></div> : null;
+        var error = this.state.error ? <div className='form-group has-error'><br /><label className='control-label'>{ this.state.error }</label></div> : <div className='form-group'><br /></div>;
 
         return (
             <div className="modal fade edit-modal" ref="modal" id="edit_post" role="dialog" tabIndex="-1" aria-hidden="true">
-- 
cgit v1.2.3-1-g7c22


From 656a88efdd2606ce8449097e740535f41aee9d64 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Tue, 25 Aug 2015 12:47:18 -0700
Subject: Fixed issue with carriage returns being counted improperly in non-ie
 browsers and updated error messages to be appropriate to what is being typed
 (message vs. post vs. edit)

---
 web/react/components/edit_post_modal.jsx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'web/react/components/edit_post_modal.jsx')

diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx
index 2dce889f8..39d058f30 100644
--- a/web/react/components/edit_post_modal.jsx
+++ b/web/react/components/edit_post_modal.jsx
@@ -4,6 +4,7 @@
 var Client = require('../utils/client.jsx');
 var AsyncClient = require('../utils/async_client.jsx');
 var Constants = require('../utils/constants.jsx');
+var utils = require('../utils/utils.jsx');
 var Textbox = require('./textbox.jsx');
 var BrowserStore = require('../stores/browser_store.jsx');
 
@@ -40,9 +41,11 @@ module.exports = React.createClass({
     handleEditInput: function(editText) {
         var newError = this.state.error;
 
-        if (!this.state.error && editText.length >= Constants.MAX_POST_LEN) {
-            newError = 'Message length cannot exceed 4000 characters';
-        } else if (this.state.error === 'Message length cannot exceed 4000 characters' && editText.length < Constants.MAX_POST_LEN) {
+        var len = utils.getLengthOfTextInTextarea(editText);
+
+        if (!this.state.error && len >= Constants.MAX_POST_LEN) {
+            newError = 'New message length cannot exceed 4000 characters';
+        } else if (this.state.error === 'New message length cannot exceed 4000 characters' && len < Constants.MAX_POST_LEN) {
             newError = '';
         }
 
-- 
cgit v1.2.3-1-g7c22


From a56603d666a4f3e22a92a0271eef56ab613ce848 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Wed, 26 Aug 2015 09:38:06 -0700
Subject: Moved duplicate code into functions and added better handling of
 large paste text dumps

---
 web/react/components/edit_post_modal.jsx | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

(limited to 'web/react/components/edit_post_modal.jsx')

diff --git a/web/react/components/edit_post_modal.jsx b/web/react/components/edit_post_modal.jsx
index 39d058f30..8ffd5013a 100644
--- a/web/react/components/edit_post_modal.jsx
+++ b/web/react/components/edit_post_modal.jsx
@@ -39,17 +39,9 @@ module.exports = React.createClass({
         $(this.state.refocusId).focus();
     },
     handleEditInput: function(editText) {
-        var newError = this.state.error;
-
-        var len = utils.getLengthOfTextInTextarea(editText);
-
-        if (!this.state.error && len >= Constants.MAX_POST_LEN) {
-            newError = 'New message length cannot exceed 4000 characters';
-        } else if (this.state.error === 'New message length cannot exceed 4000 characters' && len < Constants.MAX_POST_LEN) {
-            newError = '';
-        }
-
-        this.setState({editText: editText, error: newError});
+        var editMessage = utils.truncateText(editText);
+        var newError = utils.checkMessageLengthError(editMessage, this.state.error, 'New message length cannot exceed ' + Constants.MAX_POST_LEN + ' characters');
+        this.setState({editText: editMessage, error: newError});
     },
     handleEditKeyPress: function(e) {
         if (e.which == 13 && !e.shiftKey && !e.altKey) {
-- 
cgit v1.2.3-1-g7c22

