jellyfin-web/dashboard-ui/scripts/medialibrarypage.js

362 lines
12 KiB
JavaScript
Raw Normal View History

2013-02-20 18:33:05 -07:00
var MediaLibraryPage = {
onPageShow: function () {
MediaLibraryPage.lastVirtualFolderName = "";
2013-04-16 21:21:24 -07:00
MediaLibraryPage.reloadLibrary(this);
2013-02-20 18:33:05 -07:00
},
2013-04-16 21:21:24 -07:00
reloadLibrary: function (page) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
var userId = getParameterByName("userId");
if (userId) {
$('#userProfileNavigation', page).show();
2013-05-21 13:36:26 -07:00
$('#defaultNavigation', page).hide();
2013-02-20 18:33:05 -07:00
ApiClient.getUser(userId).done(function (user) {
Dashboard.setPageTitle(user.Name);
$('#fldUseDefaultLibrary', page).show();
$('#chkUseDefaultLibrary', page).checked(!user.Configuration.UseCustomLibrary).checkboxradio("refresh");
if (user.Configuration.UseCustomLibrary) {
2013-04-16 21:21:24 -07:00
ApiClient.getVirtualFolders(userId).done(function (result) {
MediaLibraryPage.reloadVirtualFolders(page, result);
});
2013-04-16 21:21:24 -07:00
$(".editing_default", page).hide();
2013-02-20 18:33:05 -07:00
$('#divMediaLibrary', page).show();
} else {
$('#divMediaLibrary', page).hide();
Dashboard.hideLoadingMsg();
}
});
} else {
$('#userProfileNavigation', page).hide();
2013-05-21 13:36:26 -07:00
$('#defaultNavigation', page).show();
ApiClient.getVirtualFolders().done(function (result) {
2013-04-16 21:21:24 -07:00
MediaLibraryPage.reloadVirtualFolders(page, result);
});
2013-02-20 18:33:05 -07:00
$('#fldUseDefaultLibrary', page).hide();
$('#divMediaLibrary', page).show();
Dashboard.setPageTitle("Media Library");
}
},
2013-09-05 10:05:39 -07:00
shouldRefreshLibraryAfterChanges: function () {
return $($.mobile.activePage).is('#mediaLibraryPage');
},
2013-04-16 21:21:24 -07:00
reloadVirtualFolders: function (page, virtualFolders) {
2013-02-20 18:33:05 -07:00
if (virtualFolders) {
MediaLibraryPage.virtualFolders = virtualFolders;
} else {
virtualFolders = MediaLibraryPage.virtualFolders;
}
var html = '';
for (var i = 0, length = virtualFolders.length; i < length; i++) {
var virtualFolder = virtualFolders[i];
2013-02-20 18:33:05 -07:00
var isCollapsed = MediaLibraryPage.lastVirtualFolderName != virtualFolder.Name;
html += MediaLibraryPage.getVirtualFolderHtml(virtualFolder, isCollapsed, i);
}
$('#divVirtualFolders', page).html(html).trigger('create');
Dashboard.hideLoadingMsg();
},
getVirtualFolderHtml: function (virtualFolder, isCollapsed, index) {
isCollapsed = isCollapsed ? "true" : "false";
var html = '<div class="collapsibleVirtualFolder" data-role="collapsible" data-collapsed="' + isCollapsed + '" data-content-theme="c">';
html += '<h3>' + virtualFolder.Name + '</h3>';
2013-09-05 10:05:39 -07:00
var typeName = MediaLibraryPage.getCollectionTypeOptions().filter(function (t) {
2013-07-12 12:56:40 -07:00
return t.value == virtualFolder.CollectionType;
})[0];
typeName = typeName ? typeName.name : "General or mixed content";
html += '<p style="padding-left:.5em;">Collection type: <b>' + typeName + '</b></p>';
2013-02-20 18:33:05 -07:00
html += '<ul class="mediaFolderLocations" data-inset="true" data-role="listview" data-split-icon="minus">';
html += '<li data-role="list-divider" class="mediaLocationsHeader">Media Locations';
html += '<button type="button" data-icon="plus" data-mini="true" data-theme="c" data-inline="true" data-iconpos="notext" onclick="MediaLibraryPage.addMediaLocation(' + index + ');"></button>';
html += '</li>';
for (var i = 0, length = virtualFolder.Locations.length; i < length; i++) {
var location = virtualFolder.Locations[i];
html += '<li>';
html += '<a class="lnkMediaLocation" href="#">' + location + '</a>';
html += '<a href="#" data-index="' + i + '" data-folderindex="' + index + '" onclick="MediaLibraryPage.deleteMediaLocation(this);"></a>';
html += '</li>';
}
html += '</ul>';
html += '<p>';
2013-05-24 07:35:15 -07:00
html += '<button type="button" data-inline="true" data-icon="minus" data-folderindex="' + index + '" onclick="MediaLibraryPage.deleteVirtualFolder(this);" data-mini="true">Remove collection</button>';
html += '<button type="button" data-inline="true" data-icon="pencil" data-folderindex="' + index + '" onclick="MediaLibraryPage.renameVirtualFolder(this);" data-mini="true">Rename collection</button>';
2013-02-20 18:33:05 -07:00
html += '</p>';
html += '</div>';
return html;
},
setUseDefaultMediaLibrary: function (useDefaultLibrary) {
Dashboard.showLoadingMsg();
var userId = getParameterByName("userId");
2013-04-16 21:21:24 -07:00
var page = $.mobile.activePage;
2013-02-20 18:33:05 -07:00
ApiClient.getUser(userId).done(function (user) {
user.Configuration.UseCustomLibrary = !useDefaultLibrary;
ApiClient.updateUser(user).done(function () {
2013-04-16 21:21:24 -07:00
MediaLibraryPage.reloadLibrary(page);
});
2013-04-02 21:31:34 -07:00
2013-04-16 21:21:24 -07:00
$(".editing_default", page).hide();
2013-02-20 18:33:05 -07:00
});
},
addVirtualFolder: function () {
2013-09-04 12:16:41 -07:00
$('.collectionTypeFieldDescription').show();
2013-07-12 12:56:40 -07:00
MediaLibraryPage.getTextValue("Add Media Collection", "Name (Movies, Music, TV, etc):", "", true, function (name, type) {
2013-02-20 18:33:05 -07:00
var userId = getParameterByName("userId");
MediaLibraryPage.lastVirtualFolderName = name;
2013-09-05 10:05:39 -07:00
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
ApiClient.addVirtualFolder(name, type, userId, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
2013-02-20 18:33:05 -07:00
});
},
addMediaLocation: function (virtualFolderIndex) {
MediaLibraryPage.selectDirectory(function (path) {
if (path) {
var virtualFolder = MediaLibraryPage.virtualFolders[virtualFolderIndex];
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
var userId = getParameterByName("userId");
2013-09-05 10:05:39 -07:00
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
ApiClient.addMediaPath(virtualFolder.Name, path, userId, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
2013-02-20 18:33:05 -07:00
}
});
},
selectDirectory: function (callback) {
var picker = new DirectoryBrowser($.mobile.activePage);
picker.show({ callback: callback });
MediaLibraryPage.directoryPicker = picker;
2013-02-20 18:33:05 -07:00
},
2013-07-12 12:56:40 -07:00
getTextValue: function (header, label, initialValue, showCollectionType, callback) {
2013-02-20 18:33:05 -07:00
var page = $.mobile.activePage;
var popup = $('#popupEnterText', page);
$('h3', popup).html(header);
2013-07-12 12:56:40 -07:00
$('#lblValue', popup).html(label);
2013-02-20 18:33:05 -07:00
$('#txtValue', popup).val(initialValue);
2013-07-12 12:56:40 -07:00
if (showCollectionType) {
$('#fldCollectionType', popup).show();
} else {
$('#fldCollectionType', popup).hide();
}
2013-10-01 14:18:31 -07:00
$('#selectCollectionType', popup).html(MediaLibraryPage.getCollectionTypeOptionsHtml()).selectmenu('refresh');
2013-07-12 12:56:40 -07:00
popup.on("popupafteropen", function () {
2013-03-28 20:50:46 -07:00
$('#textEntryForm input:first', this).focus();
}).on("popupafterclose", function () {
2013-02-20 18:33:05 -07:00
$(this).off("popupafterclose").off("click");
$('#textEntryForm', this).off("submit");
2013-03-28 20:50:46 -07:00
}).popup("open");
2013-02-20 18:33:05 -07:00
$('#textEntryForm', popup).on('submit', function () {
if (callback) {
2013-07-12 12:56:40 -07:00
if (showCollectionType) {
callback($('#txtValue', popup).val(), $('#selectCollectionType', popup).val());
} else {
callback($('#txtValue', popup).val());
}
2013-02-20 18:33:05 -07:00
}
return false;
});
},
2013-07-12 12:56:40 -07:00
getCollectionTypeOptionsHtml: function () {
return MediaLibraryPage.getCollectionTypeOptions().map(function (i) {
return '<option value="' + i.value + '">' + i.name + '</option>';
}).join("");
},
getCollectionTypeOptions: function () {
return [
{ name: "General or mixed content", value: "" },
2013-07-16 11:47:05 -07:00
{ name: "Adult videos", value: "adultvideos" },
2013-09-02 16:17:10 -07:00
{ name: "Books*", value: "books" },
2013-07-12 12:56:40 -07:00
{ name: "Box sets", value: "boxsets" },
{ name: "Games*", value: "games" },
2013-07-12 12:56:40 -07:00
{ name: "Home videos", value: "homevideos" },
{ name: "Movies", value: "movies" },
{ name: "Music", value: "music" },
{ name: "Music videos", value: "musicvideos" },
{ name: "Photos*", value: "photos" },
2013-07-12 12:56:40 -07:00
{ name: "Trailers", value: "trailers" },
{ name: "TV shows", value: "tvshows" }
];
},
2013-02-20 18:33:05 -07:00
renameVirtualFolder: function (button) {
var folderIndex = button.getAttribute('data-folderindex');
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
2013-09-04 12:16:41 -07:00
$('.collectionTypeFieldDescription').hide();
2013-07-12 12:56:40 -07:00
MediaLibraryPage.getTextValue(virtualFolder.Name, "Rename " + virtualFolder.Name, virtualFolder.Name, false, function (newName) {
2013-02-20 18:33:05 -07:00
if (virtualFolder.Name != newName) {
var userId = getParameterByName("userId");
2013-09-05 10:05:39 -07:00
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
ApiClient.renameVirtualFolder(virtualFolder.Name, newName, userId, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
2013-02-20 18:33:05 -07:00
}
});
},
deleteVirtualFolder: function (button) {
var folderIndex = button.getAttribute('data-folderindex');
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
var parent = $(button).parents('.collapsibleVirtualFolder');
2013-02-20 18:33:05 -07:00
var locations = $('.lnkMediaLocation', parent).map(function () {
return this.innerHTML;
}).get();
var msg = "Are you sure you wish to remove " + virtualFolder.Name + "?";
2013-02-20 18:33:05 -07:00
if (locations.length) {
msg += "<br/><br/>The following media locations will be removed from your library:<br/><br/>";
msg += locations.join("<br/>");
}
2013-02-20 18:33:05 -07:00
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
2013-02-20 18:33:05 -07:00
Dashboard.confirm(msg, "Remove Media Folder", function (confirmResult) {
if (confirmResult) {
var userId = getParameterByName("userId");
2013-09-05 10:05:39 -07:00
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
ApiClient.removeVirtualFolder(virtualFolder.Name, userId, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
2013-02-20 18:33:05 -07:00
}
});
},
deleteMediaLocation: function (button) {
var folderIndex = button.getAttribute('data-folderindex');
var index = parseInt(button.getAttribute('data-index'));
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
var location = virtualFolder.Locations[index];
Dashboard.confirm("Are you sure you wish to remove " + location + "?", "Remove Media Location", function (confirmResult) {
if (confirmResult) {
var userId = getParameterByName("userId");
2013-09-05 10:05:39 -07:00
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
ApiClient.removeMediaPath(virtualFolder.Name, location, userId, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
2013-02-20 18:33:05 -07:00
}
});
},
processOperationResult: function (result) {
Dashboard.hideLoadingMsg();
var page = $.mobile.activePage;
$('#popupEnterText', page).popup("close");
2013-07-12 12:56:40 -07:00
if (MediaLibraryPage.directoryPicker) {
MediaLibraryPage.directoryPicker.close();
MediaLibraryPage.directoryPicker = null;
}
2013-04-16 21:21:24 -07:00
MediaLibraryPage.reloadLibrary(page);
2013-02-20 18:33:05 -07:00
}
};
$(document).on('pageshow', ".mediaLibraryPage", MediaLibraryPage.onPageShow);