var LibraryBrowser = (function (window, document, $, screen, localStorage) { var defaultBackground = "#333"; return { getDefaultPageSize: function () { var saved = localStorage.getItem('pagesize'); if (saved) { return parseInt(saved); } if (window.location.toString().toLowerCase().indexOf('localhost') != -1) { return 100; } return 20; }, loadSavedQueryValues: function (key, query) { //var values = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId()); //if (values) { // values = JSON.parse(values); // return $.extend(query, values); //} return query; }, saveQueryValues: function (key, query) { var values = {}; if (query.SortBy) { values.SortBy = query.SortBy; } if (query.SortOrder) { values.SortOrder = query.SortOrder; } localStorage.setItem(key + '_' + Dashboard.getCurrentUserId(), JSON.stringify(values)); }, saveViewSetting: function (key, value) { localStorage.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value); }, getSavedViewSetting: function (key) { var deferred = $.Deferred(); var val = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId() + '_view'); deferred.resolveWith(null, [val]); return deferred.promise(); }, getDateParamValue: function (date) { function formatDigit(i) { return i < 10 ? "0" + i : i; } var d = date; return "" + d.getFullYear() + formatDigit(d.getMonth() + 1) + formatDigit(d.getDate()) + formatDigit(d.getHours()) + formatDigit(d.getMinutes()) + formatDigit(d.getSeconds()); }, getPosterDetailViewHtml: function (options) { var items = options.items; var currentIndexValue; if (!options.shape) { options.shape = options.preferBackdrop ? "backdrop" : "poster"; } var html = ''; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; if (options.timeline) { var year = item.ProductionYear || "Unknown Year"; if (year != currentIndexValue) { html += '
' + LibraryBrowser.getRatingHtml(item) + '
'; } var childText = null; if (item.Type == "BoxSet") { childText = item.ChildCount == 1 ? "1 Movie" : item.ChildCount + " Movies"; html += '' + childText + '
'; } else if (item.Type == "GameSystem") { childText = item.ChildCount == 1 ? "1 Game" : item.ChildCount + " Games"; html += '' + childText + '
'; } else if (item.Type == "MusicAlbum") { //childText = item.ChildCount == 1 ? "1 Song" : item.ChildCount + " Songs"; //html += '' + childText + '
'; } else if (item.Type == "Genre" || item.Type == "Studio" || item.Type == "Person" || item.Type == "MusicArtist" || item.Type == "MusicGenre" || item.Type == "GameGenre") { var itemCountHtml = LibraryBrowser.getItemCountsHtml(options, item); if (itemCountHtml) { html += '' + itemCountHtml + '
'; } } else if (item.Type == "Game") { html += '' + (item.GameSystem) + '
'; } else if (item.Type == "Episode") { // Skip it. Just clutter } else { html += '' + LibraryBrowser.getMiscInfoHtml(item) + '
'; } if (item.Type == "MusicAlbum") { html += '' + LibraryBrowser.getMiscInfoHtml(item) + '
'; } html += '' + LibraryBrowser.getUserDataIconsHtml(item) + '
'; html += ''; var num = item.IndexNumber; if (num && item.ParentIndexNumber) { num = item.ParentIndexNumber + "." + num; } html += ' | ' + (num || "") + ' | '; html += '' + (item.Name || "") + ' | '; if (options.showAlbum) { if (item.Album && item.ParentId) { html += '' + item.Album + ' | '; } else { html += '' + (item.Album || '') + ' | '; } } if (options.showArtist) { if (item.Artists && item.Artists.length) { var artistLinksHtml = LibraryBrowser.getArtistLinksHtml(item.Artists); html += '' + artistLinksHtml + ' | '; } else { html += ''; } } if (options.showArtist) { if (item.AlbumArtist) { html += ' | ' + LibraryBrowser.getArtistLinksHtml([item.AlbumArtist]) + ' | '; } else { html += ''; } } var time = Dashboard.getDisplayTime(item.RunTimeTicks || 0); html += ' | ' + time + ' | '; html += '' + (item.UserData ? item.UserData.PlayCount : 0) + ' | '; html += '
'; html += name; html += '
'; } else if (!isSmallItem) { html += ''; html += LibraryBrowser.getMiscInfoHtml(item); html += '
'; } html += ''; html += ''; html += LibraryBrowser.getRatingHtml(item, false); html += ''; if (isPortrait) { html += ''; html += LibraryBrowser.getUserDataIconsHtml(item); html += ''; } else { html += ''; html += LibraryBrowser.getUserDataIconsHtml(item); html += ''; } html += '
'; //html += ''; //html += (item.OverviewHtml || item.Overview || ''); //html += '
'; html += '