From 3ad1d384ee5b054a7e8eda044e5e4dfec1f06f1b Mon Sep 17 00:00:00 2001
From: ajugo <andrej.jugovic7@gmail.com>
Date: Wed, 5 Apr 2023 15:34:48 +0200
Subject: [PATCH] Raise character limit for rich text fields and reword limit
 text error [SCI-7959] (#5221)

---
 app/assets/javascripts/results/result_texts.js |  1 -
 app/javascript/vue/protocol/container.vue      |  2 +-
 .../vue/protocol/step_elements/text.vue        |  2 +-
 app/javascript/vue/shared/tinymce.vue          | 10 ++--------
 config/initializers/constants.rb               |  2 +-
 config/locales/en.yml                          | 18 ++++++++++++++++++
 6 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/app/assets/javascripts/results/result_texts.js b/app/assets/javascripts/results/result_texts.js
index 55df6bb43..814d48b41 100644
--- a/app/assets/javascripts/results/result_texts.js
+++ b/app/assets/javascripts/results/result_texts.js
@@ -83,7 +83,6 @@
         var data = xhr.responseJSON;
         var $el;
         $form.renderFormErrors('result', data);
-        TinyMCE.highlight();
         if (data['result_text.text']) {
           $el = $form.find(
             'textarea[name=result\\[result_text_attributes\\]\\[text\\]]'
diff --git a/app/javascript/vue/protocol/container.vue b/app/javascript/vue/protocol/container.vue
index 1259a32b9..a1aba2a7a 100644
--- a/app/javascript/vue/protocol/container.vue
+++ b/app/javascript/vue/protocol/container.vue
@@ -76,7 +76,7 @@
                 :objectId="parseInt(protocol.id)"
                 :fieldName="'protocol[description]'"
                 :lastUpdated="protocol.attributes.updated_at"
-                :characterLimit="100000"
+                :characterLimit="1000000"
                 @update="updateDescription"
               />
             </div>
diff --git a/app/javascript/vue/protocol/step_elements/text.vue b/app/javascript/vue/protocol/step_elements/text.vue
index 6d2357f50..a6216d47d 100644
--- a/app/javascript/vue/protocol/step_elements/text.vue
+++ b/app/javascript/vue/protocol/step_elements/text.vue
@@ -26,7 +26,7 @@
       :objectId="element.attributes.orderable.id"
       :fieldName="'step_text[text]'"
       :lastUpdated="element.attributes.orderable.updated_at"
-      :characterLimit="100000"
+      :characterLimit="1000000"
       @update="update"
       @editingDisabled="disableEditMode"
       @editingEnabled="enableEditMode"
diff --git a/app/javascript/vue/shared/tinymce.vue b/app/javascript/vue/shared/tinymce.vue
index 8640fc092..890d97bd9 100644
--- a/app/javascript/vue/shared/tinymce.vue
+++ b/app/javascript/vue/shared/tinymce.vue
@@ -101,14 +101,8 @@
       error() {
         if(this.characterLimit && this.characterCount > this.characterLimit) {
           return(
-            this.i18n.t(
-              'inline_edit.errors.over_limit',
-              {
-                attribute: this.i18n.t('general.text.name'),
-                limit: this.numberWithSpaces(this.characterLimit)
-              }
-            )
-          )
+            this.i18n.t('errors.general_text_too_long')
+          );
         }
 
         return false
diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb
index e4306993a..a31ba97ff 100644
--- a/config/initializers/constants.rb
+++ b/config/initializers/constants.rb
@@ -18,7 +18,7 @@ class Constants
   # Max characters for long text fields
   TEXT_MAX_LENGTH = 10000
   # Max characters for rich text fields (in html format)
-  RICH_TEXT_MAX_LENGTH = 100000
+  RICH_TEXT_MAX_LENGTH = 1000000
   # Max characters for color field (given in HEX format)
   COLOR_MAX_LENGTH = 7
   # Max characters for text in dropdown list element
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 95dbdda2a..9fca81cf0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -158,16 +158,22 @@ en:
               invalid: "Invalid step order."
             name:
               taken: "This protocol template name has to be unique inside a team (this includes the archive)."
+            description:
+              too_long: 'Text is too long'
         step:
           attributes:
             step_orderable_element_order:
               invalid: "Invalid step element order"
+            description:
+              too_long: 'Text is too long'
         my_module:
           attributes:
             my_module_status_id:
               not_correct_order: "Status can be changed only on next or previous status."
             position:
               not_unique: "X and Y position has already been taken by another task in the experiment."
+            description:
+              too_long: 'Text is too long'
         my_module_status:
           attributes:
             next_status:
@@ -211,12 +217,24 @@ en:
               disabled: 'Webhooks are disabled'
             url:
               not_valid: 'Not valid URL'
+        result_text:
+          attributes:
+            text:
+              too_long: 'Text is too long'
+        step_text:
+          attributes:
+            text:
+              too_long: 'Text is too long'
+        system_notification:
+          attributes:
+            modal_body: 'Text is too long'
         connection:
           attributes:
             output_id:
               creates_cycle: "mustn't create cycle"
   errors:
     general: "Something went wrong."
+    general_text_too_long: 'Text is too long'
   storage:
     limit_reached: "Storage limit has been reached."
   helpers: