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

collection fixes

This commit is contained in:
Luke Pulverenti 2015-10-14 01:46:11 -04:00
parent 8f05744009
commit add9159c97
10 changed files with 280 additions and 294 deletions

View file

@ -1,221 +0,0 @@
(function ($, document) {
function getNewCollectionPanel(createIfNeeded) {
var panel = $('.newCollectionPanel');
if (createIfNeeded && !panel.length) {
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', onSubmit).on('submit', onSubmit);
}
return panel;
}
function showCollectionPanel(items) {
var panel = getNewCollectionPanel(true).panel('toggle');
$('.fldSelectedItemIds', panel).val(items.join(','));
require(['jqmicons']);
if (items.length) {
$('.fldSelectCollection', panel).show();
populateCollections(panel);
} else {
$('.fldSelectCollection', panel).hide();
$('#selectCollectionToAddTo', panel).html('').val('').trigger('change');
}
}
function populateCollections(panel) {
var select = $('#selectCollectionToAddTo', panel);
$('.newCollectionInfo', panel).hide();
var options = {
Recursive: true,
IncludeItemTypes: "BoxSet",
SortBy: "SortName"
};
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
var html = '';
html += '<option value="">' + Globalize.translate('OptionNewCollection') + '</option>';
html += result.Items.map(function (i) {
return '<option value="' + i.Id + '">' + i.Name + '</option>';
});
select.html(html).val('').trigger('change');
});
}
function onSubmit() {
Dashboard.showLoadingMsg();
var panel = getNewCollectionPanel(false);
var collectionId = $('#selectCollectionToAddTo', panel).val();
if (collectionId) {
addToCollection(panel, collectionId);
} else {
createCollection(panel);
}
return false;
}
pageClassOn('pageinit', "collectionEditorPage", function () {
var page = this;
// The button is created dynamically
$(page).on('click', '.btnNewCollection', function () {
BoxSetEditor.showPanel([]);
});
});
function redirectToCollection(id) {
var context = getParameterByName('context');
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
Dashboard.navigate(LibraryBrowser.getHref(item, context));
});
}
function createCollection(panel) {
var url = ApiClient.getUrl("Collections", {
Name: $('#txtNewCollectionName', panel).val(),
IsLocked: !$('#chkEnableInternetMetadata', panel).checked(),
Ids: $('.fldSelectedItemIds', panel).val() || ''
//ParentId: getParameterByName('parentId') || LibraryMenu.getTopParentId()
});
ApiClient.ajax({
type: "POST",
url: url,
dataType: "json"
}).done(function (result) {
Dashboard.hideLoadingMsg();
var id = result.Id;
panel.panel('toggle');
redirectToCollection(id);
});
}
function addToCollection(panel, id) {
var url = ApiClient.getUrl("Collections/" + id + "/Items", {
Ids: $('.fldSelectedItemIds', panel).val() || ''
});
ApiClient.ajax({
type: "POST",
url: url
}).done(function () {
Dashboard.hideLoadingMsg();
panel.panel('toggle');
Dashboard.alert(Globalize.translate('MessageItemsAdded'));
});
}
window.BoxSetEditor = {
showPanel: function (items) {
require(['jqmpanel'], function () {
showCollectionPanel(items);
});
},
supportsAddingToCollection: function (item) {
var invalidTypes = ['Person', 'Genre', 'MusicGenre', 'Studio', 'GameGenre', 'BoxSet', 'Playlist', 'UserView', 'CollectionFolder', 'Audio', 'Episode', 'TvChannel', 'Program'];
return !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
}
};
})(jQuery, document);

View file

@ -679,7 +679,7 @@
var commands = [];
if (BoxSetEditor.supportsAddingToCollection(item)) {
if (LibraryBrowser.supportsAddingToCollection(item)) {
commands.push('addtocollection');
}
@ -894,7 +894,10 @@
});
break;
case 'addtocollection':
BoxSetEditor.showPanel([itemId]);
require(['collectioneditor'], function (collectioneditor) {
new collectioneditor().show([itemId]);
});
break;
case 'playlist':
PlaylistManager.showPanel([itemId]);
@ -1446,6 +1449,13 @@
return html;
},
supportsAddingToCollection: function (item) {
var invalidTypes = ['Person', 'Genre', 'MusicGenre', 'Studio', 'GameGenre', 'BoxSet', 'Playlist', 'UserView', 'CollectionFolder', 'Audio', 'Episode', 'TvChannel', 'Program'];
return !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
},
getItemCommands: function (item, options) {
var itemCommands = [];
@ -1478,7 +1488,7 @@
}
if (options.showAddToCollection !== false) {
if (BoxSetEditor.supportsAddingToCollection(item)) {
if (LibraryBrowser.supportsAddingToCollection(item)) {
itemCommands.push('addtocollection');
}
}

View file

@ -414,7 +414,10 @@
switch (id) {
case 'addtocollection':
BoxSetEditor.showPanel([itemId]);
require(['collectioneditor'], function (collectioneditor) {
new collectioneditor().show([itemId]);
});
break;
case 'playlist':
PlaylistManager.showPanel([itemId]);
@ -1236,18 +1239,23 @@
positionTo: e.target,
callback: function (id) {
var items = selectedItems.slice(0);
switch (id) {
case 'addtocollection':
BoxSetEditor.showPanel(selectedItems);
require(['collectioneditor'], function (collectioneditor) {
new collectioneditor().show(items);
});
hideSelections();
break;
case 'playlist':
PlaylistManager.showPanel(selectedItems);
PlaylistManager.showPanel(items);
hideSelections();
break;
case 'refresh':
selectedItems.map(function (itemId) {
items.map(function (itemId) {
// TODO: Create an endpoint to do this in bulk
ApiClient.refreshItem(itemId, {
@ -1264,7 +1272,7 @@
break;
case 'sync':
SyncManager.showMenu({
items: selectedItems.map(function (i) {
items: items.map(function (i) {
return {
Id: i
};
@ -1332,40 +1340,6 @@
});
}
function addToCollection(page) {
var selection = getSelectedItems();
if (selection.length < 1) {
Dashboard.alert({
message: Globalize.translate('MessagePleaseSelectOneItem'),
title: Globalize.translate('HeaderError')
});
return;
}
BoxSetEditor.showPanel(selection);
}
function addToPlaylist(page) {
var selection = getSelectedItems();
if (selection.length < 1) {
Dashboard.alert({
message: Globalize.translate('MessagePleaseSelectOneItem'),
title: Globalize.translate('HeaderError')
});
return;
}
PlaylistManager.showPanel(selection);
}
function onItemWithActionClick(e) {
var elem = this;

View file

@ -191,14 +191,14 @@
function initPage(tabContent) {
$('select.selectView').on('change', function () {
// The button is created dynamically
$('.btnNewCollection', tabContent).on('click', function () {
var newView = this.value;
getPageData().view = newView;
require(['collectioneditor'], function (collectioneditor) {
reloadItems(tabContent);
new collectioneditor().show();
LibraryBrowser.saveViewSetting(getSavedQueryKey(), newView);
});
});
}

View file

@ -2048,7 +2048,8 @@ var AppInfo = {};
var paths = {
velocity: "bower_components/velocity/velocity.min",
tvguide: 'components/tvguide/tvguide',
directorybrowser: 'components/directorybrowser/directorybrowser'
directorybrowser: 'components/directorybrowser/directorybrowser',
collectioneditor: 'components/collectioneditor/collectioneditor'
};
if (Dashboard.isRunningInCordova()) {