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

1430 lines
46 KiB
JavaScript
Raw Normal View History

2014-03-17 07:48:16 -07:00
(function ($, document, window) {
var showOverlayTimeout;
2015-12-14 08:43:03 -07:00
function onHoverOut(e) {
var elem = e.target;
if (!elem.classList.contains('card')) {
return;
}
2014-03-17 07:48:16 -07:00
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
2015-12-14 08:43:03 -07:00
elem = elem.querySelector('.cardOverlayTarget');
if (elem) {
slideDownToHide(elem);
}
}
2014-03-17 07:48:16 -07:00
2015-12-14 08:43:03 -07:00
function slideDownToHide(elem) {
2014-03-17 07:48:16 -07:00
2015-12-14 08:43:03 -07:00
if (elem.classList.contains('hide')) {
return;
2015-06-28 18:10:45 -07:00
}
2015-12-14 08:43:03 -07:00
requestAnimationFrame(function () {
var keyframes = [
{ height: '100%', offset: 0 },
{ height: '0', offset: 1 }];
var timing = { duration: 300, iterations: 1, fill: 'forwards', easing: 'ease-out' };
elem.animate(keyframes, timing).onfinish = function () {
elem.classList.add('hide');
};
});
}
function slideUpToShow(elem) {
if (!elem.classList.contains('hide')) {
return;
}
elem.classList.remove('hide');
requestAnimationFrame(function () {
elem.style.display = 'block';
var keyframes = [
{ height: '0', offset: 0 },
{ height: '100%', offset: 1 }];
var timing = { duration: 300, iterations: 1, fill: 'forwards', easing: 'ease-out' };
elem.animate(keyframes, timing);
});
2014-03-17 07:48:16 -07:00
}
2014-08-01 19:34:45 -07:00
function getOverlayHtml(item, currentUser, card, commands) {
2014-03-17 07:48:16 -07:00
var html = '';
2014-08-01 19:34:45 -07:00
html += '<div class="cardOverlayInner">';
2014-03-17 07:48:16 -07:00
2014-08-01 19:34:45 -07:00
var className = card.className.toLowerCase();
var isMiniItem = className.indexOf('mini') != -1;
var isSmallItem = isMiniItem || className.indexOf('small') != -1;
var isPortrait = className.indexOf('portrait') != -1;
var isSquare = className.indexOf('square') != -1;
2014-03-17 07:48:16 -07:00
2014-06-23 09:05:19 -07:00
var parentName = isSmallItem || isMiniItem || isPortrait ? null : item.SeriesName;
2014-03-17 07:48:16 -07:00
var name = LibraryBrowser.getPosterViewDisplayName(item, true);
2014-08-01 19:34:45 -07:00
html += '<div style="margin-bottom:1em;">';
2014-06-23 09:05:19 -07:00
var logoHeight = isSmallItem || isMiniItem ? 20 : 26;
2014-03-17 07:48:16 -07:00
var imgUrl;
if (parentName && item.ParentLogoItemId) {
imgUrl = ApiClient.getScaledImageUrl(item.ParentLogoItemId, {
2015-12-14 08:43:03 -07:00
maxHeight: logoHeight,
2014-03-17 07:48:16 -07:00
type: 'logo',
tag: item.ParentLogoImageTag
});
2014-11-18 19:45:12 -07:00
html += '<img src="' + imgUrl + '" style="max-height:' + logoHeight + 'px;max-width:100%;" />';
2014-03-17 07:48:16 -07:00
}
else if (item.ImageTags.Logo) {
imgUrl = ApiClient.getScaledImageUrl(item.Id, {
2015-12-14 08:43:03 -07:00
maxHeight: logoHeight,
type: 'logo',
tag: item.ImageTags.Logo
2014-03-17 07:48:16 -07:00
});
2014-11-18 19:45:12 -07:00
html += '<img src="' + imgUrl + '" style="max-height:' + logoHeight + 'px;max-width:100%;" />';
2014-03-17 07:48:16 -07:00
}
else {
html += parentName || name;
}
html += '</div>';
if (parentName) {
html += '<p>';
html += name;
html += '</p>';
2014-06-23 09:05:19 -07:00
} else if (!isSmallItem && !isMiniItem) {
2014-03-17 07:48:16 -07:00
html += '<p class="itemMiscInfo" style="white-space:nowrap;">';
html += LibraryBrowser.getMiscInfoHtml(item);
html += '</p>';
}
2014-06-23 09:05:19 -07:00
if (!isMiniItem) {
2015-01-03 12:38:22 -07:00
html += '<div style="margin:1em 0 .75em;">';
2014-06-23 09:05:19 -07:00
if (isPortrait) {
2015-01-01 22:36:27 -07:00
html += '<div class="itemCommunityRating">';
html += LibraryBrowser.getRatingHtml(item, false);
html += '</div>';
2015-01-03 12:38:22 -07:00
html += '<div class="userDataIcons" style="margin:.5em 0 0em;">';
2014-06-23 09:05:19 -07:00
html += LibraryBrowser.getUserDataIconsHtml(item);
2015-01-01 22:36:27 -07:00
html += '</div>';
2014-06-23 09:05:19 -07:00
} else {
2015-01-01 22:36:27 -07:00
2015-01-03 12:38:22 -07:00
html += '<span class="itemCommunityRating" style="vertical-align:middle;">';
2015-01-01 22:36:27 -07:00
html += LibraryBrowser.getRatingHtml(item, false);
html += '</span>';
2015-01-03 12:38:22 -07:00
html += '<span class="userDataIcons" style="vertical-align:middle;">';
2014-06-23 09:05:19 -07:00
html += LibraryBrowser.getUserDataIconsHtml(item);
html += '</span>';
}
html += '</div>';
2014-03-17 07:48:16 -07:00
}
html += '<div>';
var buttonMargin = isPortrait || isSquare ? "margin:0 4px 0 0;" : "margin:0 10px 0 0;";
var buttonCount = 0;
2014-03-29 08:40:32 -07:00
if (MediaController.canPlay(item)) {
2014-03-17 07:48:16 -07:00
var resumePosition = (item.UserData || {}).PlaybackPositionTicks || 0;
2015-06-30 10:21:20 -07:00
html += '<paper-icon-button icon="play-circle-outline" class="btnPlayItem" data-itemid="' + item.Id + '" data-itemtype="' + item.Type + '" data-isfolder="' + item.IsFolder + '" data-mediatype="' + item.MediaType + '" data-resumeposition="' + resumePosition + '"></paper-icon-button>';
2014-03-17 07:48:16 -07:00
buttonCount++;
}
if (commands.indexOf('trailer') != -1) {
2015-06-29 18:56:25 -07:00
html += '<paper-icon-button icon="videocam" class="btnPlayTrailer" data-itemid="' + item.Id + '"></paper-icon-button>';
2014-03-17 07:48:16 -07:00
buttonCount++;
}
2015-07-14 09:39:34 -07:00
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnMoreCommands"></paper-icon-button>';
2014-08-15 09:35:41 -07:00
buttonCount++;
2014-03-17 07:48:16 -07:00
html += '</div>';
html += '</div>';
return html;
}
function onTrailerButtonClick() {
var id = this.getAttribute('data-itemid');
2015-12-14 08:43:03 -07:00
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), id).then(function (trailers) {
2014-03-29 08:40:32 -07:00
MediaController.play({ items: trailers });
2014-03-17 07:48:16 -07:00
});
return false;
}
function onPlayItemButtonClick() {
var id = this.getAttribute('data-itemid');
var type = this.getAttribute('data-itemtype');
var isFolder = this.getAttribute('data-isfolder') == 'true';
var mediaType = this.getAttribute('data-mediatype');
var resumePosition = parseInt(this.getAttribute('data-resumeposition'));
LibraryBrowser.showPlayMenu(this, id, type, isFolder, mediaType, resumePosition);
return false;
}
2014-08-07 21:36:51 -07:00
function onMoreButtonClick() {
2014-08-15 09:35:41 -07:00
var card = $(this).parents('.card')[0];
2014-08-07 21:36:51 -07:00
2014-08-15 09:35:41 -07:00
showContextMenu(card, {
showPlayOptions: false
});
2014-08-07 21:36:51 -07:00
return false;
}
2015-09-23 09:16:06 -07:00
function onContextMenu(e) {
2015-09-05 09:58:27 -07:00
var card = parentWithClass(e.target, 'card');
2015-09-05 21:53:37 -07:00
if (card) {
2015-10-07 14:42:29 -07:00
var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
if (!itemSelectionPanel) {
showContextMenu(card, {});
}
2015-09-05 21:53:37 -07:00
e.preventDefault();
return false;
}
}
2014-08-15 09:35:41 -07:00
function showContextMenu(card, options) {
2014-08-01 19:34:45 -07:00
var displayContextItem = card;
2014-07-19 21:46:29 -07:00
2015-07-06 00:06:09 -07:00
if (!card.classList.contains('card') && !card.classList.contains('listItem')) {
2014-11-10 20:41:19 -07:00
card = $(card).parents('.listItem,.card')[0];
2014-07-19 21:46:29 -07:00
}
2014-08-01 19:34:45 -07:00
var itemId = card.getAttribute('data-itemid');
2014-08-11 16:41:11 -07:00
var playlistItemId = card.getAttribute('data-playlistitemid');
2014-08-01 19:34:45 -07:00
var commands = card.getAttribute('data-commands').split(',');
var itemType = card.getAttribute('data-itemtype');
var mediaType = card.getAttribute('data-mediatype');
var playbackPositionTicks = parseInt(card.getAttribute('data-positionticks') || '0');
var playAccess = card.getAttribute('data-playaccess');
var locationType = card.getAttribute('data-locationtype');
2014-08-21 08:55:35 -07:00
var index = card.getAttribute('data-index');
2014-03-18 18:35:40 -07:00
2015-06-05 07:27:01 -07:00
var albumid = card.getAttribute('data-albumid');
var artistid = card.getAttribute('data-artistid');
2015-12-14 08:43:03 -07:00
Dashboard.getCurrentUser().then(function (user) {
2014-03-18 18:35:40 -07:00
2015-06-20 17:49:42 -07:00
var items = [];
2014-07-15 12:16:16 -07:00
2015-01-23 21:50:45 -07:00
if (commands.indexOf('addtocollection') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonAddToCollection'),
id: 'addtocollection',
ironIcon: 'add'
});
2015-01-23 21:50:45 -07:00
}
2014-08-21 19:24:38 -07:00
if (commands.indexOf('playlist') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonAddToPlaylist'),
id: 'playlist',
ironIcon: 'playlist-add'
});
2014-08-21 19:24:38 -07:00
}
2015-12-30 10:02:11 -07:00
if (user.Policy.EnableContentDownloading && AppInfo.supportsDownloading) {
if (mediaType) {
items.push({
name: Globalize.translate('ButtonDownload'),
id: 'download',
ironIcon: 'file-download'
});
}
}
2015-02-05 22:39:07 -07:00
if (commands.indexOf('delete') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete',
ironIcon: 'delete'
});
2015-02-05 22:39:07 -07:00
}
2015-12-18 10:34:04 -07:00
if (user.Policy.IsAdministrator) {
if (commands.indexOf('edit') != -1) {
items.push({
name: Globalize.translate('ButtonEdit'),
id: 'edit',
ironIcon: 'mode-edit'
});
}
if (commands.indexOf('editimages') != -1) {
items.push({
name: Globalize.translate('ButtonEditImages'),
id: 'editimages',
ironIcon: 'photo'
});
}
if (commands.indexOf('editsubtitles') != -1) {
items.push({
name: Globalize.translate('ButtonEditSubtitles'),
id: 'editsubtitles',
ironIcon: 'closed-caption'
});
}
2014-08-21 19:24:38 -07:00
}
2015-09-16 19:33:45 -07:00
if (commands.indexOf('instantmix') != -1) {
2015-09-16 18:33:46 -07:00
items.push({
2015-09-16 19:33:45 -07:00
name: Globalize.translate('ButtonInstantMix'),
id: 'instantmix',
ironIcon: 'shuffle'
2015-09-16 18:33:46 -07:00
});
}
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonOpen'),
id: 'open',
ironIcon: 'folder-open'
});
2014-08-21 19:24:38 -07:00
2014-08-15 09:35:41 -07:00
if (options.showPlayOptions !== false) {
2014-08-21 08:55:35 -07:00
2015-03-25 11:29:21 -07:00
if (MediaController.canPlayByAttributes(itemType, mediaType, playAccess, locationType)) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonPlay'),
id: 'play',
ironIcon: 'play-arrow'
});
2014-08-21 08:55:35 -07:00
if (commands.indexOf('playfromhere') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonPlayAllFromHere'),
id: 'playallfromhere',
ironIcon: 'play-arrow'
});
2014-08-21 08:55:35 -07:00
}
2014-08-15 09:35:41 -07:00
}
2015-12-14 08:43:03 -07:00
if (mediaType == 'Video' && AppInfo.supportsExternalPlayers && AppSettings.enableExternalPlayers()) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonPlayExternalPlayer'),
id: 'externalplayer',
ironIcon: 'airplay'
});
2014-09-15 20:33:30 -07:00
}
2014-08-15 09:35:41 -07:00
if (playbackPositionTicks && mediaType != "Audio") {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonResume'),
id: 'resume',
ironIcon: 'play-arrow'
});
2014-08-15 09:35:41 -07:00
}
2014-08-15 09:35:41 -07:00
if (commands.indexOf('trailer') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonPlayTrailer'),
id: 'trailer',
ironIcon: 'play-arrow'
});
2014-08-15 09:35:41 -07:00
}
2014-06-30 21:26:50 -07:00
}
2014-07-19 21:46:29 -07:00
if (MediaController.canQueueMediaType(mediaType, itemType)) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonQueue'),
id: 'queue',
ironIcon: 'playlist-add'
});
2014-08-21 08:55:35 -07:00
if (commands.indexOf('queuefromhere') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonQueueAllFromHere'),
id: 'queueallfromhere',
ironIcon: 'playlist-add'
});
2014-08-21 08:55:35 -07:00
}
}
2014-07-19 21:46:29 -07:00
if (commands.indexOf('shuffle') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonShuffle'),
id: 'shuffle',
ironIcon: 'shuffle'
});
2014-03-18 21:59:45 -07:00
}
2015-08-24 20:13:04 -07:00
if (commands.indexOf('record') != -1) {
items.push({
name: Globalize.translate('ButtonRecord'),
id: 'record',
ironIcon: 'videocam'
});
}
2015-09-15 20:55:26 -07:00
if (commands.indexOf('removefromcollection') != -1) {
items.push({
name: Globalize.translate('ButtonRemoveFromCollection'),
id: 'removefromcollection',
ironIcon: 'remove'
});
}
2014-08-05 21:18:13 -07:00
if (commands.indexOf('removefromplaylist') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonRemoveFromPlaylist'),
id: 'removefromplaylist',
ironIcon: 'remove'
});
2014-08-05 21:18:13 -07:00
}
2015-07-01 22:08:05 -07:00
if (user.Policy.EnablePublicSharing) {
items.push({
name: Globalize.translate('ButtonShare'),
id: 'share',
ironIcon: 'share'
});
}
2014-12-10 23:20:28 -07:00
if (commands.indexOf('sync') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonSync'),
id: 'sync',
2015-10-16 15:21:03 -07:00
ironIcon: 'sync'
2015-06-20 17:49:42 -07:00
});
2015-06-05 07:27:01 -07:00
}
if (albumid) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonViewAlbum'),
id: 'album',
ironIcon: 'album'
});
2015-06-05 07:27:01 -07:00
}
if (artistid) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonViewArtist'),
id: 'artist',
ironIcon: 'person'
});
2014-12-10 23:20:28 -07:00
}
2015-06-28 07:45:21 -07:00
var href = card.getAttribute('data-href') || card.href;
if (!href) {
2015-06-29 11:45:42 -07:00
var links = card.getElementsByTagName('a');
if (links.length) {
href = links[0].href;
2015-06-28 07:45:21 -07:00
}
}
2015-06-20 17:49:42 -07:00
require(['actionsheet'], function () {
ActionSheetElement.show({
items: items,
positionTo: displayContextItem,
callback: function (id) {
switch (id) {
case 'addtocollection':
2015-10-13 22:46:11 -07:00
require(['collectioneditor'], function (collectioneditor) {
new collectioneditor().show([itemId]);
});
2015-06-20 17:49:42 -07:00
break;
case 'playlist':
PlaylistManager.showPanel([itemId]);
break;
case 'delete':
2016-01-19 12:03:46 -07:00
LibraryBrowser.deleteItems([itemId]);
2015-06-20 17:49:42 -07:00
break;
case 'download':
{
var downloadHref = ApiClient.getUrl("Items/" + itemId + "/Download", {
api_key: ApiClient.accessToken()
});
window.location.href = downloadHref;
break;
}
case 'edit':
2015-09-19 19:06:56 -07:00
LibraryBrowser.editMetadata(itemId);
2015-06-20 17:49:42 -07:00
break;
case 'refresh':
ApiClient.refreshItem(itemId, {
Recursive: true,
ImageRefreshMode: 'FullRefresh',
MetadataRefreshMode: 'FullRefresh',
ReplaceAllImages: false,
ReplaceAllMetadata: true
});
break;
case 'instantmix':
MediaController.instantMix(itemId);
break;
case 'shuffle':
MediaController.shuffle(itemId);
break;
case 'open':
Dashboard.navigate(href);
break;
case 'album':
Dashboard.navigate('itemdetails.html?id=' + albumid);
2015-09-05 09:58:27 -07:00
break;
2015-08-24 20:13:04 -07:00
case 'record':
2015-12-15 11:24:41 -07:00
require(['components/recordingcreator/recordingcreator'], function (recordingcreator) {
recordingcreator.show(itemId);
});
2015-06-20 17:49:42 -07:00
break;
case 'artist':
2015-08-18 21:08:03 -07:00
Dashboard.navigate('itemdetails.html?context=music&id=' + artistid);
2015-06-20 17:49:42 -07:00
break;
case 'play':
2015-06-23 15:13:06 -07:00
MediaController.play(itemId);
2015-06-20 17:49:42 -07:00
break;
case 'playallfromhere':
2015-08-18 21:08:03 -07:00
playAllFromHere(index, $(card).parents('.itemsContainer'), 'play');
2015-06-20 17:49:42 -07:00
break;
case 'queue':
MediaController.queue(itemId);
break;
case 'trailer':
2015-12-14 08:43:03 -07:00
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), itemId).then(function (trailers) {
2015-06-20 17:49:42 -07:00
MediaController.play({ items: trailers });
});
break;
case 'resume':
MediaController.play({
ids: [itemId],
startPositionTicks: playbackPositionTicks
});
break;
case 'queueallfromhere':
2015-08-18 21:08:03 -07:00
playAllFromHere(index, $(card).parents('.itemsContainer'), 'queue');
2015-06-20 17:49:42 -07:00
break;
case 'sync':
SyncManager.showMenu({
items: [
{
Id: itemId
}]
});
break;
2015-09-17 09:04:04 -07:00
case 'editsubtitles':
2015-09-16 18:33:46 -07:00
LibraryBrowser.editSubtitles(itemId);
break;
2015-09-17 09:04:04 -07:00
case 'editimages':
LibraryBrowser.editImages(itemId);
break;
2015-06-20 17:49:42 -07:00
case 'externalplayer':
LibraryBrowser.playInExternalPlayer(itemId);
break;
2015-07-01 22:08:05 -07:00
case 'share':
require(['sharingmanager'], function () {
SharingManager.showMenu(Dashboard.getCurrentUserId(), itemId);
});
break;
2015-06-20 17:49:42 -07:00
case 'removefromplaylist':
$(card).parents('.itemsContainer').trigger('removefromplaylist', [playlistItemId]);
break;
2015-09-15 20:55:26 -07:00
case 'removefromcollection':
$(card).parents('.collectionItems').trigger('removefromcollection', [itemId]);
break;
2015-06-20 17:49:42 -07:00
default:
break;
}
}
});
});
2014-03-18 18:35:40 -07:00
});
}
2015-09-27 16:32:09 -07:00
function onListViewPlayButtonClick(e, playButton) {
2015-09-05 09:58:27 -07:00
var card = e.target;
2015-07-06 00:06:09 -07:00
if (!card.classList.contains('card') && !card.classList.contains('listItem')) {
card = $(card).parents('.listItem,.card')[0];
}
var id = card.getAttribute('data-itemid');
var type = card.getAttribute('data-itemtype');
var isFolder = card.getAttribute('data-isfolder') == 'true';
var mediaType = card.getAttribute('data-mediatype');
2015-07-17 15:32:00 -07:00
var resumePosition = parseInt(card.getAttribute('data-positionticks'));
2015-07-06 00:06:09 -07:00
2015-07-06 19:25:23 -07:00
if (type == 'MusicAlbum' || type == 'MusicArtist' || type == 'MusicGenre' || type == 'Playlist') {
2015-07-06 00:06:09 -07:00
isFolder = true;
}
2015-08-16 21:08:33 -07:00
if (type == 'Program') {
id = card.getAttribute('data-channelid');
}
2015-07-06 00:06:09 -07:00
LibraryBrowser.showPlayMenu(playButton, id, type, isFolder, mediaType, resumePosition);
e.preventDefault();
return false;
}
function isClickable(target) {
while (target != null) {
var tagName = target.tagName || '';
2015-07-14 09:39:34 -07:00
if (tagName == 'A' || tagName.indexOf('BUTTON') != -1 || tagName.indexOf('INPUT') != -1) {
2015-07-06 00:06:09 -07:00
return true;
}
return false;
//target = target.parentNode;
}
return false;
}
2015-09-27 16:32:09 -07:00
function onCardClick(e) {
2015-09-27 16:32:09 -07:00
var playButton = parentWithClass(e.target, 'cardOverlayPlayButton');
2015-09-05 09:58:27 -07:00
2015-09-27 16:32:09 -07:00
if (playButton) {
return onListViewPlayButtonClick(e, playButton);
}
var listviewMenuButton = parentWithClass(e.target, 'listviewMenuButton') || parentWithClass(e.target, 'cardOverlayMoreButton');
if (listviewMenuButton) {
showContextMenu(listviewMenuButton, {});
e.preventDefault();
return false;
}
2015-12-15 22:30:14 -07:00
var button = parentWithClass(e.target, 'btnUserItemRating');
if (button) {
2015-12-14 21:55:43 -07:00
e.stopPropagation();
e.preventDefault();
return false;
}
2015-09-27 16:32:09 -07:00
var card = parentWithClass(e.target, 'card');
if (card) {
var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
if (itemSelectionPanel) {
return onItemSelectionPanelClick(e, itemSelectionPanel);
}
if (card.classList.contains('groupedCard')) {
2015-10-26 09:29:42 -07:00
return onGroupedCardClick(e, card);
2015-09-27 16:32:09 -07:00
}
2015-09-05 09:58:27 -07:00
}
2015-09-27 16:32:09 -07:00
}
function onGroupedCardClick(e, card) {
2014-08-01 19:34:45 -07:00
var itemId = card.getAttribute('data-itemid');
var context = card.getAttribute('data-context');
2014-07-15 12:16:16 -07:00
var userId = Dashboard.getCurrentUserId();
var options = {
2014-08-01 19:34:45 -07:00
Limit: parseInt($('.playedIndicator', card).html() || '10'),
2014-07-05 08:01:29 -07:00
Fields: "PrimaryImageAspectRatio,DateCreated",
ParentId: itemId,
GroupItems: false
};
2015-06-28 07:45:21 -07:00
var target = e.target;
2015-07-06 00:06:09 -07:00
if (isClickable(target)) {
2015-06-07 20:16:42 -07:00
return;
}
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).then(function (items) {
2015-05-14 19:16:57 -07:00
2015-06-07 18:23:56 -07:00
if (items.length == 1) {
Dashboard.navigate(LibraryBrowser.getHref(items[0], context));
return;
}
2015-09-21 08:43:10 -07:00
var url = 'itemdetails.html?id=' + itemId;
if (context) {
url += '&context=' + context;
}
2015-12-14 08:43:03 -07:00
Dashboard.navigate(url);
2015-05-14 19:16:57 -07:00
});
2015-12-14 08:43:03 -07:00
e.stopPropagation();
2015-05-14 19:16:57 -07:00
e.preventDefault();
return false;
}
2015-09-05 09:58:27 -07:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
2015-05-14 19:16:57 -07:00
$.fn.createCardMenus = function (options) {
2014-03-17 07:48:16 -07:00
2014-05-21 09:49:19 -07:00
var preventHover = false;
2014-03-17 07:48:16 -07:00
function onShowTimerExpired(elem) {
2015-06-28 07:45:21 -07:00
elem = elem.querySelector('a');
2014-11-11 21:51:40 -07:00
2015-09-27 16:32:09 -07:00
if (elem.querySelector('.itemSelectionPanel')) {
2014-03-17 18:45:41 -07:00
return;
}
2015-06-28 07:45:21 -07:00
var innerElem = elem.querySelector('.cardOverlayTarget');
2014-11-11 21:51:40 -07:00
2015-12-14 08:43:03 -07:00
if (!innerElem) {
innerElem = document.createElement('div');
innerElem.classList.add('hide');
innerElem.classList.add('cardOverlayTarget');
parentWithClass(elem, 'cardContent').appendChild(innerElem);
}
2014-11-11 21:51:40 -07:00
var dataElement = elem;
2015-05-20 09:28:55 -07:00
while (dataElement && !dataElement.getAttribute('data-itemid')) {
2014-11-11 21:51:40 -07:00
dataElement = dataElement.parentNode;
}
var id = dataElement.getAttribute('data-itemid');
var commands = dataElement.getAttribute('data-commands').split(',');
2014-03-17 07:48:16 -07:00
var promise1 = ApiClient.getItem(Dashboard.getCurrentUserId(), id);
var promise2 = Dashboard.getCurrentUser();
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-03-17 07:48:16 -07:00
2015-12-14 08:43:03 -07:00
var item = responses[0];
var user = responses[1];
2014-03-17 07:48:16 -07:00
2015-06-28 07:45:21 -07:00
var card = elem;
2015-01-01 22:36:27 -07:00
2015-06-28 07:45:21 -07:00
while (!card.classList.contains('card')) {
card = card.parentNode;
2015-01-01 22:36:27 -07:00
}
2015-06-28 07:45:21 -07:00
innerElem.innerHTML = getOverlayHtml(item, user, card, commands);
2014-03-17 07:48:16 -07:00
$('.btnPlayItem', innerElem).on('click', onPlayItemButtonClick);
2014-03-17 07:48:16 -07:00
$('.btnPlayTrailer', innerElem).on('click', onTrailerButtonClick);
2014-08-07 21:36:51 -07:00
$('.btnMoreCommands', innerElem).on('click', onMoreButtonClick);
2014-03-17 07:48:16 -07:00
});
2015-06-28 18:10:45 -07:00
$(innerElem).show();
2014-03-17 07:48:16 -07:00
2015-12-14 08:43:03 -07:00
slideUpToShow(innerElem);
2014-03-17 07:48:16 -07:00
}
2015-07-06 00:06:09 -07:00
function onHoverIn(e) {
2014-03-17 07:48:16 -07:00
2015-12-14 08:43:03 -07:00
var elem = e.target;
if (!elem.classList.contains('cardImage')) {
return;
}
2014-05-21 09:49:19 -07:00
if (preventHover === true) {
preventHover = false;
return;
}
2014-03-17 07:48:16 -07:00
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
2015-07-06 00:06:09 -07:00
while (!elem.classList.contains('card')) {
elem = elem.parentNode;
}
2014-03-17 07:48:16 -07:00
showOverlayTimeout = setTimeout(function () {
onShowTimerExpired(elem);
}, 1000);
}
2014-05-21 09:49:19 -07:00
function preventTouchHover() {
preventHover = true;
2014-03-17 07:48:16 -07:00
}
2015-12-14 08:43:03 -07:00
for (var i = 0, length = this.length; i < length; i++) {
2015-07-06 00:06:09 -07:00
2015-12-14 08:43:03 -07:00
var curr = this[i];
curr.removeEventListener('click', onCardClick);
curr.addEventListener('click', onCardClick);
2015-09-23 09:16:06 -07:00
2015-12-14 08:43:03 -07:00
if (AppInfo.isTouchPreferred) {
2015-06-29 11:45:42 -07:00
2015-12-14 08:43:03 -07:00
curr.removeEventListener('contextmenu', disableEvent);
curr.addEventListener('contextmenu', disableEvent);
}
else {
curr.removeEventListener('contextmenu', onContextMenu);
curr.addEventListener('contextmenu', onContextMenu);
2015-06-29 11:45:42 -07:00
2015-12-14 08:43:03 -07:00
curr.removeEventListener('mouseenter', onHoverIn);
curr.addEventListener('mouseenter', onHoverIn, true);
2015-05-14 19:16:57 -07:00
2015-12-14 08:43:03 -07:00
curr.removeEventListener('mouseleave', onHoverOut);
curr.addEventListener('mouseleave', onHoverOut, true);
curr.removeEventListener("touchstart", preventTouchHover);
curr.addEventListener("touchstart", preventTouchHover);
}
initTapHoldMenus(curr);
2015-09-23 09:16:06 -07:00
}
2015-05-14 19:16:57 -07:00
return this;
2014-03-17 07:48:16 -07:00
};
2015-09-27 17:59:30 -07:00
function initTapHoldMenus(elem) {
if (elem.classList.contains('itemsContainer')) {
initTapHold(elem);
return;
}
var elems = elem.querySelectorAll('.itemsContainer');
2015-09-28 20:35:50 -07:00
2015-09-27 17:59:30 -07:00
for (var i = 0, length = elems.length; i < length; i++) {
initTapHold(elems[i]);
}
}
function initTapHold(element) {
if (!LibraryBrowser.allowSwipe(element)) {
return;
}
2015-12-14 08:43:03 -07:00
if (element.classList.contains('hasTapHold')) {
return;
}
2015-09-27 17:59:30 -07:00
require(['hammer'], function (Hammer) {
var hammertime = new Hammer(element);
2015-12-14 08:43:03 -07:00
element.classList.add('hasTapHold');
2015-09-27 17:59:30 -07:00
hammertime.on('press', onTapHold);
hammertime.on('pressup', onTapHoldUp);
});
2015-12-14 08:43:03 -07:00
2015-10-20 15:06:49 -07:00
showTapHoldHelp(element);
2015-10-14 19:55:19 -07:00
}
2015-10-20 15:06:49 -07:00
function showTapHoldHelp(element) {
2015-10-14 19:55:19 -07:00
2015-10-20 15:06:49 -07:00
var page = $(element).parents('.page')[0];
if (!page) {
2015-10-14 21:32:10 -07:00
return;
}
2015-10-14 19:55:19 -07:00
// Don't do this on the home page
2015-10-25 08:48:44 -07:00
if (page.classList.contains('homePage') || page.classList.contains('itemDetailPage') || page.classList.contains('liveTvPage')) {
2015-10-14 19:55:19 -07:00
return;
}
2015-10-25 08:48:44 -07:00
var expectedValue = "8";
2015-10-14 19:55:19 -07:00
if (appStorage.getItem("tapholdhelp") == expectedValue) {
return;
}
appStorage.setItem("tapholdhelp", expectedValue);
Dashboard.alert({
message: Globalize.translate('TryMultiSelectMessage'),
title: Globalize.translate('HeaderTryMultiSelect')
});
2015-09-27 17:59:30 -07:00
}
2015-09-23 09:16:06 -07:00
function disableEvent(e) {
e.preventDefault();
2015-12-14 08:43:03 -07:00
e.stopPropagation();
2015-09-23 09:16:06 -07:00
return false;
}
function onTapHold(e) {
2015-09-27 16:32:09 -07:00
var card = parentWithClass(e.target, 'card');
if (card) {
showSelections(card);
2015-12-26 11:35:53 -07:00
if (e.stopPropagation) {
2015-12-14 08:43:03 -07:00
e.stopPropagation();
}
2015-09-27 16:32:09 -07:00
e.preventDefault();
return false;
}
2015-12-14 08:43:03 -07:00
e.preventDefault();
e.stopPropagation();
return false;
2015-09-27 16:32:09 -07:00
}
function onTapHoldUp(e) {
var itemSelectionPanel = parentWithClass(e.target, 'itemSelectionPanel');
if (itemSelectionPanel) {
if (!parentWithClass(e.target, 'chkItemSelect')) {
var chkItemSelect = itemSelectionPanel.querySelector('.chkItemSelect');
if (chkItemSelect) {
chkItemSelect.checked = !chkItemSelect.checked;
}
}
2015-12-14 08:43:03 -07:00
e.preventDefault();
return false;
2015-09-27 16:32:09 -07:00
}
2015-09-23 09:16:06 -07:00
}
2015-09-27 16:32:09 -07:00
function onItemSelectionPanelClick(e, itemSelectionPanel) {
// toggle the checkbox, if it wasn't clicked on
if (!parentWithClass(e.target, 'chkItemSelect')) {
var chkItemSelect = itemSelectionPanel.querySelector('.chkItemSelect');
if (chkItemSelect) {
var newValue = !chkItemSelect.checked;
chkItemSelect.checked = newValue;
updateItemSelection(chkItemSelect, newValue);
}
}
e.preventDefault();
2015-12-14 08:43:03 -07:00
e.stopPropagation();
2015-09-27 16:32:09 -07:00
return false;
}
2015-10-13 22:02:30 -07:00
function onSelectionChange(e) {
updateItemSelection(this, this.checked);
}
2015-09-27 16:32:09 -07:00
function showSelection(item) {
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
var itemSelectionPanel = item.querySelector('.itemSelectionPanel');
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
if (!itemSelectionPanel) {
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
itemSelectionPanel = document.createElement('div');
itemSelectionPanel.classList.add('itemSelectionPanel');
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
item.querySelector('.cardContent').appendChild(itemSelectionPanel);
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
var chkItemSelect = document.createElement('paper-checkbox');
chkItemSelect.classList.add('chkItemSelect');
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
$(chkItemSelect).on('change', onSelectionChange);
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
itemSelectionPanel.appendChild(chkItemSelect);
2015-09-27 16:32:09 -07:00
}
}
2015-09-27 16:32:09 -07:00
function showSelectionCommands() {
2015-09-27 16:32:09 -07:00
var selectionCommandsPanel = document.querySelector('.selectionCommandsPanel');
2015-09-27 16:32:09 -07:00
if (!selectionCommandsPanel) {
2015-09-27 16:32:09 -07:00
selectionCommandsPanel = document.createElement('div');
selectionCommandsPanel.classList.add('selectionCommandsPanel');
document.body.appendChild(selectionCommandsPanel);
var html = '';
html += '<div style="float:left;">';
html += '<paper-icon-button class="btnCloseSelectionPanel" icon="close"></paper-icon-button>';
html += '<span class="itemSelectionCount"></span>';
html += '</div>';
2015-12-14 08:43:03 -07:00
html += '<paper-icon-button class="btnSelectionPanelOptions" icon="more-vert" style="margin-left:auto;"></paper-icon-button>';
2014-03-18 18:35:40 -07:00
2015-09-27 16:32:09 -07:00
selectionCommandsPanel.innerHTML = html;
$('.btnCloseSelectionPanel', selectionCommandsPanel).on('click', hideSelections);
2015-10-07 18:49:40 -07:00
var btnSelectionPanelOptions = selectionCommandsPanel.querySelector('.btnSelectionPanelOptions');
$(btnSelectionPanelOptions).on('click', showMenuForSelectedItems);
2015-12-14 08:43:03 -07:00
if (!browserInfo.mobile) {
2015-10-15 22:36:16 -07:00
shake(btnSelectionPanelOptions, 1);
}
2015-09-27 16:32:09 -07:00
}
}
2015-10-07 18:49:40 -07:00
function shake(elem, iterations) {
var keyframes = [
{ transform: 'translate3d(0, 0, 0)', offset: 0 },
{ transform: 'translate3d(-10px, 0, 0)', offset: 0.1 },
{ transform: 'translate3d(10px, 0, 0)', offset: 0.2 },
{ transform: 'translate3d(-10px, 0, 0)', offset: 0.3 },
{ transform: 'translate3d(10px, 0, 0)', offset: 0.4 },
{ transform: 'translate3d(-10px, 0, 0)', offset: 0.5 },
{ transform: 'translate3d(10px, 0, 0)', offset: 0.6 },
{ transform: 'translate3d(-10px, 0, 0)', offset: 0.7 },
{ transform: 'translate3d(10px, 0, 0)', offset: 0.8 },
{ transform: 'translate3d(-10px, 0, 0)', offset: 0.9 },
{ transform: 'translate3d(0, 0, 0)', offset: 1 }];
var timing = { duration: 900, iterations: iterations };
return elem.animate(keyframes, timing);
}
2015-09-27 16:32:09 -07:00
function showSelections(initialCard) {
2016-01-19 12:03:46 -07:00
require(['paper-checkbox'], function () {
2015-12-26 11:35:53 -07:00
var cards = document.querySelectorAll('.card');
for (var i = 0, length = cards.length; i < length; i++) {
showSelection(cards[i]);
}
2014-03-17 18:45:41 -07:00
2015-12-26 11:35:53 -07:00
showSelectionCommands();
initialCard.querySelector('.chkItemSelect').checked = true;
updateItemSelection(initialCard, true);
});
2015-09-27 16:32:09 -07:00
}
function hideSelections() {
var selectionCommandsPanel = document.querySelector('.selectionCommandsPanel');
if (selectionCommandsPanel) {
selectionCommandsPanel.parentNode.removeChild(selectionCommandsPanel);
selectedItems = [];
var elems = document.querySelectorAll('.itemSelectionPanel');
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].parentNode.removeChild(elems[i]);
}
}
2014-03-17 18:45:41 -07:00
}
2015-09-27 16:32:09 -07:00
var selectedItems = [];
function updateItemSelection(chkItemSelect, selected) {
var id = parentWithClass(chkItemSelect, 'card').getAttribute('data-itemid');
if (selected) {
var current = selectedItems.filter(function (i) {
return i == id;
});
if (!current.length) {
selectedItems.push(id);
}
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
} else {
selectedItems = selectedItems.filter(function (i) {
return i != id;
});
2015-06-28 07:45:21 -07:00
}
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
if (selectedItems.length) {
var itemSelectionCount = document.querySelector('.itemSelectionCount');
if (itemSelectionCount) {
itemSelectionCount.innerHTML = selectedItems.length;
}
} else {
hideSelections();
2015-06-28 07:45:21 -07:00
}
2014-03-17 18:45:41 -07:00
}
2014-03-18 18:35:40 -07:00
2015-09-27 16:32:09 -07:00
function showMenuForSelectedItems(e) {
2015-09-27 17:59:30 -07:00
2015-12-14 08:43:03 -07:00
Dashboard.getCurrentUser().then(function (user) {
2015-09-27 16:32:09 -07:00
var items = [];
items.push({
name: Globalize.translate('ButtonAddToCollection'),
id: 'addtocollection',
ironIcon: 'add'
});
items.push({
name: Globalize.translate('ButtonAddToPlaylist'),
id: 'playlist',
ironIcon: 'playlist-add'
});
2016-01-19 12:03:46 -07:00
if (user.Policy.EnableContentDeletion) {
items.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete',
ironIcon: 'delete'
});
}
2015-12-30 10:02:11 -07:00
if (user.Policy.EnableContentDownloading && AppInfo.supportsDownloading) {
//items.push({
// name: Globalize.translate('ButtonDownload'),
// id: 'download',
// ironIcon: 'file-download'
//});
}
2015-10-19 19:06:05 -07:00
items.push({
name: Globalize.translate('HeaderGroupVersions'),
id: 'groupvideos',
ironIcon: 'call-merge'
});
2015-09-27 17:59:30 -07:00
items.push({
name: Globalize.translate('ButtonRefresh'),
id: 'refresh',
ironIcon: 'refresh'
});
items.push({
name: Globalize.translate('ButtonSync'),
id: 'sync',
2015-10-16 15:21:03 -07:00
ironIcon: 'sync'
2015-09-27 17:59:30 -07:00
});
2015-09-27 16:32:09 -07:00
require(['actionsheet'], function () {
ActionSheetElement.show({
items: items,
positionTo: e.target,
callback: function (id) {
2015-10-13 22:46:11 -07:00
var items = selectedItems.slice(0);
2015-09-27 16:32:09 -07:00
switch (id) {
2014-03-18 18:35:40 -07:00
2015-09-27 16:32:09 -07:00
case 'addtocollection':
2015-10-13 22:46:11 -07:00
require(['collectioneditor'], function (collectioneditor) {
new collectioneditor().show(items);
});
2015-09-27 18:50:11 -07:00
hideSelections();
2015-09-27 16:32:09 -07:00
break;
case 'playlist':
2015-10-13 22:46:11 -07:00
PlaylistManager.showPanel(items);
2015-09-27 18:50:11 -07:00
hideSelections();
2015-09-27 16:32:09 -07:00
break;
2016-01-19 12:03:46 -07:00
case 'delete':
LibraryBrowser.deleteItems(items).then(function () {
Dashboard.navigate('index.html');
});
hideSelections();
break;
2015-10-19 19:06:05 -07:00
case 'groupvideos':
combineVersions($($.mobile.activePage)[0], items);
break;
2015-09-27 17:59:30 -07:00
case 'refresh':
2015-10-13 22:46:11 -07:00
items.map(function (itemId) {
2015-09-27 17:59:30 -07:00
// TODO: Create an endpoint to do this in bulk
ApiClient.refreshItem(itemId, {
Recursive: true,
ImageRefreshMode: 'FullRefresh',
MetadataRefreshMode: 'FullRefresh',
ReplaceAllImages: false,
ReplaceAllMetadata: true
});
});
2015-09-27 18:50:11 -07:00
hideSelections();
2015-09-27 17:59:30 -07:00
break;
case 'sync':
SyncManager.showMenu({
2015-10-13 22:46:11 -07:00
items: items.map(function (i) {
2015-09-27 17:59:30 -07:00
return {
Id: i
};
})
});
2015-09-27 18:50:11 -07:00
hideSelections();
2015-09-27 17:59:30 -07:00
break;
2015-09-27 16:32:09 -07:00
default:
break;
}
}
});
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
});
});
}
2014-03-17 18:45:41 -07:00
2015-10-19 19:06:05 -07:00
function combineVersions(page, selection) {
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
if (selection.length < 2) {
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
Dashboard.alert({
2014-06-03 20:34:36 -07:00
message: Globalize.translate('MessagePleaseSelectTwoItems'),
2014-05-30 12:23:56 -07:00
title: Globalize.translate('HeaderError')
2014-03-17 18:45:41 -07:00
});
return;
}
2015-10-19 19:06:05 -07:00
var msg = Globalize.translate('MessageTheSelectedItemsWillBeGrouped');
2014-03-18 18:35:40 -07:00
2015-06-19 15:01:47 -07:00
Dashboard.confirm(msg, Globalize.translate('HeaderGroupVersions'), function (confirmResult) {
2014-03-18 18:35:40 -07:00
if (confirmResult) {
Dashboard.showLoadingMsg();
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-03-18 18:35:40 -07:00
type: "POST",
url: ApiClient.getUrl("Videos/MergeVersions", { Ids: selection.join(',') })
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-03-18 18:35:40 -07:00
Dashboard.hideLoadingMsg();
2015-10-19 19:06:05 -07:00
hideSelections();
2014-03-18 18:35:40 -07:00
$('.itemsContainer', page).trigger('needsrefresh');
});
}
});
2014-03-17 18:45:41 -07:00
}
2014-11-11 21:51:40 -07:00
function onItemWithActionClick(e) {
2014-08-30 07:26:29 -07:00
2015-12-14 08:43:03 -07:00
var elem = parentWithClass(e.target, 'itemWithAction');
if (!elem) {
return;
}
2014-11-11 21:51:40 -07:00
2014-08-30 07:26:29 -07:00
var action = elem.getAttribute('data-action');
2014-11-11 21:51:40 -07:00
var elemWithAttributes = elem;
if (action) {
while (!elemWithAttributes.getAttribute('data-itemid')) {
elemWithAttributes = elemWithAttributes.parentNode;
}
}
2014-10-20 13:23:40 -07:00
var index;
var itemsContainer;
var itemId = elemWithAttributes.getAttribute('data-itemid');
2014-08-30 07:26:29 -07:00
if (action == 'play') {
MediaController.play(itemId);
}
else if (action == 'playallfromhere') {
2014-10-20 13:23:40 -07:00
index = elemWithAttributes.getAttribute('data-index');
2015-09-04 10:34:50 -07:00
2014-10-20 13:23:40 -07:00
itemsContainer = $(elem).parents('.itemsContainer');
2014-08-30 07:26:29 -07:00
2015-08-18 21:08:03 -07:00
playAllFromHere(index, itemsContainer, 'play');
2014-08-30 07:26:29 -07:00
}
2015-10-07 14:42:29 -07:00
else if (action == 'instantmix') {
MediaController.instantMix(itemId);
}
2014-08-30 07:26:29 -07:00
2015-12-14 08:43:03 -07:00
e.stopPropagation();
e.preventDefault();
2014-08-30 07:26:29 -07:00
return false;
}
2015-08-18 21:08:03 -07:00
function playAllFromHere(index, itemsContainer, method) {
2015-08-27 21:19:08 -07:00
var ids = $('.mediaItem', itemsContainer).get().map(function (i) {
2015-09-10 11:28:22 -07:00
var node = i;
var id = node.getAttribute('data-itemid');
while (!id) {
node = node.parentNode;
id = node.getAttribute('data-itemid');
}
return id;
2015-08-18 21:08:03 -07:00
});
ids = ids.slice(index);
ApiClient.getItems(Dashboard.getCurrentUserId(), {
2015-08-27 21:19:08 -07:00
2015-08-18 21:08:03 -07:00
Ids: ids.join(','),
Fields: 'MediaSources,Chapters',
Limit: 100
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2015-08-18 21:08:03 -07:00
MediaController[method]({
items: result.Items
});
});
}
2015-09-07 21:22:38 -07:00
pageClassOn('pageinit', "libraryPage", function () {
2014-03-17 18:45:41 -07:00
var page = this;
2015-12-14 08:43:03 -07:00
page.addEventListener('click', onItemWithActionClick);
2015-01-22 23:15:15 -07:00
2015-09-28 20:35:50 -07:00
var itemsContainers = page.querySelectorAll('.itemsContainer:not(.noautoinit)');
2015-06-28 07:45:21 -07:00
for (var i = 0, length = itemsContainers.length; i < length; i++) {
$(itemsContainers[i]).createCardMenus();
}
2014-07-19 21:46:29 -07:00
2015-09-07 21:22:38 -07:00
});
2015-09-27 18:50:11 -07:00
pageClassOn('pagebeforehide', "libraryPage", function () {
2014-06-03 20:34:36 -07:00
var page = this;
2015-09-27 16:32:09 -07:00
hideSelections();
2014-03-17 18:45:41 -07:00
});
2014-08-01 19:34:45 -07:00
function renderUserDataChanges(card, userData) {
if (userData.Played) {
2015-12-14 08:43:03 -07:00
var playedIndicator = card.querySelector('.playedIndicator');
2015-12-14 08:43:03 -07:00
if (!playedIndicator) {
playedIndicator = document.createElement('div');
playedIndicator.classList.add('playedIndicator');
card.querySelector('.cardContent').appendChild(playedIndicator);
}
2015-12-14 08:43:03 -07:00
playedIndicator.innerHTML = '<iron-icon icon="check"></iron-icon>';
}
else if (userData.UnplayedItemCount) {
2015-12-14 08:43:03 -07:00
var playedIndicator = card.querySelector('.playedIndicator');
if (!playedIndicator) {
2015-12-14 08:43:03 -07:00
playedIndicator = document.createElement('div');
playedIndicator.classList.add('playedIndicator');
card.querySelector('.cardContent').appendChild(playedIndicator);
}
2015-12-14 08:43:03 -07:00
playedIndicator.innerHTML = userData.UnplayedItemCount;
}
2015-09-19 19:06:56 -07:00
var progressHtml = LibraryBrowser.getItemProgressBarHtml(userData);
if (progressHtml) {
var cardProgress = card.querySelector('.cardProgress');
if (!cardProgress) {
cardProgress = document.createElement('div');
cardProgress.classList.add('cardProgress');
2015-09-19 19:06:56 -07:00
$('.cardFooter', card).append(cardProgress);
}
2015-09-19 19:06:56 -07:00
cardProgress.innerHTML = progressHtml;
}
else {
$('.cardProgress', card).remove();
}
}
function onUserDataChanged(userData) {
2015-08-27 21:19:08 -07:00
$(document.querySelectorAll("*[data-itemid='" + userData.ItemId + "']")).each(function () {
2014-07-19 21:46:29 -07:00
2015-01-03 12:38:22 -07:00
var mediaType = this.getAttribute('data-mediatype');
2014-07-19 21:46:29 -07:00
2015-01-03 12:38:22 -07:00
if (mediaType == 'Video') {
this.setAttribute('data-positionticks', (userData.PlaybackPositionTicks || 0));
if ($(this).hasClass('card')) {
renderUserDataChanges(this, userData);
}
2014-07-19 21:46:29 -07:00
}
});
}
function onWebSocketMessage(e, data) {
var msg = data;
if (msg.MessageType === "UserDataChanged") {
if (msg.Data.UserId == Dashboard.getCurrentUserId()) {
for (var i = 0, length = msg.Data.UserDataList.length; i < length; i++) {
onUserDataChanged(msg.Data.UserDataList[i]);
}
}
}
}
2014-10-25 11:32:58 -07:00
function initializeApiClient(apiClient) {
2015-12-23 10:46:01 -07:00
Events.off(apiClient, "websocketmessage", onWebSocketMessage);
Events.on(apiClient, "websocketmessage", onWebSocketMessage);
2014-10-25 11:32:58 -07:00
}
2015-06-30 10:21:20 -07:00
function clearRefreshTimes() {
$('.hasrefreshtime').removeClass('hasrefreshtime').removeAttr('data-lastrefresh');
}
2015-12-14 08:43:03 -07:00
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
2015-06-30 10:21:20 -07:00
2015-12-23 10:46:01 -07:00
Events.on(ConnectionManager, 'apiclientcreated', function (e, apiClient) {
2015-12-14 08:43:03 -07:00
initializeApiClient(apiClient);
2014-10-25 11:32:58 -07:00
});
2015-12-14 08:43:03 -07:00
Events.on(ConnectionManager, 'localusersignedin', clearRefreshTimes);
Events.on(ConnectionManager, 'localusersignedout', clearRefreshTimes);
2014-03-17 07:48:16 -07:00
})(jQuery, document, window);