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-06-14 22:15:30 +08:00
|
|
|
/* global Uint8Array fabric tui animateSpinner */
|
|
|
|
/* global Assets I18n PerfectScrollbar refreshProtocolStatusBar */
|
2019-03-22 16:27:50 +08:00
|
|
|
//= require assets
|
|
|
|
|
2019-04-02 22:38:53 +08:00
|
|
|
var FilePreviewModal = (function() {
|
2019-03-22 16:27:50 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-02 22:38:53 +08:00
|
|
|
var readOnly = false;
|
2019-05-21 23:29:33 +08:00
|
|
|
var CHECK_READY_DELAY = 5000;
|
|
|
|
var CHECK_READY_TRIES_LIMIT = 60;
|
|
|
|
var checkReadyCntr;
|
2019-04-02 22:38:53 +08:00
|
|
|
|
|
|
|
function initPreviewModal(options = {}) {
|
2019-03-22 16:27:50 +08:00
|
|
|
var name;
|
|
|
|
var url;
|
|
|
|
var downloadUrl;
|
2019-04-02 22:38:53 +08:00
|
|
|
readOnly = options.readOnly;
|
|
|
|
|
2019-03-22 16:27:50 +08:00
|
|
|
$('.file-preview-link').off('click');
|
|
|
|
$('.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);
|
|
|
|
});
|
2019-04-02 22:38:53 +08:00
|
|
|
}
|
2019-03-22 16:27:50 +08:00
|
|
|
|
|
|
|
// Adding rotation icon
|
|
|
|
function updateFabricControls() {
|
|
|
|
fabric.Object.prototype.drawBorders = function(ctx, styleOverride = {}) {
|
|
|
|
var wh = this._calculateCurrentDimensions();
|
|
|
|
var strokeWidth = 1 / this.borderScaleFactor;
|
|
|
|
var width = wh.x + strokeWidth;
|
|
|
|
var height = wh.y + strokeWidth;
|
|
|
|
var drawRotatingPoint = typeof styleOverride.hasRotatingPoint !== 'undefined'
|
|
|
|
? styleOverride.hasRotatingPoint : this.hasRotatingPoint;
|
|
|
|
var hasControls = typeof styleOverride.hasControls !== 'undefined'
|
|
|
|
? styleOverride.hasControls : this.hasControls;
|
|
|
|
var rotatingPointOffset = typeof styleOverride.rotatingPointOffset !== 'undefined'
|
|
|
|
? styleOverride.rotatingPointOffset : this.rotatingPointOffset;
|
|
|
|
var rotateHeight = -height / 2;
|
|
|
|
ctx.save();
|
|
|
|
ctx.strokeStyle = styleOverride.borderColor || this.borderColor;
|
|
|
|
this._setLineDash(ctx, styleOverride.borderDashArray || this.borderDashArray, null);
|
|
|
|
ctx.strokeRect(
|
|
|
|
-width / 2,
|
|
|
|
-height / 2,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
|
|
|
if (drawRotatingPoint && this.isControlVisible('mtr') && hasControls) {
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(0, rotateHeight);
|
|
|
|
ctx.lineTo(0, rotateHeight - rotatingPointOffset + 10);
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
fabric.Object.prototype.drawControls = function(ctx) {
|
|
|
|
var rotationImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAHEklEQVRoge2bYYgdVxXHf/8lhGUJYQ1hKSFIiDXUEoq+e1lClLgfRLSGfNGSVvxgVIyiIqGWEhfpp6IBayiSBJQiQo3YKEQqsQSpmkopYWYJIUSIEkrYhhiWEEIoyxLe3w8zb53Mm/fezNvdlhf7h8feeTv3zvnPPffcc885T8b8P2Hs/RbgvcYHhB90rFurgWOIY8A4sNN2S9JHbG+VtBEYt70E3AFuSvoXcDH/3E7SpL1WcqnKaMUQ1wFjSZosNR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AcZoxbxWDE+IPyg47+vLtaj5o1LZgAAAABJRU5ErkJggg==';
|
|
|
|
var rotate = new Image();
|
|
|
|
var rotateLeft;
|
|
|
|
var rotateTop;
|
|
|
|
var wh = this._calculateCurrentDimensions();
|
|
|
|
var width = wh.x;
|
|
|
|
var height = wh.y;
|
|
|
|
var scaleOffset = this.cornerSize;
|
|
|
|
var left = -(width + scaleOffset) / 2;
|
|
|
|
var top = -(height + scaleOffset) / 2;
|
|
|
|
var methodName = this.transparentCorners ? 'stroke' : 'fill';
|
|
|
|
|
|
|
|
if (!this.hasControls) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
ctx.save();
|
|
|
|
ctx.strokeStyle = this.cornerColor;
|
|
|
|
ctx.fillStyle = this.cornerColor;
|
|
|
|
if (!this.transparentCorners) {
|
|
|
|
ctx.strokeStyle = this.cornerStrokeColor;
|
|
|
|
}
|
|
|
|
this._setLineDash(ctx, this.cornerDashArray, null);
|
|
|
|
|
|
|
|
// top-left
|
|
|
|
this._drawControl(
|
|
|
|
'tl',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left,
|
|
|
|
top
|
|
|
|
);
|
|
|
|
|
|
|
|
// top-right
|
|
|
|
this._drawControl(
|
|
|
|
'tr',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left + width,
|
|
|
|
top
|
|
|
|
);
|
|
|
|
|
|
|
|
// bottom-left
|
|
|
|
this._drawControl(
|
|
|
|
'bl',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left,
|
|
|
|
top + height
|
|
|
|
);
|
|
|
|
|
|
|
|
// bottom-right
|
|
|
|
this._drawControl(
|
|
|
|
'br',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left + width,
|
|
|
|
top + height
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!this.get('lockUniScaling')) {
|
|
|
|
// middle-top
|
|
|
|
this._drawControl(
|
|
|
|
'mt',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left + width / 2,
|
|
|
|
top
|
|
|
|
);
|
|
|
|
|
|
|
|
// middle-bottom
|
|
|
|
this._drawControl(
|
|
|
|
'mb',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left + width / 2,
|
|
|
|
top + height
|
|
|
|
);
|
|
|
|
|
|
|
|
// middle-right
|
|
|
|
this._drawControl(
|
|
|
|
'mr',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left + width,
|
|
|
|
top + height / 2
|
|
|
|
);
|
|
|
|
|
|
|
|
// middle-left
|
|
|
|
this._drawControl(
|
|
|
|
'ml',
|
|
|
|
ctx,
|
|
|
|
methodName,
|
|
|
|
left,
|
|
|
|
top + height / 2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// middle-top-rotate
|
|
|
|
if (this.hasRotatingPoint) {
|
|
|
|
rotate.src = rotationImage;
|
|
|
|
rotateLeft = left + width / 2 - 6;
|
|
|
|
rotateTop = top - this.rotatingPointOffset - 6;
|
|
|
|
ctx.drawImage(rotate, rotateLeft, rotateTop, 32, 32);
|
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-24 13:06:05 +08:00
|
|
|
function preInitImageEditor(data) {
|
|
|
|
$.ajax({
|
|
|
|
url: data['download-url'],
|
|
|
|
type: 'get',
|
|
|
|
success: function(responseData) {
|
|
|
|
var fileUrl = responseData;
|
|
|
|
initImageEditor(data, fileUrl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initImageEditor(data, fileUrl) {
|
2019-03-22 16:27:50 +08:00
|
|
|
var imageEditor;
|
2019-04-26 21:21:01 +08:00
|
|
|
var ps;
|
2019-03-22 16:27:50 +08:00
|
|
|
var blackTheme = {
|
|
|
|
'common.bi.image': '',
|
|
|
|
'common.bisize.width': '0',
|
|
|
|
'common.bisize.height': '0',
|
|
|
|
'common.backgroundImage': 'none',
|
|
|
|
'common.backgroundColor': '#1e1e1e',
|
|
|
|
'common.border': '0px',
|
|
|
|
|
|
|
|
// header
|
|
|
|
'header.backgroundImage': 'none',
|
|
|
|
'header.backgroundColor': 'transparent',
|
|
|
|
'header.border': '0px',
|
|
|
|
|
|
|
|
// load button
|
|
|
|
'loadButton.backgroundColor': '#fff',
|
|
|
|
'loadButton.border': '1px solid #ddd',
|
|
|
|
'loadButton.color': '#222',
|
|
|
|
'loadButton.fontFamily': '\'Noto Sans\', sans-serif',
|
|
|
|
'loadButton.fontSize': '12px',
|
|
|
|
|
|
|
|
// download button
|
|
|
|
'downloadButton.backgroundColor': '#fdba3b',
|
|
|
|
'downloadButton.border': '1px solid #fdba3b',
|
|
|
|
'downloadButton.color': '#fff',
|
|
|
|
'downloadButton.fontFamily': '\'Noto Sans\', sans-serif',
|
|
|
|
'downloadButton.fontSize': '12px',
|
|
|
|
|
|
|
|
// main icons
|
|
|
|
'menu.normalIcon.path': '/images/icon-d.svg',
|
|
|
|
'menu.normalIcon.name': 'icon-d',
|
|
|
|
'menu.activeIcon.path': '/images/icon-b.svg',
|
|
|
|
'menu.activeIcon.name': 'icon-b',
|
|
|
|
'menu.disabledIcon.path': '/images/icon-a.svg',
|
|
|
|
'menu.disabledIcon.name': 'icon-a',
|
|
|
|
'menu.hoverIcon.path': '/images/icon-c.svg',
|
|
|
|
'menu.hoverIcon.name': 'icon-c',
|
|
|
|
'menu.iconSize.width': '24px',
|
|
|
|
'menu.iconSize.height': '24px',
|
|
|
|
|
|
|
|
// submenu primary color
|
|
|
|
'submenu.backgroundColor': '#1e1e1e',
|
|
|
|
'submenu.partition.color': '#3c3c3c',
|
|
|
|
|
|
|
|
// submenu icons
|
|
|
|
'submenu.normalIcon.path': '/images/icon-d.svg',
|
|
|
|
'submenu.normalIcon.name': 'icon-d',
|
|
|
|
'submenu.activeIcon.path': '/images/icon-c.svg',
|
|
|
|
'submenu.activeIcon.name': 'icon-c',
|
|
|
|
'submenu.iconSize.width': '32px',
|
|
|
|
'submenu.iconSize.height': '32px',
|
|
|
|
|
|
|
|
// submenu labels
|
|
|
|
'submenu.normalLabel.color': '#8a8a8a',
|
|
|
|
'submenu.normalLabel.fontWeight': 'lighter',
|
|
|
|
'submenu.activeLabel.color': '#fff',
|
|
|
|
'submenu.activeLabel.fontWeight': 'lighter',
|
|
|
|
|
|
|
|
// checkbox style
|
|
|
|
'checkbox.border': '0px',
|
|
|
|
'checkbox.backgroundColor': '#fff',
|
|
|
|
|
|
|
|
// range style
|
|
|
|
'range.pointer.color': '#fff',
|
|
|
|
'range.bar.color': '#666',
|
|
|
|
'range.subbar.color': '#d1d1d1',
|
|
|
|
|
|
|
|
'range.disabledPointer.color': '#414141',
|
|
|
|
'range.disabledBar.color': '#282828',
|
|
|
|
'range.disabledSubbar.color': '#414141',
|
|
|
|
|
|
|
|
'range.value.color': '#fff',
|
|
|
|
'range.value.fontWeight': 'lighter',
|
|
|
|
'range.value.fontSize': '11px',
|
|
|
|
'range.value.border': '1px solid #353535',
|
|
|
|
'range.value.backgroundColor': '#151515',
|
|
|
|
'range.title.color': '#fff',
|
|
|
|
'range.title.fontWeight': 'lighter',
|
|
|
|
|
|
|
|
// colorpicker style
|
|
|
|
'colorpicker.button.border': '1px solid #1e1e1e',
|
|
|
|
'colorpicker.title.color': '#fff'
|
|
|
|
};
|
|
|
|
|
2019-07-23 21:02:33 +08:00
|
|
|
animateSpinner(null, true);
|
2019-03-22 16:27:50 +08:00
|
|
|
imageEditor = new tui.ImageEditor('#tui-image-editor', {
|
|
|
|
includeUI: {
|
|
|
|
loadImage: {
|
2019-07-24 13:06:05 +08:00
|
|
|
path: fileUrl,
|
2019-03-22 16:27:50 +08:00
|
|
|
name: data.filename
|
|
|
|
},
|
|
|
|
theme: blackTheme,
|
|
|
|
initMenu: 'draw',
|
|
|
|
menuBarPosition: 'bottom'
|
|
|
|
},
|
2019-04-26 21:21:01 +08:00
|
|
|
cssMaxWidth: 700,
|
2019-04-18 15:11:27 +08:00
|
|
|
cssMaxHeight: 500,
|
2019-03-22 16:27:50 +08:00
|
|
|
selectionStyle: {
|
|
|
|
cornerSize: 20,
|
|
|
|
rotatingPointOffset: 70,
|
|
|
|
borderColor: '#333',
|
|
|
|
cornerColor: '#333',
|
|
|
|
cornerStyle: 'circle',
|
|
|
|
borderScaleFactor: 3
|
|
|
|
|
|
|
|
},
|
|
|
|
usageStatistics: false
|
|
|
|
});
|
2019-04-26 21:21:01 +08:00
|
|
|
|
2019-04-09 15:07:58 +08:00
|
|
|
imageEditor.on('image_loaded', () => {
|
|
|
|
$('.file-save-link').css('display', '');
|
2019-07-23 21:02:33 +08:00
|
|
|
animateSpinner(null, false);
|
2019-04-09 15:07:58 +08:00
|
|
|
});
|
2019-04-26 21:21:01 +08:00
|
|
|
|
|
|
|
ps = new PerfectScrollbar($('.tui-image-editor-wrap')[0], { wheelSpeed: 0.5 });
|
|
|
|
$('#tui-image-editor .tui-image-editor').on('mousewheel', (e) => {
|
|
|
|
var imageOriginalSize = {
|
|
|
|
width: imageEditor._graphics.canvasImage.width,
|
|
|
|
height: imageEditor._graphics.canvasImage.height
|
|
|
|
};
|
|
|
|
var wDelta = e.originalEvent.wheelDelta || e.originalEvent.deltaY;
|
2019-04-15 15:49:44 +08:00
|
|
|
var imageEditorWindow = e.currentTarget;
|
2019-04-26 21:21:01 +08:00
|
|
|
var scrollContainer = $('.tui-image-editor-wrap');
|
2019-04-15 15:49:44 +08:00
|
|
|
var initWidth = imageEditorWindow.style.width;
|
|
|
|
var initHeight = imageEditorWindow.style.height;
|
2019-04-26 21:21:01 +08:00
|
|
|
|
|
|
|
var scrollContainerInitial = {
|
|
|
|
top: scrollContainer.scrollTop(),
|
|
|
|
left: scrollContainer.scrollLeft(),
|
|
|
|
height: scrollContainer[0].scrollHeight,
|
|
|
|
width: scrollContainer[0].scrollWidth
|
|
|
|
};
|
|
|
|
|
|
|
|
var mousePosition = {
|
2019-05-13 17:01:39 +08:00
|
|
|
top: e.clientY - (imageEditorWindow.offsetTop - scrollContainerInitial.top),
|
2019-04-26 21:21:01 +08:00
|
|
|
left: e.clientX - $(imageEditorWindow).offset().left
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-15 15:49:44 +08:00
|
|
|
var newWidth;
|
|
|
|
var newHeight;
|
2019-04-26 21:21:01 +08:00
|
|
|
var offsetY;
|
|
|
|
var offsetX;
|
2019-04-15 15:49:44 +08:00
|
|
|
if (wDelta > 0) {
|
|
|
|
newWidth = parseInt(initWidth, 10) * 1.1;
|
|
|
|
newHeight = parseInt(initHeight, 10) * 1.1;
|
2019-04-26 21:21:01 +08:00
|
|
|
if (newWidth > imageOriginalSize.width || newHeight > imageOriginalSize.height) {
|
|
|
|
newWidth = imageOriginalSize.width;
|
|
|
|
newHeight = imageOriginalSize.height;
|
|
|
|
}
|
2019-04-15 15:49:44 +08:00
|
|
|
} else {
|
|
|
|
newWidth = parseInt(initWidth, 10) * 0.9;
|
|
|
|
newHeight = parseInt(initHeight, 10) * 0.9;
|
2019-04-26 21:21:01 +08:00
|
|
|
if (parseInt(imageEditorWindow.dataset.minWidth, 10) * 0.5 > parseInt(newWidth, 10)) {
|
|
|
|
newWidth = parseInt(imageEditorWindow.dataset.minWidth, 10) * 0.5;
|
|
|
|
newHeight = parseInt(imageEditorWindow.dataset.minHeight, 10) * 0.5;
|
|
|
|
}
|
2019-04-15 15:49:44 +08:00
|
|
|
}
|
|
|
|
imageEditorWindow.style.width = newWidth + 'px';
|
|
|
|
imageEditorWindow.style.height = newHeight + 'px';
|
|
|
|
$(imageEditorWindow).find('canvas, .tui-image-editor-canvas-container')
|
|
|
|
.css('max-width', imageEditorWindow.style.width)
|
|
|
|
.css('max-height', imageEditorWindow.style.height);
|
|
|
|
if (imageEditorWindow.dataset.minHeight === undefined) {
|
|
|
|
imageEditorWindow.dataset.minHeight = initHeight;
|
|
|
|
imageEditorWindow.dataset.minWidth = initWidth;
|
|
|
|
}
|
2019-04-26 21:21:01 +08:00
|
|
|
|
|
|
|
offsetY = (scrollContainer[0].scrollHeight - scrollContainerInitial.height)
|
|
|
|
* (mousePosition.top / scrollContainerInitial.height);
|
|
|
|
offsetX = (scrollContainer[0].scrollWidth - scrollContainerInitial.width)
|
|
|
|
* (mousePosition.left / scrollContainerInitial.width);
|
|
|
|
|
|
|
|
scrollContainer.scrollTop(scrollContainerInitial.top + offsetY);
|
|
|
|
scrollContainer.scrollLeft(scrollContainerInitial.left + offsetX);
|
|
|
|
|
|
|
|
ps.update();
|
|
|
|
|
2019-04-15 15:49:44 +08:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2019-04-26 21:21:01 +08:00
|
|
|
$('.tui-image-editor-wrap')[0].onwheel = function() { return false; };
|
|
|
|
$('.tui-image-editor-wrap').css('height', 'calc(100% - 150px)');
|
2019-03-22 16:27:50 +08:00
|
|
|
|
|
|
|
$('#fileEditModal').find('.file-name').text('Editing: ' + data.filename);
|
|
|
|
$('#fileEditModal').modal('show');
|
|
|
|
|
|
|
|
$('.tui-image-editor-header').hide();
|
|
|
|
|
2019-04-09 15:07:58 +08:00
|
|
|
$('.file-save-link').css('display', 'none');
|
2019-03-22 16:27:50 +08:00
|
|
|
$('.file-save-link').off().click(function(ev) {
|
2019-04-03 22:31:56 +08:00
|
|
|
var imageBlob;
|
|
|
|
var imageDataURL;
|
2019-04-15 15:49:44 +08:00
|
|
|
var imageParams;
|
2019-03-22 16:27:50 +08:00
|
|
|
var dataUpload = new FormData();
|
2019-04-03 22:31:56 +08:00
|
|
|
var blobArray;
|
|
|
|
var bytePosition;
|
|
|
|
|
2019-03-22 16:27:50 +08:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2019-04-03 22:31:56 +08:00
|
|
|
|
2019-04-15 15:49:44 +08:00
|
|
|
if (data['mime-type'] === 'image/png') {
|
|
|
|
imageParams = { format: 'png' };
|
|
|
|
} else {
|
|
|
|
imageParams = { format: 'jpeg', quality: (data.quality / 100) };
|
|
|
|
}
|
2019-04-03 22:31:56 +08:00
|
|
|
|
2019-04-15 15:49:44 +08:00
|
|
|
imageDataURL = imageEditor.toDataURL(imageParams);
|
2019-04-03 22:31:56 +08:00
|
|
|
imageDataURL = atob(imageDataURL.split(',')[1]);
|
|
|
|
|
|
|
|
blobArray = new Uint8Array(imageDataURL.length);
|
|
|
|
|
|
|
|
for (bytePosition = 0; bytePosition < imageDataURL.length; bytePosition += 1) {
|
|
|
|
blobArray[bytePosition] = imageDataURL.charCodeAt(bytePosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
imageBlob = new Blob([blobArray]);
|
|
|
|
|
|
|
|
dataUpload.append('image', imageBlob);
|
2019-03-22 16:27:50 +08:00
|
|
|
animateSpinner(null, true);
|
|
|
|
$.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);
|
2019-05-21 23:29:33 +08:00
|
|
|
Assets.setupAssetsLoading();
|
2019-03-22 16:27:50 +08:00
|
|
|
}
|
|
|
|
}).done(function() {
|
|
|
|
animateSpinner(null, false);
|
|
|
|
imageEditor.destroy();
|
|
|
|
imageEditor = {};
|
|
|
|
$('#tui-image-editor').html('');
|
|
|
|
$('#fileEditModal').modal('hide');
|
2019-05-22 16:31:29 +08:00
|
|
|
if (typeof refreshProtocolStatusBar === 'function') refreshProtocolStatusBar();
|
2019-03-22 16:27:50 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
window.onresize = function() {
|
|
|
|
imageEditor.ui.resizeEditor();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function openPreviewModal(name, url, downloadUrl) {
|
|
|
|
var modal = $('#filePreviewModal');
|
|
|
|
updateFabricControls();
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
var link = modal.find('.file-download-link');
|
|
|
|
modal.find('.file-preview-container').empty();
|
|
|
|
modal.find('.file-wopi-controls').empty();
|
|
|
|
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 === 'image') {
|
|
|
|
if (data.processing) {
|
2019-05-13 22:53:58 +08:00
|
|
|
modal.find('.file-preview-container').append(data['processing-img']);
|
2019-03-22 16:27:50 +08:00
|
|
|
} else {
|
|
|
|
animateSpinner('.file-preview-container', false);
|
|
|
|
modal.find('.file-preview-container')
|
|
|
|
.append($('<img>')
|
|
|
|
.attr('src', data['large-preview-url'])
|
|
|
|
.attr('alt', name)
|
|
|
|
.click(function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
}));
|
2019-04-02 22:38:53 +08:00
|
|
|
if (!readOnly && data.editable) {
|
2019-03-22 16:27:50 +08:00
|
|
|
modal.find('.file-edit-link').css('display', '');
|
|
|
|
modal.find('.file-edit-link').off().click(function(ev) {
|
2019-06-19 21:19:47 +08:00
|
|
|
$.post('/files/' + data.id + '/start_edit_image');
|
2019-03-22 16:27:50 +08:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
modal.modal('hide');
|
2019-07-24 13:06:05 +08:00
|
|
|
preInitImageEditor(data);
|
2019-03-22 16:27:50 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
modal.find('.file-edit-link').css('display', 'none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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
|
|
|
if (data.processing) {
|
2019-05-21 23:29:33 +08:00
|
|
|
setTimeout(function() {
|
|
|
|
checkFileReady(url, modal);
|
|
|
|
}, CHECK_READY_DELAY);
|
2019-03-22 16:27:50 +08:00
|
|
|
}
|
|
|
|
modal.find('.file-name').text(name);
|
|
|
|
modal.find('.preview-close').click(function() {
|
2019-05-21 23:29:33 +08:00
|
|
|
checkReadyCntr = CHECK_READY_TRIES_LIMIT;
|
2019-03-22 16:27:50 +08:00
|
|
|
modal.modal('hide');
|
2019-05-22 16:31:29 +08:00
|
|
|
if (typeof refreshProtocolStatusBar === 'function') refreshProtocolStatusBar();
|
2019-03-22 16:27:50 +08:00
|
|
|
});
|
|
|
|
modal.modal();
|
|
|
|
modal.find('a[disabled=disabled]').click(function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
});
|
|
|
|
$('.modal-backdrop').last().css('z-index', modal.css('z-index') - 1);
|
2019-05-21 23:29:33 +08:00
|
|
|
checkReadyCntr = 0;
|
2019-03-22 16:27:50 +08:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkFileReady(url, modal) {
|
|
|
|
$.get(url, function(data) {
|
|
|
|
if (data.processing) {
|
|
|
|
$('.file-download-link')
|
|
|
|
.addClass('disabled-with-click-events')
|
|
|
|
.attr(
|
|
|
|
'title',
|
|
|
|
I18n.t('general.file.processing')
|
|
|
|
)
|
|
|
|
.click(function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
});
|
2019-05-21 23:29:33 +08:00
|
|
|
if (checkReadyCntr < CHECK_READY_TRIES_LIMIT) {
|
|
|
|
setTimeout(function() {
|
|
|
|
checkFileReady(url, modal);
|
|
|
|
}, CHECK_READY_DELAY);
|
|
|
|
}
|
2019-03-22 16:27:50 +08:00
|
|
|
} else {
|
2019-07-08 18:45:22 +08:00
|
|
|
if (data.type === 'image' || (data.type === 'file' && data['preview-icon'])) {
|
2019-03-22 16:27:50 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
$('.file-download-link')
|
|
|
|
.removeClass('disabled-with-click-events')
|
|
|
|
.removeAttr('title')
|
|
|
|
.off();
|
|
|
|
}
|
|
|
|
});
|
2019-05-21 23:29:33 +08:00
|
|
|
|
|
|
|
checkReadyCntr += 1;
|
2019-03-22 16:27:50 +08:00
|
|
|
}
|
2019-04-02 22:38:53 +08:00
|
|
|
|
|
|
|
return Object.freeze({
|
|
|
|
init: initPreviewModal
|
|
|
|
});
|
2019-03-22 16:27:50 +08:00
|
|
|
}(window));
|