diff --git a/ApiClient.js b/ApiClient.js index 2442141e6c..572cb0cf24 100644 --- a/ApiClient.js +++ b/ApiClient.js @@ -2589,7 +2589,6 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; - /** * Reports a user has stopped playing an item * @param {String} userId @@ -2629,6 +2628,42 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { url: url }); }; + + self.sendBrowseCommand = function (sessionId, options) { + + if (!sessionId) { + throw new Error("null sessionId"); + } + + if (!options) { + throw new Error("null options"); + } + + var url = self.getUrl("Sessions/" + sessionId + "/Viewing", options); + + return self.ajax({ + type: "POST", + url: url + }); + }; + + self.sendPlayCommand = function (sessionId, options) { + + if (!sessionId) { + throw new Error("null sessionId"); + } + + if (!options) { + throw new Error("null options"); + } + + var url = self.getUrl("Sessions/" + sessionId + "/Playing", options); + + return self.ajax({ + type: "POST", + url: url + }); + }; } }(jQuery, navigator, window.JSON, window.WebSocket, setTimeout); diff --git a/dashboard-ui/itembynamedetails.html b/dashboard-ui/itembynamedetails.html index e175133f74..df1595f2e8 100644 --- a/dashboard-ui/itembynamedetails.html +++ b/dashboard-ui/itembynamedetails.html @@ -127,6 +127,17 @@ +
+ + + + + +
diff --git a/dashboard-ui/itemdetails.html b/dashboard-ui/itemdetails.html index cffa3b4c9d..88162550da 100644 --- a/dashboard-ui/itemdetails.html +++ b/dashboard-ui/itemdetails.html @@ -127,7 +127,7 @@ - +
'; + + html += '
'; + + $(document.body).append(html); + + var popup = $('#remoteControlFlyout').popup({ history: false }).trigger('create').popup("open").on("popupafterclose", function () { + + $(this).off("popupafterclose").remove(); + }); + + $('#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: context + + }); + } + else if (command == "Play") { + promise = ApiClient.sendPlayCommand(sessionIds[0], { + + ItemIds: [item.Id].join(','), + PlayCommand: 'PlayNow' + + }); + } + + 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], elem); + + }); + } + + function renderSessions(sessions, users, elem) { + + if (!sessions.length) { + elem.html('

There are currently no available media browser sessions to control.

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

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

'; + + html += '

Send To 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 += '
ClientDeviceUser
' + 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 += '
'; + html += '
'; + + elem.html(html).trigger('create'); + + $('.checkboxCell', elem).html(''); + + $('#remoteControlFlyout').popup("reposition", {}); + } + function remoteControl() { var self = this; - self.showMenu = function (page, item) { - - $('#confirmFlyout').popup("close").remove(); - - var html = '
'; - - html += '
'; - html += '

Remote Control

'; - html += '
'; - - html += '
'; - - html += '
test'; - html += '
'; - - html += '

'; - html += '

'; - - html += '
'; - - html += '
'; - - $(document.body).append(html); - - $('#remoteControlFlyout').popup({ history: false }).trigger('create').popup("open").on("popupafterclose", function () { - - $(this).off("popupafterclose").remove(); - }); + self.showMenu = function (page, item, context) { + showMenu(page, item, context, ApiClient.getSessions({ SupportsRemoteControl: true }), ApiClient.getUsers()); }; } diff --git a/packages.config b/packages.config index b575b4c458..8590d6e8ae 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file