';
}
list.html(html).listview('refresh');
}
function editableListViewValues(list) {
return list.find('a.data').map(function () { return $(this).text(); }).get();
}
function generateSliders(fields, type) {
var html = '';
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var name = field.name;
var value = field.value || field.name;
html += '
";
html += generateSliders(metadatafields, 'Fields');
container.html(html).trigger('create');
for (var fieldIndex = 0; fieldIndex < lockedFields.length; fieldIndex++) {
var field = lockedFields[fieldIndex];
$('#lock' + field).val(field).slider('refresh');
}
}
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 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: $('#chkDisplaySpecialsInline', form).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: $('#txtAlbumArtist', form).val(),
Artists: $('#txtArtist', form).val().split(';'),
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: $('#txtPremiereDate', form).val() || null,
DateCreated: $('#txtDateAdded', form).val() || null,
EndDate: $('#txtEndDate', form).val() || null,
ProductionYear: $('#txtProductionYear', form).val(),
AspectRatio: $('#txtOriginalAspectRatio', form).val(),
Video3DFormat: $('#select3dFormat', form).val(),
OfficialRating: $('#selectOfficialRating', form).val(),
CustomRating: $('#selectCustomRating', form).val(),
People: currentItem.People,
LockData: $("#chkLockData", form).prop('checked'),
LockedFields: $('.selectLockedField', form).map(function () {
var value = $(this).val();
if (value != '') return value;
}).get()
};
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] : [];
ApiClient.updateItem(item).done(function () {
Dashboard.alert(Globalize.translate('MessageItemSaved'));
MetadataEditor.getItemPromise().done(function (i) {
$(form).parents('.page').trigger('itemsaved', [i]);
});
});
return false;
};
self.addElementToEditableListview = function (source, sortCallback) {
var input = $(source).parent().find('input[type="text"], select');
var text = input.val();
input.val('');
if (text == '') return;
var list = $(source).parents('[data-role="editableListviewContainer"]').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.onDeleteFormSubmitted = function () {
var page = $(this).parents('.page');
if ($('#fldChallengeValue', page).val() != $('#txtDeleteTest', page).val()) {
Dashboard.alert(Globalize.translate('MessageValueNotCorrect'));
} else {
performDelete(page);
}
return false;
};
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;
};
}
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();
$('.btnSearchAgain', page).hide();
$('.popupIdentify', 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 showIdentificationSearchResults(page, results) {
$('.popupIdentifyForm', page).hide();
$('.identificationSearchResults', page).show();
$('.btnSearchAgain', page).show();
var html = '';
for (var i = 0, length = results.length; i < length; i++) {
var result = results[i];
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 += '
';
}
var elem = $('.identificationSearchResultList', page).html(html).trigger('create');
$('.searchImage', elem).on('click', function () {
Dashboard.showLoadingMsg();
var index = parseInt(this.getAttribute('data-index'));
var currentResult = results[index];
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl("Items/RemoteSearch/Apply/" + currentItem.Id),
data: JSON.stringify(currentResult),
contentType: "application/json"
}).done(function () {
Dashboard.hideLoadingMsg();
$('.popupIdentify', page).popup('close');
reload(page);
});
});
}
function performAdvancedRefresh(page) {
$('.popupAdvancedRefresh', page).popup('open');
$('#selectMetadataRefreshMode', page).val('all').selectmenu('refresh');
$('#selectImageRefreshMode', page).val('missing').selectmenu('refresh');
}
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) {
$('#refreshLoading', page).show();
$('#btnDelete', page).buttonEnabled(false);
$('.btnRefresh', page).buttonEnabled(false);
$('.btnSave', page).buttonEnabled(false);
ApiClient.refreshItem(currentItem.Id, options).done(function () {
reload(page);
});
}
$(document).on('pageinit', "#editItemMetadataPage", function () {
var page = this;
$('.btnRefreshAdvanced', this).on('click', function () {
performAdvancedRefresh(page);
});
$('.btnSimpleRefresh', this).on('click', function () {
performSimpleRefresh(page);
});
$('#btnIdentify', page).on('click', function () {
showIdentificationForm(page);
});
$('.btnSearchAgain', page).on('click', function () {
$('.popupIdentifyForm', page).show();
$('.identificationSearchResults', page).hide();
$('.btnSearchAgain', page).hide();
});
$('#btnDelete', this).on('click', function () {
LibraryBrowser.deleteItem(currentItem.Id);
});
$('.libraryTree', page).on('itemclicked', function (event, data) {
if (data.id != currentItem.Id) {
MetadataEditor.currentItemId = data.id;
MetadataEditor.currentItemName = data.itemName;
MetadataEditor.currentItemType = data.itemType;
//Dashboard.navigate('edititemmetadata.html?id=' + data.id);
//$.mobile.urlHistory.ignoreNextHashChange = true;
window.location.hash = 'editItemMetadataPage?id=' + data.id;
reload(page);
}
});
$("#btnAddPerson", page).on('click', function (event, data) {
editPerson(page, {});
});
}).on('pagebeforeshow', "#editItemMetadataPage", function () {
var page = this;
reload(page);
$(LibraryBrowser).on('itemdeleting.editor', function (e, itemId) {
if (currentItem && currentItem.Id == itemId) {
Dashboard.navigate('edititemmetadata.html');
}
});
}).on('pagehide', "#editItemMetadataPage", function () {
$(LibraryBrowser).off('itemdeleting.editor');
var page = this;
reload(page);
});
})(jQuery, document, window);