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

319 lines
9.9 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2013-04-04 21:15:00 -07:00
var view = "Poster";
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-08 14:05:00 -07:00
Fields: "PrimaryImageAspectRatio,UserData,DisplayMediaType",
Limit: 100,
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
var userData = item.UserData || {};
if (userData.Played) {
html += '<img class="imgUserItemRating" src="css/images/userdata/played.png" alt="Played" title="Played" />';
} else {
html += '<img class="imgUserItemRating" src="css/images/userdata/unplayed.png" alt="Played" title="Played" />';
}
if (typeof userData.Likes == "undefined") {
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_down_off.png" alt="Dislike" title="Dislike" />';
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_up_off.png" alt="Like" title="Like" />';
} else if (userData.Likes) {
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_down_off.png" alt="Dislike" title="Dislike" />';
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_up_on.png" alt="Liked" title="Like" />';
} else {
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_down_on.png" alt="Dislike" title="Dislike" />';
html += '<img class="imgUserItemRating" src="css/images/userdata/thumbs_up_off.png" alt="Like" title="Like" />';
}
if (userData.IsFavorite) {
html += '<img class="imgUserItemRating" src="css/images/userdata/heart_on.png" alt="Favorite" title="Favorite" />';
} else {
html += '<img class="imgUserItemRating" src="css/images/userdata/heart_off.png" alt="Favorite" title="Favorite" />';
}
html += '</td>';
2013-04-01 20:28:20 -07:00
html += '</tr>';
return html;
}
2013-04-08 14:05:00 -07:00
function getPagingHtml(result) {
var html = '';
var pageCount = Math.round(result.TotalRecordCount / query.Limit);
var pageNumber = (query.StartIndex / query.Limit) + 1;
var dropdownHtml = '<select data-enhance="false" data-role="none">';
for (var i = 1; i <= pageCount; i++) {
if (i == pageNumber) {
dropdownHtml += '<option value="' + i + '" selected="selected">' + i + '</option>';
} else {
dropdownHtml += '<option value="' + i + '">' + i + '</option>';
}
}
dropdownHtml += '</select>';
html += '<div class="listPaging">';
html += 'Results ' + (query.StartIndex + 1) + '-' + (query.StartIndex + query.Limit) + ' of ' + result.TotalRecordCount + ', page ' + dropdownHtml + ' of ' + pageCount;
html += '</div>';
return html;
}
2013-04-01 20:28:20 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
2013-04-08 14:05:00 -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) {
html += getPagingHtml(result);
}
2013-04-04 21:15:00 -07:00
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) {
html += getPagingHtml(result);
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');
$('select', elem).on('change', function() {
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);