jellyfin-web/dashboard-ui/scripts/edititemmetadata.js

1559 lines
52 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
2013-08-02 13:36:44 -07:00
var currentItem;
2015-01-11 13:31:09 -07:00
var currentSearchResult;
2014-12-21 11:58:17 -07:00
var metadataEditorInfo;
2013-08-02 13:36:44 -07:00
function reload(page) {
2015-08-15 17:41:55 -07:00
page = $(page)[0];
2015-03-17 21:09:31 -07:00
unbindItemChanged(page);
2013-08-02 13:36:44 -07:00
Dashboard.showLoadingMsg();
2013-12-28 09:58:13 -07:00
var promise1 = MetadataEditor.getItemPromise();
2014-12-21 23:50:29 -07:00
var promise2 = MetadataEditor.currentItemId ?
ApiClient.getJSON(ApiClient.getUrl('Items/' + MetadataEditor.currentItemId + '/MetadataEditor')) :
{};
2013-12-28 09:58:13 -07:00
2014-12-20 22:57:06 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2013-12-28 09:58:13 -07:00
var item = response1[0];
2014-12-21 11:58:17 -07:00
metadataEditorInfo = response2[0];
2014-03-01 15:34:27 -07:00
2014-02-23 20:27:13 -07:00
currentItem = item;
if (item.Type == "UserRootFolder") {
2015-08-24 20:13:04 -07:00
$('.editPageInnerContent', page)[0].style.visibility = 'hidden';
2015-06-12 20:42:19 -07:00
Dashboard.hideLoadingMsg();
2014-02-23 20:27:13 -07:00
return;
} else {
2015-08-24 20:13:04 -07:00
$('.editPageInnerContent', page)[0].style.visibility = 'visible';
2014-02-23 20:27:13 -07:00
}
2013-12-28 09:58:13 -07:00
2014-12-20 22:57:06 -07:00
var languages = metadataEditorInfo.Cultures;
var countries = metadataEditorInfo.Countries;
2014-12-21 11:58:17 -07:00
renderContentTypeOptions(page, metadataEditorInfo);
2014-12-20 22:57:06 -07:00
loadExternalIds(page, item, metadataEditorInfo.ExternalIdInfos);
2014-02-21 14:44:10 -07:00
2013-12-28 09:58:13 -07:00
Dashboard.populateLanguages($('#selectLanguage', page), languages);
Dashboard.populateCountries($('#selectCountry', page), countries);
2013-08-02 13:36:44 -07:00
2013-05-22 09:52:22 -07:00
LibraryBrowser.renderName(item, $('.itemName', page), true);
2013-08-02 13:36:44 -07:00
setFieldVisibilities(page, item);
2014-12-20 22:57:06 -07:00
fillItemInfo(page, item, metadataEditorInfo.ParentalRatingOptions);
if (item.Type == "BoxSet") {
2015-08-24 13:37:34 -07:00
page.querySelector('.collectionItemsTabButton').classList.remove('hide');
} else {
2015-08-24 13:37:34 -07:00
page.querySelector('.collectionItemsTabButton').classList.add('hide');
}
2014-07-16 20:17:14 -07:00
if (item.MediaType == "Video" && item.LocationType == "FileSystem" && item.Type !== 'TvChannel') {
2015-08-24 13:37:34 -07:00
page.querySelector('.subtitleTabButton').classList.remove('hide');
2014-05-16 21:24:10 -07:00
} else {
2015-08-24 13:37:34 -07:00
page.querySelector('.subtitleTabButton').classList.add('hide');
2014-05-16 21:24:10 -07:00
}
if (item.MediaType == 'Photo') {
$('#btnEditImages', page).hide();
} else {
$('#btnEditImages', page).show();
}
2014-06-24 14:45:21 -07:00
if (item.MediaType == "Video" && item.Type != "Episode") {
$('#fldShortOverview', page).show();
} else {
$('#fldShortOverview', page).hide();
}
2014-06-28 19:30:20 -07:00
if (item.MediaType == "Video" && item.Type != "Episode") {
$('#fldTagline', page).show();
} else {
$('#fldTagline', page).hide();
}
2015-07-14 13:29:51 -07:00
Dashboard.hideLoadingMsg();
bindItemChanged(page);
});
}
2014-12-21 11:58:17 -07:00
function renderContentTypeOptions(page, metadataInfo) {
if (metadataInfo.ContentTypeOptions.length) {
$('#fldContentType', page).show();
} else {
$('#fldContentType', page).hide();
}
var html = metadataInfo.ContentTypeOptions.map(function (i) {
return '<option value="' + i.Value + '">' + i.Name + '</option>';
}).join('');
$('#selectContentType', page).html(html).val(metadataInfo.ContentType || '').selectmenu('refresh');
}
2014-02-21 14:44:10 -07:00
function onExternalIdChange() {
var formatString = this.getAttribute('data-formatstring');
var buttonClass = this.getAttribute('data-buttonclass');
if (this.value) {
$('.' + buttonClass).attr('href', formatString.replace('{0}', this.value));
} else {
$('.' + buttonClass).attr('href', '#');
}
}
function loadExternalIds(page, item, externalIds) {
var html = '';
var providerIds = item.ProviderIds || {};
for (var i = 0, length = externalIds.length; i < length; i++) {
var idInfo = externalIds[i];
var id = "txt1" + idInfo.Key;
var buttonId = "btnOpen1" + idInfo.Key;
var formatString = idInfo.UrlFormatString || '';
2015-08-15 17:41:55 -07:00
var labelText = Globalize.translate('LabelDynamicExternalId').replace('{0}', idInfo.Name);
2014-02-21 14:44:10 -07:00
2015-08-15 17:41:55 -07:00
html += '<div>';
2014-02-21 14:44:10 -07:00
var value = providerIds[idInfo.Key] || '';
2015-08-15 17:41:55 -07:00
html += '<paper-input style="display:inline-block;width:80%;" class="txtExternalId" value="' + value + '" data-providerkey="' + idInfo.Key + '" data-formatstring="' + formatString + '" data-buttonclass="' + buttonId + '" id="' + id + '" label="' + labelText + '"></paper-input>';
2014-02-21 14:44:10 -07:00
if (formatString) {
2015-08-15 17:41:55 -07:00
html += '<a class="clearLink ' + buttonId + '" href="#" target="_blank" data-role="none" style="float: none; width: 1.75em"><paper-icon-button icon="open-in-browser"></paper-icon-button></a>';
2014-02-21 14:44:10 -07:00
}
html += '</div>';
}
var elem = $('.externalIds', page).html(html).trigger('create');
$('.txtExternalId', elem).on('change', onExternalIdChange).trigger('change');
}
function setFieldVisibilities(page, item) {
2013-05-22 09:52:22 -07:00
2014-09-28 09:50:33 -07:00
if (item.Path && item.LocationType != 'Remote') {
2013-08-17 16:25:23 -07:00
$('#fldPath', page).show();
} else {
$('#fldPath', page).hide();
}
if (item.Type == "Series") {
$('#fldSeriesRuntime', page).show();
} else {
$('#fldSeriesRuntime', page).hide();
}
if (item.Type == "Series" || item.Type == "Person") {
$('#fldEndDate', page).show();
} else {
$('#fldEndDate', page).hide();
}
if (item.Type == "Movie" || item.MediaType == "Game" || item.MediaType == "Trailer" || item.Type == "MusicVideo") {
$('#fldBudget', page).show();
$('#fldRevenue', page).show();
} else {
$('#fldBudget', page).hide();
$('#fldRevenue', page).hide();
}
2013-07-16 09:03:28 -07:00
if (item.Type == "MusicAlbum") {
$('#albumAssociationMessage', page).show();
} else {
$('#albumAssociationMessage', page).hide();
}
2013-05-22 15:01:37 -07:00
if (item.MediaType == "Game") {
$('#fldPlayers', page).show();
} else {
$('#fldPlayers', page).hide();
}
2015-09-01 12:18:25 -07:00
if (item.Type == "Movie" || item.Type == "Trailer") {
2013-05-22 15:01:37 -07:00
$('#fldCriticRating', page).show();
$('#fldCriticRatingSummary', page).show();
} else {
$('#fldCriticRating', page).hide();
$('#fldCriticRatingSummary', page).hide();
}
2014-01-14 22:01:58 -07:00
if (item.Type == "Movie") {
$('#fldAwardSummary', page).show();
} else {
$('#fldAwardSummary', page).hide();
}
if (item.Type == "Movie" || item.Type == "Trailer") {
$('#fldMetascore', page).show();
} else {
$('#fldMetascore', page).hide();
}
if (item.Type == "Series") {
$('#fldStatus', page).show();
$('#fldAirDays', page).show();
$('#fldAirTime', page).show();
} else {
$('#fldStatus', page).hide();
$('#fldAirDays', page).hide();
$('#fldAirTime', page).hide();
}
2013-05-22 15:01:37 -07:00
2014-03-17 18:45:41 -07:00
if (item.MediaType == "Video" && item.Type != "TvChannel") {
$('#fld3dFormat', page).show();
} else {
$('#fld3dFormat', page).hide();
}
2013-05-22 15:01:37 -07:00
if (item.Type == "Audio") {
$('#fldAlbumArtist', page).show();
} else {
$('#fldAlbumArtist', page).hide();
}
if (item.Type == "Audio" || item.Type == "MusicVideo") {
2013-05-22 15:01:37 -07:00
$('#fldArtist', page).show();
$('#fldAlbum', page).show();
} else {
$('#fldArtist', page).hide();
$('#fldAlbum', page).hide();
}
if (item.Type == "Episode") {
$('#collapsibleDvdEpisodeInfo', page).show();
} else {
$('#collapsibleDvdEpisodeInfo', page).hide();
}
if (item.Type == "Episode" && item.ParentIndexNumber == 0) {
$('#collapsibleSpecialEpisodeInfo', page).show();
} else {
$('#collapsibleSpecialEpisodeInfo', page).hide();
}
2014-03-17 18:45:41 -07:00
if (item.Type == "Person" || item.Type == "Genre" || item.Type == "Studio" || item.Type == "GameGenre" || item.Type == "MusicGenre" || item.Type == "TvChannel") {
$('#fldCommunityRating', page).hide();
$('#fldCommunityVoteCount', page).hide();
$('#genresCollapsible', page).hide();
2014-05-16 12:16:29 -07:00
$('#peopleCollapsible', page).hide();
$('#studiosCollapsible', page).hide();
2014-03-17 18:45:41 -07:00
if (item.Type == "TvChannel") {
$('#fldOfficialRating', page).show();
} else {
$('#fldOfficialRating', page).hide();
}
$('#fldCustomRating', page).hide();
} else {
$('#fldCommunityRating', page).show();
$('#fldCommunityVoteCount', page).show();
$('#genresCollapsible', page).show();
2014-05-16 12:16:29 -07:00
$('#peopleCollapsible', page).show();
$('#studiosCollapsible', page).show();
$('#fldOfficialRating', page).show();
$('#fldCustomRating', page).show();
}
2014-10-01 17:28:16 -07:00
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicArtist") {
2014-07-05 08:01:29 -07:00
$('#countriesCollapsible', page).show();
} else {
$('#countriesCollapsible', page).hide();
}
2014-03-17 18:45:41 -07:00
if (item.Type == "TvChannel") {
$('#tagsCollapsible', page).hide();
$('#metadataSettingsCollapsible', page).hide();
$('#fldPremiereDate', page).hide();
$('#fldSortName', page).hide();
$('#fldDateAdded', page).hide();
$('#fldYear', page).hide();
} else {
$('#tagsCollapsible', page).show();
$('#metadataSettingsCollapsible', page).show();
$('#fldPremiereDate', page).show();
$('#fldSortName', page).show();
$('#fldDateAdded', page).show();
$('#fldYear', page).show();
2014-03-01 10:53:56 -07:00
}
2014-03-01 15:34:27 -07:00
2014-03-08 11:17:05 -07:00
if (item.Type == "Movie" ||
item.Type == "Trailer" ||
item.Type == "Series" ||
item.Type == "Game" ||
item.Type == "BoxSet" ||
item.Type == "Person" ||
item.Type == "Book" ||
item.Type == "MusicAlbum" ||
item.Type == "MusicArtist") {
2014-05-16 12:16:29 -07:00
2014-03-01 10:53:56 -07:00
$('#btnIdentify', page).show();
} else {
$('#btnIdentify', page).hide();
}
2014-01-14 09:06:26 -07:00
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "BoxSet") {
$('#keywordsCollapsible', page).show();
} else {
$('#keywordsCollapsible', page).hide();
}
2014-03-17 18:45:41 -07:00
if (item.MediaType == "Video" && item.Type != "TvChannel") {
2014-01-19 11:08:31 -07:00
$('#fldSourceType', page).show();
} else {
$('#fldSourceType', page).hide();
}
if (item.Type == "Person") {
2015-08-21 08:34:42 -07:00
page.querySelector('#txtProductionYear').label = Globalize.translate('LabelBirthYear');
2015-09-01 12:18:25 -07:00
page.querySelector("label[for='txtPremiereDate']").innerHTML = Globalize.translate('LabelBirthDate');
page.querySelector("label[for='txtEndDate']").innerHTML = Globalize.translate('LabelDeathDate');
$('#fldPlaceOfBirth', page).show();
} else {
2015-08-21 08:34:42 -07:00
page.querySelector('#txtProductionYear').label = Globalize.translate('LabelYear');
2015-09-01 12:18:25 -07:00
page.querySelector("label[for='txtPremiereDate']").innerHTML = Globalize.translate('LabelReleaseDate');
page.querySelector("label[for='txtEndDate']").innerHTML = Globalize.translate('LabelEndDate');
$('#fldPlaceOfBirth', page).hide();
}
2014-03-17 18:45:41 -07:00
if (item.MediaType == "Video" && item.Type != "TvChannel") {
$('#fldOriginalAspectRatio', page).show();
} else {
$('#fldOriginalAspectRatio', page).hide();
}
if (item.Type == "Audio" || item.Type == "Episode" || item.Type == "Season") {
$('#fldIndexNumber', page).show();
if (item.Type == "Episode") {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtIndexNumber').label = Globalize.translate('LabelEpisodeNumber');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Season") {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtIndexNumber').label = Globalize.translate('LabelSeasonNumber');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Audio") {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtIndexNumber').label = Globalize.translate('LabelTrackNumber');
2014-02-12 22:11:54 -07:00
} else {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtIndexNumber').label = Globalize.translate('LabelNumber');
}
} else {
$('#fldIndexNumber', page).hide();
}
if (item.Type == "Audio" || item.Type == "Episode") {
$('#fldParentIndexNumber', page).show();
if (item.Type == "Episode") {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtParentIndexNumber').label = Globalize.translate('LabelSeasonNumber');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Audio") {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtParentIndexNumber').label = Globalize.translate('LabelDiscNumber');
2014-02-12 22:11:54 -07:00
} else {
2015-08-16 11:37:53 -07:00
page.querySelector('#txtParentIndexNumber').label = Globalize.translate('LabelParentNumber');
}
} else {
$('#fldParentIndexNumber', page).hide();
}
if (item.Type == "Series") {
$('#fldDisplaySpecialsInline', page).show();
} else {
$('#fldDisplaySpecialsInline', page).hide();
}
if (item.Type == "BoxSet") {
$('#fldDisplayOrder', page).show();
2014-08-24 08:48:06 -07:00
$('#labelDisplayOrder', page).html(Globalize.translate('LabelTitleDisplayOrder'));
2014-12-20 18:23:56 -07:00
$('#selectDisplayOrder', page).html('<option value="SortName">' + Globalize.translate('OptionSortName') + '</option><option value="PremiereDate">' + Globalize.translate('OptionReleaseDate') + '</option>').selectmenu('refresh');
} else {
$('#selectDisplayOrder', page).html('').selectmenu('refresh');
$('#fldDisplayOrder', page).hide();
}
var displaySettingFields = $('.fldDisplaySetting', page);
if (displaySettingFields.filter(function (index) {
return displaySettingFields[index].style.display != 'none';
}).length) {
$('#collapsibleDisplaySettings', page).show();
} else {
$('#collapsibleDisplaySettings', page).hide();
}
}
2014-12-20 22:57:06 -07:00
function fillItemInfo(page, item, parentalRatingOptions) {
2014-12-20 22:57:06 -07:00
var select = $('#selectOfficialRating', page);
2013-05-22 09:52:22 -07:00
2014-12-20 22:57:06 -07:00
populateRatings(parentalRatingOptions, select, item.OfficialRating);
2014-12-20 22:57:06 -07:00
select.val(item.OfficialRating || "").selectmenu('refresh');
2014-12-20 22:57:06 -07:00
select = $('#selectCustomRating', page);
2013-05-22 09:52:22 -07:00
2014-12-20 22:57:06 -07:00
populateRatings(parentalRatingOptions, select, item.CustomRating);
2014-12-20 22:57:06 -07:00
select.val(item.CustomRating || "").selectmenu('refresh');
2014-07-27 15:01:29 -07:00
var selectStatus = $('#selectStatus', page);
populateStatus(selectStatus);
selectStatus.val(item.Status || "").selectmenu('refresh');
2013-06-19 06:54:45 -07:00
$('#select3dFormat', page).val(item.Video3DFormat || "").selectmenu('refresh');
2014-02-12 22:11:54 -07:00
$('.chkAirDay', page).each(function () {
2014-02-09 10:44:25 -07:00
this.checked = (item.AirDays || []).indexOf(this.getAttribute('data-day')) != -1;
2015-08-16 11:37:53 -07:00
});
2014-02-12 22:11:54 -07:00
2014-05-16 12:16:29 -07:00
populateListView($('#listCountries', page), item.ProductionLocations || []);
populateListView($('#listGenres', page), item.Genres);
2014-06-04 09:15:44 -07:00
populatePeople(page, item.People || []);
populateListView($('#listStudios', page), (item.Studios || []).map(function (element) { return element.Name || ''; }));
populateListView($('#listTags', page), item.Tags);
2014-01-14 09:06:26 -07:00
populateListView($('#listKeywords', page), item.Keywords);
2014-02-18 22:21:03 -07:00
var lockData = (item.LockData || false);
2015-08-15 17:41:55 -07:00
var chkLockData = page.querySelector("#chkLockData");
chkLockData.checked = lockData;
if (chkLockData.checked) {
2013-06-19 06:54:45 -07:00
$('#providerSettingsContainer', page).hide();
2014-02-18 22:21:03 -07:00
} else {
$('#providerSettingsContainer', page).show();
2013-06-14 22:30:48 -07:00
}
populateInternetProviderSettings(page, item, item.LockedFields);
2013-12-28 22:32:03 -07:00
2015-08-16 11:37:53 -07:00
page.querySelector('#chkDisplaySpecialsInline').checked = item.DisplaySpecialsWithSeasons || false;
2013-06-19 06:54:45 -07:00
2013-08-17 16:25:23 -07:00
$('#txtPath', page).val(item.Path || '');
$('#txtName', page).val(item.Name || "");
2015-09-01 12:18:25 -07:00
page.querySelector('#txtOverview').value = item.Overview || '';
2014-06-24 14:45:21 -07:00
$('#txtShortOverview', page).val(item.ShortOverview || "");
2014-07-16 20:17:14 -07:00
$('#txtTagline', page).val((item.Taglines && item.Taglines.length ? item.Taglines[0] : ''));
2014-03-24 10:54:45 -07:00
$('#txtSortName', page).val(item.ForcedSortName || "");
$('#txtDisplayMediaType', page).val(item.DisplayMediaType || "");
$('#txtCommunityRating', page).val(item.CommunityRating || "");
$('#txtCommunityVoteCount', page).val(item.VoteCount || "");
$('#txtHomePageUrl', page).val(item.HomePageUrl || "");
2014-01-14 22:01:58 -07:00
$('#txtAwardSummary', page).val(item.AwardSummary || "");
$('#txtMetascore', page).val(item.Metascore || "");
$('#txtBudget', page).val(item.Budget || "");
$('#txtRevenue', page).val(item.Revenue || "");
$('#txtCriticRating', page).val(item.CriticRating || "");
$('#txtCriticRatingSummary', page).val(item.CriticRatingSummary || "");
$('#txtIndexNumber', page).val(('IndexNumber' in item) ? item.IndexNumber : "");
$('#txtParentIndexNumber', page).val(('ParentIndexNumber' in item) ? item.ParentIndexNumber : "");
2013-05-22 15:01:37 -07:00
$('#txtPlayers', page).val(item.Players || "");
$('#txtAbsoluteEpisodeNumber', page).val(('AbsoluteEpisodeNumber' in item) ? item.AbsoluteEpisodeNumber : "");
$('#txtDvdEpisodeNumber', page).val(('DvdEpisodeNumber' in item) ? item.DvdEpisodeNumber : "");
$('#txtDvdSeasonNumber', page).val(('DvdSeasonNumber' in item) ? item.DvdSeasonNumber : "");
$('#txtAirsBeforeSeason', page).val(('AirsBeforeSeasonNumber' in item) ? item.AirsBeforeSeasonNumber : "");
$('#txtAirsAfterSeason', page).val(('AirsAfterSeasonNumber' in item) ? item.AirsAfterSeasonNumber : "");
2013-12-14 18:17:57 -07:00
$('#txtAirsBeforeEpisode', page).val(('AirsBeforeEpisodeNumber' in item) ? item.AirsBeforeEpisodeNumber : "");
2013-05-22 15:01:37 -07:00
$('#txtAlbum', page).val(item.Album || "");
2015-03-13 08:54:20 -07:00
2015-03-13 10:25:28 -07:00
$('#txtAlbumArtist', page).val((item.AlbumArtists || []).map(function (a) {
return a.Name;
}).join(';'));
2013-05-22 15:01:37 -07:00
2014-01-03 13:43:44 -07:00
$('#selectDisplayOrder', page).val(item.DisplayOrder).selectmenu('refresh');
2015-03-13 10:25:28 -07:00
$('#txtArtist', page).val((item.ArtistItems || []).map(function (a) {
return a.Name;
}).join(';'));
var date;
if (item.DateCreated) {
try {
date = parseISO8601Date(item.DateCreated, { toLocal: true });
$('#txtDateAdded', page).val(date.toISOString().slice(0, 10));
2014-02-12 22:11:54 -07:00
} catch (e) {
$('#txtDateAdded', page).val('');
}
} else {
$('#txtDateAdded', page).val('');
}
if (item.PremiereDate) {
try {
date = parseISO8601Date(item.PremiereDate, { toLocal: true });
$('#txtPremiereDate', page).val(date.toISOString().slice(0, 10));
2014-02-12 22:11:54 -07:00
} catch (e) {
$('#txtPremiereDate', page).val('');
}
} else {
$('#txtPremiereDate', page).val('');
}
if (item.EndDate) {
try {
date = parseISO8601Date(item.EndDate, { toLocal: true });
$('#txtEndDate', page).val(date.toISOString().slice(0, 10));
2014-02-12 22:11:54 -07:00
} catch (e) {
$('#txtEndDate', page).val('');
}
} else {
$('#txtEndDate', page).val('');
}
$('#txtProductionYear', page).val(item.ProductionYear || "");
2015-09-01 12:18:25 -07:00
$('#txtAirTime', page).val(item.AirTime || '');
var placeofBirth = item.ProductionLocations && item.ProductionLocations.length ? item.ProductionLocations[0] : '';
$('#txtPlaceOfBirth', page).val(placeofBirth);
$('#txtOriginalAspectRatio', page).val(item.AspectRatio || "");
2013-05-22 15:01:37 -07:00
2013-12-28 09:58:13 -07:00
$('#selectLanguage', page).val(item.PreferredMetadataLanguage || "").selectmenu('refresh');
$('#selectCountry', page).val(item.PreferredMetadataCountryCode || "").selectmenu('refresh');
if (item.RunTimeTicks) {
var minutes = item.RunTimeTicks / 600000000;
2013-09-26 07:47:57 -07:00
$('#txtSeriesRuntime', page).val(Math.round(minutes));
} else {
$('#txtSeriesRuntime', page).val("");
}
}
2014-06-04 09:15:44 -07:00
function populatePeople(page, people) {
2014-05-16 12:16:29 -07:00
var lastType = '';
var html = '';
2014-06-04 09:15:44 -07:00
var elem = $('#peopleList', page);
2014-05-16 12:16:29 -07:00
for (var i = 0, length = people.length; i < length; i++) {
var person = people[i];
2014-08-24 08:48:06 -07:00
var type = person.Type || Globalize.translate('PersonTypePerson');
2014-05-16 12:16:29 -07:00
if (type != lastType) {
html += '<li data-role="list-divider">' + type + '</li>';
lastType = type;
}
2014-06-04 09:15:44 -07:00
html += '<li><a class="btnEditPerson" href="#" data-index="' + i + '">';
2014-05-16 12:16:29 -07:00
2014-07-16 20:17:14 -07:00
html += '<h3>' + (person.Name || '') + '</h3>';
2014-05-16 12:16:29 -07:00
if (person.Role && person.Role != lastType) {
html += '<p>' + (person.Role) + '</p>';
}
html += '</a>';
2014-07-16 20:17:14 -07:00
html += '<a class="btnDeletePerson" href="#" data-icon="delete" data-index="' + i + '">' + Globalize.translate('Delete') + '</a>';
2014-05-16 12:16:29 -07:00
html += '</li>';
}
elem.html(html).listview('refresh');
$('.btnDeletePerson', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-index'));
currentItem.People.splice(index, 1);
2014-06-04 09:15:44 -07:00
populatePeople(page, currentItem.People);
});
$('.btnEditPerson', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-index'));
editPerson(page, currentItem.People[index], index);
2014-05-16 12:16:29 -07:00
});
}
2014-06-04 09:15:44 -07:00
function editPerson(page, person, index) {
$('#popupEditPerson', page).popup("open");
$('#txtPersonName', page).val(person.Name || '');
$('#selectPersonType', page).val(person.Type || '').selectmenu('refresh');
$('#txtPersonRole', page).val(person.Role || '');
if (index == null) {
index = '';
}
$("#fldPersonIndex", page).val(index);
}
function savePersonInfo(page) {
$('#popupEditPerson', page).popup("close");
var index = $("#fldPersonIndex", page).val();
var person;
var isNew = true;
if (index) {
isNew = false;
index = parseInt(index);
person = currentItem.People[index];
} else {
person = {};
}
person.Name = $('#txtPersonName', page).val();
person.Type = $('#selectPersonType', page).val();
person.Role = $('#txtPersonRole', page).val();
if (isNew) {
currentItem.People.push(person);
}
populatePeople(page, currentItem.People);
}
2014-07-27 15:01:29 -07:00
function populateRatings(allParentalRatings, select, currentValue) {
var html = "";
html += "<option value=''></option>";
var ratings = [];
var i, length, rating;
2014-07-27 15:01:29 -07:00
var currentValueFound = false;
for (i = 0, length = allParentalRatings.length; i < length; i++) {
rating = allParentalRatings[i];
ratings.push({ Name: rating.Name, Value: rating.Name });
2014-07-27 15:01:29 -07:00
if (rating.Name == currentValue) {
currentValueFound = true;
}
}
if (currentValue && !currentValueFound) {
ratings.push({ Name: currentValue, Value: currentValue });
}
for (i = 0, length = ratings.length; i < length; i++) {
rating = ratings[i];
html += "<option value='" + rating.Value + "'>" + rating.Name + "</option>";
}
select.html(html).selectmenu("refresh");
}
2013-05-22 09:52:22 -07:00
function populateStatus(select) {
var html = "";
html += "<option value=''></option>";
2014-07-16 20:17:14 -07:00
html += "<option value='Continuing'>" + Globalize.translate('OptionContinuing') + "</option>";
html += "<option value='Ended'>" + Globalize.translate('OptionEnded') + "</option>";
select.html(html).selectmenu("refresh");
}
2013-06-19 06:54:45 -07:00
function populateListView(list, items, sortCallback) {
items = items || [];
2013-06-19 06:54:45 -07:00
if (typeof (sortCallback) === 'undefined') {
items.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
} else {
items = sortCallback(items);
}
var html = '';
for (var i = 0; i < items.length; i++) {
2013-11-28 11:27:29 -07:00
html += '<li data-mini="true"><a class="data">' + items[i] + '</a><a href="#" onclick="EditItemMetadataPage.removeElementFromListview(this)" class="btnRemoveFromEditorList"></a></li>';
}
list.html(html).listview('refresh');
}
function editableListViewValues(list) {
return list.find('a.data').map(function () { return $(this).text(); }).get();
}
2013-06-14 22:30:48 -07:00
2015-08-15 17:41:55 -07:00
function generateSliders(fields, currentFields) {
2013-06-14 22:30:48 -07:00
var html = '';
for (var i = 0; i < fields.length; i++) {
2013-06-14 22:30:48 -07:00
var field = fields[i];
var name = field.name;
var value = field.value || field.name;
2015-08-15 17:41:55 -07:00
var checkedHtml = currentFields.indexOf(value) == -1 ? ' checked' : '';
html += '<paper-checkbox class="selectLockedField" data-value="' + value + '" style="display:block;margin:1em 0;"' + checkedHtml + '>' + name + '</paper-checkbox>';
2013-06-14 22:30:48 -07:00
}
return html;
}
2014-02-12 22:11:54 -07:00
function populateInternetProviderSettings(page, item, lockedFields) {
2013-06-14 22:30:48 -07:00
var container = $('#providerSettingsContainer', page);
lockedFields = lockedFields || new Array();
var metadatafields = [
2014-07-16 20:17:14 -07:00
{ name: Globalize.translate('OptionName'), value: "Name" },
{ name: Globalize.translate('OptionOverview'), value: "Overview" },
{ name: Globalize.translate('OptionGenres'), value: "Genres" },
{ name: Globalize.translate('OptionParentalRating'), value: "OfficialRating" },
{ name: Globalize.translate('OptionPeople'), value: "Cast" }
];
if (item.Type == "Person") {
2014-07-16 20:17:14 -07:00
metadatafields.push({ name: Globalize.translate('OptionBirthLocation'), value: "ProductionLocations" });
} else {
2014-07-16 20:17:14 -07:00
metadatafields.push({ name: Globalize.translate('OptionProductionLocations'), value: "ProductionLocations" });
}
if (item.Type == "Series") {
2014-07-16 20:17:14 -07:00
metadatafields.push({ name: Globalize.translate('OptionRuntime'), value: "Runtime" });
}
2014-07-16 20:17:14 -07:00
metadatafields.push({ name: Globalize.translate('OptionStudios'), value: "Studios" });
metadatafields.push({ name: Globalize.translate('OptionTags'), value: "Tags" });
metadatafields.push({ name: Globalize.translate('OptionKeywords'), value: "Keywords" });
metadatafields.push({ name: Globalize.translate('OptionImages'), value: "Images" });
metadatafields.push({ name: Globalize.translate('OptionBackdrops'), value: "Backdrops" });
2013-12-28 22:32:03 -07:00
if (item.Type == "Game") {
2014-07-16 20:17:14 -07:00
metadatafields.push({ name: Globalize.translate('OptionScreenshots'), value: "Screenshots" });
}
2013-12-28 22:32:03 -07:00
2013-06-14 22:30:48 -07:00
var html = '';
2015-08-15 17:41:55 -07:00
html += "<h1>" + Globalize.translate('HeaderEnabledFields') + "</h1>";
html += "<p>" + Globalize.translate('HeaderEnabledFieldsHelp') + "</p>";
html += generateSliders(metadatafields, lockedFields);
container.html(html);
2013-06-14 22:30:48 -07:00
}
2014-02-12 22:11:54 -07:00
2014-02-09 10:44:25 -07:00
function getSelectedAirDays(form) {
2014-02-12 22:11:54 -07:00
return $('.chkAirDay:checked', form).map(function () {
2014-02-09 10:44:25 -07:00
return this.getAttribute('data-day');
}).get();
}
2013-06-14 22:30:48 -07:00
2014-10-06 16:58:46 -07:00
function onDeleted(id) {
2014-12-20 18:23:56 -07:00
2014-10-06 16:58:46 -07:00
var elem = $('#' + id)[0];
2014-02-12 22:11:54 -07:00
2014-10-06 16:58:46 -07:00
$('.libraryTree').jstree("select_node", elem, true)
.jstree("delete_node", '#' + id);
2014-02-12 22:11:54 -07:00
}
2015-03-13 08:54:20 -07:00
function getAlbumArtists(form) {
2015-06-29 11:45:42 -07:00
return $('#txtAlbumArtist', form).val().trim().split(';').filter(function (s) {
2015-06-07 12:24:45 -07:00
2015-06-29 11:45:42 -07:00
return s.length > 0;
2015-06-07 12:24:45 -07:00
}).map(function (a) {
2015-03-13 08:54:20 -07:00
return {
Name: a
};
});
}
2015-03-13 10:25:28 -07:00
function getArtists(form) {
2015-06-29 11:45:42 -07:00
return $('#txtArtist', form).val().trim().split(';').filter(function (s) {
2015-06-07 12:24:45 -07:00
2015-06-29 11:45:42 -07:00
return s.length > 0;
2015-06-07 12:24:45 -07:00
}).map(function (a) {
2015-03-13 10:25:28 -07:00
return {
Name: a
};
});
}
function editItemMetadataPage() {
2013-05-27 19:36:51 -07:00
var self = this;
2013-05-22 09:52:22 -07:00
self.onSubmit = function () {
2013-05-27 19:36:51 -07:00
var form = this;
var item = {
2013-08-02 13:36:44 -07:00
Id: currentItem.Id,
2013-05-27 19:36:51 -07:00
Name: $('#txtName', form).val(),
2014-03-24 10:54:45 -07:00
ForcedSortName: $('#txtSortName', form).val(),
2013-05-27 19:36:51 -07:00
DisplayMediaType: $('#txtDisplayMediaType', form).val(),
CommunityRating: $('#txtCommunityRating', form).val(),
2013-12-08 10:57:18 -07:00
VoteCount: $('#txtCommunityVoteCount', form).val(),
2013-05-27 19:36:51 -07:00
HomePageUrl: $('#txtHomePageUrl', form).val(),
Budget: $('#txtBudget', form).val(),
Revenue: $('#txtRevenue', form).val(),
CriticRating: $('#txtCriticRating', form).val(),
CriticRatingSummary: $('#txtCriticRatingSummary', form).val(),
IndexNumber: $('#txtIndexNumber', form).val() || null,
2015-08-16 11:37:53 -07:00
DisplaySpecialsWithSeasons: form.querySelector('#chkDisplaySpecialsInline').checked,
AbsoluteEpisodeNumber: $('#txtAbsoluteEpisodeNumber', form).val(),
DvdEpisodeNumber: $('#txtDvdEpisodeNumber', form).val(),
DvdSeasonNumber: $('#txtDvdSeasonNumber', form).val(),
AirsBeforeSeasonNumber: $('#txtAirsBeforeSeason', form).val(),
AirsAfterSeasonNumber: $('#txtAirsAfterSeason', form).val(),
2013-12-14 18:17:57 -07:00
AirsBeforeEpisodeNumber: $('#txtAirsBeforeEpisode', form).val(),
ParentIndexNumber: $('#txtParentIndexNumber', form).val() || null,
DisplayOrder: $('#selectDisplayOrder', form).val(),
2013-05-27 19:36:51 -07:00
Players: $('#txtPlayers', form).val(),
Album: $('#txtAlbum', form).val(),
2015-03-13 08:54:20 -07:00
AlbumArtist: getAlbumArtists(form),
2015-03-13 10:25:28 -07:00
ArtistItems: getArtists(form),
2014-01-14 22:01:58 -07:00
Metascore: $('#txtMetascore', form).val(),
AwardSummary: $('#txtAwardSummary', form).val(),
Overview: $('#txtOverview', form).val(),
2014-06-24 14:45:21 -07:00
ShortOverview: $('#txtShortOverview', form).val(),
Status: $('#selectStatus', form).val(),
2014-02-09 10:44:25 -07:00
AirDays: getSelectedAirDays(form),
2014-07-16 20:17:14 -07:00
AirTime: $('#txtAirTime', form).val(),
Genres: editableListViewValues($("#listGenres", form)),
2014-05-16 12:16:29 -07:00
ProductionLocations: editableListViewValues($("#listCountries", form)),
Tags: editableListViewValues($("#listTags", form)),
2014-01-14 09:06:26 -07:00
Keywords: editableListViewValues($("#listKeywords", form)),
2013-06-19 06:54:45 -07:00
Studios: editableListViewValues($("#listStudios", form)).map(function (element) { return { Name: element }; }),
2013-06-14 22:30:48 -07:00
2014-12-20 18:23:56 -07:00
PremiereDate: EditItemMetadataPage.getDateFromForm(form, '#txtPremiereDate', 'PremiereDate'),
DateCreated: EditItemMetadataPage.getDateFromForm(form, '#txtDateAdded', 'DateCreated'),
EndDate: EditItemMetadataPage.getDateFromForm(form, '#txtEndDate', 'EndDate'),
2013-05-27 19:36:51 -07:00
ProductionYear: $('#txtProductionYear', form).val(),
AspectRatio: $('#txtOriginalAspectRatio', form).val(),
Video3DFormat: $('#select3dFormat', form).val(),
2013-06-14 22:30:48 -07:00
2013-05-27 19:36:51 -07:00
OfficialRating: $('#selectOfficialRating', form).val(),
CustomRating: $('#selectCustomRating', form).val(),
2013-06-09 00:50:35 -07:00
People: currentItem.People,
2015-08-15 17:41:55 -07:00
LockData: form.querySelector("#chkLockData").checked,
LockedFields: $('.selectLockedField', form).get().filter(function (c) {
return !c.checked;
}).map(function (c) {
return c.getAttribute('data-value');
})
2013-05-27 19:36:51 -07:00
};
2014-02-21 14:44:10 -07:00
item.ProviderIds = $.extend({}, currentItem.ProviderIds || {});
$('.txtExternalId', form).each(function () {
var providerkey = this.getAttribute('data-providerkey');
2014-02-12 22:11:54 -07:00
2014-02-21 14:44:10 -07:00
item.ProviderIds[providerkey] = this.value;
2014-02-09 14:11:11 -07:00
});
2013-12-28 09:58:13 -07:00
item.PreferredMetadataLanguage = $('#selectLanguage', form).val();
item.PreferredMetadataCountryCode = $('#selectCountry', form).val();
if (currentItem.Type == "Person") {
var placeOfBirth = $('#txtPlaceOfBirth', form).val();
item.ProductionLocations = placeOfBirth ? [placeOfBirth] : [];
}
if (currentItem.Type == "Series") {
// 600000000
var seriesRuntime = $('#txtSeriesRuntime', form).val();
item.RunTimeTicks = seriesRuntime ? (seriesRuntime * 600000000) : null;
}
2014-06-28 19:30:20 -07:00
var tagline = $('#txtTagline', form).val();
item.Taglines = tagline ? [tagline] : [];
2014-12-21 11:58:17 -07:00
self.submitUpdatedItem(form, item);
return false;
};
self.submitUpdatedItem = function (form, item) {
2015-03-17 21:09:31 -07:00
var page = $(form).parents('.page');
unbindItemChanged(page);
2014-12-21 11:58:17 -07:00
function afterContentTypeUpdated() {
2013-05-27 19:36:51 -07:00
2014-07-16 20:17:14 -07:00
Dashboard.alert(Globalize.translate('MessageItemSaved'));
2013-05-27 19:36:51 -07:00
MetadataEditor.getItemPromise().done(function (i) {
2015-03-17 21:09:31 -07:00
page.trigger('itemsaved', [i]);
bindItemChanged(page);
});
2014-12-21 11:58:17 -07:00
}
2014-12-21 11:58:17 -07:00
ApiClient.updateItem(item).done(function () {
2014-12-21 11:58:17 -07:00
var newContentType = $('#selectContentType', form).val() || '';
if ((metadataEditorInfo.ContentType || '') != newContentType) {
ApiClient.ajax({
url: ApiClient.getUrl('Items/' + item.Id + '/ContentType', {
ContentType: newContentType
}),
type: 'POST'
}).done(function () {
afterContentTypeUpdated();
});
} else {
afterContentTypeUpdated();
}
});
2013-06-19 06:54:45 -07:00
};
2014-12-20 18:23:56 -07:00
self.getDateFromForm = function (form, element, property) {
var val = $(element, form).val();
if (!val) {
return null;
}
if (currentItem[property]) {
var date = parseISO8601Date(currentItem[property], { toLocal: true });
var parts = date.toISOString().split('T');
// If the date is the same, preserve the time
if (parts[0].indexOf(val) == 0) {
var iso = parts[1];
val += 'T' + iso;
}
}
return val;
};
2013-06-19 06:54:45 -07:00
self.addElementToEditableListview = function (source, sortCallback) {
2015-01-20 13:19:54 -07:00
var parent = $(source).parents('*[data-role="editableListviewContainer"]');
var input = parent.find('.txtEditableListview, select');
2013-06-09 00:50:35 -07:00
var text = input.val();
2015-01-20 13:19:54 -07:00
2013-06-09 00:50:35 -07:00
if (text == '') return;
2015-01-20 13:19:54 -07:00
var list = parent.find('ul[data-role="listview"]');
2013-06-09 00:50:35 -07:00
var items = editableListViewValues(list);
items.push(text);
populateListView(list, items, sortCallback);
2013-06-09 00:50:35 -07:00
};
2013-06-19 06:54:45 -07:00
2013-06-14 22:30:48 -07:00
self.setProviderSettingsContainerVisibility = function (source) {
2014-02-11 20:46:27 -07:00
if (!$(source).prop('checked')) {
2013-06-14 22:30:48 -07:00
$('#providerSettingsContainer').show();
} else {
$('#providerSettingsContainer').hide();
}
};
2013-06-19 06:54:45 -07:00
self.removeElementFromListview = function (source) {
2013-06-09 00:50:35 -07:00
var list = $(source).parents('ul[data-role="listview"]');
$(source).parent().remove();
list.listview('refresh');
};
2014-02-12 22:11:54 -07:00
2014-03-01 15:34:27 -07:00
self.onIdentificationFormSubmitted = function () {
var page = $(this).parents('.page');
searchForIdentificationResults(page);
return false;
};
2014-06-04 09:15:44 -07:00
self.onRefreshFormSubmit = function () {
var page = $(this).parents('.page');
refreshFromPopupOptions(page);
return false;
};
2014-06-04 09:15:44 -07:00
self.onPersonInfoFormSubmit = function () {
var page = $(this).parents('.page');
savePersonInfo(page);
return false;
};
2015-01-11 13:31:09 -07:00
self.onIdentificationOptionsSubmit = function () {
var page = $(this).parents('.page');
submitIdentficationResult(page);
return false;
};
}
window.EditItemMetadataPage = new editItemMetadataPage();
2014-03-01 15:34:27 -07:00
function showIdentificationForm(page) {
var item = currentItem;
2014-07-01 22:16:59 -07:00
ApiClient.getJSON(ApiClient.getUrl("Items/" + item.Id + "/ExternalIdInfos")).done(function (idList) {
2014-03-01 15:34:27 -07:00
var html = '';
var providerIds = item.ProviderIds || {};
for (var i = 0, length = idList.length; i < length; i++) {
var idInfo = idList[i];
var id = "txtLookup" + idInfo.Key;
html += '<div data-role="fieldcontain">';
2014-12-20 18:23:56 -07:00
var idLabel = Globalize.translate('LabelDynamicExternalId').replace('{0}', idInfo.Name);
2014-08-24 08:48:06 -07:00
html += '<label for="' + id + '">' + idLabel + '</label>';
2014-03-01 15:34:27 -07:00
var value = providerIds[idInfo.Key] || '';
html += '<input class="txtLookupId" value="' + value + '" data-providerkey="' + idInfo.Key + '" id="' + id + '" data-mini="true" />';
html += '</div>';
}
$('#txtLookupName', page).val(item.Name);
2014-03-02 08:42:21 -07:00
2014-03-01 15:34:27 -07:00
if (item.Type == "Person" || item.Type == "BoxSet") {
$('.fldLookupYear', page).hide();
$('#txtLookupYear', page).val('');
} else {
$('.fldLookupYear', page).show();
$('#txtLookupYear', page).val(item.ProductionYear);
}
$('.identifyProviderIds', page).html(html).trigger('create');
2014-08-24 08:48:06 -07:00
$('.identificationHeader', page).html(Globalize.translate('HeaderIdentify'));
2014-03-01 15:34:27 -07:00
$('.popupIdentifyForm', page).show();
$('.identificationSearchResults', page).hide();
2015-01-11 13:31:09 -07:00
$('.identifyOptionsForm', page).hide();
$('.btnIdentifyBack', page).hide();
2014-03-01 15:34:27 -07:00
2015-07-15 10:20:08 -07:00
$('.popupIdentifyItem', page).popup('open');
2014-03-01 15:34:27 -07:00
});
}
function searchForIdentificationResults(page) {
var lookupInfo = {
ProviderIds: {}
};
$('.identifyField', page).each(function () {
var value = this.value;
if (value) {
if (this.type == 'number') {
value = parseInt(value);
}
lookupInfo[this.getAttribute('data-lookup')] = value;
}
});
var hasId = false;
$('.txtLookupId', page).each(function () {
var value = this.value;
if (value) {
hasId = true;
}
lookupInfo.ProviderIds[this.getAttribute('data-providerkey')] = value;
});
if (!hasId && !lookupInfo.Name) {
2014-07-16 20:17:14 -07:00
Dashboard.alert(Globalize.translate('MessagePleaseEnterNameOrId'));
2014-03-01 15:34:27 -07:00
return;
}
2014-03-02 08:42:21 -07:00
if (currentItem.GameSystem) {
lookupInfo.GameSystem = currentItem.GameSystem;
}
2014-03-01 15:34:27 -07:00
lookupInfo = {
SearchInfo: lookupInfo,
IncludeDisabledProviders: true
};
2014-03-02 08:42:21 -07:00
Dashboard.showLoadingMsg();
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-03-01 15:34:27 -07:00
type: "POST",
url: ApiClient.getUrl("Items/RemoteSearch/" + currentItem.Type),
data: JSON.stringify(lookupInfo),
contentType: "application/json"
}).done(function (results) {
2014-03-02 08:42:21 -07:00
Dashboard.hideLoadingMsg();
2014-03-01 15:34:27 -07:00
showIdentificationSearchResults(page, results);
});
}
function getSearchImageDisplayUrl(url, provider) {
return ApiClient.getUrl("Items/RemoteSearch/Image", { imageUrl: url, ProviderName: provider });
}
2015-01-11 13:31:09 -07:00
function getSearchResultHtml(result, index) {
var html = '';
var cssClass = "searchImageContainer remoteImageContainer";
if (currentItem.Type == "Episode") {
cssClass += " searchBackdropImageContainer";
}
else if (currentItem.Type == "MusicAlbum" || currentItem.Type == "MusicArtist") {
cssClass += " searchDiscImageContainer";
}
else {
cssClass += " searchPosterImageContainer";
}
html += '<div class="' + cssClass + '">';
if (result.ImageUrl) {
var displayUrl = getSearchImageDisplayUrl(result.ImageUrl, result.SearchProviderName);
html += '<a href="#" class="searchImage" data-index="' + index + '" style="background-image:url(\'' + displayUrl + '\');">';
} else {
html += '<a href="#" class="searchImage" data-index="' + index + '" style="background-image:url(\'css/images/items/list/remotesearch.png\');background-position: center center;">';
}
html += '</a>';
html += '<div class="remoteImageDetails">';
html += result.Name;
html += '</div>';
html += '<div class="remoteImageDetails">';
html += result.ProductionYear || '&nbsp;';
html += '</div>';
if (result.GameSystem) {
html += '<div class="remoteImageDetails">';
html += result.GameSystem;
html += '</div>';
}
html += '</div>';
return html;
}
2014-03-01 15:34:27 -07:00
function showIdentificationSearchResults(page, results) {
$('.popupIdentifyForm', page).hide();
$('.identificationSearchResults', page).show();
2015-01-11 13:31:09 -07:00
$('.identifyOptionsForm', page).hide();
$('.btnIdentifyBack', page).show();
2014-03-01 15:34:27 -07:00
var html = '';
for (var i = 0, length = results.length; i < length; i++) {
var result = results[i];
2015-01-11 13:31:09 -07:00
html += getSearchResultHtml(result, i);
}
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
var elem = $('.identificationSearchResultList', page).html(html).trigger('create');
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
$('.searchImage', elem).on('click', function () {
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
var index = parseInt(this.getAttribute('data-index'));
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
var currentResult = results[index];
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
showIdentifyOptions(page, currentResult);
});
}
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
function showIdentifyOptions(page, identifyResult) {
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
$('.popupIdentifyForm', page).hide();
$('.identificationSearchResults', page).hide();
$('.identifyOptionsForm', page).show();
$('.btnIdentifyBack', page).show();
$('#chkIdentifyReplaceImages', page).checked(true).checkboxradio('refresh');
2015-01-11 13:31:09 -07:00
currentSearchResult = identifyResult;
2014-03-01 15:34:27 -07:00
2015-01-11 13:31:09 -07:00
var lines = [];
lines.push(identifyResult.Name);
if (identifyResult.ProductionYear) {
lines.push(identifyResult.ProductionYear);
2014-03-01 15:34:27 -07:00
}
2015-01-11 13:31:09 -07:00
if (identifyResult.GameSystem) {
lines.push(identifyResult.GameSystem);
}
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
var resultHtml = lines.join('<br/>');
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
if (identifyResult.ImageUrl) {
var displayUrl = getSearchImageDisplayUrl(identifyResult.ImageUrl, identifyResult.SearchProviderName);
2015-01-11 13:31:09 -07:00
resultHtml = '<img src="' + displayUrl + '" style="max-height:160px;" /><br/>' + resultHtml;
}
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
$('.selectedSearchResult', page).html(resultHtml);
}
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
function submitIdentficationResult(page) {
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
Dashboard.showLoadingMsg();
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
var options = {
ReplaceAllImages: $('#chkIdentifyReplaceImages', page).checked()
};
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl("Items/RemoteSearch/Apply/" + currentItem.Id, options),
data: JSON.stringify(currentSearchResult),
contentType: "application/json"
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
}).done(function () {
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
Dashboard.hideLoadingMsg();
2015-07-15 10:20:08 -07:00
$('.popupIdentifyItem', page).popup('close');
2015-01-11 13:31:09 -07:00
reload(page);
2014-03-02 08:42:21 -07:00
});
2014-03-01 15:34:27 -07:00
}
function performAdvancedRefresh(page) {
$('.popupAdvancedRefresh', page).popup('open');
$('#selectMetadataRefreshMode', page).val('all').selectmenu('refresh');
$('#selectImageRefreshMode', page).val('missing').selectmenu('refresh');
}
2014-10-20 13:23:40 -07:00
function performSimpleRefresh(page) {
refreshWithOptions(page, {
Recursive: true,
ImageRefreshMode: 'FullRefresh',
MetadataRefreshMode: 'FullRefresh',
ReplaceAllMetadata: true
});
}
function refreshFromPopupOptions(page) {
var metadataRefreshMode = $('#selectMetadataRefreshMode', page).val();
var imageRefreshMode = $('#selectImageRefreshMode', page).val();
refreshWithOptions(page, {
Recursive: true,
ImageRefreshMode: imageRefreshMode == 'none' ? 'None' : 'FullRefresh',
MetadataRefreshMode: metadataRefreshMode == 'none' ? 'None' : (metadataRefreshMode == 'local' ? 'ValidationOnly' : 'FullRefresh'),
ReplaceAllImages: imageRefreshMode == 'all',
ReplaceAllMetadata: metadataRefreshMode == 'all'
});
$('.popupAdvancedRefresh', page).popup('close');
}
function refreshWithOptions(page, options) {
2015-07-13 14:26:11 -07:00
Dashboard.showLoadingMsg();
2015-04-19 08:54:20 -07:00
ApiClient.refreshItem(currentItem.Id, options);
2015-07-13 14:26:11 -07:00
if (!ApiClient.isWebSocketOpen()) {
// For now this is a hack
setTimeout(function () {
Dashboard.hideLoadingMsg();
}, 5000);
}
}
2015-03-17 21:09:31 -07:00
function onWebSocketMessageReceived(e, data) {
var msg = data;
if (msg.MessageType === "LibraryChanged") {
if (msg.Data.ItemsUpdated.indexOf(currentItem.Id) != -1) {
2015-04-19 08:54:20 -07:00
var page = $.mobile.activePage;
2015-06-26 20:27:38 -07:00
Logger.log('Item updated - reloading metadata');
2015-04-19 08:54:20 -07:00
reload(page);
2015-03-17 21:09:31 -07:00
}
}
}
function bindItemChanged(page) {
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived);
}
function unbindItemChanged(page) {
$(ApiClient).off("websocketmessage", onWebSocketMessageReceived);
}
2015-06-29 11:45:42 -07:00
function onItemDeleted(e, itemId) {
if (currentItem && currentItem.Id == itemId) {
if (currentItem.ParentId) {
Dashboard.navigate('edititemmetadata.html?id=' + currentItem.ParentId);
} else {
Dashboard.navigate('edititemmetadata.html');
}
}
}
2015-07-16 16:55:16 -07:00
function showMoreMenu(page, elem) {
2015-08-15 17:41:55 -07:00
2015-07-15 04:26:47 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-07-22 10:23:48 -07:00
2015-07-15 04:26:47 -07:00
var moreCommands = LibraryBrowser.getMoreCommands(currentItem, user);
var menuItems = [];
menuItems.push({
name: Globalize.translate('ButtonAdvancedRefresh'),
id: 'refresh',
ironIcon: 'refresh'
});
if (moreCommands.indexOf('delete') != -1) {
menuItems.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete',
ironIcon: 'delete'
});
}
2015-07-15 04:26:47 -07:00
require(['actionsheet'], function () {
ActionSheetElement.show({
items: menuItems,
2015-07-16 16:55:16 -07:00
positionTo: elem,
2015-07-15 04:26:47 -07:00
callback: function (id) {
switch (id) {
case 'refresh':
performAdvancedRefresh(page);
break;
case 'delete':
LibraryBrowser.deleteItem(currentItem.Id);
break;
default:
break;
}
}
});
});
});
2015-07-15 04:26:47 -07:00
}
2015-08-24 13:37:34 -07:00
function showTab(page, index) {
$('.editorTab', page).addClass('hide')[index].classList.remove('hide');
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#editItemMetadataPage", function () {
2015-07-15 04:26:47 -07:00
var page = this;
2014-10-20 13:23:40 -07:00
$('.btnSimpleRefresh', this).on('click', function () {
performSimpleRefresh(page);
});
2014-03-01 15:34:27 -07:00
$('#btnIdentify', page).on('click', function () {
showIdentificationForm(page);
});
2015-01-11 13:31:09 -07:00
$('.btnIdentifyBack', page).on('click', function () {
2014-03-02 08:42:21 -07:00
2015-01-11 13:31:09 -07:00
if ($('.identifyOptionsForm', page).is(':visible')) {
$('.identifyOptionsForm', page).hide();
$('.identificationSearchResults', page).show();
$('.popupIdentifyForm', page).hide();
} else {
$('.identificationSearchResults', page).hide();
$('.popupIdentifyForm', page).show();
$(this).hide();
}
2014-03-01 15:34:27 -07:00
});
2013-08-02 13:36:44 -07:00
$('.libraryTree', page).on('itemclicked', function (event, data) {
2013-08-02 13:36:44 -07:00
if (data.id != currentItem.Id) {
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 = 'editItemMetadataPage?id=' + data.id;
2015-08-24 13:37:34 -07:00
$(page.querySelector('paper-tabs')).trigger('tabchange');
2013-08-02 13:36:44 -07:00
}
});
2014-06-04 09:15:44 -07:00
$("#btnAddPerson", page).on('click', function (event, data) {
editPerson(page, {});
});
2015-06-12 20:42:19 -07:00
$('.editItemMetadataForm').off('submit', EditItemMetadataPage.onSubmit).on('submit', EditItemMetadataPage.onSubmit);
$('.popupIdentifyForm').off('submit', EditItemMetadataPage.onIdentificationFormSubmitted).on('submit', EditItemMetadataPage.onIdentificationFormSubmitted);
$('.popupEditPersonForm').off('submit', EditItemMetadataPage.onPersonInfoFormSubmit).on('submit', EditItemMetadataPage.onPersonInfoFormSubmit);
$('.popupAdvancedRefreshForm').off('submit', EditItemMetadataPage.onRefreshFormSubmit).on('submit', EditItemMetadataPage.onRefreshFormSubmit);
$('.identifyOptionsForm').off('submit', EditItemMetadataPage.onIdentificationOptionsSubmit).on('submit', EditItemMetadataPage.onIdentificationOptionsSubmit);
2015-07-14 13:29:51 -07:00
var tabs = page.querySelector('paper-tabs');
2015-08-24 13:37:34 -07:00
configurePaperLibraryTabs(page, tabs);
2015-07-14 13:29:51 -07:00
$(tabs).on('iron-select', function () {
2015-08-24 13:37:34 -07:00
Events.trigger(this, 'tabchange');
2015-07-14 13:29:51 -07:00
2015-08-24 13:37:34 -07:00
}).on('tabchange', function () {
var selected = this.selected;
2015-09-01 12:18:25 -07:00
2015-08-24 13:37:34 -07:00
showTab(page, selected);
2015-07-14 13:29:51 -07:00
loadTab(page, parseInt(this.selected));
});
2015-07-15 04:26:47 -07:00
page.querySelector('.btnMore iron-icon').icon = AppInfo.moreIcon;
$('.btnMore', page).on('click', function () {
2015-07-16 16:55:16 -07:00
showMoreMenu(page, this);
2015-07-15 04:26:47 -07:00
});
2015-06-12 20:42:19 -07:00
}).on('pageshowready', "#editItemMetadataPage", function () {
var page = this;
2015-06-29 11:45:42 -07:00
$(LibraryBrowser).on('itemdeleting', onItemDeleted);
2014-10-06 16:58:46 -07:00
2015-07-15 04:26:47 -07:00
var selected = parseInt(getParameterByName('tab') || '0');
2015-08-24 13:37:34 -07:00
page.querySelector('paper-tabs').selected = selected;
2015-07-14 13:29:51 -07:00
2015-06-20 17:49:42 -07:00
}).on('pagebeforehide', "#editItemMetadataPage", function () {
2014-10-06 16:58:46 -07:00
var page = this;
2015-06-29 11:45:42 -07:00
$(LibraryBrowser).off('itemdeleting', onItemDeleted);
2014-10-06 16:58:46 -07:00
2015-03-17 21:09:31 -07:00
unbindItemChanged(page);
2014-10-06 16:58:46 -07:00
});
2015-08-24 13:37:34 -07:00
function configurePaperLibraryTabs(ownerpage, tabs) {
2015-07-14 13:29:51 -07:00
tabs.hideScrollButtons = true;
2015-08-24 13:37:34 -07:00
tabs.noSlide = true;
tabs.noink = true;
2015-07-14 13:29:51 -07:00
2015-09-01 12:18:25 -07:00
$(ownerpage).on('pageshowready', function () {
2015-07-14 13:29:51 -07:00
2015-08-24 13:37:34 -07:00
var selected = tabs.selected;
2015-07-14 13:29:51 -07:00
2015-08-24 13:37:34 -07:00
if (selected == null) {
Logger.log('selected tab is null, checking query string');
selected = parseInt(getParameterByName('tab') || '0');
Logger.log('selected tab will be ' + selected);
tabs.selected = selected;
} else {
Events.trigger(tabs, 'tabchange');
}
2015-07-14 13:29:51 -07:00
});
}
function loadTab(page, index) {
switch (index) {
case 0:
reload(page);
break;
default:
2015-08-24 13:37:34 -07:00
reload(page);
2015-07-14 13:29:51 -07:00
break;
}
}
2013-08-02 13:36:44 -07:00
})(jQuery, document, window);