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

209 lines
5.7 KiB
JavaScript
Raw Normal View History

2016-07-16 21:20:36 -07:00
define(['apphost'], function (appHost) {
2016-10-17 22:06:48 -07:00
'use strict';
2016-05-11 10:46:44 -07:00
function getDisplayName(item, options) {
if (!item) {
throw new Error("null item passed into getDisplayName");
}
options = options || {};
2016-10-17 22:06:48 -07:00
if (item.Type === 'Timer') {
2016-10-03 22:15:39 -07:00
item = item.ProgramInfo || item;
}
2017-01-21 13:27:07 -07:00
var name = ((item.Type === 'Program' || item.Type === 'Recording') && (item.IsSeries || item.EpisodeTitle) ? item.EpisodeTitle : item.Name) || '';
2016-05-11 10:46:44 -07:00
2016-10-17 22:06:48 -07:00
if (item.Type === "TvChannel") {
2016-05-11 10:46:44 -07:00
if (item.Number) {
return item.Number + ' ' + name;
}
return name;
}
2016-10-17 22:06:48 -07:00
if (/*options.isInlineSpecial &&*/ item.Type === "Episode" && item.ParentIndexNumber === 0) {
2016-05-11 10:46:44 -07:00
2016-05-12 12:21:43 -07:00
name = Globalize.translate('sharedcomponents#ValueSpecialEpisodeName', name);
2016-05-11 10:46:44 -07:00
2016-10-17 22:06:48 -07:00
} else if ((item.Type === "Episode" || item.Type === 'Program') && item.IndexNumber != null && item.ParentIndexNumber != null) {
2016-05-11 10:46:44 -07:00
var displayIndexNumber = item.IndexNumber;
2016-12-14 13:58:55 -07:00
var number = displayIndexNumber;
2016-05-11 10:46:44 -07:00
if (options.includeParentInfo !== false) {
2016-12-14 13:58:55 -07:00
number = "S" + item.ParentIndexNumber + ", E" + number;
2016-05-11 10:46:44 -07:00
}
if (item.IndexNumberEnd) {
displayIndexNumber = item.IndexNumberEnd;
number += "-" + displayIndexNumber;
}
2016-09-22 23:57:24 -07:00
name = name ? (number + " - " + name) : number;
2016-05-11 10:46:44 -07:00
}
return name;
}
2016-05-21 23:08:44 -07:00
function supportsAddingToCollection(item) {
2016-07-16 21:20:36 -07:00
2016-10-17 22:06:48 -07:00
if (item.Type === 'Timer' || item.Type === 'SeriesTimer') {
2016-07-16 21:20:36 -07:00
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
2016-10-17 22:06:48 -07:00
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
2016-10-09 00:18:43 -07:00
return false;
}
}
2016-10-17 22:06:48 -07:00
return !item.CollectionType && invalidTypes.indexOf(item.Type) === -1 && item.MediaType !== 'Photo';
2016-05-21 23:08:44 -07:00
}
function supportsAddingToPlaylist(item) {
2016-10-08 21:58:57 -07:00
2016-10-17 22:06:48 -07:00
if (item.Type === 'Program') {
2016-05-21 23:08:44 -07:00
return false;
}
2016-12-02 01:03:38 -07:00
if (item.Type === 'TvChannel') {
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'Timer') {
2016-05-21 23:08:44 -07:00
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'SeriesTimer') {
2016-10-02 20:49:52 -07:00
return false;
}
2016-10-09 00:18:43 -07:00
2016-10-17 22:06:48 -07:00
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
2016-10-09 00:18:43 -07:00
return false;
}
}
2016-10-17 22:06:48 -07:00
return item.MediaType || item.IsFolder || item.Type === "Genre" || item.Type === "MusicGenre" || item.Type === "MusicArtist";
2016-05-21 23:08:44 -07:00
}
2016-10-09 00:18:43 -07:00
function canEdit(user, item) {
var itemType = item.Type;
2016-10-17 22:06:48 -07:00
if (itemType === "UserRootFolder" || /*itemType == "CollectionFolder" ||*/ itemType === "UserView") {
return false;
}
2016-10-17 22:06:48 -07:00
if (itemType === 'Program') {
2016-07-18 22:09:14 -07:00
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
2016-10-09 00:18:43 -07:00
return false;
}
}
2016-10-09 00:18:43 -07:00
return user.Policy.IsAdministrator;
}
2016-12-24 12:15:27 -07:00
function isLocalItem(item) {
if (item && item.Id && item.Id.indexOf('local') === 0) {
return true;
}
return false;
}
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,
2016-12-24 12:15:27 -07:00
isLocalItem: isLocalItem,
2016-07-16 18:58:51 -07:00
canIdentify: function (user, itemType) {
2016-10-17 22:06:48 -07:00
if (itemType === "Movie" ||
itemType === "Trailer" ||
itemType === "Series" ||
itemType === "Game" ||
itemType === "BoxSet" ||
itemType === "Person" ||
itemType === "Book" ||
itemType === "MusicAlbum" ||
itemType === "MusicArtist") {
2016-07-16 18:58:51 -07:00
if (user.Policy.IsAdministrator) {
return true;
}
}
return false;
},
canEdit: canEdit,
2016-07-16 18:58:51 -07:00
2016-10-09 00:18:43 -07:00
canEditImages: function (user, item) {
var itemType = item.Type;
2016-07-16 18:58:51 -07:00
2016-10-17 22:06:48 -07:00
if (itemType === 'UserView') {
2016-07-21 14:23:34 -07:00
if (user.Policy.IsAdministrator) {
return true;
}
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
2016-10-09 00:18:43 -07:00
return false;
}
}
2016-10-17 22:06:48 -07:00
return itemType !== 'Timer' && itemType !== 'SeriesTimer' && canEdit(user, item);
2016-07-16 18:58:51 -07:00
},
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) {
2016-12-02 01:03:38 -07:00
if (item.Type === 'Program') {
return false;
}
if (item.Type === 'TvChannel') {
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'Timer') {
2016-07-16 21:20:36 -07:00
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'SeriesTimer') {
2016-10-02 20:49:52 -07:00
return false;
}
2016-10-17 22:06:48 -07:00
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
2016-10-09 00:18:43 -07:00
return false;
}
}
2016-07-16 21:20:36 -07:00
return user.Policy.EnablePublicSharing && appHost.supports('sharing');
2016-12-08 08:43:05 -07:00
},
enableDateAddedDisplay: function(item) {
return !item.IsFolder && item.MediaType && item.Type !== 'Program' && item.Type !== 'TvChannel' && item.Type !== 'Trailer';
2016-07-16 18:58:51 -07:00
}
2016-05-11 10:46:44 -07:00
};
});