Simplify TinyMCE assets for MarvinJS

This commit is contained in:
Anton Ignatov 2019-07-19 09:27:03 +02:00
parent bdc2dbbac1
commit ad7130d3b2
4 changed files with 5 additions and 7 deletions

View file

@ -137,7 +137,6 @@ var MarvinJsEditorApi = (function() {
var imgstr = "<img src='" + json.image.url + "'";
imgstr += " width='300' height='300'";
imgstr += " data-mce-token='" + json.image.token + "'";
imgstr += " data-source-id='" + json.image.source_id + "'";
imgstr += " data-source-type='" + json.image.source_type + "'";
imgstr += " alt='description-" + json.image.token + "' />";
return imgstr;

View file

@ -47,7 +47,7 @@ var TinyMCE = (function() {
// Edit link
editLink = editorContainer.find('.tinymce-active-object-handler .file-edit-link');
if (image[0].dataset.sourceId) {
if (image[0].dataset.sourceType) {
editLink.css('display', 'inline-block');
marvinJsEdit = (image[0].dataset.sourceType === 'marvinjs' && typeof (MarvinJsEditor) !== 'undefined');
if (!marvinJsEdit) editLink.css('display', 'none');
@ -55,7 +55,7 @@ var TinyMCE = (function() {
if (marvinJsEdit) {
MarvinJsEditor.open({
mode: 'edit-tinymce',
marvinUrl: '/tiny_mce_assets/' + image[0].dataset.sourceId + '/marvinjs',
marvinUrl: '/tiny_mce_assets/' + image[0].dataset.mceToken + '/marvinjs',
image: image
});
}

View file

@ -39,7 +39,7 @@ class TinyMceAssetsController < ApplicationController
end
def marvinjs_show
asset = current_team.tiny_mce_assets.find_by_id(params[:id])
asset = current_team.tiny_mce_assets.find_by_id(Base62.decode(params[:id]))
return render_404 unless asset
render json: {
@ -55,7 +55,6 @@ class TinyMceAssetsController < ApplicationController
image: {
url: rails_representation_url(result[:asset].preview),
token: Base62.encode(result[:asset].id),
source_id: result[:asset].id,
source_type: result[:asset].image.metadata[:asset_type]
}
}, content_type: 'text/html'
@ -76,7 +75,7 @@ class TinyMceAssetsController < ApplicationController
private
def load_vars
@asset = current_team.tiny_mce_assets.find_by_id(params[:id])
@asset = current_team.tiny_mce_assets.find_by_id(Base62.decode(params[:id]))
return render_404 unless @asset
@assoc ||= @asset.object

View file

@ -29,7 +29,7 @@ class MarvinJsService
def update_sketch(params, current_user)
if params[:object_type] == 'TinyMceAsset'
asset = current_user.current_team.tiny_mce_assets.find(params[:id])
asset = current_user.current_team.tiny_mce_assets.find(Base62.decode(params[:id]))
attachment = asset&.image
else
asset = current_user.current_team.assets.find(params[:id])