2019-03-22 16:27:50 +08:00
|
|
|
/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
|
|
|
|
/* eslint no-use-before-define: ["error", { "functions": false }]*/
|
2019-04-26 21:21:01 +08:00
|
|
|
/* eslint-disable no-underscore-dangle */
|
2019-09-24 03:07:03 +08:00
|
|
|
/* global Uint8Array fabric tui animateSpinner Assets ActiveStoragePreviews
|
|
|
|
PerfectScrollbar MarvinJsEditor refreshProtocolStatusBar */
|
2019-07-12 17:34:41 +08:00
|
|
|
|
2019-03-22 16:27:50 +08:00
|
|
|
|
2019-04-02 22:38:53 +08:00
|
|
|
var FilePreviewModal = (function() {
|
2019-03-22 16:27:50 +08:00
|
|
|
'use strict';
|
|
|
|
|
2020-10-19 21:23:34 +08:00
|
|
|
//var readOnly = false;
|
2019-04-02 22:38:53 +08:00
|
|
|
|
|
|
|
function initPreviewModal(options = {}) {
|
2020-10-19 21:23:34 +08:00
|
|
|
$(document).on('click', '.file-preview-link', function(e) {
|
2019-03-22 16:27:50 +08:00
|
|
|
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();
|
|
|
|
//});
|
2019-04-02 22:38:53 +08:00
|
|
|
}
|
2019-03-22 16:27:50 +08:00
|
|
|
|
|
|
|
// Adding rotation icon
|
|
|
|
|
|
|
|
|
|
|
|
function openPreviewModal(name, url, downloadUrl) {
|
2020-10-19 21:23:34 +08:00
|
|
|
|
|
|
|
/*
|
2019-03-22 16:27:50 +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();
|
2019-03-22 16:27:50 +08:00
|
|
|
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');
|
2019-10-01 22:14:28 +08:00
|
|
|
if (data.type === 'previewable') {
|
2019-09-24 03:07:03 +08:00
|
|
|
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();
|
|
|
|
}));
|
|
|
|
}
|
2019-09-24 03:07:03 +08:00
|
|
|
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);
|
2019-09-24 03:07:03 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
modal.find('.file-edit-link').css('display', 'none');
|
2019-03-22 16:27:50 +08:00
|
|
|
}
|
2019-07-02 19:15:57 +08:00
|
|
|
} else if (data.type === 'marvinjs') {
|
|
|
|
openMarvinEditModal(data, modal);
|
2019-03-22 16:27:50 +08:00
|
|
|
} else {
|
2019-04-02 23:45:26 +08:00
|
|
|
modal.find('.file-edit-link').css('display', 'none');
|
2019-03-22 16:27:50 +08:00
|
|
|
modal.find('.file-preview-container').html(data['preview-icon']);
|
|
|
|
}
|
2019-04-02 23:45:26 +08:00
|
|
|
if (readOnly) {
|
|
|
|
modal.find('#wopi_file_edit_button').remove();
|
|
|
|
}
|
2019-03-22 16:27:50 +08:00
|
|
|
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-03-22 16:27:50 +08:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:11:41 +08:00
|
|
|
function clearPrevieModal() {
|
2019-04-27 18:46:45 +08:00
|
|
|
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) {
|
2019-04-27 18:46:45 +08:00
|
|
|
modal.find('.file-preview-container')
|
2019-07-02 19:15:57 +08:00
|
|
|
.append($('<img>')
|
2019-09-24 03:07:03 +08:00
|
|
|
.css('opacity', 0)
|
2019-07-02 19:15:57 +08:00
|
|
|
.attr('src', data['large-preview-url'])
|
2019-07-15 23:17:14 +08:00
|
|
|
.attr('alt', data.name)
|
2019-09-24 03:07:03 +08:00
|
|
|
.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');
|
2019-08-09 15:47:07 +08:00
|
|
|
$.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');
|
|
|
|
}
|
2019-04-27 18:46:45 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 22:38:53 +08:00
|
|
|
return Object.freeze({
|
2020-10-19 21:23:34 +08:00
|
|
|
init: initPreviewModal
|
2019-04-02 22:38:53 +08:00
|
|
|
});
|
2020-10-19 21:23:34 +08:00
|
|
|
}());
|
|
|
|
|
|
|
|
FilePreviewModal.init();
|