";
html += generateSliders(metadatafields, lockedFields);
container.html(html);
}
function getSelectedAirDays(form) {
return $('.chkAirDay:checked', form).map(function () {
return this.getAttribute('data-day');
}).get();
}
function onDeleted(id) {
var elem = $('#' + id)[0];
$('.libraryTree').jstree("select_node", elem, true)
.jstree("delete_node", '#' + id);
}
function getAlbumArtists(form) {
return $('#txtAlbumArtist', form).val().trim().split(';').filter(function (s) {
return s.length > 0;
}).map(function (a) {
return {
Name: a
};
});
}
function getArtists(form) {
return $('#txtArtist', form).val().trim().split(';').filter(function (s) {
return s.length > 0;
}).map(function (a) {
return {
Name: a
};
});
}
function editItemMetadataPage() {
var self = this;
self.onSubmit = function () {
var form = this;
var item = {
Id: currentItem.Id,
Name: $('#txtName', form).val(),
ForcedSortName: $('#txtSortName', form).val(),
DisplayMediaType: $('#txtDisplayMediaType', form).val(),
CommunityRating: $('#txtCommunityRating', form).val(),
VoteCount: $('#txtCommunityVoteCount', form).val(),
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,
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(),
AirsBeforeEpisodeNumber: $('#txtAirsBeforeEpisode', form).val(),
ParentIndexNumber: $('#txtParentIndexNumber', form).val() || null,
DisplayOrder: $('#selectDisplayOrder', form).val(),
Players: $('#txtPlayers', form).val(),
Album: $('#txtAlbum', form).val(),
AlbumArtist: getAlbumArtists(form),
ArtistItems: getArtists(form),
Metascore: $('#txtMetascore', form).val(),
AwardSummary: $('#txtAwardSummary', form).val(),
Overview: $('#txtOverview', form).val(),
ShortOverview: $('#txtShortOverview', form).val(),
Status: $('#selectStatus', form).val(),
AirDays: getSelectedAirDays(form),
AirTime: $('#txtAirTime', form).val(),
Genres: editableListViewValues($("#listGenres", form)),
ProductionLocations: editableListViewValues($("#listCountries", form)),
Tags: editableListViewValues($("#listTags", form)),
Keywords: editableListViewValues($("#listKeywords", form)),
Studios: editableListViewValues($("#listStudios", form)).map(function (element) { return { Name: element }; }),
PremiereDate: EditItemMetadataPage.getDateFromForm(form, '#txtPremiereDate', 'PremiereDate'),
DateCreated: EditItemMetadataPage.getDateFromForm(form, '#txtDateAdded', 'DateCreated'),
EndDate: EditItemMetadataPage.getDateFromForm(form, '#txtEndDate', 'EndDate'),
ProductionYear: $('#txtProductionYear', form).val(),
AspectRatio: $('#txtOriginalAspectRatio', form).val(),
Video3DFormat: $('#select3dFormat', form).val(),
OfficialRating: $('#selectOfficialRating', form).val(),
CustomRating: $('#selectCustomRating', form).val(),
People: currentItem.People,
LockData: form.querySelector("#chkLockData").checked,
LockedFields: $('.selectLockedField', form).get().filter(function (c) {
return !c.checked;
}).map(function (c) {
return c.getAttribute('data-value');
})
};
item.ProviderIds = $.extend({}, currentItem.ProviderIds || {});
$('.txtExternalId', form).each(function () {
var providerkey = this.getAttribute('data-providerkey');
item.ProviderIds[providerkey] = this.value;
});
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;
}
var tagline = $('#txtTagline', form).val();
item.Taglines = tagline ? [tagline] : [];
self.submitUpdatedItem(form, item);
return false;
};
self.submitUpdatedItem = function (form, item) {
var page = $(form).parents('.page');
unbindItemChanged(page);
function afterContentTypeUpdated() {
Dashboard.alert(Globalize.translate('MessageItemSaved'));
MetadataEditor.getItemPromise().done(function (i) {
page.trigger('itemsaved', [i]);
bindItemChanged(page);
});
}
ApiClient.updateItem(item).done(function () {
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();
}
});
};
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;
};
self.addElementToEditableListview = function (source, sortCallback) {
var parent = $(source).parents('*[data-role="editableListviewContainer"]');
var input = parent.find('.txtEditableListview, select');
var text = input.val();
if (text == '') return;
var list = parent.find('ul[data-role="listview"]');
var items = editableListViewValues(list);
items.push(text);
populateListView(list, items, sortCallback);
};
self.setProviderSettingsContainerVisibility = function (source) {
if (!$(source).prop('checked')) {
$('#providerSettingsContainer').show();
} else {
$('#providerSettingsContainer').hide();
}
};
self.removeElementFromListview = function (source) {
var list = $(source).parents('ul[data-role="listview"]');
$(source).parent().remove();
list.listview('refresh');
};
self.onIdentificationFormSubmitted = function () {
var page = $(this).parents('.page');
searchForIdentificationResults(page);
return false;
};
self.onRefreshFormSubmit = function () {
var page = $(this).parents('.page');
refreshFromPopupOptions(page);
return false;
};
self.onPersonInfoFormSubmit = function () {
var page = $(this).parents('.page');
savePersonInfo(page);
return false;
};
self.onIdentificationOptionsSubmit = function () {
var page = $(this).parents('.page');
submitIdentficationResult(page);
return false;
};
}
window.EditItemMetadataPage = new editItemMetadataPage();
function showIdentificationForm(page) {
var item = currentItem;
ApiClient.getJSON(ApiClient.getUrl("Items/" + item.Id + "/ExternalIdInfos")).done(function (idList) {
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 += '
';
var idLabel = Globalize.translate('LabelDynamicExternalId').replace('{0}', idInfo.Name);
html += '';
var value = providerIds[idInfo.Key] || '';
html += '';
html += '
';
}
$('#txtLookupName', page).val(item.Name);
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');
$('.identificationHeader', page).html(Globalize.translate('HeaderIdentify'));
$('.popupIdentifyForm', page).show();
$('.identificationSearchResults', page).hide();
$('.identifyOptionsForm', page).hide();
$('.btnIdentifyBack', page).hide();
$('.popupIdentifyItem', page).popup('open');
});
}
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) {
Dashboard.alert(Globalize.translate('MessagePleaseEnterNameOrId'));
return;
}
if (currentItem.GameSystem) {
lookupInfo.GameSystem = currentItem.GameSystem;
}
lookupInfo = {
SearchInfo: lookupInfo,
IncludeDisabledProviders: true
};
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl("Items/RemoteSearch/" + currentItem.Type),
data: JSON.stringify(lookupInfo),
contentType: "application/json"
}).done(function (results) {
Dashboard.hideLoadingMsg();
showIdentificationSearchResults(page, results);
});
}
function getSearchImageDisplayUrl(url, provider) {
return ApiClient.getUrl("Items/RemoteSearch/Image", { imageUrl: url, ProviderName: provider });
}
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 += '
';
if (result.ImageUrl) {
var displayUrl = getSearchImageDisplayUrl(result.ImageUrl, result.SearchProviderName);
html += '';
} else {
html += '';
}
html += '';
html += '
';
html += result.Name;
html += '
';
html += '
';
html += result.ProductionYear || ' ';
html += '
';
if (result.GameSystem) {
html += '
';
html += result.GameSystem;
html += '
';
}
html += '
';
return html;
}
function showIdentificationSearchResults(page, results) {
$('.popupIdentifyForm', page).hide();
$('.identificationSearchResults', page).show();
$('.identifyOptionsForm', page).hide();
$('.btnIdentifyBack', page).show();
var html = '';
for (var i = 0, length = results.length; i < length; i++) {
var result = results[i];
html += getSearchResultHtml(result, i);
}
var elem = $('.identificationSearchResultList', page).html(html).trigger('create');
$('.searchImage', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-index'));
var currentResult = results[index];
showIdentifyOptions(page, currentResult);
});
}
function showIdentifyOptions(page, identifyResult) {
$('.popupIdentifyForm', page).hide();
$('.identificationSearchResults', page).hide();
$('.identifyOptionsForm', page).show();
$('.btnIdentifyBack', page).show();
$('#chkIdentifyReplaceImages', page).checked(true).checkboxradio('refresh');
currentSearchResult = identifyResult;
var lines = [];
lines.push(identifyResult.Name);
if (identifyResult.ProductionYear) {
lines.push(identifyResult.ProductionYear);
}
if (identifyResult.GameSystem) {
lines.push(identifyResult.GameSystem);
}
var resultHtml = lines.join(' ');
if (identifyResult.ImageUrl) {
var displayUrl = getSearchImageDisplayUrl(identifyResult.ImageUrl, identifyResult.SearchProviderName);
resultHtml = ' ' + resultHtml;
}
$('.selectedSearchResult', page).html(resultHtml);
}
function submitIdentficationResult(page) {
Dashboard.showLoadingMsg();
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"
}).done(function () {
Dashboard.hideLoadingMsg();
$('.popupIdentifyItem', page).popup('close');
reload(page);
});
}
function performAdvancedRefresh(page) {
$('.popupAdvancedRefresh', page).popup('open');
$('#selectMetadataRefreshMode', page).val('all');
$('#selectImageRefreshMode', page).val('missing');
}
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) {
Dashboard.showLoadingMsg();
ApiClient.refreshItem(currentItem.Id, options);
if (!ApiClient.isWebSocketOpen()) {
// For now this is a hack
setTimeout(function () {
Dashboard.hideLoadingMsg();
}, 5000);
}
}
function onWebSocketMessageReceived(e, data) {
var msg = data;
if (msg.MessageType === "LibraryChanged") {
if (msg.Data.ItemsUpdated.indexOf(currentItem.Id) != -1) {
var page = $.mobile.activePage;
Logger.log('Item updated - reloading metadata');
reload(page);
}
}
}
function bindItemChanged(page) {
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived);
}
function unbindItemChanged(page) {
$(ApiClient).off("websocketmessage", onWebSocketMessageReceived);
}
function onItemDeleted(e, itemId) {
if (currentItem && currentItem.Id == itemId) {
if (currentItem.ParentId) {
Dashboard.navigate('edititemmetadata.html?id=' + currentItem.ParentId);
} else {
Dashboard.navigate('edititemmetadata.html');
}
}
}
function showMoreMenu(page, elem) {
Dashboard.getCurrentUser().done(function (user) {
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'
});
}
require(['actionsheet'], function () {
ActionSheetElement.show({
items: menuItems,
positionTo: elem,
callback: function (id) {
switch (id) {
case 'refresh':
performAdvancedRefresh(page);
break;
case 'delete':
LibraryBrowser.deleteItem(currentItem.Id);
break;
default:
break;
}
}
});
});
});
}
function showTab(page, index) {
$('.editorTab', page).addClass('hide')[index].classList.remove('hide');
}
$(document).on('pageinit', "#editItemMetadataPage", function () {
var page = this;
$('.btnSimpleRefresh', this).on('click', function () {
performSimpleRefresh(page);
});
$('#btnIdentify', page).on('click', function () {
showIdentificationForm(page);
});
$('.btnIdentifyBack', page).on('click', function () {
if ($('.identifyOptionsForm', page).is(':visible')) {
$('.identifyOptionsForm', page).hide();
$('.identificationSearchResults', page).show();
$('.popupIdentifyForm', page).hide();
} else {
$('.identificationSearchResults', page).hide();
$('.popupIdentifyForm', page).show();
$(this).hide();
}
});
$('.libraryTree', page).on('itemclicked', function (event, data) {
if (data.id != currentItem.Id) {
//Dashboard.navigate('edititemmetadata.html?id=' + data.id);
//$.mobile.urlHistory.ignoreNextHashChange = true;
window.location.hash = 'editItemMetadataPage?id=' + data.id;
$(page.querySelector('paper-tabs')).trigger('tabchange');
}
});
$("#btnAddPerson", page).on('click', function (event, data) {
editPerson(page, {});
});
$('.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);
var tabs = page.querySelector('paper-tabs');
configurePaperLibraryTabs(page, tabs);
$(tabs).on('iron-select', function () {
var self = this;
setTimeout(function () {
Events.trigger(self, 'tabchange');
}, 400);
}).on('tabchange', function () {
var selected = this.selected;
showTab(page, selected);
loadTab(page, parseInt(this.selected));
});
page.querySelector('.btnMore iron-icon').icon = AppInfo.moreIcon;
$('.btnMore', page).on('click', function () {
showMoreMenu(page, this);
});
}).on('pageshowready', "#editItemMetadataPage", function () {
var page = this;
$(LibraryBrowser).on('itemdeleting', onItemDeleted);
var selected = parseInt(getParameterByName('tab') || '0');
page.querySelector('paper-tabs').selected = selected;
}).on('pagebeforehide', "#editItemMetadataPage", function () {
var page = this;
$(LibraryBrowser).off('itemdeleting', onItemDeleted);
unbindItemChanged(page);
});
function configurePaperLibraryTabs(ownerpage, tabs) {
tabs.hideScrollButtons = true;
tabs.noSlide = true;
// Unfortunately we can't disable this because it causes iron-select to not fire in IE and Safari.
//tabs.noink = true;
$(ownerpage).on('pageshowready', function () {
var selected = tabs.selected;
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');
}
});
}
function loadTab(page, index) {
switch (index) {
case 0:
reload(page);
break;
default:
reload(page);
break;
}
}
})(jQuery, document, window);