diff --git a/app/assets/javascripts/protocols/import_export/import.js.erb b/app/assets/javascripts/protocols/import_export/import.js.erb index b5270502e..644eb4130 100644 --- a/app/assets/javascripts/protocols/import_export/import.js.erb +++ b/app/assets/javascripts/protocols/import_export/import.js.erb @@ -231,11 +231,13 @@ function importProtocolFromFile( // display tiny_mce_assets in step description function displayTinyMceAssetInDescription(node, folder, stepGuid) { if (node.children('descriptionAssets').length === 0) { - return $(node.children('description')).html(); + var description = node.children('description').html(); + return description.replace(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/, + 'Can\'t import image'); } var description = node.children('description').html(); node.find('descriptionAssets > tinyMceAsset').each(function(i, element) { - var match = '[~tiny_mce_id:' + element.getAttribute('token_id') + ']'; + var match = '[~tiny_mce_id:' + element.getAttribute('tokenId') + ']'; var assetBytes = getAssetBytes(folder, stepGuid, element.getAttribute('fileref')); var image_tag = "" description = description.replace(match, image_tag); // replace the token with image @@ -466,7 +468,7 @@ function importProtocolFromFile( $(this).find("descriptionAssets > tinyMceAsset").each(function() { var tinyMceAsset = {}; var fileRef = $(this).attr("fileRef"); - tinyMceAsset.token_id = $(this).attr('token_id'); + tinyMceAsset.tokenId = $(this).attr('tokenId'); tinyMceAsset.fileType= $(this).children("fileType").text(); tinyMceAsset.bytes = getAssetBytes( protocolFolders[index], diff --git a/app/assets/javascripts/sitewide/tiny_mce.js.erb b/app/assets/javascripts/sitewide/tiny_mce.js.erb index 58cc01325..15b37e66b 100644 --- a/app/assets/javascripts/sitewide/tiny_mce.js.erb +++ b/app/assets/javascripts/sitewide/tiny_mce.js.erb @@ -88,8 +88,10 @@ var TinyMCE = (function() { }, destroyAll: function() { _.each(tinymce.editors, function(editor) { - editor.destroy(); - initHighlightjs(); + if(editor) { + editor.destroy(); + initHighlightjs(); + } }); }, refresh: function() { diff --git a/app/utilities/protocols_exporter.rb b/app/utilities/protocols_exporter.rb index 574371ecd..9caddbbd2 100644 --- a/app/utilities/protocols_exporter.rb +++ b/app/utilities/protocols_exporter.rb @@ -50,7 +50,7 @@ module ProtocolsExporter img_guid = get_guid(img.id) asset_file_name = "rte-#{img_guid}" \ "#{File.extname(img.image_file_name)}" - asset_xml = "\n" asset_xml << "#{img.image_file_name}\n" asset_xml << "#{img.image_content_type}\n" @@ -259,7 +259,7 @@ module ProtocolsExporter eln_xsd << "\n" eln_xsd << "\n" - eln_xsd << "\n" eln_xsd << "\n" diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index ce8276457..5c03b7a83 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -160,7 +160,7 @@ module ProtocolsImporter ) tiny_mce_img.image_content_type = tiny_mce_img_json['fileType'] tiny_mce_img.save! - description.gsub!("[~tiny_mce_id:#{tiny_mce_img_json['token_id']}]", + description.gsub!("[~tiny_mce_id:#{tiny_mce_img_json['tokenId']}]", "[~tiny_mce_id:#{tiny_mce_img.id}]") end @@ -170,7 +170,6 @@ module ProtocolsImporter # handle import from legacy exports def populate_rte_legacy(step_json) return unless step_json['description'] && step_json['description'].present? - regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ - step_json['description'].gsub(regex, '') + step_json['description'].gsub(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/, '') end end diff --git a/app/views/protocols/index/_protocol_preview_modal_body.html.erb b/app/views/protocols/index/_protocol_preview_modal_body.html.erb index cec5aa74d..bbb5912b7 100644 --- a/app/views/protocols/index/_protocol_preview_modal_body.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_body.html.erb @@ -85,7 +85,7 @@ <%= t("protocols.steps.no_description") %> <% else %>
- <%= sanitize_input(step.description) %> + <%= sanitize_input(generate_image_tag_from_token(step.description), ['img']) %>
<% end %>