diff --git a/Gemfile b/Gemfile index b485664a4..255b8954a 100644 --- a/Gemfile +++ b/Gemfile @@ -124,3 +124,4 @@ gem "rails_db", "~> 2.4" gem "meta-tags" gem "inline_svg" gem "breadcrumbs_on_rails" +gem "tinymce-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 5627f30fb..41ca6bdea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -582,6 +582,8 @@ GEM thor (1.3.2) tilt (2.4.0) timeout (0.4.1) + tinymce-rails (7.5.1) + railties (>= 3.1.1) turbo-rails (2.0.11) actionpack (>= 6.0.0) railties (>= 6.0.0) @@ -710,6 +712,7 @@ DEPENDENCIES standard (~> 1.0) stimulus-rails tailwindcss-rails (~> 2.0) + tinymce-rails tzinfo-data web-console (>= 4.1.0) webdrivers (~> 5.3.1) diff --git a/app/controllers/account/calculators_controller.rb b/app/controllers/account/calculators_controller.rb index c4d6bb1a5..afadcd9cf 100644 --- a/app/controllers/account/calculators_controller.rb +++ b/app/controllers/account/calculators_controller.rb @@ -81,7 +81,8 @@ def collect_fields_for_kind(kind) def calculator_params params.require(:calculator).permit( - :id, :en_name, :uk_name, + :id, :en_name, :uk_name, :ukranian_additional_notes, + :english_additional_notes, formulas_attributes: [:id, :expression, :en_label, :uk_label, :calculator_id, :en_unit, :uk_unit, :_destroy], fields_attributes: [:id, :en_label, :uk_label, :var_name, :kind, :_destroy, categories_attributes: [:id, :en_name, :uk_name, :price, :_destroy]] diff --git a/app/javascript/controllers/tinymce_controller.js b/app/javascript/controllers/tinymce_controller.js new file mode 100644 index 000000000..7dfe9af84 --- /dev/null +++ b/app/javascript/controllers/tinymce_controller.js @@ -0,0 +1,20 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = ['input'] + + connect() { + tinymce.init(this.tinymceConfig) + } + + disconnect() { + tinymce.remove() + } + + get tinymceConfig() { + return { + target: this.inputTarget, + ...TinyMCERails.configuration.default + } + } +} diff --git a/app/models/calculator.rb b/app/models/calculator.rb index d6e72e586..50c3d2cfa 100644 --- a/app/models/calculator.rb +++ b/app/models/calculator.rb @@ -35,6 +35,17 @@ class Calculator < ApplicationRecord validates :en_name, :uk_name, presence: true validates :en_name, :uk_name, length: { minimum: 3, maximum: 50 } validates :slug, presence: true, uniqueness: true + validates :english_additional_notes, + length: { + maximum: 500, + tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars } + } + + validates :ukranian_additional_notes, + length: { + maximum: 500, + tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars } + } def self.ransackable_attributes(auth_object = nil) ["created_at", "id", "name", "preferable", "slug", "updated_at", "uuid"] diff --git a/app/views/account/calculators/partials/_form.html.erb b/app/views/account/calculators/partials/_form.html.erb index 781d15c5d..1327f9ebe 100644 --- a/app/views/account/calculators/partials/_form.html.erb +++ b/app/views/account/calculators/partials/_form.html.erb @@ -25,6 +25,8 @@ + + <%= render "account/calculators/partials/tinymce_form", f: f %>