mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-15 17:33:31 +08:00
Merge pull request #891 from mlorb/ml-sci-1617
Add copying of TinyMce assets when cloning the protocol [SCI-1617]
This commit is contained in:
commit
c46d630f0b
2 changed files with 28 additions and 0 deletions
|
@ -44,6 +44,15 @@ module TinyMceHelper
|
||||||
destroy_removed_tiny_mce_assets(ids, ref)
|
destroy_removed_tiny_mce_assets(ids, ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def replace_tiny_mce_assets(text, img_ids)
|
||||||
|
img_ids.each do |src_id, dest_id|
|
||||||
|
regex = /\[~tiny_mce_id:#{src_id}\]/
|
||||||
|
new_token = "[~tiny_mce_id:#{dest_id}]"
|
||||||
|
text.sub!(regex, new_token)
|
||||||
|
end
|
||||||
|
text
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_removed_tiny_mce_assets(ids, ref)
|
def destroy_removed_tiny_mce_assets(ids, ref)
|
||||||
ref.tiny_mce_assets.where.not('id IN (?)', ids).destroy_all
|
ref.tiny_mce_assets.where.not('id IN (?)', ids).destroy_all
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Protocol < ActiveRecord::Base
|
class Protocol < ActiveRecord::Base
|
||||||
include SearchableModel
|
include SearchableModel
|
||||||
include RenamingUtil
|
include RenamingUtil
|
||||||
|
extend TinyMceHelper
|
||||||
|
|
||||||
after_save :update_linked_children
|
after_save :update_linked_children
|
||||||
after_destroy :decrement_linked_children
|
after_destroy :decrement_linked_children
|
||||||
|
@ -323,6 +324,24 @@ class Protocol < ActiveRecord::Base
|
||||||
table2.team = dest.team
|
table2.team = dest.team
|
||||||
step2.tables << table2
|
step2.tables << table2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Copy tinyMce assets
|
||||||
|
cloned_img_ids = []
|
||||||
|
step.tiny_mce_assets.each do |tiny_img|
|
||||||
|
tiny_img2 = TinyMceAsset.new(
|
||||||
|
image: tiny_img.image,
|
||||||
|
estimated_size: tiny_img.estimated_size,
|
||||||
|
step: step2,
|
||||||
|
team: dest.team
|
||||||
|
)
|
||||||
|
tiny_img2.save
|
||||||
|
|
||||||
|
step2.tiny_mce_assets << tiny_img2
|
||||||
|
cloned_img_ids << [tiny_img.id, tiny_img2.id]
|
||||||
|
end
|
||||||
|
step2.update(
|
||||||
|
description: replace_tiny_mce_assets(step2.description, cloned_img_ids)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Call clone helper
|
# Call clone helper
|
||||||
|
|
Loading…
Reference in a new issue