From 301b37cccd9a704b013a6859493c706735b11403 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 3 Oct 2019 10:55:54 +0200 Subject: [PATCH] Fix duplicate code in file preview --- .../javascripts/sitewide/file_preview.js | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/sitewide/file_preview.js b/app/assets/javascripts/sitewide/file_preview.js index c157c5b1c..b03dc2017 100644 --- a/app/assets/javascripts/sitewide/file_preview.js +++ b/app/assets/javascripts/sitewide/file_preview.js @@ -407,6 +407,14 @@ var FilePreviewModal = (function() { imageBlob = new Blob([blobArray]); + function closeEditor() { + animateSpinner(null, false); + imageEditor.destroy(); + imageEditor = {}; + $('#tui-image-editor').html(''); + $('#fileEditModal').modal('hide'); + } + dataUpload.append('image', imageBlob); animateSpinner(null, true); $.ajax({ @@ -419,37 +427,9 @@ var FilePreviewModal = (function() { $('#modal_link' + data.id).parent().html(res.html); } }).done(function() { - animateSpinner(null, false); - imageEditor.destroy(); - imageEditor = {}; - $('#tui-image-editor').html(''); - $('#fileEditModal').modal('hide'); + closeEditor(); + location.reload(); }); - - if (data.mode === 'tinymce') { - $.ajax({ - type: 'PUT', - url: data.url, - data: dataUpload, - contentType: false, - processData: false, - success: function(res) { - data.image.src = res.url; - } - }).done(function() { closeEditor(); }); - } else { - $.ajax({ - type: 'POST', - url: '/files/' + data.id + '/update_image', - data: dataUpload, - contentType: false, - processData: false, - success: function(res) { - $('#modal_link' + data.id).parent().html(res.html); - Assets.setupAssetsLoading(); - } - }).done(function() { closeEditor(); }); - } if (typeof refreshProtocolStatusBar === 'function') refreshProtocolStatusBar(); });