';
}
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 fieldTitle = $.trim(field.replace(/([A-Z])/g, ' $1'));
html += '
';
html += '';
html += '';
html += '
';
}
return html;
}
function populateInternetProviderSettings(page, lockedFields) {
var container = $('#providerSettingsContainer', page);
lockedFields = lockedFields || new Array();
var metadatafields = new Array("Name", "Overview", "Cast", "Genres", "ProductionLocations", "Studios", "Tags");
var html = '';
html += "
Fields
";
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 editItemMetadataPage() {
var self = this;
self.onSubmit = function () {
var form = this;
var item = {
Id: currentItem.Id,
Name: $('#txtName', form).val(),
SortName: $('#txtSortName', form).val(),
DisplayMediaType: $('#txtDisplayMediaType', form).val(),
CommunityRating: $('#txtCommunityRating', 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(),
ParentIndexNumber: $('#txtParentIndexNumber', form).val(),
Players: $('#txtPlayers', form).val(),
Album: $('#txtAlbum', form).val(),
AlbumArtist: $('#txtAlbumArtist', form).val(),
Artists: [$('#txtArtist', form).val()],
Overview: $('#txtOverview', form).val(),
Status: $('#selectStatus', form).val(),
AirDays: editableListViewValues($("#listAirDays", form)),
AirTime: convertTo12HourFormat($('#txtAirTime', form).val()),
Genres: editableListViewValues($("#listGenres", form)),
Tags: editableListViewValues($("#listTags", 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(),
Language: $('#selectLanguage', form).val(),
OfficialRating: $('#selectOfficialRating', form).val(),
CustomRating: $('#selectCustomRating', form).val(),
People: currentItem.People,
EnableInternetProviders: $("#enableInternetProviders", form).prop('checked'),
LockedFields: $('select[name="lockFields"]', form).map(function () {
var value = $(this).val();
if (value != '') return value;
}).get(),
ProviderIds:
{
Gamesdb: $('#txtGamesDb', form).val(),
Imdb: $('#txtImdb', form).val(),
Tmdb: $('#txtTmdb', form).val(),
Tvdb: $('#txtTvdb', form).val(),
Tvcom: $('#txtTvCom', form).val(),
Musicbrainz: $('#txtMusicBrainz', form).val(),
MusicBrainzReleaseGroup: $('#txtMusicBrainzReleaseGroupId', form).val(),
RottenTomatoes: $('#txtRottenTomatoes', form).val()
}
};
if (currentItem.Type == "Person") {
var placeOfBirth = $('#txtPlaceOfBirth', form).val();
item.ProductionLocations = placeOfBirth ? [placeOfBirth] : [];
}
var updatePromise;
if (currentItem.Type == "Artist") {
updatePromise = ApiClient.updateArtist(item);
}
else if (currentItem.Type == "Genre") {
updatePromise = ApiClient.updateGenre(item);
}
else if (currentItem.Type == "MusicGenre") {
updatePromise = ApiClient.updateMusicGenre(item);
}
else if (currentItem.Type == "GameGenre") {
updatePromise = ApiClient.updateGameGenre(item);
}
else if (currentItem.Type == "Person") {
updatePromise = ApiClient.updatePerson(item);
}
else if (currentItem.Type == "Studio") {
updatePromise = ApiClient.updateStudio(item);
}
else {
updatePromise = ApiClient.updateItem(item);
}
updatePromise.done(function () {
Dashboard.alert('Item saved.');
});
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.sortDaysOfTheWeek = function (list) {
var days = new Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
list.sort(function (a, b) { return days.indexOf(a) > days.indexOf(b); });
return list;
};
self.removeElementFromListview = function (source) {
var list = $(source).parents('ul[data-role="listview"]');
$(source).parent().remove();
list.listview('refresh');
};
}
window.EditItemMetadataPage = new editItemMetadataPage();
$(document).on('pageinit', "#editItemMetadataPage", function () {
var page = this;
$('#btnRefresh', this).on('click', function () {
$(this).button('disable');
$('#refreshLoading', page).show();
var refreshPromise;
var force = $('#chkForceRefresh', page).checked();
if (currentItem.Type == "Artist") {
refreshPromise = ApiClient.refreshArtist(currentItem.Name, force);
}
else if (currentItem.Type == "Genre") {
refreshPromise = ApiClient.refreshGenre(currentItem.Name, force);
}
else if (currentItem.Type == "MusicGenre") {
refreshPromise = ApiClient.refreshMusicGenre(currentItem.Name, force);
}
else if (currentItem.Type == "GameGenre") {
refreshPromise = ApiClient.refreshGameGenre(currentItem.Name, force);
}
else if (currentItem.Type == "Person") {
refreshPromise = ApiClient.refreshPerson(currentItem.Name, force);
}
else if (currentItem.Type == "Studio") {
refreshPromise = ApiClient.refreshStudio(currentItem.Name, force);
}
else {
refreshPromise = ApiClient.refreshItem(currentItem.Id, force, $('#chkRecursive', page).checked());
}
refreshPromise.done(function () {
reload(page);
});
});
$('.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);
}
});
}).on('pagebeforeshow', "#editItemMetadataPage", function () {
var page = this;
reload(page);
});
})(jQuery, document, window);