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

183 lines
4.9 KiB
JavaScript
Raw Normal View History

(function ($, document) {
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,
Fields: "PrimaryImageAspectRatio"
};
function getTableHtml(items) {
2013-04-01 21:25:58 -07:00
var html = '<div class="libraryItemsGridContainer"><table data-role="table" data-mode="reflow" class="ui-responsive table-stroke 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-01 20:28:20 -07:00
html += '<th>Name</th>';
html += '<th>Year</th>';
html += '<th>Official Rating</th>';
html += '<th>Runtime</th>';
2013-04-01 21:25:58 -07:00
html += '<th>Community Rating</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-01 21:25:58 -07:00
html += '</table></div>';
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;
var imageTags = item.ImageTags;
html += '<a href="' + url + '">';
if (imageTags.Primary) {
html += '<img class="libraryGridImage" src="' + ApiClient.getImageUrl(item.Id, {
type: "Primary",
height: 150,
tag: item.ImageTags.Primary
}) + '" />';
}
else {
2013-04-01 22:14:37 -07:00
html += '<img class="libraryGridImage" style="background:' + LibraryBrowser.getMetroColor(item.Id) + ';" src="css/images/items/list/collection.png" />';
2013-04-01 21:25:58 -07:00
}
html += '</a></td>';
html += '<td><a href="' + url + '">' + item.Name + '</a></td>';
2013-04-01 20:28:20 -07:00
html += '<td>' + (item.ProductionYear || "") + '</td>';
html += '<td>' + (item.OfficialRating || "") + '</td>';
2013-04-01 21:25:58 -07:00
html += '<td>' + (item.RunTimeTicks || "") + '</td>';
html += '<td>' + (item.CommunityRating || "") + '</td>';
2013-04-01 20:28:20 -07:00
html += '</tr>';
return html;
}
function reloadItems(page) {
Dashboard.showLoadingMsg();
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
2013-04-01 22:14:37 -07:00
$('#items', page).html(LibraryBrowser.getPosterViewHtml({
2013-04-01 20:28:20 -07:00
items: result.Items,
useAverageAspectRatio: true
2013-04-01 21:25:58 -07:00
}))/*.html(getTableHtml(result.Items)).trigger('create')*/;
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 () {
query.SortBy = this.getAttribute('data-sortby');
reloadItems(page);
});
$('.radioSortOrder', this).on('click', function () {
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;
}
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;
}
query.VideoTypes = filters;
reloadItems(page);
});
2013-04-01 20:28:20 -07:00
}).on('pageshow', "#moviesPage", function () {
reloadItems(this);
// 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-01 20:28:20 -07:00
});
})(jQuery, document);