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

1547 lines
51 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 imgUrl;
if (parentName && item.ParentLogoItemId) {
imgUrl = ApiClient.getScaledImageUrl(item.ParentLogoItemId, {
2015-11-06 08:02:22 -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-11-06 08:02:22 -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');
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;
}
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');
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
}
2015-09-17 09:04:04 -07:00
if (commands.indexOf('editimages') != -1) {
items.push({
name: Globalize.translate('ButtonEditImages'),
id: 'editimages',
ironIcon: 'photo'
});
}
if (commands.indexOf('editsubtitles') != -1) {
2015-06-20 17:49:42 -07:00
items.push({
2015-09-16 19:33:45 -07:00
name: Globalize.translate('ButtonEditSubtitles'),
2015-09-17 09:04:04 -07:00
id: 'editsubtitles',
2015-09-16 19:33:45 -07:00
ironIcon: 'closed-caption'
2015-06-20 17:49:42 -07:00
});
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-11-15 15:30:47 -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':
LibraryBrowser.deleteItem(itemId);
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':
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-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;
}
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-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-09-21 08:43:10 -07:00
var url = 'itemdetails.html?id=' + itemId;
if (context) {
url += '&context=' + context;
}
Dashboard.navigate(url);
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,
2015-11-06 08:02:22 -07:00
maxHeight: logoHeight,
2015-05-14 19:16:57 -07:00
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-09-17 20:43:30 -07:00
contentHtml += '<paper-button data-href="' + LibraryBrowser.getHref(item, context) + '" raised class="submit" 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-09-19 19:06:56 -07:00
contentHtml += '<paper-button raised class="submit btnSync"><iron-icon icon="sync"></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
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
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-27 16:32:09 -07:00
this.off('click', onCardClick);
this.on('click', onCardClick);
2015-07-06 00:06:09 -07:00
2015-09-23 09:16:06 -07:00
if (AppInfo.isTouchPreferred) {
2015-09-27 16:32:09 -07:00
this.off('contextmenu', disableEvent);
this.on('contextmenu', disableEvent);
//this.off('contextmenu', onContextMenu);
//this.on('contextmenu', onContextMenu);
2015-09-23 09:16:06 -07:00
}
else {
this.off('contextmenu', onContextMenu);
this.on('contextmenu', onContextMenu);
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
2015-09-23 09:16:06 -07:00
for (var i = 0, length = this.length; i < length; i++) {
2015-09-27 17:59:30 -07:00
initTapHoldMenus(this[i]);
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-11-02 12:29:40 -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-11-02 12:29:40 -07:00
element.classList.add('hasTapHold');
2015-09-27 17:59:30 -07:00
hammertime.on('press', onTapHold);
hammertime.on('pressup', onTapHoldUp);
});
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();
return false;
}
function onTapHold(e) {
2015-09-27 16:32:09 -07:00
var card = parentWithClass(e.target, 'card');
if (card) {
showSelections(card);
e.preventDefault();
return false;
}
}
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-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();
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-09-27 16:32:09 -07:00
itemSelectionPanel = document.createElement('div');
itemSelectionPanel.classList.add('itemSelectionPanel');
2014-03-17 18:45:41 -07:00
2015-09-27 16:32:09 -07:00
item.querySelector('.cardContent').appendChild(itemSelectionPanel);
2014-03-17 18:45:41 -07:00
2015-10-13 22:02:30 -07:00
var chkItemSelect = document.createElement('paper-checkbox');
chkItemSelect.classList.add('chkItemSelect');
2014-03-17 18:45:41 -07:00
2015-10-13 22:02:30 -07:00
$(chkItemSelect).on('change', onSelectionChange);
2014-03-17 18:45:41 -07:00
2015-10-13 22:02:30 -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-10-29 16:23:43 -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-10-15 22:36:16 -07:00
if (!$.browser.mobile) {
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) {
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-09-27 16:32:09 -07:00
showSelectionCommands();
initialCard.querySelector('.chkItemSelect').checked = true;
updateItemSelection(initialCard, true);
}
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-09-27 16:32:09 -07:00
Dashboard.getCurrentUser().done(function (user) {
var items = [];
items.push({
name: Globalize.translate('ButtonAddToCollection'),
id: 'addtocollection',
ironIcon: 'add'
});
items.push({
name: Globalize.translate('ButtonAddToPlaylist'),
id: 'playlist',
ironIcon: 'playlist-add'
});
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;
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(',') })
}).done(function () {
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
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
}
2015-10-07 14:42:29 -07:00
else if (action == 'instantmix') {
MediaController.instantMix(itemId);
}
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-09-27 16:32:09 -07:00
$(page).on('click', '.itemWithAction', 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) {
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>');
}
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);
}
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-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);