follow @Ducz0r 's suggestions

This commit is contained in:
zmagod 2017-11-24 11:45:07 +01:00
parent afbeafb137
commit d200e355ed
5 changed files with 14 additions and 11 deletions

View file

@ -231,11 +231,13 @@ function importProtocolFromFile(
// display tiny_mce_assets in step description // display tiny_mce_assets in step description
function displayTinyMceAssetInDescription(node, folder, stepGuid) { function displayTinyMceAssetInDescription(node, folder, stepGuid) {
if (node.children('descriptionAssets').length === 0) { 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]+)\]/,
'<strong>Can\'t import image</strong>');
} }
var description = node.children('description').html(); var description = node.children('description').html();
node.find('descriptionAssets > tinyMceAsset').each(function(i, element) { 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 assetBytes = getAssetBytes(folder, stepGuid, element.getAttribute('fileref'));
var image_tag = "<img style='max-width:300px; max-height:300px;' src='data:" + element.children[1].innerHTML + ";base64," + assetBytes + "' />" var image_tag = "<img style='max-width:300px; max-height:300px;' src='data:" + element.children[1].innerHTML + ";base64," + assetBytes + "' />"
description = description.replace(match, image_tag); // replace the token with image description = description.replace(match, image_tag); // replace the token with image
@ -466,7 +468,7 @@ function importProtocolFromFile(
$(this).find("descriptionAssets > tinyMceAsset").each(function() { $(this).find("descriptionAssets > tinyMceAsset").each(function() {
var tinyMceAsset = {}; var tinyMceAsset = {};
var fileRef = $(this).attr("fileRef"); var fileRef = $(this).attr("fileRef");
tinyMceAsset.token_id = $(this).attr('token_id'); tinyMceAsset.tokenId = $(this).attr('tokenId');
tinyMceAsset.fileType= $(this).children("fileType").text(); tinyMceAsset.fileType= $(this).children("fileType").text();
tinyMceAsset.bytes = getAssetBytes( tinyMceAsset.bytes = getAssetBytes(
protocolFolders[index], protocolFolders[index],

View file

@ -88,8 +88,10 @@ var TinyMCE = (function() {
}, },
destroyAll: function() { destroyAll: function() {
_.each(tinymce.editors, function(editor) { _.each(tinymce.editors, function(editor) {
editor.destroy(); if(editor) {
initHighlightjs(); editor.destroy();
initHighlightjs();
}
}); });
}, },
refresh: function() { refresh: function() {

View file

@ -50,7 +50,7 @@ module ProtocolsExporter
img_guid = get_guid(img.id) img_guid = get_guid(img.id)
asset_file_name = "rte-#{img_guid}" \ asset_file_name = "rte-#{img_guid}" \
"#{File.extname(img.image_file_name)}" "#{File.extname(img.image_file_name)}"
asset_xml = "<tinyMceAsset token_id=\"#{match[1]}\" id=\"#{img.id}\" guid=\"#{img_guid}\" " \ asset_xml = "<tinyMceAsset tokenId=\"#{match[1]}\" id=\"#{img.id}\" guid=\"#{img_guid}\" " \
"fileRef=\"#{asset_file_name}\">\n" "fileRef=\"#{asset_file_name}\">\n"
asset_xml << "<fileName>#{img.image_file_name}</fileName>\n" asset_xml << "<fileName>#{img.image_file_name}</fileName>\n"
asset_xml << "<fileType>#{img.image_content_type}</fileType>\n" asset_xml << "<fileType>#{img.image_content_type}</fileType>\n"
@ -259,7 +259,7 @@ module ProtocolsExporter
eln_xsd << "<xs:element name=\"fileType\" " \ eln_xsd << "<xs:element name=\"fileType\" " \
"type=\"xs:string\"></xs:element>\n" "type=\"xs:string\"></xs:element>\n"
eln_xsd << "</xs:all>\n" eln_xsd << "</xs:all>\n"
eln_xsd << "<xs:attribute name=\"id\" type=\"xs:int\" " \ eln_xsd << "<xs:attribute tokenId=\"xs:string\" name=\"id\" type=\"xs:int\" " \
"use=\"required\"></xs:attribute>\n" "use=\"required\"></xs:attribute>\n"
eln_xsd << "<xs:attribute name=\"guid\" type=\"xs:string\" " \ eln_xsd << "<xs:attribute name=\"guid\" type=\"xs:string\" " \
"use=\"required\"></xs:attribute>\n" "use=\"required\"></xs:attribute>\n"

View file

@ -160,7 +160,7 @@ module ProtocolsImporter
) )
tiny_mce_img.image_content_type = tiny_mce_img_json['fileType'] tiny_mce_img.image_content_type = tiny_mce_img_json['fileType']
tiny_mce_img.save! 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}]") "[~tiny_mce_id:#{tiny_mce_img.id}]")
end end
@ -170,7 +170,6 @@ module ProtocolsImporter
# handle import from legacy exports # handle import from legacy exports
def populate_rte_legacy(step_json) def populate_rte_legacy(step_json)
return unless step_json['description'] && step_json['description'].present? return unless step_json['description'] && step_json['description'].present?
regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ step_json['description'].gsub(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/, '')
step_json['description'].gsub(regex, '')
end end
end end

View file

@ -85,7 +85,7 @@
<em><%= t("protocols.steps.no_description") %></em> <em><%= t("protocols.steps.no_description") %></em>
<% else %> <% else %>
<div class="ql-editor"> <div class="ql-editor">
<%= sanitize_input(step.description) %> <%= sanitize_input(generate_image_tag_from_token(step.description), ['img']) %>
</div> </div>
<% end %> <% end %>
</div> </div>