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

1339 lines
44 KiB
JavaScript
Raw Normal View History

2014-03-17 07:48:16 -07:00
(function ($, document, window) {
var showOverlayTimeout;
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
2015-06-28 18:10:45 -07:00
var elem = this.querySelector('.cardOverlayTarget');
2014-03-17 07:48:16 -07:00
2015-06-28 18:10:45 -07:00
if ($(elem).is(':visible')) {
require(["jquery", "velocity"], function ($, Velocity) {
2014-03-17 07:48:16 -07:00
2015-06-28 18:10:45 -07:00
Velocity.animate(elem, { "height": "0" },
{
complete: function () {
$(elem).hide();
}
});
2014-03-17 07:48:16 -07:00
});
2015-06-28 18:10:45 -07:00
}
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 maxLogoWidth = isPortrait ? 100 : 200;
var imgUrl;
if (parentName && item.ParentLogoItemId) {
imgUrl = ApiClient.getScaledImageUrl(item.ParentLogoItemId, {
height: 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, {
height: 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');
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), id).done(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;
}
2014-08-01 19:34:45 -07:00
function onCardTapHold(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) {
showContextMenu(card, {});
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');
2014-07-19 21:46:29 -07:00
Dashboard.getCurrentUser().done(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-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
}
2014-12-19 23:06:27 -07:00
if (user.Policy.IsAdministrator && commands.indexOf('edit') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonEdit'),
id: 'edit',
ironIcon: 'mode-edit'
});
2014-06-30 21:26:50 -07:00
}
2014-08-21 19:24:38 -07:00
if (commands.indexOf('instantmix') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
name: Globalize.translate('ButtonInstantMix'),
id: 'instantmix',
ironIcon: 'shuffle'
});
2014-08-21 19:24:38 -07:00
}
2015-09-16 18:33:46 -07:00
if (commands.indexOf('managesubtitles') != -1) {
items.push({
name: Globalize.translate('ButtonManageSubtitles'),
id: 'managesubtitles',
ironIcon: 'closed-caption'
});
}
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-05-25 10:32:22 -07:00
if (mediaType == 'Video' && 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',
ironIcon: 'refresh'
});
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':
BoxSetEditor.showPanel([itemId]);
break;
case 'playlist':
PlaylistManager.showPanel([itemId]);
break;
case 'delete':
LibraryBrowser.deleteItem(itemId);
break;
case 'download':
{
var downloadHref = ApiClient.getUrl("Items/" + itemId + "/Download", {
api_key: ApiClient.accessToken()
});
window.location.href = downloadHref;
break;
}
case 'edit':
Dashboard.navigate('edititemmetadata.html?id=' + itemId);
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':
Dashboard.navigate('livetvnewrecording.html?programid=' + 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':
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), itemId).done(function (trailers) {
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-16 18:33:46 -07:00
case 'managesubtitles':
LibraryBrowser.editSubtitles(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
});
}
function onListViewMenuButtonClick(e) {
2015-09-05 09:58:27 -07:00
var btn = parentWithClass(e.target, 'listviewMenuButton') || parentWithClass(e.target, 'cardOverlayMoreButton');
2014-03-18 21:59:45 -07:00
2015-09-05 09:58:27 -07:00
if (btn) {
showContextMenu(btn, {});
e.preventDefault();
return false;
}
2014-03-17 07:48:16 -07:00
}
2015-07-06 00:06:09 -07:00
function onListViewPlayButtonClick(e) {
2015-09-05 09:58:27 -07:00
var playButton = parentWithClass(e.target, 'cardOverlayPlayButton');
if (!playButton) {
return;
}
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;
}
2014-08-01 19:34:45 -07:00
function onGroupedCardClick(e) {
2015-09-05 09:58:27 -07:00
var card = parentWithClass(e.target, 'groupedCard');
if (!card) {
return;
}
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-06-28 07:45:21 -07:00
var buttonParents = $(target).parents('a:not(.card,.cardContent),button:not(.card,.cardContent)');
2015-06-09 21:01:14 -07:00
if (buttonParents.length) {
2015-06-07 20:16:42 -07:00
return;
}
2015-05-14 19:16:57 -07:00
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).done(function (items) {
2015-06-07 18:23:56 -07:00
if (items.length == 1) {
Dashboard.navigate(LibraryBrowser.getHref(items[0], context));
return;
}
2015-05-14 19:16:57 -07:00
var ids = items.map(function (i) {
return i.Id;
});
showItemsOverlay({
ids: ids,
context: context
});
});
e.preventDefault();
return false;
}
function getItemsOverlay(ids, context) {
2015-05-15 11:07:36 -07:00
$('.detailsMenu').remove();
2015-06-29 11:45:42 -07:00
var html = '<div data-role="popup" class="detailsMenu" style="border:0;padding:0;" data-ids="' + ids.join(',') + '" data-context="' + (context || '') + '">';
2015-05-14 19:16:57 -07:00
html += '<div style="padding:1em 1em;background:rgba(20,20,20,1);margin:0;text-align:center;" class="detailsMenuHeader">';
2015-08-28 08:02:22 -07:00
html += '<paper-icon-button icon="keyboard-arrow-left" class="detailsMenuLeftButton"></paper-icon-button>';
2015-05-18 09:40:20 -07:00
html += '<h3 style="font-weight:400;margin:.5em 0;"></h3>';
2015-08-28 08:02:22 -07:00
html += '<paper-icon-button icon="keyboard-arrow-right" class="detailsMenuRightButton"></paper-icon-button>';
2015-05-14 19:16:57 -07:00
html += '</div>';
html += '<div class="detailsMenuContent" style="background-position:center center;background-repeat:no-repeat;background-size:cover;">';
2015-05-15 08:46:20 -07:00
html += '<div style="padding:.5em 1em 1em;background:rgba(10,10,10,.80);" class="detailsMenuContentInner">';
2015-05-14 19:16:57 -07:00
html += '</div>';
html += '</div>';
html += '</div>';
$($.mobile.activePage).append(html);
var elem = $('.detailsMenu').popup().trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
2015-06-28 07:45:21 -07:00
})[0];
2015-05-14 19:16:57 -07:00
$('.detailsMenuLeftButton', elem).on('click', function () {
2015-06-28 07:45:21 -07:00
var overlay = $(this).parents('.detailsMenu')[0];
setItemIntoOverlay(overlay, parseInt(overlay.getAttribute('data-index') || '0') - 1, context);
2015-05-14 19:16:57 -07:00
});
$('.detailsMenuRightButton', elem).on('click', function () {
2015-06-28 07:45:21 -07:00
var overlay = $(this).parents('.detailsMenu')[0];
setItemIntoOverlay(overlay, parseInt(overlay.getAttribute('data-index') || '0') + 1, context);
2015-05-14 19:16:57 -07:00
});
return elem;
}
function setItemIntoOverlay(elem, index) {
2015-06-28 07:45:21 -07:00
var ids = elem.getAttribute('data-ids').split(',');
2015-05-14 19:16:57 -07:00
var itemId = ids[index];
var userId = Dashboard.getCurrentUserId();
2015-06-28 07:45:21 -07:00
var context = elem.getAttribute('data-context');
2015-05-14 19:16:57 -07:00
2015-06-28 07:45:21 -07:00
elem.setAttribute('data-index', index);
2015-05-14 19:16:57 -07:00
if (index > 0) {
$('.detailsMenuLeftButton', elem).show();
} else {
$('.detailsMenuLeftButton', elem).hide();
}
if (index < ids.length - 1) {
$('.detailsMenuRightButton', elem).show();
} else {
$('.detailsMenuRightButton', elem).hide();
}
var promise1 = ApiClient.getItem(userId, itemId);
var promise2 = Dashboard.getCurrentUser();
$.when(promise1, promise2).done(function (response1, response2) {
var item = response1[0];
2015-05-14 19:16:57 -07:00
var user = response2[0];
var background = 'none';
2015-05-15 08:46:20 -07:00
if (AppInfo.enableDetailsMenuImages) {
2015-05-14 19:16:57 -07:00
var backdropUrl;
var screenWidth = $(window).width();
var backdropWidth = Math.min(screenWidth, 800);
if (item.BackdropImageTags && item.BackdropImageTags.length) {
backdropUrl = ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: backdropWidth,
tag: item.BackdropImageTags[0]
});
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
backdropUrl = ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
tag: item.ParentBackdropImageTags[0],
maxWidth: backdropWidth
});
}
2014-07-15 12:57:27 -07:00
2015-05-14 19:16:57 -07:00
if (backdropUrl) {
background = 'url(' + backdropUrl + ')';
2014-07-15 12:57:27 -07:00
}
}
2015-05-14 19:16:57 -07:00
$('.detailsMenuContent', elem).css('backgroundImage', background);
2015-05-14 19:16:57 -07:00
var headerHtml = LibraryBrowser.getPosterViewDisplayName(item);
$('.detailsMenuHeader', elem).removeClass('detailsMenuHeaderWithLogo');
2015-05-15 08:46:20 -07:00
if (AppInfo.enableDetailsMenuImages) {
2015-05-14 19:16:57 -07:00
var logoUrl;
2015-05-14 19:16:57 -07:00
var logoHeight = 30;
if (item.ImageTags && item.ImageTags.Logo) {
logoUrl = ApiClient.getScaledImageUrl(item.Id, {
type: "Logo",
index: 0,
height: logoHeight,
tag: item.ImageTags.Logo
});
}
if (logoUrl) {
headerHtml = '<img src="' + logoUrl + '" style="height:' + logoHeight + 'px;" />';
$('.detailsMenuHeader', elem).addClass('detailsMenuHeaderWithLogo');
}
}
$('h3', elem).html(headerHtml);
var contentHtml = '';
var miscInfo = LibraryBrowser.getMiscInfoHtml(item);
if (miscInfo) {
contentHtml += '<p>' + miscInfo + '</p>';
}
var userData = LibraryBrowser.getUserDataIconsHtml(item);
if (userData) {
2015-05-24 11:33:28 -07:00
contentHtml += '<p class="detailsMenuUserData">' + userData + '</p>';
2015-05-14 19:16:57 -07:00
}
var ratingHtml = LibraryBrowser.getRatingHtml(item);
if (ratingHtml) {
contentHtml += '<p>' + ratingHtml + '</p>';
}
if (item.Overview) {
contentHtml += '<p class="detailsMenuOverview">' + item.Overview + '</p>';
}
contentHtml += '<div class="detailsMenuButtons">';
if (MediaController.canPlay(item)) {
if (item.MediaType == 'Video' && !item.IsFolder && item.UserData && item.UserData.PlaybackPositionTicks) {
2015-06-17 23:23:44 -07:00
contentHtml += '<paper-button raised class="secondary btnResume" style="background-color:#ff8f00;"><iron-icon icon="play-arrow"></iron-icon><span>' + Globalize.translate('ButtonResume') + '</span></paper-button>';
2015-05-14 19:16:57 -07:00
}
2015-06-17 23:23:44 -07:00
contentHtml += '<paper-button raised class="secondary btnPlay"><iron-icon icon="play-arrow"></iron-icon><span>' + Globalize.translate('ButtonPlay') + '</span></paper-button>';
2015-05-14 19:16:57 -07:00
}
2015-06-17 23:23:44 -07:00
contentHtml += '<paper-button data-href="' + LibraryBrowser.getHref(item, context) + '" raised class="submit btnSync" style="background-color: #673AB7;" onclick="Dashboard.navigate(this.getAttribute(\'data-href\'));"><iron-icon icon="folder-open"></iron-icon><span>' + Globalize.translate('ButtonOpen') + '</span></paper-button>';
2015-05-14 19:16:57 -07:00
if (SyncManager.isAvailable(item, user)) {
2015-06-17 23:23:44 -07:00
contentHtml += '<paper-button raised class="submit btnSync"><iron-icon icon="refresh"></iron-icon><span>' + Globalize.translate('ButtonSync') + '</span></paper-button>';
2015-05-14 19:16:57 -07:00
}
contentHtml += '</div>';
$('.detailsMenuContentInner', elem).html(contentHtml).trigger('create');
$('.btnSync', elem).on('click', function () {
2015-06-28 07:45:21 -07:00
$(elem).popup('close');
2015-05-14 19:16:57 -07:00
SyncManager.showMenu({
items: [item]
});
2015-05-10 06:06:12 -07:00
});
2015-05-14 19:16:57 -07:00
$('.btnPlay', elem).on('click', function () {
2015-06-28 07:45:21 -07:00
$(elem).popup('close');
2015-05-14 19:16:57 -07:00
MediaController.play({
items: [item]
});
});
2015-05-14 19:16:57 -07:00
$('.btnResume', elem).on('click', function () {
2015-06-28 07:45:21 -07:00
$(elem).popup('close');
2015-05-14 19:16:57 -07:00
MediaController.play({
items: [item],
startPositionTicks: item.UserData.PlaybackPositionTicks
});
});
});
2015-05-14 19:16:57 -07:00
}
2015-05-14 19:16:57 -07:00
function showItemsOverlay(options) {
var context = options.context;
2015-08-31 21:15:10 -07:00
require(['jqmpopup'], function () {
var elem = getItemsOverlay(options.ids, context);
2015-05-14 19:16:57 -07:00
2015-08-31 21:15:10 -07:00
setItemIntoOverlay(elem, 0);
});
}
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
2014-03-18 21:59:45 -07:00
if ($('.itemSelectionPanel:visible', elem).length) {
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
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();
$.when(promise1, promise2).done(function (response1, response2) {
var item = response1[0];
var user = response2[0];
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();
innerElem.style.height = '0';
2014-03-17 07:48:16 -07:00
2015-06-28 18:10:45 -07:00
require(["jquery", "velocity"], function ($, Velocity) {
2014-03-17 07:48:16 -07:00
2015-06-28 18:10:45 -07:00
Velocity.animate(innerElem, { "height": "100%" }, "fast");
});
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
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;
}
var elem = this;
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-09-05 09:58:27 -07:00
this.off('contextmenu', onCardTapHold);
this.on('contextmenu', onCardTapHold);
2015-06-29 11:45:42 -07:00
2015-09-05 09:58:27 -07:00
this.off('click', onGroupedCardClick);
this.on('click', onGroupedCardClick);
2015-06-23 21:38:46 -07:00
2015-09-05 09:58:27 -07:00
this.off('click', onListViewMenuButtonClick);
this.on('click', onListViewMenuButtonClick);
2015-07-06 00:06:09 -07:00
2015-09-05 09:58:27 -07:00
this.off('click', onListViewPlayButtonClick);
this.on('click', onListViewPlayButtonClick);
2015-07-06 00:06:09 -07:00
2015-06-23 21:38:46 -07:00
if (!AppInfo.isTouchPreferred) {
2015-07-06 00:06:09 -07:00
this.off('mouseenter', '.card:not(.bannerCard) .cardContent', onHoverIn);
this.on('mouseenter', '.card:not(.bannerCard) .cardContent', onHoverIn);
2015-06-29 11:45:42 -07:00
2015-07-06 00:06:09 -07:00
this.off('mouseleave', '.card:not(.bannerCard) .cardContent', onHoverOut);
this.on('mouseleave', '.card:not(.bannerCard) .cardContent', onHoverOut);
2015-06-29 11:45:42 -07:00
2015-07-06 00:06:09 -07:00
this.off("touchstart", '.card:not(.bannerCard) .cardContent', preventTouchHover);
this.on("touchstart", '.card:not(.bannerCard) .cardContent', preventTouchHover);
2015-06-23 21:38:46 -07:00
}
2015-05-14 19:16:57 -07:00
return this;
2014-03-17 07:48:16 -07:00
};
2014-03-17 18:45:41 -07:00
function toggleSelections(page) {
Dashboard.showLoadingMsg();
var selectionCommands = $('.selectionCommands', page);
if (selectionCommands.is(':visible')) {
selectionCommands.hide();
$('.itemSelectionPanel', page).hide();
} else {
selectionCommands.show();
var panels = $('.itemSelectionPanel', page).show();
if (!panels.length) {
var index = 0;
$('.cardContent', page).each(function () {
var chkItemSelectId = 'chkItemSelect' + index;
$(this).append('<div class="itemSelectionPanel" onclick="return false;"><div class="ui-checkbox"><label class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-checkbox-off" for="' + chkItemSelectId + '">Select</label><input id="' + chkItemSelectId + '" type="checkbox" class="chkItemSelect" data-enhanced="true" /></div></div>');
index++;
});
$('.itemsContainer', page).trigger('create');
}
2014-03-18 18:35:40 -07:00
$('.chkItemSelect:checked', page).checked(false).checkboxradio('refresh');
2014-03-17 18:45:41 -07:00
}
Dashboard.hideLoadingMsg();
}
function hideSelections(page) {
2015-06-28 07:45:21 -07:00
var selectionCommands = page.querySelector('.selectionCommands');
if (selectionCommands) {
selectionCommands.style.display = 'none';
}
2014-03-17 18:45:41 -07:00
2015-06-28 07:45:21 -07:00
var elems = page.getElementsByClassName('itemSelectionPanel');
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].style.display = 'none';
}
2014-03-17 18:45:41 -07:00
}
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
function getSelectedItems(page) {
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
var selection = $('.chkItemSelect:checked', page);
2014-08-01 19:34:45 -07:00
return selection.parents('.card')
2014-03-18 18:35:40 -07:00
.map(function () {
2014-03-17 18:45:41 -07:00
return this.getAttribute('data-itemid');
}).get();
}
2014-03-18 18:35:40 -07:00
2015-06-29 11:45:42 -07:00
function onSyncJobListSubmit() {
hideSelections($($.mobile.activePage)[0]);
}
2014-12-10 23:20:28 -07:00
function sync(page) {
var selection = getSelectedItems(page);
if (selection.length < 1) {
Dashboard.alert({
message: Globalize.translate('MessagePleaseSelectOneItem'),
title: Globalize.translate('HeaderError')
});
return;
}
2014-12-12 20:56:30 -07:00
SyncManager.showMenu({
items: selection
});
2014-12-10 23:20:28 -07:00
2015-06-29 11:45:42 -07:00
Events.off(SyncManager, 'jobsubmit', onSyncJobListSubmit);
Events.on(SyncManager, 'jobsubmit', onSyncJobListSubmit);
2014-12-10 23:20:28 -07:00
}
2014-03-17 18:45:41 -07:00
function combineVersions(page) {
var selection = getSelectedItems(page);
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;
}
2014-08-01 19:34:45 -07:00
var names = $('.chkItemSelect:checked', page).parents('.card').get().reverse().map(function (e) {
2014-03-18 18:35:40 -07:00
2014-08-01 19:34:45 -07:00
return $('.cardText', e).html();
2014-03-18 18:35:40 -07:00
}).join('<br/>');
2014-05-30 12:23:56 -07:00
var msg = Globalize.translate('MessageTheFollowingItemsWillBeGrouped') + "<br/><br/>" + names;
2014-03-18 18:35:40 -07:00
2014-05-30 12:23:56 -07:00
msg += "<br/><br/>" + Globalize.translate('MessageConfirmItemGrouping');
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(',') })
}).done(function () {
Dashboard.hideLoadingMsg();
2014-06-03 20:34:36 -07:00
hideSelections(page);
2014-03-18 18:35:40 -07:00
$('.itemsContainer', page).trigger('needsrefresh');
});
}
});
2014-03-17 18:45:41 -07:00
}
2014-06-03 20:34:36 -07:00
function addToCollection(page) {
2014-06-03 20:34:36 -07:00
var selection = getSelectedItems(page);
if (selection.length < 1) {
Dashboard.alert({
message: Globalize.translate('MessagePleaseSelectOneItem'),
title: Globalize.translate('HeaderError')
});
return;
}
2015-01-23 21:50:45 -07:00
BoxSetEditor.showPanel(selection);
2014-06-03 20:34:36 -07:00
}
2014-03-17 18:45:41 -07:00
function addToPlaylist(page) {
2014-08-07 21:36:51 -07:00
var selection = getSelectedItems(page);
if (selection.length < 1) {
Dashboard.alert({
message: Globalize.translate('MessagePleaseSelectOneItem'),
title: Globalize.translate('HeaderError')
});
return;
}
PlaylistManager.showPanel(selection);
}
2014-11-11 21:51:40 -07:00
function onItemWithActionClick(e) {
2014-08-30 07:26:29 -07:00
var elem = this;
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
}
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
}).done(function (result) {
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-06-28 07:45:21 -07:00
var btnAddToPlaylist = page.querySelector('.btnAddToPlaylist');
if (btnAddToPlaylist) {
Events.on(btnAddToPlaylist, 'click', function () {
addToPlaylist(page);
});
}
2015-06-28 07:45:21 -07:00
var btnMergeVersions = page.querySelector('.btnMergeVersions');
if (btnMergeVersions) {
Events.on(btnMergeVersions, 'click', function () {
combineVersions(page);
});
}
2014-03-17 18:45:41 -07:00
2015-06-28 07:45:21 -07:00
var btnSyncItems = page.querySelector('.btnSyncItems');
if (btnSyncItems) {
Events.on(btnSyncItems, 'click', function () {
sync(page);
});
}
2014-12-10 23:20:28 -07:00
2015-06-28 07:45:21 -07:00
var btnAddToCollection = page.querySelector('.btnAddToCollection');
if (btnAddToCollection) {
Events.on(btnAddToCollection, 'click', function () {
addToCollection(page);
});
}
2014-06-03 20:34:36 -07:00
2015-06-28 07:45:21 -07:00
$(page.getElementsByClassName('viewTabButton')).on('click', function () {
2014-07-19 21:46:29 -07:00
2015-08-15 11:17:22 -07:00
var parent = $(this).parents('.viewPanel');
$('.viewTabButton', parent).removeClass('ui-btn-active');
2015-06-28 07:45:21 -07:00
this.classList.add('ui-btn-active');
2014-07-19 21:46:29 -07:00
2015-08-15 11:17:22 -07:00
$('.viewTab', parent).hide();
$('.' + this.getAttribute('data-tab'), parent).show();
2014-07-19 21:46:29 -07:00
});
2015-08-15 11:17:22 -07:00
$('select.selectPageSize', $('.viewPanel', page)).html(LibraryBrowser.getDefaultPageSizeSelections().map(function (i) {
2014-07-19 21:46:29 -07:00
return '<option value="' + i + '">' + i + '</option>';
2015-09-03 10:01:51 -07:00
}).join(''));
2014-07-19 21:46:29 -07:00
2015-01-22 23:15:15 -07:00
$(page).on('click', '.btnToggleSelections', function () {
2014-07-19 21:46:29 -07:00
2015-01-22 23:15:15 -07:00
toggleSelections(page);
2014-07-19 21:46:29 -07:00
2015-09-04 10:34:50 -07:00
}).on('click', '.itemWithAction', onItemWithActionClick);
2015-01-22 23:15:15 -07:00
2015-06-28 07:45:21 -07:00
var itemsContainers = page.getElementsByClassName('itemsContainer');
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
});
pageClassOn('pagebeforeshow', "libraryPage", function () {
2014-06-03 20:34:36 -07:00
var page = this;
hideSelections(page);
2015-08-15 11:17:22 -07:00
$(page.querySelectorAll('.viewTabButton:first-child')).trigger('click');
2014-03-17 18:45:41 -07:00
});
2014-08-01 19:34:45 -07:00
function renderUserDataChanges(card, userData) {
if (userData.Played) {
2014-08-01 19:34:45 -07:00
if (!$('.playedIndicator', card).length) {
2014-08-01 19:34:45 -07:00
$('<div class="playedIndicator"></div>').insertAfter($('.cardOverlayTarget', card));
}
2015-06-29 21:33:53 -07:00
$('.playedIndicator', card).html('<iron-icon icon="check"></iron-icon>');
2014-08-01 19:34:45 -07:00
$('.cardProgress', card).remove();
}
else if (userData.UnplayedItemCount) {
2014-08-01 19:34:45 -07:00
if (!$('.playedIndicator', card).length) {
2014-08-01 19:34:45 -07:00
$('<div class="playedIndicator"></div>').insertAfter($('.cardOverlayTarget', card));
}
2014-08-01 19:34:45 -07:00
$('.playedIndicator', card).html(userData.UnplayedItemCount);
}
else {
2014-08-01 19:34:45 -07:00
$('.playedIndicator', card).remove();
var progressHtml = LibraryBrowser.getItemProgressBarHtml(userData);
2014-08-01 19:34:45 -07:00
$('.cardProgress', card).html(progressHtml);
}
}
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-06-29 11:45:42 -07:00
$(apiClient).off('websocketmessage', onWebSocketMessage).on('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-05-19 12:15:40 -07:00
Dashboard.ready(function () {
2014-10-25 11:32:58 -07:00
2015-05-19 12:15:40 -07:00
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
initializeApiClient(apiClient);
});
2015-06-30 10:21:20 -07:00
Events.on(ConnectionManager, 'localusersignedin', clearRefreshTimes);
Events.on(ConnectionManager, 'localusersignedout', clearRefreshTimes);
2014-10-25 11:32:58 -07:00
});
2014-03-17 07:48:16 -07:00
})(jQuery, document, window);