From 0fde38b94f1d391ab765a513367d64da7f4b1e97 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 3 Aug 2013 10:38:56 -0400 Subject: [PATCH] added methods to edit ibn images --- ApiClient.js | 187 ++++++++++++++++++----- dashboard-ui/scripts/edititemimages.js | 8 +- dashboard-ui/scripts/edititemmetadata.js | 8 +- packages.config | 2 +- 4 files changed, 155 insertions(+), 50 deletions(-) diff --git a/ApiClient.js b/ApiClient.js index a75da62dcd..e989d8ff17 100644 --- a/ApiClient.js +++ b/ApiClient.js @@ -80,18 +80,15 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { else if ($.browser.firefox || $.browser.mozilla) { name = "Firefox"; } - - if (name) - { - if ($.browser.version) - { - name += " " + $.browser.version; - } - } - else - { - name = "Web Browser"; - } + + if (name) { + if ($.browser.version) { + name += " " + $.browser.version; + } + } + else { + name = "Web Browser"; + } if ($.browser.ipad) { name += " Ipad"; @@ -1046,17 +1043,41 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; - self.deleteItemImage = function (itemId, imageType, imageIndex) { - - if (!itemId) { - throw new Error("null itemId"); - } + self.deleteItemImage = function (itemId, itemType, itemName, imageType, imageIndex) { if (!imageType) { throw new Error("null imageType"); } - var url = self.getUrl("Items/" + itemId + "/Images/" + imageType); + if (!itemType) { + throw new Error("null itemType"); + } + + var url; + + if (itemType == "Artist") { + url = self.getUrl("Artists/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Genre") { + url = self.getUrl("Genres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "GameGenre") { + url = self.getUrl("GameGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "MusicGenre") { + url = self.getUrl("MusicGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Person") { + url = self.getUrl("Persons/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Studio") { + url = self.getUrl("Studios/" + self.encodeName(itemName) + "/Images"); + } + else { + url = self.getUrl("Items/" + itemId + "/Images"); + } + + url += "/" + imageType; if (imageIndex != null) { url += "/" + imageIndex; @@ -1068,17 +1089,41 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; - self.updateItemImageIndex = function (itemId, imageType, imageIndex, newIndex) { - - if (!itemId) { - throw new Error("null itemId"); - } + self.updateItemImageIndex = function (itemId, itemType, itemName, imageType, imageIndex, newIndex) { if (!imageType) { throw new Error("null imageType"); } - var url = self.getUrl("Items/" + itemId + "/Images/" + imageType + "/" + imageIndex + "/Index", { newIndex: newIndex }); + if (!itemType) { + throw new Error("null itemType"); + } + + var url; + + var options = { newIndex: newIndex }; + + if (itemType == "Artist") { + url = self.getUrl("Artists/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else if (itemType == "Genre") { + url = self.getUrl("Genres/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else if (itemType == "GameGenre") { + url = self.getUrl("GameGenres/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else if (itemType == "MusicGenre") { + url = self.getUrl("MusicGenres/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else if (itemType == "Person") { + url = self.getUrl("Persons/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else if (itemType == "Studio") { + url = self.getUrl("Studios/" + self.encodeName(itemName) + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } + else { + url = self.getUrl("Items/" + itemId + "/Images/" + imageType + "/" + imageIndex + "/Index", options); + } return self.ajax({ type: "POST", @@ -1086,13 +1131,35 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; - self.getItemImageInfos = function (itemId) { + self.getItemImageInfos = function (itemId, itemType, itemName) { - if (!itemId) { - throw new Error("null itemId"); + if (!itemType) { + throw new Error("null itemType"); } - var url = self.getUrl("Items/" + itemId + "/Images"); + var url; + + if (itemType == "Artist") { + url = self.getUrl("Artists/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Genre") { + url = self.getUrl("Genres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "GameGenre") { + url = self.getUrl("GameGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "MusicGenre") { + url = self.getUrl("MusicGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Person") { + url = self.getUrl("Persons/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Studio") { + url = self.getUrl("Studios/" + self.encodeName(itemName) + "/Images"); + } + else { + url = self.getUrl("Items/" + itemId + "/Images"); + } return self.ajax({ type: "GET", @@ -1191,7 +1258,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { return deferred.promise(); }; - self.uploadItemImage = function (itemId, imageType, file) { + self.uploadItemImage = function (itemId, itemType, itemName, imageType, file) { if (!itemId) { throw new Error("null itemId"); @@ -1209,6 +1276,32 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("File must be an image."); } + var url; + + if (itemType == "Artist") { + url = self.getUrl("Artists/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Genre") { + url = self.getUrl("Genres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "GameGenre") { + url = self.getUrl("GameGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "MusicGenre") { + url = self.getUrl("MusicGenres/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Person") { + url = self.getUrl("Persons/" + self.encodeName(itemName) + "/Images"); + } + else if (itemType == "Studio") { + url = self.getUrl("Studios/" + self.encodeName(itemName) + "/Images"); + } + else { + url = self.getUrl("Items/" + itemId + "/Images"); + } + + url += "/" + imageType; + var deferred = $.Deferred(); var reader = new FileReader(); @@ -1227,8 +1320,6 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { // Split by a comma to remove the url: prefix var data = e.target.result.split(',')[1]; - var url = self.getUrl("Items/" + itemId + "/Images/" + imageType); - self.ajax({ type: "POST", url: url, @@ -2243,6 +2334,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }); }; + self.getAncestorItems = function (itemId, userId) { + + if (!itemId) { + throw new Error("null itemId"); + } + + var options = {}; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("Items/" + itemId + "/Ancestors", options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + /** * Gets items based on a query, typically for children of a folder * @param {String} userId @@ -3509,13 +3621,12 @@ MediaBrowser.SHA1 = function (msg) { /(iphone)/.exec(ua) || /(android)/.exec(ua) || []; - - var browser = match[1] || ""; - - if (ua.indexOf("like gecko") != -1 && ua.indexOf('webkit') == -1 && ua.indexOf('opera') == -1) - { - browser = "msie"; - } + + var browser = match[1] || ""; + + if (ua.indexOf("like gecko") != -1 && ua.indexOf('webkit') == -1 && ua.indexOf('opera') == -1) { + browser = "msie"; + } return { browser: browser, diff --git a/dashboard-ui/scripts/edititemimages.js b/dashboard-ui/scripts/edititemimages.js index fa1a2e2ea9..d1015f07f0 100644 --- a/dashboard-ui/scripts/edititemimages.js +++ b/dashboard-ui/scripts/edititemimages.js @@ -29,7 +29,7 @@ $('#btnEditPeople', page).show(); } - ApiClient.getItemImageInfos(currentItem.Id).done(function (imageInfos) { + ApiClient.getItemImageInfos(currentItem.Id, currentItem.Type, currentItem.Name).done(function (imageInfos) { renderStandardImages(page, item, imageInfos); renderBackdrops(page, item, imageInfos); renderScreenshots(page, item, imageInfos); @@ -219,7 +219,7 @@ var imageType = $('#selectImageType', page).val(); - ApiClient.uploadItemImage(currentItem.Id, imageType, file).done(function () { + ApiClient.uploadItemImage(currentItem.Id, currentItem.Type, currentItem.Name, imageType, file).done(function () { $('#uploadImage', page).val('').trigger('change'); $('#popupUpload', page).popup("close"); @@ -237,7 +237,7 @@ Dashboard.confirm("Are you sure you wish to delete this image?", "Delete " + type + " Image", function (result) { if (result) { - ApiClient.deleteItemImage(currentItem.Id, type, index).done(function () { + ApiClient.deleteItemImage(currentItem.Id, currentItem.Type, currentItem.Name, type, index).done(function () { processImageChangeResult(page); @@ -253,7 +253,7 @@ var page = $.mobile.activePage; - ApiClient.updateItemImageIndex(currentItem.Id, type, index, newIndex).done(function () { + ApiClient.updateItemImageIndex(currentItem.Id, currentItem.Type, currentItem.Name, type, index, newIndex).done(function () { processImageChangeResult(page); diff --git a/dashboard-ui/scripts/edititemmetadata.js b/dashboard-ui/scripts/edititemmetadata.js index 645083cc95..37cfbe4d17 100644 --- a/dashboard-ui/scripts/edititemmetadata.js +++ b/dashboard-ui/scripts/edititemmetadata.js @@ -65,9 +65,6 @@ if (elem) { elem.scrollIntoView(); - - var sidebar = $('.editPageSidebar', page); - sidebar.scrollTop(sidebar.scrollTop() - sidebar.height() / 3); } $(document).scrollTop(0); @@ -121,10 +118,7 @@ if (id) { - $.getJSON(ApiClient.getUrl("Items/" + id + "/Ancestors", { - userId: Dashboard.getCurrentUserId() - - })).done(function (ancestors) { + ApiClient.getAncestorItems(id, Dashboard.getCurrentUserId()).done(function (ancestors) { var ids = ancestors.map(function (i) { return i.Id; diff --git a/packages.config b/packages.config index 8b53d9d782..8fdd0ef058 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file