(function (window, document, $) { function showMenu(options, sessionsPromise, usersPromise) { var playFromRendered; var trailersRendered; var specialFeaturesRendered; var themeVideosRendered; var themeSongsRendered; var item = options.item; var html = '
'; html += '
'; html += '
Remote Control
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '

'; html += ''; html += ''; html += ''; html += ''; html += '

'; html += '
'; html += '
'; $(document.body).append(html); var popup = $('#remoteControlFlyout').popup({ history: false, tolerance: 0, corners: false }).trigger('create').popup("open").on("popupafterclose", function () { $(this).off("popupafterclose").remove(); }); popup.on('click', '.trSession', function () { $('input', this).checked(true); }).on('click', '.trSelectPlayTime', function () { $('input', this).checked(true); }).on('click', '.trItem', function () { $('input', this).checked(true); }); $('#sendToForm', popup).on('submit', function () { var checkboxes = $('.chkClient', popup); if (!checkboxes.length) { $('#remoteControlFlyout').popup("close"); return false; } checkboxes = $('.chkClient:checked', popup); if (!checkboxes.length) { Dashboard.alert('Please select a device to control.'); return false; } var sessionIds = []; checkboxes.parents('.trSession').each(function () { sessionIds.push(this.getAttribute('data-sessionid')); }); var command = $('#selectCommand', popup).val(); var promise; if (command == "Browse") { promise = ApiClient.sendBrowseCommand(sessionIds[0], { ItemId: item.Id, ItemName: item.Name, ItemType: item.Type, Context: options.context }); } else if (command == "Play" || command == "PlayFromChapter") { var checkedChapter = $('.chkSelectPlayTime:checked', popup); var ticks = checkedChapter.length ? checkedChapter.parents('.trSelectPlayTime').attr('data-ticks') : 0; promise = ApiClient.sendPlayCommand(sessionIds[0], { ItemIds: [item.Id].join(','), PlayCommand: $('#fldPlayCommand', popup).val(), StartPositionTicks: ticks }); } else if (command == "Resume") { promise = ApiClient.sendPlayCommand(sessionIds[0], { ItemIds: [item.Id].join(','), PlayCommand: 'PlayNow', StartPositionTicks: item.UserData.PlaybackPositionTicks }); } else if (command == "Trailer" || command == "SpecialFeature" || command == "ThemeSong" || command == "ThemeVideo") { var id = $('.chkSelectItem:checked', popup).parents('.trItem').attr('data-id'); if (!id) { Dashboard.alert('Please select an item.'); return false; } promise = ApiClient.sendPlayCommand(sessionIds[0], { ItemIds: [id].join(','), PlayCommand: $('#fldPlayCommand', popup).val() }); } promise.done(function () { $('#remoteControlFlyout').popup("close"); }); return false; }); var elem = $('.sessionsPopupContent'); $.when(sessionsPromise, usersPromise).done(function (response1, response2) { var deviceId = ApiClient.deviceId(); var sessions = response1[0].filter(function (s) { return s.DeviceId != deviceId; }); renderSessions(sessions, response2[0], options, elem); $('#selectCommand', popup).on('change', function () { var playFromMenu = $('.playFromMenu', popup).hide(); var trailersElem = $('.trailers', popup).hide(); var specialFeaturesElem = $('.specialFeatures', popup).hide(); var themeSongsElem = $('.themeSongs', popup).hide(); var themeVideosElem = $('.themeVideos', popup).hide(); var playButtonContainer = $('#playButtonContainer', popup).hide(); var queueButtonContainer = $('#queueButtonContainer', popup).hide(); var okButtonContainer = $('#okButtonContainer', popup).hide(); var value = this.value; if (value == "Browse") { okButtonContainer.show(); } else if (value == "Play") { playButtonContainer.show(); queueButtonContainer.show(); } else if (value == "Resume") { playButtonContainer.show(); } else if (value == "PlayFromChapter" && item.Chapters && item.Chapters.length) { playFromMenu.show(); playButtonContainer.show(); if (!playFromRendered) { playFromRendered = true; renderPlayFromOptions(playFromMenu, item); } $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); } else if (value == "Trailer") { trailersElem.show(); playButtonContainer.show(); queueButtonContainer.show(); if (!trailersRendered) { trailersRendered = true; ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), item.Id).done(function (trailers) { renderVideos(trailersElem, trailers, 'Trailers'); $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); }); } } else if (value == "SpecialFeature") { specialFeaturesElem.show(); playButtonContainer.show(); queueButtonContainer.show(); if (!specialFeaturesRendered) { specialFeaturesRendered = true; ApiClient.getSpecialFeatures(Dashboard.getCurrentUserId(), item.Id).done(function (videos) { renderVideos(specialFeaturesElem, videos, 'Special Features'); $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); }); } } else if (value == "ThemeSong") { themeSongsElem.show(); playButtonContainer.show(); queueButtonContainer.show(); if (!themeSongsRendered) { themeSongsRendered = true; ApiClient.getThemeSongs(Dashboard.getCurrentUserId(), item.Id).done(function (result) { renderVideos(themeSongsElem, result.Items, 'Theme Songs'); $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); }); } } else if (value == "ThemeVideo") { themeVideosElem.show(); playButtonContainer.show(); queueButtonContainer.show(); if (!themeVideosRendered) { themeVideosRendered = true; ApiClient.getThemeVideos(Dashboard.getCurrentUserId(), item.Id).done(function (result) { renderVideos(themeVideosElem, result.Items, 'Theme Videos'); $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); }); } } }); }); } function renderPlayFromOptions(elem, item) { var html = ''; html += '

Play from scene

'; html += '
'; html += ''; html += ''; for (var i = 0, length = item.Chapters.length; i < length; i++) { var chapter = item.Chapters[i]; html += ''; var name = chapter.Name || ("Chapter " + (i + 1)); html += ''; html += ''; html += ''; html += ''; } html += ''; html += '
'; var imgUrl; if (chapter.ImageTag) { imgUrl = ApiClient.getImageUrl(item.Id, { maxheight: 80, tag: chapter.ImageTag, type: "Chapter", index: i }); } else { imgUrl = "css/images/media/chapterflyout.png"; } html += ''; html += '' + name + '
' + DashboardPage.getDisplayText(chapter.StartPositionTicks) + '
'; html += '
'; elem.html(html); $('.tdSelectPlayTime', elem).html(''); $('.chkSelectPlayTime:first', elem).checked(true); } function renderSessions(sessions, users, options, elem) { if (!sessions.length) { elem.html('

There are currently no available media browser sessions to control.

'); $('#remoteControlFlyout').popup("reposition", {}); return; } var item = options.item; var html = ''; html += '
'; html += ''; html += ''; html += '
'; html += ''; html += ''; html += ''; html += ''; html += ''; html += '

Select Device

'; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; for (var i = 0, length = sessions.length; i < length; i++) { var session = sessions[i]; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; } html += ''; html += '
ClientDeviceUserNow Playing
' + session.Client + '' + session.DeviceName + ''; var user = null; if (session.UserId) { user = users.filter(function (u) { return u.Id == session.UserId; })[0]; } html += user ? user.Name : ' '; html += ''; html += session.NowPlayingItem ? session.NowPlayingItem.Name : ''; html += '
'; html += ''; elem.html(html).trigger('create'); $('.tdSelectSession', elem).html(''); $('.chkClient:first', elem).checked(true); $('#remoteControlFlyout').popup("reposition", { tolerance: 0 }); } function renderVideos(elem, videos, header) { var html = ''; html += '

' + header + '

'; html += '
'; html += ''; html += ''; for (var i = 0, length = videos.length; i < length; i++) { var video = videos[i]; html += ''; html += ''; html += ''; html += ''; html += ''; } html += ''; html += '
'; var imgUrl; if (video.ImageTags && video.ImageTags.Primary) { imgUrl = ApiClient.getImageUrl(video.Id, { maxheight: 80, tag: video.ImageTags.Primary, type: "Primary" }); html += ''; } html += '' + video.Name; if (video.RunTimeTicks) { html += '
' + DashboardPage.getDisplayText(video.RunTimeTicks); } html += '
'; html += '
'; elem.html(html); $('.tdSelectItem', elem).html(''); $('.chkSelectItem:first', elem).checked(true); } function remoteControl() { var self = this; self.showMenu = function (options) { showMenu(options, ApiClient.getSessions({ SupportsRemoteControl: true }), ApiClient.getUsers()); }; } window.RemoteControl = new remoteControl(); })(window, document, jQuery);