1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

add Add to collection buttons

This commit is contained in:
Luke Pulverenti 2015-01-23 23:50:45 -05:00
parent 9b452f3b53
commit 218e086d94
19 changed files with 481 additions and 214 deletions

View file

@ -270,25 +270,92 @@
(function ($, document) {
function showNewCollectionPanel(page, items) {
function getNewCollectionPanel(createIfNeeded) {
$('.fldSelectedItemIds', page).val(items.join(','));
var panel = $('.newCollectionPanel');
var panel = $('.newCollectionPanel', page).panel('toggle');
if (createIfNeeded && !panel.length) {
populateCollections(panel);
var html = '';
html += '<div>';
html += '<div data-role="panel" class="newCollectionPanel" data-position="right" data-display="overlay" data-position-fixed="true" data-theme="a">';
html += '<form class="newCollectionForm">';
html += '<h3>' + Globalize.translate('HeaderAddToCollection') + '</h3>';
html += '<div class="fldSelectCollection">';
html += '<br />';
html += '<label for="selectCollectionToAddTo">' + Globalize.translate('LabelSelectCollection') + '</label>';
html += '<select id="selectCollectionToAddTo" data-mini="true"></select>';
html += '</div>';
html += '<div class="newCollectionInfo">';
html += '<br />';
html += '<div>';
html += '<label for="txtNewCollectionName">' + Globalize.translate('LabelName') + '</label>';
html += '<input type="text" id="txtNewCollectionName" required="required" />';
html += '<div class="fieldDescription">' + Globalize.translate('NewCollectionNameExample') + '</div>';
html += '</div>';
html += '<br />';
html += '<div>';
html += '<label for="chkEnableInternetMetadata">' + Globalize.translate('OptionSearchForInternetMetadata') + '</label>';
html += '<input type="checkbox" id="chkEnableInternetMetadata" data-mini="true" />';
html += '</div>';
// newCollectionInfo
html += '</div>';
html += '<br />';
html += '<p>';
html += '<input class="fldSelectedItemIds" type="hidden" />';
html += '<button type="submit" data-icon="plus" data-mini="true" data-theme="b">' + Globalize.translate('ButtonSubmit') + '</button>';
html += '</p>';
html += '</form>';
html += '</div>';
html += '</div>';
panel = $(html).appendTo(document.body).trigger('create').find('.newCollectionPanel');
$('#selectCollectionToAddTo', panel).on('change', function () {
if (this.value) {
$('.newCollectionInfo', panel).hide();
$('#txtNewCollectionName', panel).removeAttr('required');
} else {
$('.newCollectionInfo', panel).show();
$('#txtNewCollectionName', panel).attr('required', 'required');
}
});
$('.newCollectionForm', panel).off('submit', BoxSetEditor.onNewCollectionSubmit).on('submit', BoxSetEditor.onNewCollectionSubmit);
}
return panel;
}
function showCollectionPanel(items) {
var panel = getNewCollectionPanel(true).panel('toggle');
$('.fldSelectedItemIds', panel).val(items.join(','));
if (items.length) {
$('.fldSelectCollection', panel).show();
populateCollections(panel);
} else {
$('.fldSelectCollection', panel).hide();
$('#selectCollectionToAddTo', panel).html('').val('').selectmenu('refresh').trigger('change');
}
}
function populateCollections(panel) {
var select = $('#selectCollectionToAddTo', panel);
if (!select.length) {
$('#txtNewCollectionName', panel).val('').focus();
return;
}
$('.newCollectionInfo', panel).hide();
var options = {
@ -320,18 +387,7 @@
// The button is created dynamically
$(page).on('click', '.btnNewCollection', function () {
showNewCollectionPanel(page, []);
});
$('#selectCollectionToAddTo', page).on('change', function () {
if (this.value) {
$('.newCollectionInfo', page).hide();
$('#txtNewCollectionName', page).removeAttr('required');
} else {
$('.newCollectionInfo', page).show();
$('#txtNewCollectionName', page).attr('required', 'required');
}
showCollectionPanel(page, []);
});
});
@ -346,13 +402,13 @@
});
}
function createCollection(page) {
function createCollection(panel) {
var url = ApiClient.getUrl("Collections", {
Name: $('#txtNewCollectionName', page).val(),
IsLocked: !$('#chkEnableInternetMetadata', page).checked(),
Ids: $('.fldSelectedItemIds', page).val() || ''
Name: $('#txtNewCollectionName', panel).val(),
IsLocked: !$('#chkEnableInternetMetadata', panel).checked(),
Ids: $('.fldSelectedItemIds', panel).val() || ''
//ParentId: getParameterByName('parentId') || LibraryMenu.getTopParentId()
@ -369,17 +425,17 @@
var id = result.Id;
$('.newCollectionPanel', page).panel('toggle');
panel.panel('toggle');
redirectToCollection(id);
});
}
function addToCollection(page, id) {
function addToCollection(panel, id) {
var url = ApiClient.getUrl("Collections/" + id + "/Items", {
Ids: $('.fldSelectedItemIds', page).val() || ''
Ids: $('.fldSelectedItemIds', panel).val() || ''
});
ApiClient.ajax({
@ -390,33 +446,39 @@
Dashboard.hideLoadingMsg();
$('.newCollectionPanel', page).panel('toggle');
redirectToCollection(id);
panel.panel('toggle');
Dashboard.alert(Globalize.translate('MessageItemsAdded'));
});
}
window.BoxSetEditor = {
showPanel: function (page, items) {
showNewCollectionPanel(page, items);
showPanel: function (items) {
showCollectionPanel(items);
},
onNewCollectionSubmit: function () {
Dashboard.showLoadingMsg();
var page = $(this).parents('.page');
var panel = getNewCollectionPanel(false);
var collectionId = $('#selectCollectionToAddTo', page).val();
var collectionId = $('#selectCollectionToAddTo', panel).val();
if (collectionId) {
addToCollection(page, collectionId);
addToCollection(panel, collectionId);
} else {
createCollection(page);
createCollection(panel);
}
return false;
},
supportsAddingToCollection: function (item) {
return item.LocationType == 'FileSystem';
}
};