2015-04-19 08:54:20 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2015-05-12 21:55:19 -07:00
|
|
|
|
var view = LibraryBrowser.getDefaultItemsView('Poster', 'PosterCard');
|
2015-04-19 08:54:20 -07:00
|
|
|
|
|
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
|
|
|
|
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
|
|
|
|
return 'photos' + (query.ParentId || '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadItems(page) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
|
|
|
|
|
|
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
viewButton: false,
|
|
|
|
|
showLimit: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.listTopPaging', page).html(pagingHtml).trigger('create');
|
|
|
|
|
|
|
|
|
|
updateFilterControls(page);
|
|
|
|
|
|
2015-05-12 21:55:19 -07:00
|
|
|
|
if (AppInfo.hasLowImageBandwidth) {
|
|
|
|
|
if (view == 'Poster') {
|
|
|
|
|
view = 'PosterCard';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (view == "Poster") {
|
|
|
|
|
// Poster
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "auto",
|
|
|
|
|
context: getParameterByName('context') || 'photos',
|
|
|
|
|
showTitle: query.MediaTypes != 'Photo',
|
|
|
|
|
overlayText: true,
|
|
|
|
|
lazy: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
|
|
|
|
|
// Poster
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "auto",
|
|
|
|
|
context: getParameterByName('context') || 'photos',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showPremiereDate: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-04-19 08:54:20 -07:00
|
|
|
|
|
|
|
|
|
var elem = $('#items', page).html(html).lazyChildren();
|
|
|
|
|
|
|
|
|
|
$(pagingHtml).appendTo(elem).trigger('create');
|
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filtersLoaded;
|
|
|
|
|
function reloadFiltersIfNeeded(page) {
|
|
|
|
|
|
|
|
|
|
if (!filtersLoaded) {
|
|
|
|
|
|
|
|
|
|
filtersLoaded = true;
|
|
|
|
|
|
|
|
|
|
QueryFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () {
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setQueryPerContext(page) {
|
|
|
|
|
|
|
|
|
|
var context = getParameterByName('context');
|
|
|
|
|
|
|
|
|
|
$('.libraryViewNav a', page).removeClass('ui-btn-active');
|
|
|
|
|
|
|
|
|
|
if (context == 'photos-photos') {
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.MediaTypes = 'Photo';
|
|
|
|
|
$('.lnkPhotos', page).addClass('ui-btn-active');
|
|
|
|
|
}
|
|
|
|
|
else if (context == 'photos-videos') {
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.MediaTypes = 'Video';
|
|
|
|
|
$('.lnkVideos', page).addClass('ui-btn-active');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
query.Recursive = false;
|
|
|
|
|
query.MediaTypes = null;
|
|
|
|
|
$('.lnkPhotoAlbums', page).addClass('ui-btn-active');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.ParentId = getParameterByName('parentId') || LibraryMenu.getTopParentId();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
function startSlideshow(page, itemQuery, startItemId) {
|
2015-04-22 06:28:45 -07:00
|
|
|
|
|
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
var localQuery = $.extend({}, itemQuery);
|
2015-04-22 06:28:45 -07:00
|
|
|
|
localQuery.StartIndex = 0;
|
|
|
|
|
localQuery.Limit = null;
|
|
|
|
|
localQuery.MediaTypes = "Photo";
|
|
|
|
|
localQuery.Recursive = true;
|
|
|
|
|
localQuery.Filters = "IsNotFolder";
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(userId, localQuery).done(function (result) {
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
showSlideshow(page, result.Items, startItemId);
|
2015-04-22 06:28:45 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
function showSlideshow(page, items, startItemId) {
|
2015-04-22 06:28:45 -07:00
|
|
|
|
|
|
|
|
|
var slideshowItems = items.map(function (item) {
|
|
|
|
|
|
|
|
|
|
var imgUrl = ApiClient.getScaledImageUrl(item.Id, {
|
|
|
|
|
|
|
|
|
|
tag: item.ImageTags.Primary,
|
|
|
|
|
type: 'Primary'
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
title: item.Name,
|
|
|
|
|
href: imgUrl
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
var index = items.map(function (i) {
|
|
|
|
|
return i.Id;
|
|
|
|
|
|
|
|
|
|
}).indexOf(startItemId);
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.loadSwipebox().done(function () {
|
2015-04-22 06:28:45 -07:00
|
|
|
|
|
2015-05-08 20:48:43 -07:00
|
|
|
|
$.swipebox(slideshowItems, {
|
|
|
|
|
initialIndexOnArray: index,
|
|
|
|
|
hideBarsDelay: 30000
|
|
|
|
|
});
|
2015-04-22 06:28:45 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
function onListItemClick(e) {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
var info = LibraryBrowser.getListItemInfo(this);
|
|
|
|
|
|
|
|
|
|
if (info.mediaType == 'Photo') {
|
|
|
|
|
Photos.startSlideshow(page, query, info.id);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-19 08:54:20 -07:00
|
|
|
|
$(document).on('pageinit', "#photosPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.viewPanel', page).on('panelopen', function () {
|
|
|
|
|
|
|
|
|
|
reloadFiltersIfNeeded(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.radioSortBy', this).on('click', function () {
|
|
|
|
|
query.SortBy = this.getAttribute('data-sortby');
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.radioSortOrder', this).on('click', function () {
|
|
|
|
|
query.SortOrder = this.getAttribute('data-sortorder');
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
$(page).on('click', '.mediaItem', onListItemClick);
|
|
|
|
|
|
2015-04-19 08:54:20 -07:00
|
|
|
|
$('.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;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#radioBasicFilters', this).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
$('.basicFilters', page).show();
|
|
|
|
|
$('.advancedFilters', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.basicFilters', page).hide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#radioAdvancedFilters', this).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
$('.advancedFilters', page).show();
|
|
|
|
|
$('.basicFilters', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.advancedFilters', page).hide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#selectPageSize', page).on('change', function () {
|
|
|
|
|
query.Limit = parseInt(this.value);
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pagebeforeshow', "#photosPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
setQueryPerContext(page);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
QueryFilters.onPageShow(page, query);
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.getSavedViewSetting(viewKey).done(function (val) {
|
|
|
|
|
|
|
|
|
|
if (val) {
|
|
|
|
|
$('#selectView', page).val(val).selectmenu('refresh').trigger('change');
|
|
|
|
|
} else {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#photosPage", function () {
|
|
|
|
|
|
|
|
|
|
updateFilterControls(this);
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 21:29:04 -07:00
|
|
|
|
window.Photos = {
|
|
|
|
|
startSlideshow: startSlideshow
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-19 08:54:20 -07:00
|
|
|
|
})(jQuery, document);
|