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

421 lines
12 KiB
JavaScript
Raw Normal View History

2013-04-03 21:21:46 -07:00
(function ($, document) {
var view = LibraryBrowser.getDefaultItemsView('Poster', 'List');
2013-04-29 19:00:42 -07:00
// The base query options
var query = {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "BoxSet",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName",
2013-04-29 19:00:42 -07:00
StartIndex: 0
};
2013-04-03 21:21:46 -07:00
2014-05-06 19:28:19 -07:00
function getSavedQueryKey() {
return 'collections' + (query.ParentId || '');
}
2013-04-29 19:00:42 -07:00
function reloadItems(page) {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.showLoadingMsg();
2013-04-03 21:21:46 -07:00
2014-07-19 21:46:29 -07:00
var promise1 = ApiClient.getItems(Dashboard.getCurrentUserId(), query);
var promise2 = Dashboard.getCurrentUser();
$.when(promise1, promise2).done(function (response1, response2) {
var result = response1[0];
var user = response2[0];
2013-04-03 21:21:46 -07:00
2013-05-17 12:18:54 -07:00
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
2013-04-29 19:00:42 -07:00
var html = '';
2013-04-03 21:21:46 -07:00
2014-07-19 21:46:29 -07:00
var addiontalButtonsHtml = user.Configuration.IsAdministrator ?
('<button class="btnNewCollection" data-mini="true" data-icon="plus" data-inline="true" data-iconpos="notext">' + Globalize.translate('ButtonNew') + '</button>') :
'';
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false,
additionalButtonsHtml: addiontalButtonsHtml
});
$('.listTopPaging', page).html(pagingHtml).trigger('create');
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
if (result.TotalRecordCount) {
2014-05-31 07:30:59 -07:00
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'movies',
sortBy: query.SortBy
});
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
2014-07-19 21:46:29 -07:00
showTitle: false,
centerText: true,
lazy: true
});
}
2014-05-31 07:30:59 -07:00
2014-07-19 21:46:29 -07:00
html += pagingHtml;
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).hide();
2014-07-19 21:46:29 -07:00
} else {
2014-05-31 07:30:59 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).show();
}
2013-04-11 08:43:57 -07:00
$('.itemsContainer', page).html(html).trigger('create').createCardMenus();
2013-04-11 08:43:57 -07:00
2013-04-29 19:00:42 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
2013-04-15 15:03:05 -07:00
2013-04-29 19:00:42 -07:00
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
2013-04-15 15:03:05 -07:00
2014-05-06 19:28:19 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-10-18 09:09:47 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
function updateFilterControls(page) {
// Reset form values using the last used query
$('.radioSortBy', page).each(function () {
this.checked = (query.SortBy || '').toLowerCase() == this.getAttribute('data-sortby').toLowerCase();
}).checkboxradio('refresh');
$('.radioSortOrder', page).each(function () {
this.checked = (query.SortOrder || '').toLowerCase() == this.getAttribute('data-sortorder').toLowerCase();
}).checkboxradio('refresh');
$('.chkStandardFilter', page).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
$('#selectView', page).val(view).selectmenu('refresh');
2013-10-18 09:09:47 -07:00
$('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh');
$('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh');
$('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh');
$('.alphabetPicker', page).alphaValue(query.NameStartsWithOrGreater);
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
2013-10-18 09:09:47 -07:00
}
2013-04-29 19:00:42 -07:00
$(document).on('pageinit', "#boxsetsPage", function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
var page = this;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.radioSortBy', this).on('click', function () {
query.SortBy = this.getAttribute('data-sortby');
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.radioSortOrder', this).on('click', function () {
query.SortOrder = this.getAttribute('data-sortorder');
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.chkStandardFilter', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
filters = (',' + filters).replace(',' + filterName, '').substring(1);
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.Filters = filters;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkTrailer', this).on('change', function () {
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasTrailer = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkThemeSong', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasThemeSong = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkThemeVideo', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasThemeVideo = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
reloadItems(page);
}).on('alphaclear', function (e) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
reloadItems(page);
});
$('#selectView', this).on('change', function () {
view = this.value;
reloadItems(page);
LibraryBrowser.saveViewSetting(getSavedQueryKey(), view);
});
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
reloadItems(page);
});
2013-04-29 19:00:42 -07:00
}).on('pagebeforeshow', "#boxsetsPage", function () {
2013-04-03 21:21:46 -07:00
var page = this;
2014-07-19 21:46:29 -07:00
var context = getParameterByName('context');
if (context == 'movies') {
$('.collectionTabs', page).hide();
$('.movieTabs', page).show();
} else {
$('.collectionTabs', page).show();
$('.movieTabs', page).hide();
}
2014-09-29 21:47:30 -07:00
//query.ParentId = LibraryMenu.getTopParentId();
2014-05-06 19:28:19 -07:00
2013-05-15 12:40:47 -07:00
var limit = LibraryBrowser.getDefaultPageSize();
// If the default page size has changed, the start index will have to be reset
if (limit != query.Limit) {
query.Limit = limit;
query.StartIndex = 0;
}
var viewkey = getSavedQueryKey();
LibraryBrowser.loadSavedQueryValues(viewkey, query);
LibraryBrowser.getSavedViewSetting(viewkey).done(function (val) {
if (val) {
$('#selectView', page).val(val).selectmenu('refresh').trigger('change');
} else {
reloadItems(page);
}
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
}).on('pageshow', "#boxsetsPage", function () {
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(this);
2014-05-31 07:30:59 -07:00
});
})(jQuery, document);
(function ($, document) {
2014-06-03 20:34:36 -07:00
function showNewCollectionPanel(page, items) {
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
$('.fldSelectedItemIds', page).val(items.join(','));
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
var panel = $('.newCollectionPanel', page).panel('toggle');
populateCollections(panel);
}
function populateCollections(panel) {
var select = $('#selectCollectionToAddTo', panel);
if (!select.length) {
$('#txtNewCollectionName', panel).val('').focus();
return;
}
$('.newCollectionInfo', panel).hide();
var options = {
Recursive: true,
IncludeItemTypes: "BoxSet"
};
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('').selectmenu('refresh').trigger('change');
});
2014-05-31 07:30:59 -07:00
}
$(document).on('pageinit', ".collectionEditorPage", function () {
var page = this;
2014-07-19 21:46:29 -07:00
$('.itemsContainer', page).on('itemsrendered', function () {
$('.btnNewCollection', page).off('click.newcollectionpanel').on('click.newcollectionpanel', function () {
showNewCollectionPanel(page, []);
});
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
});
$('#selectCollectionToAddTo', page).on('change', function () {
if (this.value) {
$('.newCollectionInfo', page).hide();
$('#txtNewCollectionName', page).removeAttr('required');
} else {
$('.newCollectionInfo', page).show();
$('#txtNewCollectionName', page).attr('required', 'required');
}
2014-05-31 07:30:59 -07:00
});
2013-04-29 19:00:42 -07:00
});
2013-04-03 21:21:46 -07:00
function redirectToCollection(id) {
var context = getParameterByName('context');
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
Dashboard.navigate(LibraryBrowser.getHref(item, context));
});
}
2014-06-03 20:34:36 -07:00
function createCollection(page) {
2014-06-03 20:34:36 -07:00
var url = ApiClient.getUrl("Collections", {
2014-06-03 20:34:36 -07:00
Name: $('#txtNewCollectionName', page).val(),
IsLocked: !$('#chkEnableInternetMetadata', page).checked(),
Ids: $('.fldSelectedItemIds', page).val() || ''
2014-06-03 20:34:36 -07:00
//ParentId: getParameterByName('parentId') || LibraryMenu.getTopParentId()
});
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-06-03 20:34:36 -07:00
type: "POST",
url: url,
dataType: "json"
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
}).done(function (result) {
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
Dashboard.hideLoadingMsg();
2014-06-03 20:34:36 -07:00
var id = result.Id;
2014-06-03 20:34:36 -07:00
$('.newCollectionPanel', page).panel('toggle');
redirectToCollection(id);
2014-06-03 20:34:36 -07:00
});
}
2014-06-03 20:34:36 -07:00
function addToCollection(page, id) {
2014-06-03 20:34:36 -07:00
var url = ApiClient.getUrl("Collections/" + id + "/Items", {
Ids: $('.fldSelectedItemIds', page).val() || ''
});
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-06-03 20:34:36 -07:00
type: "POST",
url: url
}).done(function () {
Dashboard.hideLoadingMsg();
$('.newCollectionPanel', page).panel('toggle');
redirectToCollection(id);
2014-06-03 20:34:36 -07:00
});
}
window.BoxSetEditor = {
showPanel: function (page, items) {
showNewCollectionPanel(page, items);
},
onNewCollectionSubmit: function () {
Dashboard.showLoadingMsg();
var page = $(this).parents('.page');
var collectionId = $('#selectCollectionToAddTo', page).val();
if (collectionId) {
addToCollection(page, collectionId);
} else {
createCollection(page);
}
2014-03-05 22:17:13 -07:00
return false;
}
};
2013-04-03 21:21:46 -07:00
})(jQuery, document);