2016-07-21 19:11:15 +08:00
|
|
|
function setupAssetsLoading() {
|
2016-12-09 20:59:49 +08:00
|
|
|
var DELAY = 2500;
|
|
|
|
var REPETITIONS = 60;
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
|
|
function refreshAssets() {
|
|
|
|
var elements = $("[data-status='asset-loading']");
|
|
|
|
|
|
|
|
if (!elements.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.each(elements, function(_, el) {
|
|
|
|
var $el = $(el);
|
|
|
|
|
|
|
|
// Perform an AJAX call to present URL
|
|
|
|
// to check if file already exists
|
|
|
|
$.ajax({
|
|
|
|
url: $el.data("present-url"),
|
|
|
|
type: "GET",
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
2017-03-16 22:38:11 +08:00
|
|
|
var wopiBtns;
|
2016-07-21 19:11:15 +08:00
|
|
|
$el.attr("data-status", "asset-loaded");
|
2016-12-09 20:59:49 +08:00
|
|
|
$el.find('img').hide();
|
|
|
|
$el.next().hide();
|
2016-07-21 19:11:15 +08:00
|
|
|
$el.html("");
|
|
|
|
|
2018-03-30 17:50:28 +08:00
|
|
|
if (data.type === 'image') {
|
2016-07-21 19:11:15 +08:00
|
|
|
$el.html(
|
2018-03-30 17:50:28 +08:00
|
|
|
"<a class='file-preview-link' id='modal_link" +
|
2017-01-06 23:41:24 +08:00
|
|
|
data['asset-id'] + "' data-status='asset-present' " +
|
2018-03-30 17:50:28 +08:00
|
|
|
"href='" + data['download-url'] + "' data-preview-url='" +
|
|
|
|
data['preview-url'] + "'>" +
|
|
|
|
"<img src='" + data['image-tag-url'] + "'><p>" +
|
2017-01-06 23:41:24 +08:00
|
|
|
data.filename + '</p></a>'
|
2016-07-21 19:11:15 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$el.html(
|
2018-03-30 17:50:28 +08:00
|
|
|
"<a class='file-preview-link' id='modal_link" +
|
|
|
|
data['asset-id'] + "' data-status='asset-present' " +
|
|
|
|
"href='" + data['download-url'] + "' data-preview-url='" +
|
|
|
|
data['preview-url'] + "'><p>" +
|
|
|
|
data.filename + '</p></a>'
|
2016-07-21 19:11:15 +08:00
|
|
|
);
|
|
|
|
}
|
2016-12-09 20:59:49 +08:00
|
|
|
animateSpinner(null, false);
|
2016-12-20 00:36:18 +08:00
|
|
|
initPreviewModal();
|
2016-07-21 19:11:15 +08:00
|
|
|
},
|
2017-01-06 22:58:23 +08:00
|
|
|
error: function(data) {
|
|
|
|
if (data.status == 403) {
|
2016-12-09 20:59:49 +08:00
|
|
|
$el.find('img').hide();
|
|
|
|
$el.next().hide();
|
2016-07-21 19:11:15 +08:00
|
|
|
// Image/file exists, but user doesn't have
|
|
|
|
// rights to download it
|
|
|
|
if (type === "image") {
|
|
|
|
$el.html(
|
2017-01-06 22:58:23 +08:00
|
|
|
"<img src='" + data['image-tag-url'] + "'><p>" +
|
2016-12-09 20:59:49 +08:00
|
|
|
data.filename + "</p>"
|
2016-07-21 19:11:15 +08:00
|
|
|
);
|
|
|
|
} else {
|
2016-12-09 20:59:49 +08:00
|
|
|
$el.html("<p>" + data.filename + "</p>");
|
2016-07-21 19:11:15 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Do nothing, file is not yet present
|
2016-12-09 20:59:49 +08:00
|
|
|
animateSpinner(null, false);
|
2016-07-21 19:11:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function finalizeAssets() {
|
|
|
|
var elements = $("[data-status='asset-loading']");
|
|
|
|
|
|
|
|
$.each(elements, function(_, el) {
|
|
|
|
var $el = $(el);
|
|
|
|
$el.attr("data-status", "asset-failed");
|
|
|
|
$el.html($el.data("filename"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var cntr = 0;
|
|
|
|
var intervalId = window.setInterval(function() {
|
|
|
|
cntr++;
|
|
|
|
if (cntr >= REPETITIONS || !refreshAssets()) {
|
|
|
|
finalizeAssets();
|
|
|
|
window.clearInterval(intervalId);
|
|
|
|
}
|
|
|
|
}, DELAY);
|
2016-08-19 21:36:12 +08:00
|
|
|
}
|