2018-03-30 17:50:28 +08:00
|
|
|
(function(global) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
global.initPreviewModal = function initPreviewModal() {
|
|
|
|
var name;
|
|
|
|
var url;
|
|
|
|
var downloadUrl;
|
2018-04-04 20:13:37 +08:00
|
|
|
$('.file-preview-link').off('click');
|
2018-03-30 17:50:28 +08:00
|
|
|
$('.file-preview-link').click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
name = $(this).find('p').text();
|
|
|
|
url = $(this).data('preview-url');
|
|
|
|
downloadUrl = $(this).attr('href');
|
|
|
|
openPreviewModal(name, url, downloadUrl);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function openPreviewModal(name, url, downloadUrl) {
|
|
|
|
var modal = $('#filePreviewModal');
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
modal.find('.file-preview-container').empty();
|
|
|
|
modal.find('.file-wopi-controls').empty();
|
|
|
|
if (data.hasOwnProperty('wopi-controls')) {
|
|
|
|
modal.find('.file-wopi-controls').html(data['wopi-controls']);
|
|
|
|
}
|
|
|
|
var link = modal.find('.file-download-link');
|
|
|
|
link.attr('href', downloadUrl);
|
|
|
|
link.attr('data-no-turbolink', true);
|
|
|
|
link.attr('data-status', 'asset-present');
|
|
|
|
if (data['type'] === 'image') {
|
2018-04-24 19:11:55 +08:00
|
|
|
if(data['processing']) {
|
2018-05-16 16:40:49 +08:00
|
|
|
animateSpinner('.file-preview-container', true);
|
2018-04-24 19:11:55 +08:00
|
|
|
} else {
|
2018-05-16 16:40:49 +08:00
|
|
|
animateSpinner('.file-preview-container', false);
|
2018-04-24 19:11:55 +08:00
|
|
|
modal.find('.file-preview-container')
|
|
|
|
.append($('<img>')
|
|
|
|
.attr('src', data['large-preview-url'])
|
|
|
|
.attr('alt', name)
|
|
|
|
.click(function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2018-03-30 17:50:28 +08:00
|
|
|
} else {
|
|
|
|
modal.find('.file-preview-container').html(data['preview-icon']);
|
|
|
|
}
|
2018-04-26 23:00:51 +08:00
|
|
|
if(data['processing']) {
|
|
|
|
checkFileReady(url, modal);
|
|
|
|
}
|
2018-03-30 17:50:28 +08:00
|
|
|
modal.find('.file-name').text(name);
|
2018-06-11 19:03:11 +08:00
|
|
|
modal.find('.preview-close').click(function() {
|
2018-03-30 17:50:28 +08:00
|
|
|
modal.modal('hide');
|
|
|
|
});
|
|
|
|
modal.modal();
|
2019-01-01 01:10:12 +08:00
|
|
|
modal.find('a[disabled=disabled]').click(function(ev){
|
|
|
|
ev.preventDefault();
|
|
|
|
});
|
2018-03-30 17:50:28 +08:00
|
|
|
$('.modal-backdrop').last().css('z-index', modal.css('z-index') - 1);
|
|
|
|
},
|
|
|
|
error: function(ev) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-04-24 19:11:55 +08:00
|
|
|
|
|
|
|
function checkFileReady(url, modal) {
|
|
|
|
$.get(url, function(data) {
|
|
|
|
if(data['processing']) {
|
2018-05-10 15:47:10 +08:00
|
|
|
$('.file-download-link')
|
|
|
|
.addClass('disabled-with-click-events')
|
|
|
|
.attr('title',
|
2018-05-16 16:40:49 +08:00
|
|
|
'<%= I18n.t('general.file.processing')%>')
|
2018-05-10 15:47:10 +08:00
|
|
|
.click(function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
});
|
2018-04-24 19:11:55 +08:00
|
|
|
setTimeout(function() {
|
|
|
|
checkFileReady(url, modal);
|
|
|
|
}, 10000);
|
|
|
|
} else {
|
2018-04-26 23:00:51 +08:00
|
|
|
if(data['type'] === 'image') {
|
|
|
|
modal.find('.file-preview-container').empty();
|
|
|
|
modal.find('.file-preview-container')
|
|
|
|
.append($('<img>')
|
|
|
|
.attr('src', data['large-preview-url'])
|
|
|
|
.attr('alt', data['filename'])
|
|
|
|
.click(function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
modal.find('.file-name').text(data['filename']);
|
|
|
|
modal.find('.modal-body').click(function() {
|
|
|
|
modal.modal('hide');
|
|
|
|
});
|
|
|
|
modal.modal();
|
|
|
|
$('.modal-backdrop').last().css('z-index', modal.css('z-index') - 1);
|
|
|
|
}
|
2018-05-10 15:47:10 +08:00
|
|
|
$('.file-download-link')
|
|
|
|
.removeClass('disabled-with-click-events')
|
|
|
|
.removeAttr('title')
|
|
|
|
.off();
|
2018-04-24 19:11:55 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-03-30 17:50:28 +08:00
|
|
|
})(window);
|