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

1663 lines
55 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
2013-08-02 13:36:44 -07:00
function getNode(item, folderState) {
2013-08-02 13:36:44 -07:00
var state = item.IsFolder ? folderState : '';
2013-06-27 06:31:49 -07:00
2013-08-02 13:36:44 -07:00
var name = item.Name;
2013-06-27 06:31:49 -07:00
// Channel number
if (item.Number) {
name = item.Number + " - " + name;
}
2013-08-02 13:36:44 -07:00
if (item.IndexNumber != null && item.Type != "Season") {
name = item.IndexNumber + " - " + name;
2013-06-27 06:31:49 -07:00
}
var cssClass = "editorNode";
if (item.LocationType == "Offline") {
cssClass += " offlineEditorNode";
}
var htmlName = "<div class='" + cssClass + "'>";
2014-02-18 22:21:03 -07:00
if (item.LockData) {
htmlName += '<img src="css/images/editor/lock.png" />';
}
htmlName += name;
if (!item.LocalTrailerCount && item.Type == "Movie") {
htmlName += '<img src="css/images/editor/missingtrailer.png" title="Missing local trailer." />';
}
if (!item.ImageTags || !item.ImageTags.Primary) {
htmlName += '<img src="css/images/editor/missingprimaryimage.png" title="Missing primary image." />';
}
if (!item.BackdropImageTags || !item.BackdropImageTags.length) {
if (item.Type !== "Episode" && item.Type !== "Season" && item.MediaType !== "Audio" && item.Type !== "Channel") {
htmlName += '<img src="css/images/editor/missingbackdrop.png" title="Missing backdrop image." />';
}
}
if (!item.ImageTags || !item.ImageTags.Logo) {
2013-11-21 13:48:26 -07:00
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Series" || item.Type == "MusicArtist" || item.Type == "BoxSet") {
htmlName += '<img src="css/images/editor/missinglogo.png" title="Missing logo image." />';
}
}
if (item.Type == "Episode" && item.LocationType == "Virtual") {
try {
if (item.PremiereDate && (new Date().getTime() >= parseISO8601Date(item.PremiereDate, { toLocal: true }).getTime())) {
htmlName += '<img src="css/images/editor/missing.png" title="Missing episode." />';
}
} catch (err) {
}
}
htmlName += "</div>";
2013-08-02 13:36:44 -07:00
var rel = item.IsFolder ? 'folder' : 'default';
2013-06-27 06:31:49 -07:00
return { attr: { id: item.Id, rel: rel, itemtype: item.Type }, data: htmlName, state: state };
2013-08-02 13:36:44 -07:00
}
2013-06-27 06:31:49 -07:00
2014-02-21 08:27:44 -07:00
function loadChildrenOfRootNode(callback, openItems) {
2014-02-20 22:04:11 -07:00
var promise1 = $.getJSON(ApiClient.getUrl("Library/MediaFolders"));
2014-01-14 13:03:35 -07:00
var promise2 = ApiClient.getLiveTvInfo();
$.when(promise1, promise2).done(function (response1, response2) {
2014-02-20 22:04:11 -07:00
var mediaFolders = response1[0].Items;
2014-01-14 13:03:35 -07:00
var liveTvInfo = response2[0];
var nodes = [];
2014-02-20 22:04:11 -07:00
var i, length;
for (i = 0, length = mediaFolders.length; i < length; i++) {
2014-02-21 08:27:44 -07:00
var state = openItems.indexOf(mediaFolders[i].Id) == -1 ? 'closed' : 'open';
nodes.push(getNode(mediaFolders[i], state));
2014-02-20 22:04:11 -07:00
}
2014-02-20 22:04:11 -07:00
for (i = 0, length = liveTvInfo.Services.length; i < length; i++) {
2014-02-09 14:11:11 -07:00
var service = liveTvInfo.Services[i];
2014-02-12 22:11:54 -07:00
2014-02-09 14:11:11 -07:00
var name = service.Name;
2014-02-09 14:11:11 -07:00
var cssClass = "editorNode";
2014-02-09 14:11:11 -07:00
var htmlName = "<div class='" + cssClass + "'>";
2014-02-09 14:11:11 -07:00
htmlName += name;
2014-02-09 14:11:11 -07:00
htmlName += "</div>";
2014-02-09 14:11:11 -07:00
nodes.push({ attr: { id: name, rel: 'folder', itemtype: 'livetvservice' }, data: htmlName, state: 'closed' });
}
callback(nodes);
});
}
function loadLiveTvChannels(service, openItems, callback) {
2013-11-25 13:39:23 -07:00
ApiClient.getLiveTvChannels({ ServiceName: service }).done(function (result) {
2013-11-25 13:39:23 -07:00
var nodes = result.Items.map(function (i) {
var state = openItems.indexOf(i.Id) == -1 ? 'closed' : 'open';
return getNode(i, state);
});
callback(nodes);
});
}
function loadNode(page, node, openItems, selectedId, currentUser, callback) {
2013-06-27 06:31:49 -07:00
2013-08-02 13:36:44 -07:00
if (node == '-1') {
2013-06-27 06:31:49 -07:00
2014-02-21 08:27:44 -07:00
loadChildrenOfRootNode(callback, openItems);
return;
}
2013-06-27 06:31:49 -07:00
var id = node.attr("id");
2013-08-02 13:36:44 -07:00
var itemtype = node.attr("itemtype");
if (itemtype == 'livetvservice') {
loadLiveTvChannels(id, openItems, callback);
2013-08-02 13:36:44 -07:00
return;
2013-06-27 06:31:49 -07:00
}
var query = {
ParentId: id,
Fields: 'Settings'
};
2013-12-28 22:32:03 -07:00
if (itemtype != "Season" && itemtype != "Series") {
query.SortBy = "SortName";
}
2013-06-27 06:31:49 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
2013-07-01 10:17:33 -07:00
2013-08-02 13:36:44 -07:00
var nodes = result.Items.map(function (i) {
2013-07-01 10:17:33 -07:00
2013-08-02 13:36:44 -07:00
var state = openItems.indexOf(i.Id) == -1 ? 'closed' : 'open';
2013-06-27 06:31:49 -07:00
2013-08-02 13:36:44 -07:00
return getNode(i, state);
});
callback(nodes);
if (selectedId && result.Items.filter(function (f) {
return f.Id == selectedId;
}).length) {
selectNode(page, selectedId);
}
});
}
function selectNode(page, id) {
var elem = $('#' + id, page)[0];
$.jstree._reference(".libraryTree", page).select_node(elem);
if (elem) {
elem.scrollIntoView();
2013-06-27 06:31:49 -07:00
}
2013-08-02 13:36:44 -07:00
$(document).scrollTop(0);
2013-06-27 06:31:49 -07:00
}
function initializeTree(page, currentUser, openItems, selectedId) {
2013-08-02 13:36:44 -07:00
$('.libraryTree', page).jstree({
"plugins": ["themes", "ui", "json_data"],
data: function (node, callback) {
loadNode(page, node, openItems, selectedId, currentUser, callback);
2013-08-02 13:36:44 -07:00
},
json_data: {
data: function (node, callback) {
loadNode(page, node, openItems, selectedId, currentUser, callback);
2013-08-02 13:36:44 -07:00
}
},
core: { initially_open: [], load_open: true, html_titles: true },
2013-08-02 13:36:44 -07:00
ui: { initially_select: [] },
themes: {
theme: 'mb3',
2013-12-01 13:17:40 -07:00
url: 'thirdparty/jstree1.0/themes/mb3/style.css?v=' + Dashboard.initialServerVersion
2013-08-02 13:36:44 -07:00
}
}).off('select_node.jstree').on('select_node.jstree', function (event, data) {
var eventData = {
id: data.rslt.obj.attr("id"),
itemType: data.rslt.obj.attr("itemtype")
};
$(this).trigger('itemclicked', [eventData]);
});
}
$(document).on('pagebeforeshow', ".metadataEditorPage", function () {
window.MetadataEditor = new metadataEditor();
var page = this;
Dashboard.getCurrentUser().done(function (user) {
var id = MetadataEditor.currentItemId;
if (id) {
2013-08-02 13:36:44 -07:00
ApiClient.getAncestorItems(id, user.Id).done(function (ancestors) {
2013-08-02 13:36:44 -07:00
var ids = ancestors.map(function (i) {
return i.Id;
});
2013-08-02 13:36:44 -07:00
initializeTree(page, user, ids, id);
2013-08-02 13:36:44 -07:00
});
} else {
initializeTree(page, user, []);
}
2013-08-02 13:36:44 -07:00
});
2013-08-02 13:36:44 -07:00
}).on('pagebeforehide', ".metadataEditorPage", function () {
var page = this;
$('.libraryTree', page).off('select_node.jstree');
});
function metadataEditor() {
var self = this;
function ensureInitialValues() {
if (self.currentItemType || self.currentItemName || self.currentItemId) {
return;
}
var url = window.location.hash || window.location.toString();
var name = getParameterByName('person', url);
if (name) {
self.currentItemType = "Person";
self.currentItemName = name;
return;
}
name = getParameterByName('studio', url);
if (name) {
self.currentItemType = "Studio";
self.currentItemName = name;
return;
}
name = getParameterByName('genre', url);
if (name) {
self.currentItemType = "Genre";
self.currentItemName = name;
return;
}
name = getParameterByName('musicgenre', url);
if (name) {
self.currentItemType = "MusicGenre";
self.currentItemName = name;
return;
}
2013-08-02 13:36:44 -07:00
name = getParameterByName('gamegenre', url);
if (name) {
self.currentItemType = "GameGenre";
self.currentItemName = name;
return;
}
2013-11-21 13:48:26 -07:00
name = getParameterByName('musicartist', url);
2013-08-02 13:36:44 -07:00
if (name) {
2013-11-21 13:48:26 -07:00
self.currentItemType = "MusicArtist";
2013-08-02 13:36:44 -07:00
self.currentItemName = name;
return;
}
name = getParameterByName('channelid', url);
if (name) {
self.currentItemType = "Channel";
self.currentItemId = name;
return;
}
2013-08-02 13:36:44 -07:00
var id = getParameterByName('id', url);
if (id) {
self.currentItemId = id;
self.currentItemType = null;
}
};
self.getItemPromise = function () {
var currentItemType = self.currentItemType;
var currentItemName = self.currentItemName;
var currentItemId = self.currentItemId;
if (currentItemType == "Channel") {
return ApiClient.getLiveTvChannel(currentItemId);
}
2013-08-02 13:36:44 -07:00
if (currentItemType == "Person") {
return ApiClient.getPerson(currentItemName, Dashboard.getCurrentUserId());
}
if (currentItemType == "Studio") {
return ApiClient.getStudio(currentItemName, Dashboard.getCurrentUserId());
}
if (currentItemType == "Genre") {
return ApiClient.getGenre(currentItemName, Dashboard.getCurrentUserId());
}
if (currentItemType == "MusicGenre") {
return ApiClient.getMusicGenre(currentItemName, Dashboard.getCurrentUserId());
}
if (currentItemType == "GameGenre") {
return ApiClient.getGameGenre(currentItemName, Dashboard.getCurrentUserId());
}
2013-11-21 13:48:26 -07:00
if (currentItemType == "MusicArtist" && currentItemName) {
2013-08-02 13:36:44 -07:00
return ApiClient.getArtist(currentItemName, Dashboard.getCurrentUserId());
}
if (currentItemId) {
return ApiClient.getItem(Dashboard.getCurrentUserId(), currentItemId);
}
return ApiClient.getRootFolder(Dashboard.getCurrentUserId());
};
self.getEditQueryString = function (item) {
var query;
if (item.Type == "Person" ||
item.Type == "Studio" ||
item.Type == "Genre" ||
item.Type == "MusicGenre" ||
item.Type == "GameGenre" ||
2013-11-21 13:48:26 -07:00
item.Type == "MusicArtist") {
2013-08-02 13:36:44 -07:00
query = item.Type + "=" + ApiClient.encodeName(item.Name);
2013-05-22 15:01:37 -07:00
} else {
2013-08-02 13:36:44 -07:00
query = "id=" + item.Id;
2013-05-22 15:01:37 -07:00
}
2013-08-02 13:36:44 -07:00
var context = getParameterByName('context');
if (context) {
query += "&context=" + context;
}
return query;
};
ensureInitialValues();
}
})(jQuery, document, window);
(function ($, document, window) {
var currentItem;
2013-12-28 09:58:13 -07:00
var languagesPromise;
var countriesPromise;
function ensureLanguagePromises() {
languagesPromise = languagesPromise || ApiClient.getCultures();
countriesPromise = countriesPromise || ApiClient.getCountries();
}
2013-08-02 13:36:44 -07:00
function updateTabs(page, item) {
var query = MetadataEditor.getEditQueryString(item);
$('#btnEditPeople', page).attr('href', 'edititempeople.html?' + query);
$('#btnEditImages', page).attr('href', 'edititemimages.html?' + query);
}
function reload(page) {
Dashboard.showLoadingMsg();
2013-12-28 09:58:13 -07:00
ensureLanguagePromises();
var promise1 = MetadataEditor.getItemPromise();
var promise2 = languagesPromise;
var promise3 = countriesPromise;
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
var item = response1[0];
var languages = response2[0];
var countries = response3[0];
Dashboard.populateLanguages($('#selectLanguage', page), languages);
Dashboard.populateCountries($('#selectCountry', page), countries);
2013-08-02 13:36:44 -07:00
if (item.LocationType == "Offline") {
2013-11-27 12:04:19 -07:00
$('.saveButtonContainer', page).hide();
} else {
2013-11-27 12:04:19 -07:00
$('.saveButtonContainer', page).show();
}
2013-12-24 11:37:29 -07:00
$('#btnRefresh', page).buttonEnabled(true);
$('#btnDelete', page).buttonEnabled(true);
$('.btnSave', page).buttonEnabled(true);
$('#refreshLoading', page).hide();
currentItem = item;
2013-08-03 07:49:33 -07:00
if (item.IsFolder) {
2013-10-18 14:12:05 -07:00
$('#fldRecursive', page).css("display", "inline-block");
2013-08-03 07:49:33 -07:00
} else {
$('#fldRecursive', page).hide();
}
2014-01-29 13:30:26 -07:00
if (item.Type != "Channel" &&
item.Type != "Genre" &&
item.Type != "Studio" &&
item.Type != "MusicGenre" &&
item.Type != "GameGenre" &&
item.Type != "Person" &&
item.Type != "MusicArtist" &&
item.Type != "UserRootFolder") {
2013-10-18 14:12:05 -07:00
$('#fldDelete', page).show();
} else {
$('#fldDelete', page).hide();
}
2013-05-22 09:52:22 -07:00
LibraryBrowser.renderName(item, $('.itemName', page), true);
2013-08-02 13:36:44 -07:00
updateTabs(page, item);
setFieldVisibilities(page, item);
fillItemInfo(page, item);
if (item.Type == "Person" || item.Type == "Studio" || item.Type == "MusicGenre" || item.Type == "Genre" || item.Type == "MusicArtist" || item.Type == "GameGenre" || item.Type == "Channel") {
2013-08-02 13:36:44 -07:00
$('#btnEditPeople', page).hide();
2013-06-27 11:40:50 -07:00
} else {
2013-08-02 13:36:44 -07:00
$('#btnEditPeople', page).show();
2013-06-27 11:40:50 -07:00
}
Dashboard.hideLoadingMsg();
});
}
function setFieldVisibilities(page, item) {
2013-05-22 09:52:22 -07:00
2013-08-17 16:25:23 -07:00
if (item.Path) {
$('#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();
}
if (item.MediaType == "Game" || item.Type == "MusicAlbum") {
$('#fldGamesDb', page).show();
} else {
$('#fldGamesDb', page).hide();
}
if (item.MediaType == "Game" && (item.GameSystem == "Nintendo" || item.GameSystem == "Super Nintendo")) {
$('#fldNesBoxName', page).show();
$('#fldNesBoxRom', page).show();
} else {
$('#fldNesBoxName', page).hide();
$('#fldNesBoxRom', page).hide();
}
2013-05-22 15:01:37 -07:00
if (item.MediaType == "Game") {
$('#fldPlayers', page).show();
} else {
$('#fldPlayers', page).hide();
}
2013-09-22 15:42:21 -07:00
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicVideo" || item.Type == "Series" || item.Type == "Game") {
2013-05-22 15:01:37 -07:00
$('#fldCriticRating', page).show();
$('#fldCriticRatingSummary', page).show();
$('#fldRottenTomatoes', page).show();
} else {
$('#fldCriticRating', page).hide();
$('#fldCriticRatingSummary', page).hide();
$('#fldRottenTomatoes', 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();
}
2014-02-08 23:08:10 -07:00
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Person" || item.Type == "BoxSet" || item.Type == "MusicAlbum" || item.Type == "Series") {
2013-05-22 15:01:37 -07:00
$('#fldTmdb', page).show();
} else {
$('#fldTmdb', page).hide();
}
2013-12-07 18:42:15 -07:00
if (item.Type == "Movie") {
$('#fldTmdbCollection', page).show();
} else {
$('#fldTmdbCollection', page).hide();
}
2013-07-16 09:03:28 -07:00
if (item.Type == "Series" || item.Type == "Season" || item.Type == "Episode" || item.Type == "MusicAlbum") {
2013-05-22 15:01:37 -07:00
$('#fldTvdb', page).show();
$('#fldTvCom', page).show();
} else {
$('#fldTvdb', page).hide();
$('#fldTvCom', page).hide();
}
2013-07-16 09:03:28 -07:00
if (item.Type == "Series" || item.Type == "Season" || item.Type == "Episode") {
$('#fldTvCom', page).show();
} else {
$('#fldTvCom', page).hide();
}
if (item.Type == "Series") {
$('#fldZap2It', page).show();
} else {
$('#fldZap2It', 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
if (item.MediaType == "Video" && item.Type != "Channel") {
$('#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 == "Movie" || item.Type == "Trailer" || item.Type == "Person" || item.Type == "Series" || item.Type == "Season" || item.Type == "Episode" || item.Type == "MusicVideo") {
2013-05-22 15:01:37 -07:00
$('#fldImdb', page).show();
} else {
$('#fldImdb', page).hide();
}
2013-11-21 13:48:26 -07:00
if (item.Type == "Audio" || item.Type == "MusicArtist" || item.Type == "MusicAlbum") {
2013-05-22 15:01:37 -07:00
$('#fldMusicBrainz', page).show();
} else {
$('#fldMusicBrainz', page).hide();
}
2013-06-19 06:54:45 -07:00
if (item.Type == "MusicAlbum" || item.Type == "Audio") {
$('#fldMusicBrainzAlbumId', page).show();
} else {
$('#fldMusicBrainzAlbumId', page).hide();
}
if (item.Type == "Audio") {
$('#fldMusicBrainzAlbumArtistId', page).show();
} else {
$('#fldMusicBrainzAlbumArtistId', page).hide();
}
2014-02-09 14:11:11 -07:00
if (item.Type == "MusicArtist" || item.Type == "MusicAlbum") {
$('#fldAudioDbArtistId', page).show();
} else {
$('#fldAudioDbArtistId', page).hide();
}
if (item.Type == "MusicAlbum") {
$('#fldAudioDbAlbumId', page).show();
} else {
$('#fldAudioDbAlbumId', page).hide();
}
if (item.Type == "MusicArtist" || item.Type == "Audio") {
$('#fldMusicBrainzArtistId', page).show();
} else {
$('#fldMusicBrainzArtistId', page).hide();
}
if (item.Type == "MusicAlbum" || item.Type == "Audio") {
2013-06-09 01:26:57 -07:00
$('#fldMusicBrainzReleaseGroupId', page).show();
} else {
$('#fldMusicBrainzReleaseGroupId', page).hide();
}
2013-05-22 15:01:37 -07:00
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();
}
if (item.Type == "Person" || item.Type == "Genre" || item.Type == "Studio" || item.Type == "GameGenre" || item.Type == "MusicGenre" || item.Type == "Channel") {
$('#fldCommunityRating', page).hide();
$('#fldCommunityVoteCount', page).hide();
$('#genresCollapsible', page).hide();
$('#studiosCollapsible', page).hide();
if (item.Type == "Channel") {
$('#fldOfficialRating', page).show();
} else {
$('#fldOfficialRating', page).hide();
}
$('#fldCustomRating', page).hide();
} else {
$('#fldCommunityRating', page).show();
$('#fldCommunityVoteCount', page).show();
$('#genresCollapsible', page).show();
$('#studiosCollapsible', page).show();
$('#fldOfficialRating', page).show();
$('#fldCustomRating', page).show();
}
if (item.Type == "Channel") {
$('#tagsCollapsible', page).hide();
$('#metadataSettingsCollapsible', page).hide();
$('#fldPremiereDate', page).hide();
$('#fldSortName', page).hide();
$('#fldDateAdded', page).hide();
$('#fldYear', page).hide();
$('.fldRefresh', page).hide();
} else {
$('#tagsCollapsible', page).show();
$('#metadataSettingsCollapsible', page).show();
$('#fldPremiereDate', page).show();
$('#fldSortName', page).show();
$('#fldDateAdded', page).show();
$('#fldYear', page).show();
$('.fldRefresh', page).show();
}
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();
}
if (item.MediaType == "Video" && item.Type != "Channel") {
2014-01-19 11:08:31 -07:00
$('#fldSourceType', page).show();
} else {
$('#fldSourceType', page).hide();
}
if (item.Type == "Person") {
$('#lblPremiereDate', page).html('Date of birth');
$('#lblYear', page).html('Birth year');
$('#lblEndDate', page).html('Death date');
$('#fldPlaceOfBirth', page).show();
} else {
$('#lblPremiereDate', page).html('Release date');
$('#lblYear', page).html('Year');
$('#lblEndDate', page).html('End date');
$('#fldPlaceOfBirth', page).hide();
}
if (item.MediaType == "Video" && item.Type != "Channel") {
$('#fldOriginalAspectRatio', page).show();
} else {
$('#fldOriginalAspectRatio', page).hide();
}
if (item.Type == "Audio" || item.Type == "Episode" || item.Type == "Season") {
$('#fldIndexNumber', page).show();
if (item.Type == "Episode") {
$('#lblIndexNumber', page).html('Episode number');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Season") {
$('#lblIndexNumber', page).html('Season number');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Audio") {
$('#lblIndexNumber', page).html('Track number');
2014-02-12 22:11:54 -07:00
} else {
$('#lblIndexNumber', page).html('Number');
}
} else {
$('#fldIndexNumber', page).hide();
}
if (item.Type == "Audio" || item.Type == "Episode") {
$('#fldParentIndexNumber', page).show();
if (item.Type == "Episode") {
$('#lblParentIndexNumber', page).html('Season number');
2014-02-12 22:11:54 -07:00
} else if (item.Type == "Audio") {
$('#lblParentIndexNumber', page).html('Disc number');
2014-02-12 22:11:54 -07:00
} else {
$('#lblParentIndexNumber', page).html('Parent number');
}
} else {
$('#fldParentIndexNumber', page).hide();
}
if (item.Type == "Series") {
$('#fldDisplaySpecialsInline', page).show();
} else {
$('#fldDisplaySpecialsInline', page).hide();
}
if (item.Type == "BoxSet") {
$('#fldDisplayOrder', page).show();
2014-01-03 13:43:44 -07:00
$('#labelDisplayOrder', page).html('Title display order:');
$('#selectDisplayOrder', page).html('<option value="SortName">Sort Name</option><option value="PremiereDate">Release Date</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();
}
}
function fillItemInfo(page, item) {
ApiClient.getParentalRatings().done(function (result) {
2013-05-22 09:52:22 -07:00
var select = $('#selectOfficialRating', page);
populateRatings(result, select);
select.val(item.OfficialRating || "").selectmenu('refresh');
2013-05-22 09:52:22 -07:00
select = $('#selectCustomRating', page);
populateRatings(result, select);
select.val(item.CustomRating || "").selectmenu('refresh');
});
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;
}).checkboxradio('refresh');
2014-02-12 22:11:54 -07:00
populateListView($('#listGenres', page), item.Genres);
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);
var chkLockData = $("#chkLockData", page).attr('checked', lockData).checkboxradio('refresh');
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
$("#chkDisplaySpecialsInline", page).checked(item.DisplaySpecialsWithSeasons || false).checkboxradio('refresh');
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 || "");
$('#txtOverview', page).val(item.Overview || "");
$('#txtSortName', page).val(item.SortName || "");
$('#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 || "");
$('#txtAlbumArtist', page).val(item.AlbumArtist || "");
2014-01-03 13:43:44 -07:00
$('#selectDisplayOrder', page).val(item.DisplayOrder).selectmenu('refresh');
2013-05-22 15:01:37 -07:00
var artists = item.Artists || [];
$('#txtArtist', page).val(artists.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 || "");
$('#txtAirTime', page).val(convertTo24HourFormat(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
var providerIds = item.ProviderIds || {};
$('#txtGamesDb', page).val(providerIds.Gamesdb || "");
$('#txtImdb', page).val(providerIds.Imdb || "");
$('#txtTmdb', page).val(providerIds.Tmdb || "");
2013-12-07 18:42:15 -07:00
$('#txtTmdbCollection', page).val(providerIds.TmdbCollection || "");
2013-05-22 15:01:37 -07:00
$('#txtTvdb', page).val(providerIds.Tvdb || "");
$('#txtTvCom', page).val(providerIds.Tvcom || "");
$('#txtMusicBrainzArtistId', page).val(providerIds.MusicBrainzArtist || "");
$('#txtMusicBrainzAlbumId', page).val(providerIds.MusicBrainzAlbum || "");
$('#txtMusicBrainzAlbumArtistId', page).val(providerIds.MusicBrainzAlbumArtist || "");
2014-02-09 14:11:11 -07:00
$('#txtAudioDbArtist', page).val(providerIds.AudioDbArtist || "");
$('#txtAudioDbAlbum', page).val(providerIds.AudioDbAlbum || "");
$('#txtMusicBrainzReleaseGroupId', page).val(providerIds.MusicBrainzReleaseGroup || "");
2013-05-22 15:01:37 -07:00
$('#txtRottenTomatoes', page).val(providerIds.RottenTomatoes || "");
$('#txtZap2It', page).val(providerIds.Zap2It || "");
$('#txtNesBoxName', page).val(providerIds.NesBox || "");
$('#txtNesBoxRom', page).val(providerIds.NesBoxRom || "");
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("");
}
$('.txtProviderId', page).trigger('change');
}
function convertTo24HourFormat(time) {
if (time == "")
return time;
var match = time.match(/^(\d+):(\d+)(.*)$/);
2013-06-19 06:54:45 -07:00
if (match) {
var hours = Number(match[1]);
var minutes = Number(match[2]);
var ampm = $.trim(match[3]);
ampm = ampm.toUpperCase();
if (ampm == "PM" && hours < 12) hours = hours + 12;
if (ampm == "AM" && hours == 12) hours = 0;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if (hours < 10) sHours = "0" + sHours;
if (minutes < 10) sMinutes = "0" + sMinutes;
return sHours + ":" + sMinutes;
} else {
return time;
}
}
function convertTo12HourFormat(time) {
if (time == "")
return time;
var hours = Number(time.match(/^(\d+)/)[1]);
var minutes = Number(time.match(/:(\d+)/)[1]);
var ampm = "AM";
if (hours >= 12) {
ampm = "PM";
hours = hours - 12;
hours = hours == 0 ? 12 : hours;
}
hours = hours == 0 ? 12 : hours;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if (hours < 10) sHours = "0" + sHours;
if (minutes < 10) sMinutes = "0" + sMinutes;
return sHours + ":" + sMinutes + " " + ampm;
}
2013-06-19 06:54:45 -07:00
function populateRatings(allParentalRatings, select) {
var html = "";
html += "<option value=''></option>";
var ratings = [];
var i, length, rating;
for (i = 0, length = allParentalRatings.length; i < length; i++) {
rating = allParentalRatings[i];
ratings.push({ Name: rating.Name, Value: rating.Name });
}
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>";
html += "<option value='Continuing'>Continuing</option>";
html += "<option value='Ended'>Ended</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
function generateSliders(fields, type) {
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;
var fieldTitle = $.trim(name.replace(/([A-Z])/g, ' $1'));
2013-06-14 22:30:48 -07:00
html += '<div data-role="fieldcontain">';
html += '<label for="lock' + value + '">' + fieldTitle + ':</label>';
html += '<select class="selectLockedField" id="lock' + value + '" data-role="slider" data-mini="true">';
html += '<option value="' + value + '">Off</option>';
2013-06-16 18:49:06 -07:00
html += '<option value="" selected="selected">On</option>';
2013-06-14 22:30:48 -07:00
html += '</select>';
html += '</div>';
}
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 = [
{ name: "Name" },
{ name: "Overview" },
{ name: "Genres" },
{ name: "Parental Rating", value: "OfficialRating" },
{ name: "People", value: "Cast" }
];
if (item.Type == "Person") {
metadatafields.push({ name: "Birth location", value: "ProductionLocations" });
} else {
metadatafields.push({ name: "Production Locations", value: "ProductionLocations" });
}
if (item.Type == "Series") {
metadatafields.push({ name: "Runtime" });
}
metadatafields.push({ name: "Studios" });
metadatafields.push({ name: "Tags" });
2014-01-14 09:06:26 -07:00
metadatafields.push({ name: "Keywords" });
2013-12-14 17:26:01 -07:00
metadatafields.push({ name: "Images" });
metadatafields.push({ name: "Backdrops" });
2013-12-28 22:32:03 -07:00
if (item.Type == "Game") {
metadatafields.push({ name: "Screenshots" });
}
2013-12-28 22:32:03 -07:00
2013-06-14 22:30:48 -07:00
var html = '';
2013-12-28 22:32:03 -07:00
html += "<h1>Fields</h1>";
html += "<p>Slide a field to 'off' to lock it and prevent it's data from being changed.</p>";
2013-06-14 22:30:48 -07:00
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');
}
}
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-02-12 22:11:54 -07:00
function performDelete(page) {
$('#btnDelete', page).buttonEnabled(false);
$('#btnRefresh', page).buttonEnabled(false);
$('.btnSave', page).buttonEnabled(false);
$('#refreshLoading', page).show();
var parentId = currentItem.ParentId;
ApiClient.deleteItem(currentItem.Id).done(function () {
var elem = $('#' + parentId)[0];
$('.libraryTree').jstree("select_node", elem, true)
.jstree("delete_node", '#' + currentItem.Id);
});
}
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(),
SortName: $('#txtSortName', form).val(),
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(),
DisplaySpecialsWithSeasons: $('#chkDisplaySpecialsInline', form).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(),
2013-05-27 19:36:51 -07:00
ParentIndexNumber: $('#txtParentIndexNumber', form).val(),
DisplayOrder: $('#selectDisplayOrder', form).val(),
2013-05-27 19:36:51 -07:00
Players: $('#txtPlayers', form).val(),
Album: $('#txtAlbum', form).val(),
AlbumArtist: $('#txtAlbumArtist', form).val(),
Artists: $('#txtArtist', form).val().split(';'),
2014-01-14 22:01:58 -07:00
Metascore: $('#txtMetascore', form).val(),
AwardSummary: $('#txtAwardSummary', form).val(),
Overview: $('#txtOverview', form).val(),
Status: $('#selectStatus', form).val(),
2014-02-09 10:44:25 -07:00
AirDays: getSelectedAirDays(form),
AirTime: convertTo12HourFormat($('#txtAirTime', form).val()),
Genres: editableListViewValues($("#listGenres", 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
PremiereDate: $('#txtPremiereDate', form).val() || null,
DateCreated: $('#txtDateAdded', form).val() || null,
2013-08-02 13:36:44 -07:00
EndDate: $('#txtEndDate', form).val() || null,
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,
2014-02-18 22:21:03 -07:00
LockData: $("#chkLockData", form).prop('checked'),
LockedFields: $('.selectLockedField', form).map(function () {
2013-06-14 22:30:48 -07:00
var value = $(this).val();
if (value != '') return value;
2014-02-09 14:11:11 -07:00
}).get()
2013-05-27 19:36:51 -07:00
};
2014-02-09 14:11:11 -07:00
item.ProviderIds = $.extend(currentItem.ProviderIds, {
2014-02-12 22:11:54 -07:00
2014-02-09 14:11:11 -07:00
Gamesdb: $('#txtGamesDb', form).val(),
Imdb: $('#txtImdb', form).val(),
Tmdb: $('#txtTmdb', form).val(),
TmdbCollection: $('#txtTmdbCollection', form).val(),
Tvdb: $('#txtTvdb', form).val(),
Tvcom: $('#txtTvCom', form).val(),
AudioDbArtist: $('#txtAudioDbArtist', form).val(),
AudioDbAlbum: $('#txtAudioDbAlbum', form).val(),
MusicBrainzAlbum: $('#txtMusicBrainzAlbumId', form).val(),
MusicBrainzAlbumArtist: $('#txtMusicBrainzAlbumArtistId', form).val(),
MusicBrainzArtist: $('#txtMusicBrainzArtistId', form).val(),
MusicBrainzReleaseGroup: $('#txtMusicBrainzReleaseGroupId', form).val(),
RottenTomatoes: $('#txtRottenTomatoes', form).val(),
Zap2It: $('#txtZap2It', form).val(),
NesBox: $('#txtNesBoxName', form).val(),
NesBoxRom: $('#txtNesBoxRom', form).val()
2014-02-12 22:11:54 -07:00
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;
}
2013-06-24 07:53:49 -07:00
var updatePromise;
2013-06-29 08:47:20 -07:00
2013-11-21 13:48:26 -07:00
if (currentItem.Type == "MusicArtist") {
2013-06-24 07:53:49 -07:00
updatePromise = ApiClient.updateArtist(item);
}
2013-06-29 08:47:20 -07:00
else if (currentItem.Type == "Genre") {
2013-06-24 07:53:49 -07:00
updatePromise = ApiClient.updateGenre(item);
}
2013-06-29 08:47:20 -07:00
else if (currentItem.Type == "MusicGenre") {
2013-06-24 07:53:49 -07:00
updatePromise = ApiClient.updateMusicGenre(item);
}
2013-07-01 10:17:33 -07:00
else if (currentItem.Type == "GameGenre") {
updatePromise = ApiClient.updateGameGenre(item);
}
2013-06-29 08:47:20 -07:00
else if (currentItem.Type == "Person") {
2013-06-24 07:53:49 -07:00
updatePromise = ApiClient.updatePerson(item);
}
2013-06-29 08:47:20 -07:00
else if (currentItem.Type == "Studio") {
2013-06-24 07:53:49 -07:00
updatePromise = ApiClient.updateStudio(item);
}
else {
updatePromise = ApiClient.updateItem(item);
}
updatePromise.done(function () {
2013-05-27 19:36:51 -07:00
Dashboard.alert('Item saved.');
});
return false;
2013-06-19 06:54:45 -07:00
};
self.addElementToEditableListview = function (source, sortCallback) {
var input = $(source).parent().find('input[type="text"], select');
2013-06-09 00:50:35 -07:00
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);
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
self.onDeleteFormSubmitted = function () {
var page = $(this).parents('.page');
if ($('#fldChallengeValue', page).val() != $('#txtDeleteTest', page).val()) {
Dashboard.alert('The value entered is not correct. Please try again.');
2014-02-12 22:11:54 -07:00
} else {
performDelete(page);
}
return false;
};
}
window.EditItemMetadataPage = new editItemMetadataPage();
$(document).on('pageinit', "#editItemMetadataPage", function () {
var page = this;
$('#txtGamesDb', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenGamesDb', page).attr('href', 'http://thegamesdb.net/game/' + val);
} else {
$('#btnOpenGamesDb', page).attr('href', '#');
}
});
$('#txtNesBoxName', this).on('change', function () {
var val = this.value;
var urlPrefix = currentItem.GameSystem == "Nintendo" ? "http://nesbox.com/game/" : "http://snesbox.com/game/";
if (val) {
$('#btnOpenNesBox', page).attr('href', urlPrefix + val);
} else {
$('#btnOpenNesBox', page).attr('href', '#');
}
});
$('#txtNesBoxRom', this).on('change', function () {
var val = this.value;
var romName = $('#txtNesBoxName', page).val();
var urlPrefix = currentItem.GameSystem == "Nintendo" ? "http://nesbox.com/game/" : "http://snesbox.com/game/";
if (val && romName) {
$('#btnOpenNesBoxRom', page).attr('href', urlPrefix + romName + '/rom/' + val);
} else {
$('#btnOpenNesBoxRom', page).attr('href', '#');
}
});
$('#txtImdb', this).on('change', function () {
var val = this.value;
if (val) {
if (currentItem.Type == "Person") {
$('#btnOpenImdb', page).attr('href', 'http://www.imdb.com/name/' + val);
} else {
$('#btnOpenImdb', page).attr('href', 'http://www.imdb.com/title/' + val);
}
} else {
$('#btnOpenImdb', page).attr('href', '#');
}
});
2014-02-09 14:11:11 -07:00
$('#txtAudioDbArtist', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenAudioDbArtist', page).attr('href', 'http://www.theaudiodb.com/artist/' + val);
} else {
$('#btnOpenAudioDbArtist', page).attr('href', '#');
}
});
$('#txtAudioDbAlbum', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenAudioDbAlbum', page).attr('href', 'http://www.theaudiodb.com/album/' + val);
} else {
$('#btnOpenAudioDbAlbum', page).attr('href', '#');
}
});
$('#txtMusicBrainzAlbumId', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenMusicBrainzAlbum', page).attr('href', 'http://musicbrainz.org/release/' + val);
} else {
$('#btnOpenMusicBrainzAlbum', page).attr('href', '#');
}
});
$('#txtMusicBrainzAlbumArtistId', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenMusicBrainzAlbumArtist', page).attr('href', 'http://musicbrainz.org/artist/' + val);
} else {
$('#btnOpenMusicBrainzAlbumArtist', page).attr('href', '#');
}
});
$('#txtMusicBrainzArtistId', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenMusicBrainzArtist', page).attr('href', 'http://musicbrainz.org/artist/' + val);
} else {
$('#btnOpenMusicBrainzArtist', page).attr('href', '#');
}
});
$('#txtMusicBrainzReleaseGroupId', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenMusicbrainzReleaseGroup', page).attr('href', 'http://musicbrainz.org/release-group/' + val);
} else {
$('#btnOpenMusicbrainzReleaseGroup', page).attr('href', '#');
}
});
$('#txtTmdb', this).on('change', function () {
var val = this.value;
if (val) {
if (currentItem.Type == "Movie" || currentItem.Type == "Trailer" || currentItem.Type == "MusicVideo")
$('#btnOpenTmdb', page).attr('href', 'http://www.themoviedb.org/movie/' + val);
else if (currentItem.Type == "BoxSet")
$('#btnOpenTmdb', page).attr('href', 'http://www.themoviedb.org/collection/' + val);
else if (currentItem.Type == "Person")
$('#btnOpenTmdb', page).attr('href', 'http://www.themoviedb.org/person/' + val);
} else {
$('#btnOpenTmdb', page).attr('href', '#');
}
});
2013-12-07 18:42:15 -07:00
$('#txtTmdbCollection', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenTmdbCollection', page).attr('href', 'http://www.themoviedb.org/collection/' + val);
} else {
$('#btnOpenTmdbCollection', page).attr('href', '#');
}
});
$('#txtTvdb', this).on('change', function () {
var val = this.value;
2013-10-12 20:39:22 -07:00
if (val && currentItem.Type == "Series") {
$('#btnOpenTvdb', page).attr('href', 'http://thetvdb.com/index.php?tab=series&id=' + val);
} else {
$('#btnOpenTvdb', page).attr('href', '#');
}
});
$('#txtZap2It', this).on('change', function () {
var val = this.value;
if (val) {
$('#btnOpenZap2It', page).attr('href', 'http://tvlistings.zap2it.com/tv/dexter/' + val);
} else {
$('#btnOpenZap2It', page).attr('href', '#');
}
});
$('#btnRefresh', this).on('click', function () {
2013-12-24 11:37:29 -07:00
$('#btnDelete', page).buttonEnabled(false);
$('#btnRefresh', page).buttonEnabled(false);
$('.btnSave', page).buttonEnabled(false);
$('#refreshLoading', page).show();
2013-06-27 13:08:38 -07:00
var refreshPromise;
2014-02-12 22:11:54 -07:00
var force = $('#selectRefreshMode', page).val() == 'all';
2013-07-22 10:23:48 -07:00
2013-11-21 13:48:26 -07:00
if (currentItem.Type == "MusicArtist") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshArtist(currentItem.Name, force);
2013-06-27 13:08:38 -07:00
}
else if (currentItem.Type == "Genre") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshGenre(currentItem.Name, force);
2013-06-27 13:08:38 -07:00
}
else if (currentItem.Type == "MusicGenre") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshMusicGenre(currentItem.Name, force);
2013-06-27 13:08:38 -07:00
}
2013-07-01 10:17:33 -07:00
else if (currentItem.Type == "GameGenre") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshGameGenre(currentItem.Name, force);
2013-07-01 10:17:33 -07:00
}
2013-06-27 13:08:38 -07:00
else if (currentItem.Type == "Person") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshPerson(currentItem.Name, force);
2013-06-27 13:08:38 -07:00
}
else if (currentItem.Type == "Studio") {
2013-07-22 10:23:48 -07:00
refreshPromise = ApiClient.refreshStudio(currentItem.Name, force);
2013-06-27 13:08:38 -07:00
}
else {
2014-02-09 14:11:11 -07:00
refreshPromise = ApiClient.refreshItem(currentItem.Id, force, true);
2013-06-27 13:08:38 -07:00
}
refreshPromise.done(function () {
reload(page);
});
});
2014-02-12 22:11:54 -07:00
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
$('#btnDelete', this).on('click', function () {
if (currentItem.LocationType != "Remote" && currentItem.LocationType != "Virtual") {
2014-02-12 22:11:54 -07:00
$('.deletePath', page).html((currentItem.Path || ''));
2014-02-12 22:11:54 -07:00
var val1 = getRandomInt(6, 12);
var val2 = getRandomInt(8, 16);
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
$('#challengeValueText', page).html(val1 + ' * ' + val2 + ':');
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
var val = val1 * val2;
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
$('#fldChallengeValue', page).val(val);
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
$('#popupConfirmDelete', page).popup('open');
2014-02-12 22:11:54 -07:00
} else {
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
var msg = "<p>Are you sure you wish to delete this item from your library?</p>";
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
Dashboard.confirm(msg, "Confirm Deletion", function (result) {
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
if (result) {
performDelete(page);
}
2013-10-18 14:12:05 -07:00
2014-02-12 22:11:54 -07:00
});
}
2013-10-18 14:12:05 -07:00
});
2013-08-02 13:36:44 -07:00
$('.libraryTree', page).on('itemclicked', function (event, data) {
if (data.itemType == "livetvservice") {
return;
}
2014-02-12 22:11:54 -07:00
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.currentItemName = data.itemName;
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;
2013-08-02 13:36:44 -07:00
reload(page);
}
});
}).on('pagebeforeshow', "#editItemMetadataPage", function () {
var page = this;
2013-08-02 13:36:44 -07:00
reload(page);
});
2013-08-02 13:36:44 -07:00
})(jQuery, document, window);