From 210572734a04e6a5c03c975db059966417ca7418 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 12 Apr 2013 20:42:51 -0400 Subject: [PATCH] add ability to mark studios, genres and people as favorites --- ApiClient.js | 83 +++++++++++++++++++++++++- dashboard-ui/scripts/librarybrowser.js | 40 ++++++++++--- packages.config | 2 +- 3 files changed, 114 insertions(+), 11 deletions(-) diff --git a/ApiClient.js b/ApiClient.js index be4267d3c6..65012f94d2 100644 --- a/ApiClient.js +++ b/ApiClient.js @@ -1671,7 +1671,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** - * Updates a user's favorite status for an item and returns the updated UserItemData object. + * Updates a user's favorite status for an item. * @param {String} userId * @param {String} itemId * @param {Boolean} isFavorite @@ -1723,6 +1723,87 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; + /** + * Updates a user's favorite status for a person. + * @param {String} userId + * @param {String} name + * @param {Boolean} isFavorite + */ + self.updateFavoritePersonStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/FavoritePersons/" + name); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url, + dataType: "json" + }); + }; + + /** + * Updates a user's favorite status for a genre. + * @param {String} userId + * @param {String} name + * @param {Boolean} isFavorite + */ + self.updateFavoriteGenreStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/FavoriteGenre/" + name); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url, + dataType: "json" + }); + }; + + /** + * Updates a user's favorite status for a studio. + * @param {String} userId + * @param {String} name + * @param {Boolean} isFavorite + */ + self.updateFavoriteStudioStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/FavoriteStudios/" + name); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url, + dataType: "json" + }); + }; + /** * Clears a user's personal rating for an item * @param {String} userId diff --git a/dashboard-ui/scripts/librarybrowser.js b/dashboard-ui/scripts/librarybrowser.js index ad551a3363..927c027fe9 100644 --- a/dashboard-ui/scripts/librarybrowser.js +++ b/dashboard-ui/scripts/librarybrowser.js @@ -563,6 +563,16 @@ var itemId = item.Id; var type = item.Type; + + if (type == "Person") { + itemId = item.Name; + } + else if (type == "Studio") { + itemId = item.Name; + } + else if (type == "Genre") { + itemId = item.Name; + } if (item.MediaType) { if (userData.Played) { @@ -616,12 +626,24 @@ markFavorite: function (link) { var id = link.getAttribute('data-itemid'); + var type = link.getAttribute('data-type'); var $link = $(link); var markAsFavorite = $link.hasClass('imgFavoriteOff'); - ApiClient.updateFavoriteStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); + if (type == "Person") { + ApiClient.updateFavoritePersonStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); + } + else if (type == "Studio") { + ApiClient.updateFavoriteStudioStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); + } + else if (type == "Genre") { + ApiClient.updateFavoriteGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); + } + else { + ApiClient.updateFavoriteStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); + } if (markAsFavorite) { link.src = "css/images/userdata/heart_on.png"; @@ -697,21 +719,21 @@ if (item.Type == "Person") { url = ApiClient.getPersonImageUrl(item.Name, { - width: 800, + maxwidth: 800, tag: imageTags.Primary, type: "primary" }); } else if (item.Type == "Genre") { url = ApiClient.getGenreImageUrl(item.Name, { - width: 800, + maxwidth: 800, tag: imageTags.Primary, type: "primary" }); } else if (item.Type == "Studio") { url = ApiClient.getStudioImageUrl(item.Name, { - width: 800, + maxwidth: 800, tag: imageTags.Primary, type: "primary" }); @@ -719,7 +741,7 @@ else { url = ApiClient.getImageUrl(item.Id, { type: "Primary", - width: 800, + maxwidth: 800, tag: item.ImageTags.Primary }); } @@ -728,7 +750,7 @@ url = ApiClient.getImageUrl(item.Id, { type: "Backdrop", - width: 800, + maxwidth: 800, tag: item.BackdropImageTags[0] }); } @@ -736,7 +758,7 @@ url = ApiClient.getImageUrl(item.Id, { type: "Thumb", - width: 800, + maxwidth: 800, tag: item.ImageTags.Thumb }); } @@ -744,7 +766,7 @@ url = ApiClient.getImageUrl(item.Id, { type: "Disc", - width: 800, + maxwidth: 800, tag: item.ImageTags.Disc }); } @@ -850,7 +872,7 @@ elem.hide(); } }, - + renderBudget: function (elem, item) { if (item.Budget) { elem.show().html('Budget:  $' + item.Budget); diff --git a/packages.config b/packages.config index 8669c3db34..74c1b370fa 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file