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
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]+)\]/,
'<strong>Can\'t import image</strong>');
}
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 = "<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
@ -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],

View file

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

View file

@ -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 = "<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"
asset_xml << "<fileName>#{img.image_file_name}</fileName>\n"
asset_xml << "<fileType>#{img.image_content_type}</fileType>\n"
@ -259,7 +259,7 @@ module ProtocolsExporter
eln_xsd << "<xs:element name=\"fileType\" " \
"type=\"xs:string\"></xs:element>\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"
eln_xsd << "<xs:attribute name=\"guid\" type=\"xs:string\" " \
"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.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

View file

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