scinote-web/app/assets/javascripts/sitewide/file_preview.js

161 lines
5.3 KiB
JavaScript
Raw Normal View History

/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
/* eslint no-use-before-define: ["error", { "functions": false }]*/
/* eslint-disable no-underscore-dangle */
/* global Uint8Array fabric tui animateSpinner Assets ActiveStoragePreviews
PerfectScrollbar MarvinJsEditor refreshProtocolStatusBar */
var FilePreviewModal = (function() {
'use strict';
2020-10-19 21:23:34 +08:00
//var readOnly = false;
function initPreviewModal(options = {}) {
2020-10-19 21:23:34 +08:00
$(document).on('click', '.file-preview-link', function(e) {
e.preventDefault();
2020-10-19 21:23:34 +08:00
$.get($(this).data('preview-url'), function(result) {
$('#filePreviewModal .modal-content').html(result.html);
$('#filePreviewModal').modal('show');
})
})
//var name;
//var url;
//var downloadUrl;
//readOnly = options.readOnly;
//return false;
//
//$('.file-preview-link').off('click');
//$('.file-preview-link').click(function(e) {
// if ($(e.target.offsetParent).hasClass('change-preview-type')) return;
// e.preventDefault();
// name = $(this).find('.attachment-label').text();
// url = $(this).data('preview-url');
// downloadUrl = $(this).attr('href');
// openPreviewModal(name, url, downloadUrl);
// return true;
//});
//
//$('#filePreviewModal').find('.preview-close').click(function() {
// $('#filePreviewModal').find('.file-preview-container').html('');
// $('#filePreviewModal').modal('hide');
// if (typeof refreshProtocolStatusBar === 'function') refreshProtocolStatusBar();
//});
}
// Adding rotation icon
function openPreviewModal(name, url, downloadUrl) {
2020-10-19 21:23:34 +08:00
/*
var modal = $('#filePreviewModal');
updateFabricControls();
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
success: function(data) {
var link = modal.find('.file-download-link');
2019-04-29 01:11:41 +08:00
clearPrevieModal();
if (Object.prototype.hasOwnProperty.call(data, 'wopi-controls')) {
modal.find('.file-wopi-controls').html(data['wopi-controls']);
}
link.attr('href', downloadUrl);
link.attr('data-no-turbolink', true);
link.attr('data-status', 'asset-present');
if (data.type === 'previewable') {
animateSpinner('.file-preview-container', false);
2020-08-25 19:22:36 +08:00
if (data['wopi-preview-url']) {
modal.find('.file-preview-container')
.html(`<iframe class="wopi-file-preview" src="${data['wopi-preview-url']}"></iframe>`);
} else {
modal.find('.file-preview-container')
.append($('<img>')
.css('opacity', 0)
.attr('src', data['large-preview-url'])
.attr('alt', name)
.on('error', ActiveStoragePreviews.reCheckPreview)
.on('load', ActiveStoragePreviews.showPreview)
.click(function(ev) {
ev.stopPropagation();
}));
}
if (!readOnly && data.editable) {
modal.find('.file-edit-link').css('display', '');
modal.find('.file-edit-link').off().click(function(ev) {
$.post('/files/' + data.id + '/start_edit_image');
ev.preventDefault();
ev.stopPropagation();
modal.modal('hide');
2020-10-19 21:23:34 +08:00
//preInitImageEditor(data);
});
} else {
modal.find('.file-edit-link').css('display', 'none');
}
2019-07-02 19:15:57 +08:00
} else if (data.type === 'marvinjs') {
openMarvinEditModal(data, modal);
} else {
modal.find('.file-edit-link').css('display', 'none');
modal.find('.file-preview-container').html(data['preview-icon']);
}
if (readOnly) {
modal.find('#wopi_file_edit_button').remove();
}
modal.find('.file-name').text(name);
modal.modal();
modal.find('a[disabled=disabled]').click(function(ev) {
ev.preventDefault();
});
$('.modal-backdrop').last().css('z-index', modal.css('z-index') - 1);
},
error: function() {
// TODO
}
2020-10-19 21:23:34 +08:00
});*/
}
2019-04-29 01:11:41 +08:00
function clearPrevieModal() {
var modal = $('#filePreviewModal');
modal.find('.file-preview-container').empty();
modal.find('.file-wopi-controls').empty();
modal.find('.file-edit-link').css('display', 'none');
}
2019-07-02 19:15:57 +08:00
function openMarvinEditModal(data, modal) {
modal.find('.file-preview-container')
2019-07-02 19:15:57 +08:00
.append($('<img>')
.css('opacity', 0)
2019-07-02 19:15:57 +08:00
.attr('src', data['large-preview-url'])
.attr('alt', data.name)
.on('error', ActiveStoragePreviews.reCheckPreview)
.on('load', ActiveStoragePreviews.showPreview)
2019-07-02 19:15:57 +08:00
.click(function(ev) {
2019-05-02 22:12:25 +08:00
ev.stopPropagation();
2019-07-02 19:15:57 +08:00
}));
if (!readOnly && data.editable) {
modal.find('.file-edit-link').css('display', '');
modal.find('.file-edit-link').off().click(function(ev) {
ev.preventDefault();
ev.stopPropagation();
modal.modal('hide');
$.post(data['update-url'] + '/start_editing');
2019-07-02 19:15:57 +08:00
MarvinJsEditor.open({
mode: 'edit',
data: data.description,
name: data.name,
marvinUrl: data['update-url']
2019-04-29 01:11:41 +08:00
});
2019-07-02 19:15:57 +08:00
});
} else {
modal.find('.file-edit-link').css('display', 'none');
}
}
return Object.freeze({
2020-10-19 21:23:34 +08:00
init: initPreviewModal
});
2020-10-19 21:23:34 +08:00
}());
FilePreviewModal.init();