Remove src when save description and rename token tag

This commit is contained in:
Anton Ignatov 2019-04-02 13:41:32 +02:00
parent fc7400bec9
commit c9f9523210
5 changed files with 12 additions and 13 deletions

View file

@ -263,7 +263,7 @@
function buildHTML(json) {
var imgstr = "<img src='" + json.image.url + "'";
imgstr += " data-token='" + json.image.token + "'";
imgstr += " data-mce-token='" + json.image.token + "'";
imgstr += " alt='description-" + json.image.token + "' />";
return imgstr;
}
@ -298,7 +298,7 @@
var images;
iframe = $('#' + editor.id).prev().find('.mce-edit-area iframe').contents();
images = $.map($('img', iframe), e => {
return e.dataset.token;
return e.dataset.mceToken;
});
$('#' + editor.id).next()[0].value = JSON.stringify(images);
return JSON.stringify(images);

View file

@ -50,7 +50,7 @@ module Api
tiny_mce_asset_params.each do |t|
image_params = t[:attributes]
token = image_params[:file_token]
unless result_text.text["data-token=\"#{token}\""]
unless result_text.text["data-mce-token=\"#{token}\""]
raise ActiveRecord::RecordInvalid,
I18n.t('api.core.errors.result_wrong_tinymce.detail')
end

View file

@ -20,7 +20,7 @@ module TinyMceImages
src='data:image/jpg;base64,#{encoded_tm_asset}' >"
html_description = Nokogiri::HTML(description)
tm_asset_to_update = html_description.css(
"img[data-token=\"#{Base62.encode(tm_asset.id)}\"]"
"img[data-mce-token=\"#{Base62.encode(tm_asset.id)}\"]"
)[0]
tm_asset_to_update.replace new_tm_asset
description = html_description.css('body').inner_html.to_s

View file

@ -59,14 +59,14 @@ class TinyMceAsset < ApplicationRecord
next unless image_to_update.object
old_description = Nokogiri::HTML(image_to_update.object[object_field])
descirption_image = old_description.css(
"img[data-token=\"#{Base62.encode(old_id)}\"]"
description_image = old_description.css(
"img[data-mce-token=\"#{Base62.encode(old_id)}\"]"
)
descirption_image.attr('src').value = image_to_update.url
descirption_image.attr('data-token').value = Base62.encode(new_id)
descirption_image[0]['class'] = 'img-responsive'
new_descirption = old_description.css('body').inner_html.to_s
image_to_update.object.update(object_field => new_descirption)
description_image.attr('src').value = ''
description_image.attr('data-mce-token').value = Base62.encode(new_id)
description_image[0]['class'] = 'img-responsive'
new_description = old_description.css('body').inner_html.to_s
image_to_update.object.update(object_field => new_description)
end
end
@ -74,7 +74,7 @@ class TinyMceAsset < ApplicationRecord
description = Nokogiri::HTML(description)
tm_assets = description.css('img')
tm_assets.each do |tm_asset|
asset_id = tm_asset.attr('data-token')
asset_id = tm_asset.attr('data-mce-token')
new_asset_url = find_by_id(Base62.decode(asset_id))
if new_asset_url
tm_asset.attributes['src'].value = new_asset_url.url

View file

@ -174,7 +174,6 @@ RSpec.describe "Api::V1::ResultsController", type: :request do
experiment_id: @valid_experiment,
task_id: @valid_task
), params: @valid_tinymce_hash_body.to_json, headers: @valid_headers
p response
expect(response).to have_http_status 201
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(