added methods to edit ibn images

This commit is contained in:
Luke Pulverenti 2013-08-03 10:38:56 -04:00
parent 0dc7a2177e
commit 0fde38b94f
4 changed files with 155 additions and 50 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.155" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.159" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.56" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.55" targetFramework="net45" />
</packages>