2013-05-04 14:20:27 -07:00
|
|
|
|
(function ($, document, window, FileReader, escape) {
|
|
|
|
|
|
|
|
|
|
var currentItem;
|
2015-10-15 22:36:16 -07:00
|
|
|
|
var currentDeferred;
|
|
|
|
|
var hasChanges = false;
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
function getBaseRemoteOptions() {
|
2014-11-14 19:31:03 -07:00
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
var options = {};
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
options.itemId = currentItem.Id;
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
function reload(page, item) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
if (item) {
|
|
|
|
|
reloadItem(page, item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), currentItem.Id).done(function (item) {
|
|
|
|
|
reloadItem(page, item);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
function reloadItem(page, item) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
currentItem = item;
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
ApiClient.getRemoteImageProviders(getBaseRemoteOptions()).done(function (providers) {
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
if (providers.length) {
|
2015-10-15 22:36:16 -07:00
|
|
|
|
$('.btnBrowseAllImages', page).removeClass('hide');
|
2015-09-17 09:04:04 -07:00
|
|
|
|
} else {
|
2015-10-15 22:36:16 -07:00
|
|
|
|
$('.btnBrowseAllImages', page).addClass('hide');
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
ApiClient.getItemImageInfos(currentItem.Id).done(function (imageInfos) {
|
2013-11-05 08:38:59 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
renderStandardImages(page, item, imageInfos, providers);
|
|
|
|
|
renderBackdrops(page, item, imageInfos, providers);
|
|
|
|
|
renderScreenshots(page, item, imageInfos, providers);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-11-05 08:38:59 -07:00
|
|
|
|
});
|
2013-05-04 21:49:49 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
function renderImages(page, item, images, imageProviders, elem) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = images.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var image = images[i];
|
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
html += '<div class="editorTile imageEditorTile">';
|
2015-09-17 18:51:22 -07:00
|
|
|
|
html += '<div class="editorTileInner">';
|
2015-07-15 04:26:47 -07:00
|
|
|
|
|
2015-07-14 12:04:16 -07:00
|
|
|
|
var height = 150;
|
|
|
|
|
|
2015-09-24 22:15:29 -07:00
|
|
|
|
html += '<div style="height:' + height + 'px;vertical-align:top;background-repeat:no-repeat;background-position:center bottom;background-size:contain;" class="lazy" data-src="' + LibraryBrowser.getImageUrl(currentItem, image.ImageType, image.ImageIndex, { height: height }) + '"></div>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-09-17 18:51:22 -07:00
|
|
|
|
html += '<div class="editorTileFooter">';
|
|
|
|
|
|
|
|
|
|
if (image.ImageType !== "Backdrop" && image.ImageType !== "Screenshot") {
|
|
|
|
|
html += '<h3>' + image.ImageType + '</h3>';
|
|
|
|
|
}
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-08-02 16:47:31 -07:00
|
|
|
|
if (image.Width && image.Height) {
|
|
|
|
|
html += '<p>' + image.Width + ' X ' + image.Height + '</p>';
|
|
|
|
|
} else {
|
|
|
|
|
html += '<p> </p>';
|
|
|
|
|
}
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
html += '<div>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
if (image.ImageType == "Backdrop" || image.ImageType == "Screenshot") {
|
|
|
|
|
|
|
|
|
|
if (i > 0) {
|
2015-09-17 10:24:23 -07:00
|
|
|
|
html += '<paper-icon-button class="btnMoveImage" icon="chevron-left" data-imagetype="' + image.ImageType + '" data-index="' + image.ImageIndex + '" data-newindex="' + (image.ImageIndex - 1) + '" title="' + Globalize.translate('ButtonMoveLeft') + '"></paper-icon-button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
2015-07-14 12:04:16 -07:00
|
|
|
|
html += '<paper-icon-button icon="chevron-left" disabled title="' + Globalize.translate('ButtonMoveLeft') + '"></paper-icon-button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < length - 1) {
|
2015-09-17 10:24:23 -07:00
|
|
|
|
html += '<paper-icon-button class="btnMoveImage" icon="chevron-right" data-imagetype="' + image.ImageType + '" data-index="' + image.ImageIndex + '" data-newindex="' + (image.ImageIndex + 1) + '" title="' + Globalize.translate('ButtonMoveRight') + '"></paper-icon-button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
2015-07-14 12:04:16 -07:00
|
|
|
|
html += '<paper-icon-button icon="chevron-right" disabled title="' + Globalize.translate('ButtonMoveRight') + '"></paper-icon-button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-17 18:51:22 -07:00
|
|
|
|
else {
|
|
|
|
|
if (imageProviders.length) {
|
|
|
|
|
html += '<paper-icon-button icon="search" data-imagetype="' + image.ImageType + '" class="btnSearchImages" title="' + Globalize.translate('ButtonBrowseOnlineImages') + '"></paper-icon-button>';
|
|
|
|
|
}
|
2013-11-05 08:38:59 -07:00
|
|
|
|
}
|
2013-10-31 18:55:38 -07:00
|
|
|
|
|
2015-09-17 10:24:23 -07:00
|
|
|
|
html += '<paper-icon-button icon="delete" data-imagetype="' + image.ImageType + '" data-index="' + (image.ImageIndex != null ? image.ImageIndex : "null") + '" class="btnDeleteImage" title="' + Globalize.translate('Delete') + '"></paper-icon-button>';
|
2015-07-15 04:26:47 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
html += '</div>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
html += '</div>';
|
2015-09-17 18:51:22 -07:00
|
|
|
|
html += '</div>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-17 10:24:23 -07:00
|
|
|
|
elem.innerHTML = html;
|
2015-09-24 22:15:29 -07:00
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2015-09-17 10:24:23 -07:00
|
|
|
|
|
|
|
|
|
$('.btnSearchImages', elem).on('click', function () {
|
|
|
|
|
showImageDownloader(page, this.getAttribute('data-imagetype'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnDeleteImage', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var type = this.getAttribute('data-imagetype');
|
|
|
|
|
var index = this.getAttribute('data-index');
|
|
|
|
|
index = index == "null" ? null : parseInt(index);
|
|
|
|
|
Dashboard.confirm(Globalize.translate('DeleteImageConfirmation'), Globalize.translate('HeaderDeleteImage'), function (result) {
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
ApiClient.deleteItemImage(currentItem.Id, type, index).done(function () {
|
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
hasChanges = true;
|
2015-09-17 10:24:23 -07:00
|
|
|
|
reload(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnMoveImage', elem).on('click', function () {
|
|
|
|
|
var type = this.getAttribute('data-imagetype');
|
|
|
|
|
var index = parseInt(this.getAttribute('data-index'));
|
|
|
|
|
var newIndex = parseInt(this.getAttribute('data-newindex'));
|
|
|
|
|
ApiClient.updateItemImageIndex(currentItem.Id, type, index, newIndex).done(function () {
|
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
hasChanges = true;
|
2015-09-17 10:24:23 -07:00
|
|
|
|
reload(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
function renderStandardImages(page, item, imageInfos, imageProviders) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
var images = imageInfos.filter(function (i) {
|
|
|
|
|
return i.ImageType != "Screenshot" && i.ImageType != "Backdrop" && i.ImageType != "Chapter";
|
2013-05-04 14:20:27 -07:00
|
|
|
|
});
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-09-17 10:24:23 -07:00
|
|
|
|
renderImages(page, item, images, imageProviders, page.querySelector('#images'));
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
function renderBackdrops(page, item, imageInfos, imageProviders) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
var images = imageInfos.filter(function (i) {
|
|
|
|
|
return i.ImageType == "Backdrop";
|
|
|
|
|
|
|
|
|
|
}).sort(function (a, b) {
|
|
|
|
|
return a.ImageIndex - b.ImageIndex;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (images.length) {
|
|
|
|
|
$('#backdropsContainer', page).show();
|
2015-09-17 10:24:23 -07:00
|
|
|
|
renderImages(page, item, images, imageProviders, page.querySelector('#backdrops'));
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
|
|
|
|
$('#backdropsContainer', page).hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
function renderScreenshots(page, item, imageInfos, imageProviders) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
var images = imageInfos.filter(function (i) {
|
|
|
|
|
return i.ImageType == "Screenshot";
|
|
|
|
|
|
|
|
|
|
}).sort(function (a, b) {
|
|
|
|
|
return a.ImageIndex - b.ImageIndex;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (images.length) {
|
|
|
|
|
$('#screenshotsContainer', page).show();
|
2013-11-05 08:38:59 -07:00
|
|
|
|
renderImages(page, item, images, imageProviders, $('#screenshots', page));
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
|
|
|
|
$('#screenshotsContainer', page).hide();
|
|
|
|
|
}
|
2013-05-04 14:20:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-17 10:24:23 -07:00
|
|
|
|
function showImageDownloader(page, imageType) {
|
|
|
|
|
require(['components/imagedownloader/imagedownloader'], function () {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
ImageDownloader.show(currentItem.Id, currentItem.Type, imageType).done(function (hasChanged) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
if (hasChanged) {
|
|
|
|
|
hasChanges = true;
|
2015-09-17 10:24:23 -07:00
|
|
|
|
reload(page);
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
2015-09-17 10:24:23 -07:00
|
|
|
|
});
|
2013-05-04 14:20:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
function initEditor(page, options) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-08-02 16:47:31 -07:00
|
|
|
|
$('.btnOpenUploadMenu', page).on('click', function () {
|
2015-07-14 12:04:16 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
require(['components/imageuploader/imageuploader'], function () {
|
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
ImageUploader.show(currentItem.Id, {
|
|
|
|
|
|
|
|
|
|
theme: options.theme
|
|
|
|
|
|
|
|
|
|
}).done(function (hasChanged) {
|
2015-09-17 09:04:04 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
if (hasChanged) {
|
|
|
|
|
hasChanges = true;
|
2015-09-17 09:04:04 -07:00
|
|
|
|
reload(page);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-14 12:04:16 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnBrowseAllImages', page).on('click', function () {
|
2015-09-17 18:51:22 -07:00
|
|
|
|
showImageDownloader(page, this.getAttribute('data-imagetype') || 'Primary');
|
2015-07-14 12:04:16 -07:00
|
|
|
|
});
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}
|
2015-05-18 18:46:31 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
function showEditor(itemId, options) {
|
|
|
|
|
|
|
|
|
|
options = options || {};
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-10-13 12:22:45 -07:00
|
|
|
|
HttpClient.send({
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
type: 'GET',
|
|
|
|
|
url: 'components/imageeditor/imageeditor.template.html'
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}).done(function (template) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
var dlg = PaperDialogHelper.createDialog({
|
|
|
|
|
theme: options.theme
|
|
|
|
|
});
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
var html = '';
|
|
|
|
|
html += '<h2 class="dialogHeader">';
|
2015-10-20 22:10:02 -07:00
|
|
|
|
html += '<paper-fab icon="arrow-back" mini class="btnCloseDialog"></paper-fab>';
|
2015-09-17 09:04:04 -07:00
|
|
|
|
html += '<div style="display:inline-block;margin-left:.6em;vertical-align:middle;">' + item.Name + '</div>';
|
|
|
|
|
html += '</h2>';
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
html += '<div class="editorContent">';
|
|
|
|
|
html += Globalize.translateDocument(template);
|
|
|
|
|
html += '</div>';
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-09-17 09:04:04 -07:00
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
document.body.appendChild(dlg);
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2015-10-15 22:36:16 -07:00
|
|
|
|
initEditor(dlg, options);
|
2015-09-17 09:04:04 -07:00
|
|
|
|
|
|
|
|
|
// Has to be assigned a z-index after the call to .open()
|
|
|
|
|
$(dlg).on('iron-overlay-closed', onDialogClosed);
|
|
|
|
|
|
|
|
|
|
PaperDialogHelper.openWithHash(dlg, 'imageeditor');
|
|
|
|
|
|
|
|
|
|
var editorContent = dlg.querySelector('.editorContent');
|
|
|
|
|
reload(editorContent, item);
|
|
|
|
|
|
2015-09-29 09:29:06 -07:00
|
|
|
|
$('.btnCloseDialog', dlg).on('click', function() {
|
|
|
|
|
|
|
|
|
|
PaperDialogHelper.close(dlg);
|
|
|
|
|
});
|
2015-09-17 09:04:04 -07:00
|
|
|
|
});
|
2015-07-14 13:29:51 -07:00
|
|
|
|
});
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDialogClosed() {
|
|
|
|
|
|
|
|
|
|
$(this).remove();
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-10-15 22:36:16 -07:00
|
|
|
|
currentDeferred.resolveWith(null, [hasChanges]);
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.ImageEditor = {
|
2015-10-15 22:36:16 -07:00
|
|
|
|
show: function (itemId, options) {
|
|
|
|
|
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
|
|
|
|
|
|
|
|
|
currentDeferred = deferred;
|
|
|
|
|
hasChanges = false;
|
2015-09-17 09:04:04 -07:00
|
|
|
|
|
2015-09-17 10:24:23 -07:00
|
|
|
|
require(['components/paperdialoghelper'], function () {
|
2015-09-17 09:04:04 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.importCss('css/metadataeditor.css');
|
2015-10-15 22:36:16 -07:00
|
|
|
|
showEditor(itemId, options);
|
2015-09-17 09:04:04 -07:00
|
|
|
|
});
|
2015-10-15 22:36:16 -07:00
|
|
|
|
return deferred.promise();
|
2015-09-17 09:04:04 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
})(jQuery, document, window, window.FileReader, escape);
|