diff options
Diffstat (limited to 'MediaBrowser.WebDashboard/ApiClient.js')
| -rw-r--r-- | MediaBrowser.WebDashboard/ApiClient.js | 119 |
1 files changed, 106 insertions, 13 deletions
diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 97a443e84..25cbc9877 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -305,6 +305,75 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi url: url }); }; + + function getRemoteImagePrefix(options) { + + var urlPrefix; + + if (options.artist) { + urlPrefix = "Artists/" + encodeName(options.artist); + delete options.artist; + } + else if (options.person) { + urlPrefix = "Persons/" + encodeName(options.person); + delete options.person; + } + else if (options.genre) { + urlPrefix = "Genres/" + encodeName(options.genre); + delete options.genre; + } + else if (options.musicGenre) { + urlPrefix = "MusicGenres/" + encodeName(options.musicGenre); + delete options.musicGenre; + } + else if (options.gameGenre) { + urlPrefix = "GameGenres/" + encodeName(options.gameGenre); + delete options.gameGenre; + } + else if (options.studio) { + urlPrefix = "Studios/" + encodeName(options.studio); + delete options.studio; + } + else { + urlPrefix = "Items/" + options.itemId; + delete options.itemId; + } + + return urlPrefix; + } + + self.getAvailableRemoteImages = function (options) { + + if (!options) { + throw new Error("null options"); + } + + var urlPrefix = getRemoteImagePrefix(options); + + var url = self.getUrl(urlPrefix + "/RemoteImages", options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + + self.downloadRemoteImage = function (options) { + + if (!options) { + throw new Error("null options"); + } + + var urlPrefix = getRemoteImagePrefix(options); + + var url = self.getUrl(urlPrefix + "/RemoteImages/Download", options); + + return self.ajax({ + type: "POST", + url: url + }); + }; /** * Gets the current server status @@ -2731,16 +2800,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; - /** - * Marks an item as played or unplayed - * This should not be used to update playstate following playback. - * There are separate playstate check-in methods for that. This should be used for a - * separate option to reset playstate. - * @param {String} userId - * @param {String} itemId - * @param {Boolean} wasPlayed - */ - self.updatePlayedStatus = function (userId, itemId, wasPlayed) { + self.getDateParamValue = function (date) { + function formatDigit(i) { + return i < 10 ? "0" + i : i; + } + + var d = date; + + return "" + d.getFullYear() + formatDigit(d.getMonth() + 1) + formatDigit(d.getDate()) + formatDigit(d.getHours()) + formatDigit(d.getMinutes()) + formatDigit(d.getSeconds()); + }; + + self.markPlayed = function (userId, itemId, date) { if (!userId) { throw new Error("null userId"); @@ -2750,12 +2820,35 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi throw new Error("null itemId"); } - var url = self.getUrl("Users/" + userId + "/PlayedItems/" + itemId); + var options = {}; - var method = wasPlayed ? "POST" : "DELETE"; + if (date) { + options.DatePlayed = self.getDateParamValue(date); + } + + var url = self.getUrl("Users/" + userId + "/PlayedItems/" + itemId, options); return self.ajax({ - type: method, + type: "POST", + url: url, + dataType: "json" + }); + }; + + self.markUnplayed = function (userId, itemId) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!itemId) { + throw new Error("null itemId"); + } + + var url = self.getUrl("Users/" + userId + "/PlayedItems/" + itemId); + + return self.ajax({ + type: "DELETE", url: url, dataType: "json" }); |
