jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/itemhelper.js

129 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-07-16 21:20:36 -07:00
define(['apphost'], function (appHost) {
2016-05-11 10:46:44 -07:00
function getDisplayName(item, options) {
if (!item) {
throw new Error("null item passed into getDisplayName");
}
options = options || {};
var name = item.EpisodeTitle || item.Name || '';
if (item.Type == "TvChannel") {
if (item.Number) {
return item.Number + ' ' + name;
}
return name;
}
if (/*options.isInlineSpecial &&*/ item.Type == "Episode" && item.ParentIndexNumber == 0) {
2016-05-12 12:21:43 -07:00
name = Globalize.translate('sharedcomponents#ValueSpecialEpisodeName', name);
2016-05-11 10:46:44 -07:00
} else if ((item.Type == "Episode" || item.Type == 'Program') && item.IndexNumber != null && item.ParentIndexNumber != null) {
var displayIndexNumber = item.IndexNumber;
var number = "E" + displayIndexNumber;
if (options.includeParentInfo !== false) {
number = "S" + item.ParentIndexNumber + ", " + number;
}
if (item.IndexNumberEnd) {
displayIndexNumber = item.IndexNumberEnd;
number += "-" + displayIndexNumber;
}
name = number + " - " + name;
}
if (item.EpisodeTitle) {
name = item.Name + ' ' + name;
}
return name;
}
2016-05-21 23:08:44 -07:00
function supportsAddingToCollection(item) {
2016-07-16 21:20:36 -07:00
if (item.Type == 'Timer') {
return false;
}
2016-05-22 09:47:14 -07:00
var invalidTypes = ['Person', 'Genre', 'MusicGenre', 'Studio', 'GameGenre', 'BoxSet', 'Playlist', 'UserView', 'CollectionFolder', 'Audio', 'TvChannel', 'Program', 'MusicAlbum', 'Timer'];
2016-05-21 23:08:44 -07:00
return !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
}
function supportsAddingToPlaylist(item) {
if (item.Type == 'Program') {
return false;
}
if (item.Type == 'Timer') {
return false;
}
return item.RunTimeTicks || item.IsFolder || item.Type == "Genre" || item.Type == "MusicGenre" || item.Type == "MusicArtist";
}
2016-05-11 10:46:44 -07:00
return {
2016-05-21 23:08:44 -07:00
getDisplayName: getDisplayName,
supportsAddingToCollection: supportsAddingToCollection,
2016-07-16 18:58:51 -07:00
supportsAddingToPlaylist: supportsAddingToPlaylist,
canIdentify: function (user, itemType) {
if (itemType == "Movie" ||
itemType == "Trailer" ||
itemType == "Series" ||
itemType == "Game" ||
itemType == "BoxSet" ||
itemType == "Person" ||
itemType == "Book" ||
itemType == "MusicAlbum" ||
itemType == "MusicArtist") {
if (user.Policy.IsAdministrator) {
return true;
}
}
return false;
},
canEdit: function (user, itemType) {
2016-07-16 21:20:36 -07:00
if (itemType == "UserRootFolder" || /*itemType == "CollectionFolder" ||*/ itemType == "UserView") {
2016-07-16 18:58:51 -07:00
return false;
}
if (user.Policy.IsAdministrator) {
return true;
}
return false;
},
canSync: function (user, item) {
if (user && !user.Policy.EnableSync) {
return false;
}
return item.SupportsSync;
2016-07-16 21:20:36 -07:00
},
canShare: function (user, item) {
if (item.Type == 'Timer') {
return false;
}
return user.Policy.EnablePublicSharing && appHost.supports('sharing');
2016-07-16 18:58:51 -07:00
}
2016-05-11 10:46:44 -07:00
};
});