mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +08:00
Fix text result creation [SCI-7778]
This commit is contained in:
parent
1ac86b8188
commit
6bddd6c716
2 changed files with 13 additions and 8 deletions
|
@ -138,8 +138,10 @@
|
|||
}
|
||||
|
||||
function processResult(ev, resultTypeEnum) {
|
||||
var textWithoutImages;
|
||||
var $form = $(ev.target.form);
|
||||
$form.clearFormErrors();
|
||||
|
||||
textValidator(ev, $form.find('#result_name'), 0, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
|
||||
|
||||
switch (resultTypeEnum) {
|
||||
|
@ -152,9 +154,11 @@
|
|||
.removeClass(GLOBAL_CONSTANTS.HAS_UNSAVED_DATA_CLASS_NAME);
|
||||
break;
|
||||
case ResultTypeEnum.TEXT:
|
||||
textWithoutImages = TinyMCE.getContent().replaceAll(/src="(data:image\/[^;]+;base64[^"]+)"/i, '');
|
||||
|
||||
textValidator(
|
||||
ev, $form.find('#result_text_attributes_textarea'), 1,
|
||||
$form.data('rich-text-max-length'), false, TinyMCE.getContent()
|
||||
$form.data('rich-text-max-length'), false, textWithoutImages
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -9,8 +9,8 @@ module TinyMceImages
|
|||
class_name: :TinyMceAsset,
|
||||
dependent: :destroy
|
||||
|
||||
before_save :clean_tiny_mce_image_urls
|
||||
before_validation :extract_base64_images
|
||||
before_save :clean_tiny_mce_image_urls
|
||||
|
||||
def prepare_for_report(field, base64_encoded_imgs = false)
|
||||
description = self[field]
|
||||
|
@ -171,16 +171,17 @@ module TinyMceImages
|
|||
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
|
||||
return unless object_field
|
||||
|
||||
text = public_send(object_field)
|
||||
return unless text
|
||||
sanitized_text = public_send(object_field)
|
||||
return unless sanitized_text
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
text.scan(/src="(data:image\/[^;]+;base64[^"]+)"/i).flatten.each do |base64_src|
|
||||
sanitized_text.scan(/src="(data:image\/[^;]+;base64[^"]+)"/i).flatten.each do |base64_src|
|
||||
base64_data = base64_src.split('base64,').last
|
||||
|
||||
tiny_image = TinyMceAsset.create!(
|
||||
team: Team.search_by_object(self),
|
||||
object: self,
|
||||
object_id: id,
|
||||
object_type: self.class.name,
|
||||
saved: true
|
||||
)
|
||||
|
||||
|
@ -191,13 +192,13 @@ module TinyMceImages
|
|||
|
||||
encoded_id = Base62.encode(tiny_image.id)
|
||||
|
||||
text.gsub!(
|
||||
sanitized_text.gsub!(
|
||||
"#{base64_src}\"",
|
||||
"\" data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\""
|
||||
)
|
||||
end
|
||||
|
||||
assign_attributes(object_field => text)
|
||||
assign_attributes(object_field => sanitized_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue