From 4ff4c3718e8334029353d462a797909765b8b857 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Sat, 20 Jul 2024 12:19:40 -0500 Subject: [PATCH] [DText] Explicitly set when color is allowed in preview (#665) --- app/controllers/dtext_previews_controller.rb | 2 +- app/inputs/dtext_input.rb | 2 +- app/javascript/src/javascripts/dtext.js | 9 +++++---- app/javascript/src/javascripts/notes.js | 4 ++-- app/javascript/src/javascripts/uploader/uploader.vue.erb | 2 +- app/views/admin/staff_notes/partials/_new.html.erb | 2 +- app/views/admin/users/edit.html.erb | 4 ++-- app/views/application/_dtext_input.html.erb | 2 +- app/views/artists/_form.html.erb | 2 +- app/views/artists/_show.html.erb | 2 +- app/views/bans/_form.html.erb | 2 +- app/views/dmails/_form.html.erb | 2 +- app/views/news_updates/_form.html.erb | 2 +- app/views/notes/_note.html.erb | 2 +- app/views/pools/edit.html.erb | 2 +- app/views/pools/new.html.erb | 2 +- app/views/post_sets/_form.html.erb | 2 +- app/views/posts/partials/show/_edit.html.erb | 2 +- app/views/user_feedbacks/_form.html.erb | 2 +- app/views/users/edit.html.erb | 4 ++-- app/views/wiki_pages/_form.html.erb | 2 +- 21 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/controllers/dtext_previews_controller.rb b/app/controllers/dtext_previews_controller.rb index 221502baf..f021fe6f6 100644 --- a/app/controllers/dtext_previews_controller.rb +++ b/app/controllers/dtext_previews_controller.rb @@ -3,7 +3,7 @@ class DtextPreviewsController < ApplicationController def create body = params[:body] || "" - dtext = helpers.format_text(body, allow_color: CurrentUser.user.is_privileged?) + dtext = helpers.format_text(body, allow_color: params[:allow_color].to_s.truthy?) render json: { html: dtext, posts: deferred_posts } end end diff --git a/app/inputs/dtext_input.rb b/app/inputs/dtext_input.rb index d68aa564b..16c39f214 100644 --- a/app/inputs/dtext_input.rb +++ b/app/inputs/dtext_input.rb @@ -9,7 +9,7 @@ class DtextInput < SimpleForm::Inputs::TextInput end merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) - @builder.template.render("dtext_input", textarea: super(merged_input_options), limit: @options[:limit]) + @builder.template.render("dtext_input", textarea: super(merged_input_options), limit: @options[:limit], allow_color: @options.key?(:allow_color) ? @options[:allow_color] : CurrentUser.user.is_privileged?) end def input_html_classes diff --git a/app/javascript/src/javascripts/dtext.js b/app/javascript/src/javascripts/dtext.js index ba644c608..c64ba6f65 100644 --- a/app/javascript/src/javascripts/dtext.js +++ b/app/javascript/src/javascripts/dtext.js @@ -6,6 +6,7 @@ DText.initialze_input = function ($element) { const $preview = $(".dtext-formatter-preview", $element); const $textarea = $(".dtext-formatter-input", $element); const $charcount = $(".dtext-formatter-charcount", $element); + const allowColor = $element.attr("data-allow-color") === "true"; // Tab switching $(".dtext-formatter-tabs a", $element).on("click", event => { @@ -13,7 +14,7 @@ DText.initialze_input = function ($element) { if ($element.attr("data-editing") == "true") { $preview.css("min-height", $textarea.outerHeight()); $element.attr("data-editing", "false"); - update_preview($textarea, $preview); + update_preview($textarea, $preview, allowColor); } else { $element.attr("data-editing", "true"); $preview.attr("loading", "false"); @@ -47,7 +48,7 @@ DText.initialize_formatting_buttons = function (element) { }; /** Refreshes the preview field to match the provided input */ -function update_preview (input, preview) { +function update_preview (input, preview, allowColor = false) { const currentText = input.val().trim(); // The input is empty, reset everything @@ -67,9 +68,9 @@ function update_preview (input, preview) { SendQueue.add(() => { $.ajax({ type: "post", - url: "/dtext_preview", + url: "/dtext_preview.json", dataType: "json", - data: { body: currentText }, + data: { body: currentText, allow_color: allowColor }, success: (response) => { // The loading was cancelled, since the user toggled back diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index 3fc88a1c4..fe1b5cc14 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -436,7 +436,7 @@ let Note = { var text = $textarea.val(); $note_body.data("original-body", text); Note.Body.set_text($note_body, $note_box, "Loading..."); - $.post("/dtext_preview.json", {body: text}).then(function (data) { + $.post("/dtext_preview.json", { body: text, allow_color: true }).then(function (data) { Note.Body.set_text($note_body, $note_box, data.html); Note.Box.resize_inner_border($note_box); $note_body.show(); @@ -470,7 +470,7 @@ let Note = { var $note_box = Note.Box.find(id); $note_box.find(".note-box-inner-border").addClass("unsaved"); Note.Body.set_text($note_body, $note_box, "Loading..."); - $.post("/dtext_preview.json", {body: text}).then(function (data) { + $.post("/dtext_preview.json", { body: text, allow_color: true }).then(function (data) { Note.Body.set_text($note_body, $note_box, data.html); $note_body.show(); $(window).trigger("e621:add_deferred_posts", data.posts); diff --git a/app/javascript/src/javascripts/uploader/uploader.vue.erb b/app/javascript/src/javascripts/uploader/uploader.vue.erb index 1fc705fb2..f29d32f1a 100644 --- a/app/javascript/src/javascripts/uploader/uploader.vue.erb +++ b/app/javascript/src/javascripts/uploader/uploader.vue.erb @@ -203,7 +203,7 @@
- <%= ApplicationController.new.render_to_string(partial: "dtext_input", locals: { limit: Danbooru.config.post_descr_max_size, textarea: ''.html_safe }) %> + <%= ApplicationController.new.render_to_string(partial: "dtext_input", locals: { limit: Danbooru.config.post_descr_max_size, textarea: ''.html_safe, allow_color: true }) %>
diff --git a/app/views/admin/staff_notes/partials/_new.html.erb b/app/views/admin/staff_notes/partials/_new.html.erb index 5bc6b16b5..16c723bf2 100644 --- a/app/views/admin/staff_notes/partials/_new.html.erb +++ b/app/views/admin/staff_notes/partials/_new.html.erb @@ -1,6 +1,6 @@ <%= error_messages_for :staff_note %> <%= custom_form_for(staff_note, url: user_staff_notes_path(user_id: user.id), method: :post) do |f| %> - <%= f.input :body, as: :dtext, label: false %> + <%= f.input :body, as: :dtext, label: false, allow_color: true %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 49ee0cff3..42649063e 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -18,8 +18,8 @@ <%= select_tag("user[enable_privacy_mode]", options_for_select([["Yes", true], ["No", false]], @user.enable_privacy_mode?)) %>
- <%= f.input :profile_about, as: :dtext, label: "About", limit: Danbooru.config.user_about_max_size %> - <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size %> + <%= f.input :profile_about, as: :dtext, label: "About", limit: Danbooru.config.user_about_max_size, allow_color: true %> + <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size, allow_color: true %> <%= f.input :base_upload_limit %> <% if CurrentUser.is_bd_staff? || !@user.is_bd_staff? %> diff --git a/app/views/application/_dtext_input.html.erb b/app/views/application/_dtext_input.html.erb index f7af81a3c..fc1349e03 100644 --- a/app/views/application/_dtext_input.html.erb +++ b/app/views/application/_dtext_input.html.erb @@ -1,4 +1,4 @@ -
+
Write Preview diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index b7f13414b..6e394c0d5 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -18,6 +18,6 @@ <% if @artist.is_note_locked? %>

Artist is note locked. Notes cannot be edited.

<% end %> - <%= f.input :notes, as: :dtext, limit: Danbooru.config.wiki_page_max_size, disabled: @artist.is_note_locked? %> + <%= f.input :notes, as: :dtext, limit: Danbooru.config.wiki_page_max_size, disabled: @artist.is_note_locked?, allow_color: true %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/artists/_show.html.erb b/app/views/artists/_show.html.erb index 857ef9b36..6ad252634 100644 --- a/app/views/artists/_show.html.erb +++ b/app/views/artists/_show.html.erb @@ -4,7 +4,7 @@ <% if @artist.notes.present? && @artist.visible? %>
- <%= format_text(@artist.notes) %> + <%= format_text(@artist.notes, allow_color: true) %>

<%= link_to "View wiki page", @artist.wiki_page %>

diff --git a/app/views/bans/_form.html.erb b/app/views/bans/_form.html.erb index afc988b9b..09bdf8f64 100644 --- a/app/views/bans/_form.html.erb +++ b/app/views/bans/_form.html.erb @@ -5,6 +5,6 @@ <% end %> <%= f.input :duration, :hint => "in days" %> <%= f.input :is_permaban, as: :boolean, hint: 'ignores days' %> - <%= f.input :reason, as: :dtext %> + <%= f.input :reason, as: :dtext, allow_color: false %> <%= f.button :submit, :value => "Ban" %> <% end %> diff --git a/app/views/dmails/_form.html.erb b/app/views/dmails/_form.html.erb index b46cd6e08..379e572fc 100644 --- a/app/views/dmails/_form.html.erb +++ b/app/views/dmails/_form.html.erb @@ -2,6 +2,6 @@ <%= custom_form_for(dmail) do |f| %> <%= f.input :to_name, label: "To", autocomplete: "user", input_html: { value: dmail.to.try(:name) } %> <%= f.input :title, as: :string, input_html: { size: 100 } %> - <%= f.input :body, as: :dtext, limit: Danbooru.config.dmail_max_size %> + <%= f.input :body, as: :dtext, limit: Danbooru.config.dmail_max_size, allow_color: false %> <%= f.button :submit, "Send", data: { disable_with: "Sending..." } %> <% end %> diff --git a/app/views/news_updates/_form.html.erb b/app/views/news_updates/_form.html.erb index 748932d0d..80ead755d 100644 --- a/app/views/news_updates/_form.html.erb +++ b/app/views/news_updates/_form.html.erb @@ -1,4 +1,4 @@ <%= custom_form_for(@news_update) do |f| %> - <%= f.input :message, as: :dtext %> + <%= f.input :message, as: :dtext, allow_color: false %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/notes/_note.html.erb b/app/views/notes/_note.html.erb index 4a71447f8..aaa5b4a6f 100644 --- a/app/views/notes/_note.html.erb +++ b/app/views/notes/_note.html.erb @@ -1 +1 @@ -
<%= format_text(note.body) %>
+
<%= format_text(note.body, allow_color: true) %>
diff --git a/app/views/pools/edit.html.erb b/app/views/pools/edit.html.erb index 832637471..d44b2b901 100644 --- a/app/views/pools/edit.html.erb +++ b/app/views/pools/edit.html.erb @@ -6,7 +6,7 @@ <%= error_messages_for "pool" %> <%= f.input :name, :as => :string, :input_html => { :value => @pool.pretty_name } %> - <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> + <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %> <%= f.input :post_ids_string, as: :text, label: "Posts" %> <%= f.input :category, :collection => ["series", "collection"], :include_blank => false %> <%= f.input :is_active %> diff --git a/app/views/pools/new.html.erb b/app/views/pools/new.html.erb index 7661c0dc5..062ab84a4 100644 --- a/app/views/pools/new.html.erb +++ b/app/views/pools/new.html.erb @@ -6,7 +6,7 @@ <%= custom_form_for(@pool) do |f| %> <%= f.input :name, :as => :string, :required => true %> - <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> + <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %> <%= f.input :post_ids_string, as: :text, label: "Posts" %> <%= f.input :category, :collection => ["series", "collection"], :include_blank => true, :selected => "", :required => true %> <%= f.input :is_active %> diff --git a/app/views/post_sets/_form.html.erb b/app/views/post_sets/_form.html.erb index 8c6274a20..f914c44f9 100644 --- a/app/views/post_sets/_form.html.erb +++ b/app/views/post_sets/_form.html.erb @@ -5,7 +5,7 @@ <%= f.input :shortname, label: 'Short Name', as: :string, hint: "The short name is used for the set's metatag name. Can only contain letters, numbers, and underscores and must contain at least one letter or underscore. set:example".html_safe %> - <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> + <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %> <%= f.input :is_public, label: "Public", hint: "Private sets are only visible to you. Public sets are visible to anyone, but only you and users you assign as maintainers can edit the set. Only accounts three days or older can make public sets." %> diff --git a/app/views/posts/partials/show/_edit.html.erb b/app/views/posts/partials/show/_edit.html.erb index e6d6ab698..3b56ff31c 100644 --- a/app/views/posts/partials/show/_edit.html.erb +++ b/app/views/posts/partials/show/_edit.html.erb @@ -42,7 +42,7 @@ <%= f.input :source, as: :text, label: "Sources", input_html: { size: "60x5", spellcheck: false } %>
- <%= f.input :description, as: :dtext, limit: Danbooru.config.post_descr_max_size %> + <%= f.input :description, as: :dtext, limit: Danbooru.config.post_descr_max_size, allow_color: true %>
<% if CurrentUser.is_privileged? %> diff --git a/app/views/user_feedbacks/_form.html.erb b/app/views/user_feedbacks/_form.html.erb index a3a14ee6f..c352ff690 100644 --- a/app/views/user_feedbacks/_form.html.erb +++ b/app/views/user_feedbacks/_form.html.erb @@ -6,6 +6,6 @@ <% unless user_feedback.new_record? %> <%= f.input :send_update_dmail, label: "Send update DMail", as: :boolean %> <% end %> - <%= f.input :body, as: :dtext, limit: Danbooru.config.user_feedback_max_size %> + <%= f.input :body, as: :dtext, limit: Danbooru.config.user_feedback_max_size, allow_color: false %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 89dd2f883..552da41c9 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -34,9 +34,9 @@ <%= f.input :avatar_id, as: :string, label: "Avatar Post ID" %> - <%= f.input :profile_about, as: :dtext, label: "About Me", limit: Danbooru.config.user_about_max_size %> + <%= f.input :profile_about, as: :dtext, label: "About Me", limit: Danbooru.config.user_about_max_size, allow_color: true %> - <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size %> + <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size, allow_color: true %> <%= f.input :time_zone, :include_blank => false %> diff --git a/app/views/wiki_pages/_form.html.erb b/app/views/wiki_pages/_form.html.erb index 28d3ad6d1..b097111fb 100644 --- a/app/views/wiki_pages/_form.html.erb +++ b/app/views/wiki_pages/_form.html.erb @@ -10,7 +10,7 @@

<%= @wiki_page.pretty_title %>

<% end %> - <%= f.input :body, as: :dtext, limit: Danbooru.config.wiki_page_max_size %> + <%= f.input :body, as: :dtext, limit: Danbooru.config.wiki_page_max_size, allow_color: true %> <% if CurrentUser.is_janitor? && @wiki_page.is_deleted? %> <%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %>