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

278 lines
8.0 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2013-04-10 22:27:27 -07:00
var view = "Tile";
2013-04-08 14:05:00 -07:00
2013-04-01 20:28:20 -07:00
// The base query options
var query = {
2013-04-01 20:28:20 -07:00
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie",
Recursive: true,
2013-04-09 21:38:04 -07:00
Fields: "PrimaryImageAspectRatio,UserData,DisplayMediaType,ItemCounts,DateCreated",
2013-04-09 09:42:55 -07:00
Limit: LibraryBrowser.getDetaultPageSize(),
2013-04-08 14:05:00 -07:00
StartIndex: 0
2013-04-01 20:28:20 -07:00
};
2013-04-08 14:05:00 -07:00
function getTableHtml(result) {
var items = result.Items;
2013-04-01 20:28:20 -07:00
2013-04-08 14:05:00 -07:00
var html = '';
2013-04-01 20:28:20 -07:00
2013-04-08 14:05:00 -07:00
html += '<table class="libraryItemsGrid">';
2013-04-01 20:28:20 -07:00
html += '<thead>';
html += '<tr>';
2013-04-01 21:25:58 -07:00
html += '<th>&nbsp;</th>';
2013-04-04 21:15:00 -07:00
html += '<th class="thName">Name</th>';
2013-04-06 13:44:14 -07:00
html += '<th class="desktopColumn">Type</th>';
html += '<th class="tabletColumn">Year</th>';
html += '<th class="tabletColumn">Rating</th>';
html += '<th class="tabletColumn">Runtime</th>';
html += '<th class="tabletColumn">Community Rating</th>';
html += '<th class="tabletColumn"></th>';
2013-04-01 20:28:20 -07:00
html += '</tr>';
html += '</thead>';
html += '<tbody>';
for (var i = 0, length = items.length; i < length; i++) {
html += getRowHtml(items[i]);
}
html += '</tbody>';
2013-04-06 13:44:14 -07:00
html += '</table>';
2013-04-01 20:28:20 -07:00
return html;
}
2013-04-01 20:28:20 -07:00
function getRowHtml(item) {
2013-04-01 20:28:20 -07:00
var html = '<tr>';
2013-04-01 21:25:58 -07:00
html += '<td>';
var url = "itemdetails.html?id=" + item.Id;
html += '<a href="' + url + '">';
2013-04-06 14:10:12 -07:00
if (item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-01 21:25:58 -07:00
2013-04-06 14:10:12 -07:00
html += '<img class="libraryGridImage" src="' + ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
2013-04-08 14:05:00 -07:00
width: 220,
2013-04-06 14:10:12 -07:00
tag: item.BackdropImageTags[0],
index: 0
}) + '" />';
}
else if (item.ImageTags && item.ImageTags.Thumb) {
html += '<img class="libraryGridImage" src="' + ApiClient.getImageUrl(item.Id, {
type: "Thumb",
2013-04-08 14:05:00 -07:00
width: 220,
2013-04-06 14:10:12 -07:00
tag: item.ImageTags.Thumb
}) + '" />';
}
else if (item.ImageTags && item.ImageTags.Primary) {
2013-04-01 21:25:58 -07:00
html += '<img class="libraryGridImage" src="' + ApiClient.getImageUrl(item.Id, {
type: "Primary",
2013-04-08 14:05:00 -07:00
width: 220,
2013-04-01 21:25:58 -07:00
tag: item.ImageTags.Primary
}) + '" />';
}
else {
2013-04-04 10:27:36 -07:00
html += '<img class="libraryGridImage" style="background:' + LibraryBrowser.getMetroColor(item.Id) + ';" src="css/images/items/list/video.png" />';
2013-04-01 21:25:58 -07:00
}
html += '</a></td>';
2013-04-04 21:15:00 -07:00
html += '<td class="tdName"><a href="' + url + '">' + item.Name + '</a></td>';
2013-04-01 20:28:20 -07:00
2013-04-06 13:44:14 -07:00
html += '<td class="desktopColumn">' + (item.VideoType == "VideoFile" ? item.DisplayMediaType : item.VideoType) + '</td>';
2013-04-01 20:28:20 -07:00
2013-04-06 13:44:14 -07:00
html += '<td class="tabletColumn">' + (item.ProductionYear || "") + '</td>';
html += '<td class="tabletColumn">' + (item.OfficialRating || "") + '</td>';
2013-04-04 21:15:00 -07:00
var minutes = (item.RunTimeTicks || 0) / 600000000;
minutes = minutes || 1;
2013-04-06 13:44:14 -07:00
html += '<td class="tabletColumn">' + parseInt(minutes) + 'min</td>';
html += '<td class="tabletColumn">' + (item.CommunityRating || "") + '</td>';
2013-04-01 20:28:20 -07:00
2013-04-06 13:44:14 -07:00
html += '<td class="tabletColumn">';
2013-04-04 21:15:00 -07:00
2013-04-10 10:11:23 -07:00
html += LibraryBrowser.getUserDataIconsHtml(item);
2013-04-04 21:15:00 -07:00
html += '</td>';
2013-04-01 20:28:20 -07:00
html += '</tr>';
return html;
}
function reloadItems(page) {
Dashboard.showLoadingMsg();
2013-04-10 22:27:27 -07:00
2013-04-01 20:28:20 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
2013-04-08 14:05:00 -07:00
var html = '';
var showPaging = result.TotalRecordCount > query.Limit;
if (showPaging) {
2013-04-11 05:23:02 -07:00
html += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, true);
2013-04-08 14:05:00 -07:00
}
2013-04-10 22:27:27 -07:00
if (view == "Tile") {
html += LibraryBrowser.getPosterDetailViewHtml({
items: result.Items,
useAverageAspectRatio: true,
preferBackdrop: true
});
}
else if (view == "Poster") {
2013-04-08 14:05:00 -07:00
html += LibraryBrowser.getPosterViewHtml({
2013-04-04 21:15:00 -07:00
items: result.Items,
useAverageAspectRatio: true
2013-04-08 14:05:00 -07:00
});
2013-04-04 21:15:00 -07:00
}
else if (view == "Grid") {
2013-04-08 14:05:00 -07:00
html += getTableHtml(result);
}
if (showPaging) {
2013-04-08 22:06:13 -07:00
html += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount);
2013-04-04 21:15:00 -07:00
}
2013-04-01 20:28:20 -07:00
2013-04-08 14:05:00 -07:00
var elem = $('#items', page);
// cleanup existing event handlers
$('select', elem).off('change');
elem.html(html).trigger('create');
2013-04-10 22:27:27 -07:00
$('select', elem).on('change', function () {
2013-04-08 14:05:00 -07:00
query.StartIndex = (parseInt(this.value) - 1) * query.Limit;
reloadItems(page);
});
2013-04-01 20:28:20 -07:00
Dashboard.hideLoadingMsg();
});
2013-04-01 20:28:20 -07:00
}
2013-04-01 20:28:20 -07:00
$(document).on('pageinit', "#moviesPage", function () {
var page = this;
2013-04-01 20:28:20 -07:00
$('.radioSortBy', this).on('click', function () {
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-01 20:28:20 -07:00
query.SortBy = this.getAttribute('data-sortby');
reloadItems(page);
});
$('.radioSortOrder', this).on('click', function () {
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-01 20:28:20 -07:00
query.SortOrder = this.getAttribute('data-sortorder');
reloadItems(page);
});
$('.chkStandardFilter', this).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-01 20:28:20 -07:00
query.Filters = filters;
reloadItems(page);
});
2013-04-04 08:38:41 -07:00
$('.chkVideoTypeFilter', this).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.VideoTypes || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-04 08:38:41 -07:00
query.VideoTypes = filters;
reloadItems(page);
});
2013-04-08 14:05:00 -07:00
2013-04-04 21:15:00 -07:00
$('#selectView', this).on('change', function () {
view = this.value;
reloadItems(page);
});
2013-04-04 08:38:41 -07:00
2013-04-07 06:34:46 -07:00
$('#chk3D', this).on('change', function () {
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-07 06:34:46 -07:00
query.VideoFormats = this.checked ? this.getAttribute('data-filter') : null;
reloadItems(page);
});
2013-04-08 14:05:00 -07:00
}).on('pagebeforeshow', "#moviesPage", function () {
reloadItems(this);
2013-04-08 14:05:00 -07:00
2013-04-01 20:28:20 -07:00
}).on('pageshow', "#moviesPage", function () {
// Reset form values using the last used query
$('.radioSortBy', this).each(function () {
this.checked = query.SortBy == this.getAttribute('data-sortby');
}).checkboxradio('refresh');
$('.radioSortOrder', this).each(function () {
this.checked = query.SortOrder == this.getAttribute('data-sortorder');
}).checkboxradio('refresh');
$('.chkStandardFilter', this).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
2013-04-04 08:38:41 -07:00
$('.chkVideoTypeFilter', this).each(function () {
var filters = "," + (query.VideoTypes || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
2013-04-06 11:59:21 -07:00
$('#selectView', this).val(view).selectmenu('refresh');
2013-04-08 14:05:00 -07:00
2013-04-07 06:34:46 -07:00
$('#chk3D', this).checked(query.VideoFormats == "Digital3D,Sbs3D").checkboxradio('refresh');
2013-04-01 20:28:20 -07:00
});
})(jQuery, document);