2013-05-04 14:20:27 -07:00
|
|
|
|
(function ($, document, window, FileReader, escape) {
|
|
|
|
|
|
|
|
|
|
var currentItem;
|
|
|
|
|
var currentFile;
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
var browsableImagePageSize = 10;
|
|
|
|
|
var browsableImageStartIndex = 0;
|
|
|
|
|
var browsableImageType = 'Primary';
|
2014-02-09 14:11:11 -07:00
|
|
|
|
var selectedProvider;
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
function updateTabs(page, item) {
|
2013-06-27 06:31:49 -07:00
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
var query = MetadataEditor.getEditQueryString(item);
|
2013-06-27 06:31:49 -07:00
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
$('#btnEditMetadata', page).attr('href', 'edititemmetadata.html?' + query);
|
2014-05-16 21:24:10 -07:00
|
|
|
|
$('#btnEditSubtitles', page).attr('href', 'edititemsubtitles.html?' + query);
|
2014-03-07 08:53:23 -07:00
|
|
|
|
$('#btnEditCollectionTitles', page).attr('href', 'editcollectionitems.html?' + query);
|
2013-06-27 06:31:49 -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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
function reloadBrowsableImages(page) {
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var options = getBaseRemoteOptions();
|
|
|
|
|
|
|
|
|
|
options.type = browsableImageType;
|
|
|
|
|
options.startIndex = browsableImageStartIndex;
|
|
|
|
|
options.limit = browsableImagePageSize;
|
2014-02-25 08:40:16 -07:00
|
|
|
|
options.IncludeAllLanguages = $('#chkAllLanguages', page).checked();
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
2014-02-09 14:11:11 -07:00
|
|
|
|
var provider = selectedProvider || '';
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
|
|
|
|
if (provider) {
|
|
|
|
|
options.ProviderName = provider;
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.getAvailableRemoteImages(options).done(function (result) {
|
|
|
|
|
|
|
|
|
|
renderRemoteImages(page, currentItem, result, browsableImageType, options.startIndex, options.limit);
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
|
|
|
|
$('#selectBrowsableImageType', page).val(browsableImageType).selectmenu('refresh');
|
|
|
|
|
|
|
|
|
|
var providersHtml = result.Providers.map(function (p) {
|
|
|
|
|
return '<option value="' + p + '">' + p + '</option>';
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
$('#selectImageProvider', page).html('<option value="">' + Globalize.translate('LabelAll') + '</option>' + providersHtml).val(provider).selectmenu('refresh');
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-10-31 14:03:24 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderRemoteImages(page, item, imagesResult, imageType, startIndex, limit) {
|
|
|
|
|
|
|
|
|
|
$('.availableImagesPaging', page).html(getPagingHtml(startIndex, limit, imagesResult.TotalRecordCount)).trigger('create');
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = imagesResult.Images.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
html += getRemoteImageHtml(imagesResult.Images[i], imageType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.availableImagesList', page).html(html).trigger('create');
|
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
browsableImageStartIndex += browsableImagePageSize;
|
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
browsableImageStartIndex -= browsableImagePageSize;
|
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
$('.btnDownloadRemoteImage', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
downloadRemoteImage(page, this.getAttribute('data-imageurl'), this.getAttribute('data-imagetype'), this.getAttribute('data-imageprovider'));
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
function downloadRemoteImage(page, url, type, provider) {
|
|
|
|
|
|
|
|
|
|
var options = getBaseRemoteOptions();
|
|
|
|
|
|
|
|
|
|
options.Type = type;
|
|
|
|
|
options.ImageUrl = url;
|
|
|
|
|
options.ProviderName = provider;
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-11-01 08:55:25 -07:00
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
ApiClient.downloadRemoteImage(options).done(function () {
|
|
|
|
|
|
2014-02-25 08:40:16 -07:00
|
|
|
|
$('.popupDownload', page).popup("close");
|
2013-10-31 18:48:14 -07:00
|
|
|
|
reload(page);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2013-11-04 14:50:37 -07:00
|
|
|
|
function getDisplayUrl(url) {
|
2014-02-08 23:08:10 -07:00
|
|
|
|
return ApiClient.getUrl("Images/Remote", { imageUrl: url });
|
2013-11-04 14:50:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
function getRemoteImageHtml(image, imageType) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
html += '<div class="remoteImageContainer">';
|
|
|
|
|
|
|
|
|
|
var cssClass = "remoteImage";
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
if (imageType == "Backdrop" || imageType == "Art" || imageType == "Thumb" || imageType == "Logo") {
|
2013-10-31 14:03:24 -07:00
|
|
|
|
cssClass += " remoteBackdropImage";
|
|
|
|
|
}
|
2013-10-31 18:48:14 -07:00
|
|
|
|
else if (imageType == "Banner") {
|
|
|
|
|
cssClass += " remoteBannerImage";
|
|
|
|
|
}
|
|
|
|
|
else if (imageType == "Disc") {
|
|
|
|
|
cssClass += " remoteDiscImage";
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
else {
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2013-11-05 15:29:07 -07:00
|
|
|
|
if (currentItem.Type == "Episode") {
|
|
|
|
|
cssClass += " remoteBackdropImage";
|
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
else if (currentItem.Type == "MusicAlbum" || currentItem.Type == "MusicArtist") {
|
2013-11-05 15:29:07 -07:00
|
|
|
|
cssClass += " remoteDiscImage";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cssClass += " remotePosterImage";
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 14:50:37 -07:00
|
|
|
|
var displayUrl = getDisplayUrl(image.ThumbnailUrl || image.Url);
|
|
|
|
|
|
|
|
|
|
html += '<a target="_blank" href="' + getDisplayUrl(image.Url) + '" class="' + cssClass + '" style="background-image:url(\'' + displayUrl + '\');">';
|
2013-10-31 18:48:14 -07:00
|
|
|
|
html += '</a>';
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
|
|
|
|
html += '<div class="remoteImageDetails">';
|
|
|
|
|
html += image.ProviderName;
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2013-11-04 12:04:23 -07:00
|
|
|
|
if (image.Width || image.Height || image.Language) {
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
|
|
|
|
html += '<div class="remoteImageDetails">';
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
2013-11-04 12:04:23 -07:00
|
|
|
|
if (image.Width || image.Height) {
|
|
|
|
|
html += image.Width + ' x ' + image.Height;
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2013-11-04 12:04:23 -07:00
|
|
|
|
if (image.Language) {
|
|
|
|
|
|
|
|
|
|
html += ' • ' + image.Language;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (image.Language) {
|
|
|
|
|
|
|
|
|
|
html += image.Language;
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
}
|
2013-11-04 12:04:23 -07:00
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
if (image.CommunityRating != null) {
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
html += '<div class="remoteImageDetails">';
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
if (image.RatingType == "Likes") {
|
|
|
|
|
html += image.CommunityRating + (image.CommunityRating == 1 ? " like" : " likes");
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (image.CommunityRating) {
|
|
|
|
|
html += image.CommunityRating.toFixed(1);
|
|
|
|
|
|
|
|
|
|
if (image.VoteCount) {
|
2013-11-05 08:12:13 -07:00
|
|
|
|
html += ' • ' + image.VoteCount + (image.VoteCount == 1 ? " vote" : " votes");
|
2013-10-31 18:48:14 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
html += "Unrated";
|
|
|
|
|
}
|
2013-10-31 14:03:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<div><button class="btnDownloadRemoteImage" data-imageprovider="' + image.ProviderName + '" data-imageurl="' + image.Url + '" data-imagetype="' + image.Type + '" type="button" data-icon="arrow-d" data-mini="true">' + Globalize.translate('ButtonDownload') + '</button></div>';
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPagingHtml(startIndex, limit, totalRecordCount) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
var recordsEnd = Math.min(startIndex + limit, totalRecordCount);
|
|
|
|
|
|
|
|
|
|
// 20 is the minimum page size
|
2013-10-31 18:48:14 -07:00
|
|
|
|
var showControls = totalRecordCount > limit;
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
|
|
|
|
html += '<div class="listPaging">';
|
|
|
|
|
|
|
|
|
|
html += '<span style="margin-right: 10px;">';
|
|
|
|
|
|
|
|
|
|
var startAtDisplay = totalRecordCount ? startIndex + 1 : 0;
|
|
|
|
|
html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount;
|
|
|
|
|
|
|
|
|
|
html += '</span>';
|
|
|
|
|
|
|
|
|
|
if (showControls) {
|
2014-01-22 13:46:01 -07:00
|
|
|
|
html += '<div data-role="controlgroup" data-type="horizontal" style="display:inline-block;">';
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button data-icon="arrow-l" data-iconpos="notext" data-inline="true" data-mini="true" class="btnPreviousPage" ' + (startIndex ? '' : 'disabled') + '>' + Globalize.translate('ButtonPreviousPage') + '</button>';
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button data-icon="arrow-r" data-iconpos="notext" data-inline="true" data-mini="true" class="btnNextPage" ' + (startIndex + limit > totalRecordCount ? 'disabled' : '') + '>' + Globalize.translate('ButtonNextPage') + '</button>';
|
2014-01-22 13:46:01 -07:00
|
|
|
|
html += '</div>';
|
2013-10-31 14:03:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2013-06-27 06:31:49 -07:00
|
|
|
|
function reload(page) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2014-02-09 14:11:11 -07:00
|
|
|
|
browsableImageStartIndex = 0;
|
|
|
|
|
browsableImageType = 'Primary';
|
|
|
|
|
selectedProvider = null;
|
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
MetadataEditor.getItemPromise().done(function (item) {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
|
|
|
|
currentItem = item;
|
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
LibraryBrowser.renderName(item, $('.itemName', page), true);
|
|
|
|
|
|
|
|
|
|
updateTabs(page, item);
|
|
|
|
|
|
2014-03-07 08:53:23 -07:00
|
|
|
|
if (item.Type == "BoxSet") {
|
|
|
|
|
$('#btnEditCollectionTitles', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnEditCollectionTitles', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
if (item.MediaType == "Video" && item.LocationType == "FileSystem" && item.Type !== 'TvChannel') {
|
2014-05-16 21:24:10 -07:00
|
|
|
|
$('#btnEditSubtitles', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnEditSubtitles', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
ApiClient.getRemoteImageProviders(getBaseRemoteOptions()).done(function (providers) {
|
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
if (providers.length) {
|
|
|
|
|
$('.lnkBrowseAllImages', page).removeClass('hide');
|
|
|
|
|
} else {
|
|
|
|
|
$('.lnkBrowseAllImages', page).addClass('hide');
|
|
|
|
|
}
|
2013-11-27 12:04:19 -07:00
|
|
|
|
|
2014-04-26 20:42:05 -07:00
|
|
|
|
ApiClient.getItemImageInfos(currentItem.Id).done(function (imageInfos) {
|
2013-11-05 08:38:59 -07:00
|
|
|
|
|
|
|
|
|
renderStandardImages(page, item, imageInfos, providers);
|
|
|
|
|
renderBackdrops(page, item, imageInfos, providers);
|
|
|
|
|
renderScreenshots(page, item, imageInfos, providers);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
});
|
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">';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2014-08-16 22:38:13 -07:00
|
|
|
|
html += '<div style="height:144px;vertical-align:top;background-repeat:no-repeat;background-size:contain;background-image:url(\'' + LibraryBrowser.getImageUrl(currentItem, image.ImageType, image.ImageIndex, { enableImageEnhancers: false, height: 144 }) + '\');"></div>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
html += '<div>';
|
2013-12-01 13:17:40 -07:00
|
|
|
|
|
2013-11-29 12:31:57 -07:00
|
|
|
|
if (image.ImageType !== "Backdrop" && image.ImageType !== "Screenshot") {
|
|
|
|
|
html += '<p>' + image.ImageType + '</p>';
|
|
|
|
|
}
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
html += '<p>' + image.Width + ' X ' + image.Height + '</p>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
html += '<p>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
if (image.ImageType == "Backdrop" || image.ImageType == "Screenshot") {
|
|
|
|
|
|
|
|
|
|
if (i > 0) {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="arrow-l" data-mini="true" data-inline="true" data-iconpos="notext" onclick="EditItemImagesPage.moveImage(\'' + image.ImageType + '\', ' + image.ImageIndex + ', ' + (i - 1) + ');" style="margin-bottom:0;">' + Globalize.translate('ButtonMoveLeft') + '</button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="arrow-l" data-mini="true" data-inline="true" data-iconpos="notext" style="margin-bottom:0;" disabled>' + Globalize.translate('ButtonMoveLeft') + '</button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < length - 1) {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" onclick="EditItemImagesPage.moveImage(\'' + image.ImageType + '\', ' + image.ImageIndex + ', ' + (i + 1) + ');" style="margin-bottom:0;">' + Globalize.translate('ButtonMoveRight') + '</button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" style="margin-bottom:0;" disabled>' + Globalize.translate('ButtonMoveRight') + '</button>';
|
2013-05-04 21:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="delete" data-mini="true" data-inline="true" data-iconpos="notext" onclick="EditItemImagesPage.deleteImage(\'' + image.ImageType + '\', ' + (image.ImageIndex != null ? image.ImageIndex : "null") + ');" style="margin-bottom:0;">' + Globalize.translate('Delete') + '</button>';
|
2013-12-01 13:17:40 -07:00
|
|
|
|
|
2013-11-05 08:38:59 -07:00
|
|
|
|
if (imageProviders.length) {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
html += '<button type="button" data-icon="cloud" data-mini="true" data-inline="true" data-iconpos="notext" onclick="EditItemImagesPage.showDownloadMenu(\'' + image.ImageType + '\');" style="margin-bottom:0;">' + Globalize.translate('ButtonBrowseOnlineImages') + '</button>';
|
2013-11-05 08:38:59 -07:00
|
|
|
|
}
|
2013-10-31 18:55:38 -07:00
|
|
|
|
|
2013-05-04 21:49:49 -07:00
|
|
|
|
html += '</p>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elem.html(html).trigger('create');
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if (images.length) {
|
|
|
|
|
$('#imagesContainer', page).show();
|
2013-11-05 08:38:59 -07:00
|
|
|
|
renderImages(page, item, images, imageProviders, $('#images', page));
|
2013-05-04 21:49:49 -07:00
|
|
|
|
} else {
|
|
|
|
|
$('#imagesContainer', page).hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2013-11-05 08:38:59 -07:00
|
|
|
|
renderImages(page, item, images, imageProviders, $('#backdrops', page));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onFileReaderError(evt) {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
switch (evt.target.error.code) {
|
|
|
|
|
case evt.target.error.NOT_FOUND_ERR:
|
2014-07-16 20:17:14 -07:00
|
|
|
|
Dashboard.showError(Globalize.translate('MessageFileNotFound'));
|
2013-05-04 14:20:27 -07:00
|
|
|
|
break;
|
|
|
|
|
case evt.target.error.ABORT_ERR:
|
|
|
|
|
break; // noop
|
|
|
|
|
default:
|
2014-07-16 20:17:14 -07:00
|
|
|
|
Dashboard.showError(Globalize.translate('MessageFileReadError'));
|
|
|
|
|
break;
|
2013-05-04 14:20:27 -07:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setFiles(page, files) {
|
|
|
|
|
|
|
|
|
|
var file = files[0];
|
|
|
|
|
|
|
|
|
|
if (!file || !file.type.match('image.*')) {
|
|
|
|
|
$('#imageOutput', page).html('');
|
|
|
|
|
$('#fldUpload', page).hide();
|
|
|
|
|
currentFile = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentFile = file;
|
|
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
|
|
|
|
|
reader.onerror = onFileReaderError;
|
|
|
|
|
reader.onloadstart = function () {
|
|
|
|
|
$('#fldUpload', page).hide();
|
|
|
|
|
};
|
|
|
|
|
reader.onabort = function () {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2014-07-16 20:17:14 -07:00
|
|
|
|
console.log('File read cancelled');
|
2013-05-04 14:20:27 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Closure to capture the file information.
|
|
|
|
|
reader.onload = (function (theFile) {
|
|
|
|
|
return function (e) {
|
|
|
|
|
|
|
|
|
|
// Render thumbnail.
|
2013-11-27 12:04:19 -07:00
|
|
|
|
var html = ['<img style="max-width:300px;max-height:100px;" src="', e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
|
|
|
|
$('#imageOutput', page).html(html);
|
|
|
|
|
$('#fldUpload', page).show();
|
|
|
|
|
};
|
|
|
|
|
})(file);
|
|
|
|
|
|
|
|
|
|
// Read in the image file as a data URL.
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function processImageChangeResult(page) {
|
|
|
|
|
|
|
|
|
|
reload(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function editItemImages() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.onSubmit = function () {
|
|
|
|
|
|
|
|
|
|
var file = currentFile;
|
|
|
|
|
|
|
|
|
|
if (!file) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/jpeg") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
var imageType = $('#selectImageType', page).val();
|
|
|
|
|
|
2014-04-26 20:42:05 -07:00
|
|
|
|
ApiClient.uploadItemImage(currentItem.Id, imageType, file).done(function () {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
2013-05-04 21:49:49 -07:00
|
|
|
|
$('#uploadImage', page).val('').trigger('change');
|
|
|
|
|
$('#popupUpload', page).popup("close");
|
2013-05-04 14:20:27 -07:00
|
|
|
|
processImageChangeResult(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
self.deleteImage = function (type, index) {
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
Dashboard.confirm(Globalize.translate('DeleteImageConfirmation'), Globalize.translate('HeaderDeleteImage'), function (result) {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
if (result) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
ApiClient.deleteItemImage(currentItem.Id, type, index).done(function () {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
processImageChangeResult(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.moveImage = function (type, index, newIndex) {
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
2014-04-26 20:42:05 -07:00
|
|
|
|
ApiClient.updateItemImageIndex(currentItem.Id, type, index, newIndex).done(function () {
|
2013-05-04 21:49:49 -07:00
|
|
|
|
|
|
|
|
|
processImageChangeResult(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2013-10-31 18:55:38 -07:00
|
|
|
|
|
2013-11-01 08:55:25 -07:00
|
|
|
|
self.showDownloadMenu = function (type) {
|
2013-11-04 08:25:06 -07:00
|
|
|
|
browsableImageStartIndex = 0;
|
2013-10-31 18:55:38 -07:00
|
|
|
|
browsableImageType = type;
|
2014-02-25 08:40:16 -07:00
|
|
|
|
|
2013-10-31 18:55:38 -07:00
|
|
|
|
$('.lnkBrowseImages').trigger('click');
|
|
|
|
|
};
|
2013-05-04 14:20:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.EditItemImagesPage = new editItemImages();
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', "#editItemImagesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
$('.libraryTree', page).on('itemclicked', function (event, data) {
|
|
|
|
|
|
|
|
|
|
if (data.id != currentItem.Id) {
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2013-08-02 13:36:44 -07:00
|
|
|
|
MetadataEditor.currentItemId = data.id;
|
|
|
|
|
MetadataEditor.currentItemType = data.itemType;
|
|
|
|
|
//Dashboard.navigate('edititemmetadata.html?id=' + data.id);
|
|
|
|
|
|
2013-12-24 11:37:29 -07:00
|
|
|
|
//$.mobile.urlHistory.ignoreNextHashChange = true;
|
2013-08-02 13:36:44 -07:00
|
|
|
|
window.location.hash = 'editItemImagesPage?id=' + data.id;
|
|
|
|
|
|
|
|
|
|
reload(page);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-31 18:55:38 -07:00
|
|
|
|
$('.lnkBrowseImages', page).on('click', function () {
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
2014-02-09 14:11:11 -07:00
|
|
|
|
selectedProvider = null;
|
|
|
|
|
|
2014-02-25 08:40:16 -07:00
|
|
|
|
$('.popupDownload', page).popup('open');
|
|
|
|
|
|
2013-10-31 14:03:24 -07:00
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#selectBrowsableImageType', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
browsableImageType = this.value;
|
|
|
|
|
browsableImageStartIndex = 0;
|
2014-02-09 14:11:11 -07:00
|
|
|
|
selectedProvider = null;
|
2013-10-31 14:03:24 -07:00
|
|
|
|
|
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-31 18:48:14 -07:00
|
|
|
|
$('#selectImageProvider', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
browsableImageStartIndex = 0;
|
2014-02-09 14:11:11 -07:00
|
|
|
|
selectedProvider = this.value;
|
2013-10-31 18:48:14 -07:00
|
|
|
|
|
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-11 20:46:27 -07:00
|
|
|
|
$('#chkAllLanguages', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
browsableImageStartIndex = 0;
|
|
|
|
|
|
|
|
|
|
reloadBrowsableImages(page);
|
|
|
|
|
});
|
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
}).on('pagebeforeshow', "#editItemImagesPage", function () {
|
2013-05-04 14:20:27 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
reload(page);
|
|
|
|
|
|
2013-05-04 21:49:49 -07:00
|
|
|
|
$('#uploadImage', page).on("change", function () {
|
|
|
|
|
setFiles(page, this.files);
|
|
|
|
|
});
|
|
|
|
|
|
2013-05-04 14:20:27 -07:00
|
|
|
|
$("#imageDropZone", page).on('dragover', function (e) {
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
e.originalEvent.dataTransfer.dropEffect = 'Copy';
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}).on('drop', function (e) {
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
setFiles(page, e.originalEvent.dataTransfer.files);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pagehide', "#editItemImagesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
currentItem = null;
|
|
|
|
|
|
2013-05-04 21:49:49 -07:00
|
|
|
|
$('#uploadImage', page).off("change");
|
|
|
|
|
|
2013-05-04 14:20:27 -07:00
|
|
|
|
$("#imageDropZone", page).off('dragover').off('drop');
|
|
|
|
|
});
|
|
|
|
|
|
2013-11-27 12:04:19 -07:00
|
|
|
|
})(jQuery, document, window, window.FileReader, escape);
|