(function ($, document, window) { var currentItem; function reload(page) { var id = getParameterByName('id'); Dashboard.showLoadingMsg(); ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) { if (item.IsFolder) { $('#fldRecursive', page).show(); } else { $('#fldRecursive', page).hide(); } $('#btnRefresh', page).button('enable'); $('#refreshLoading', page).hide(); currentItem = item; LibraryBrowser.renderName(item, $('.itemName', page), true); LibraryBrowser.renderParentName(item, $('.parentName', page)); setFieldVisibilities(page, item); fillItemInfo(page, item); Dashboard.hideLoadingMsg(); }); } function setFieldVisibilities(page, item) { if (item.Type == "Series" || item.Type == "Person") { $('#fldEndDate', page).show(); } else { $('#fldEndDate', page).hide(); } if (item.Type == "Movie" || item.MediaType == "Game" || item.MediaType == "Trailer" || item.Type == "MusicVideo") { $('#fldBudget', page).show(); $('#fldRevenue', page).show(); } else { $('#fldBudget', page).hide(); $('#fldRevenue', page).hide(); } if (item.MediaType == "Game") { $('#fldPlayers', page).show(); $('#fldGamesDb', page).show(); } else { $('#fldPlayers', page).hide(); $('#fldGamesDb', page).hide(); } if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicVideo") { $('#fldCriticRating', page).show(); $('#fldCriticRatingSummary', page).show(); $('#fldRottenTomatoes', page).show(); } else { $('#fldCriticRating', page).hide(); $('#fldCriticRatingSummary', page).hide(); $('#fldRottenTomatoes', page).hide(); } if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Person" || item.Type == "BoxSet") { $('#fldTmdb', page).show(); } else { $('#fldTmdb', page).hide(); } if (item.Type == "Series" || item.Type == "Season" || item.Type == "Episode") { $('#fldTvdb', page).show(); $('#fldTvCom', page).show(); } else { $('#fldTvdb', page).hide(); $('#fldTvCom', page).hide(); } if (item.Type == "Series") { $('#fldStatus', page).show(); $('#fldAirDays', page).show(); $('#fldAirTime', page).show(); } else { $('#fldStatus', page).hide(); $('#fldAirDays', page).hide(); $('#fldAirTime', page).hide(); } if (item.Type == "Audio") { $('#fldArtist', page).show(); $('#fldAlbum', page).show(); $('#fldAlbumArtist', page).show(); } else { $('#fldArtist', page).hide(); $('#fldAlbum', page).hide(); $('#fldAlbumArtist', page).hide(); } if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Person" || item.Type == "Series" || item.Type == "Season" || item.Type == "Episode" || item.Type == "MusicVideo") { $('#fldImdb', page).show(); } else { $('#fldImdb', page).hide(); } if (item.Type == "Audio" || item.Type == "Artist" || item.Type == "MusicArtist" || item.Type == "MusicAlbum") { $('#fldMusicBrainz', page).show(); } else { $('#fldMusicBrainz', page).hide(); } if (item.Type == "MusicAlbum") { $('#fldMusicBrainzReleaseGroupId', page).show(); } else { $('#fldMusicBrainzReleaseGroupId', page).hide(); } if (item.MediaType == "Video") { $('#fldOriginalAspectRatio', page).show(); } else { $('#fldOriginalAspectRatio', page).hide(); } if (item.Type == "Audio" || item.Type == "Episode" || item.Type == "Season") { $('#fldIndexNumber', page).show(); if (item.Type == "Episode") { $('#lblIndexNumber', page).html('Episode number'); } else if (item.Type == "Season") { $('#lblIndexNumber', page).html('Season number'); } else if (item.Type == "Audio") { $('#lblIndexNumber', page).html('Track number'); } else { $('#lblIndexNumber', page).html('Number'); } } else { $('#fldIndexNumber', page).hide(); } if (item.Type == "Audio" || item.Type == "Episode") { $('#fldParentIndexNumber', page).show(); if (item.Type == "Episode") { $('#lblParentIndexNumber', page).html('Season number'); } else if (item.Type == "Audio") { $('#lblParentIndexNumber', page).html('Disc number'); } else { $('#lblParentIndexNumber', page).html('Parent number'); } } else { $('#fldParentIndexNumber', page).hide(); } } function fillItemInfo(page, item) { ApiClient.getCultures().done(function (result) { var select = $('#selectLanguage', page); populateLanguages(result, select); select.val(item.Language || "").selectmenu('refresh'); }); ApiClient.getParentalRatings().done(function (result) { var select = $('#selectOfficialRating', page); populateRatings(result, select); select.val(item.OfficialRating || "").selectmenu('refresh'); select = $('#selectCustomRating', page); populateRatings(result, select); select.val(item.CustomRating || "").selectmenu('refresh'); }); var selectStatus = $('#selectStatus', page); populateStatus(selectStatus); selectStatus.val(item.Status || "").selectmenu('refresh'); populateListView($('#listAirDays', page), item.AirDays); populateListView($('#listGenres', page), item.Genres); populateListView($('#listStudios', page), item.Studios.map(function (element) { return element.Name || ''; })); populateListView($('#listTags', page), item.Tags); var enableInternetProviders = (item.EnableInternetProviders || false); $("#enableInternetProviders", page).attr('checked', enableInternetProviders).checkboxradio('refresh'); if (enableInternetProviders) { $('#providerSettingsContainer',page).show(); } else { $('#providerSettingsContainer',page).hide(); } populateInternetProviderSettings(page, item.LockedFields, item.LockedImages); $('#txtName', page).val(item.Name || ""); $('#txtOverview', page).val(item.Overview || ""); $('#txtSortName', page).val(item.SortName || ""); $('#txtDisplayMediaType', page).val(item.DisplayMediaType || ""); $('#txtCommunityRating', page).val(item.CommunityRating || ""); $('#txtHomePageUrl', page).val(item.HomePageUrl || ""); $('#txtBudget', page).val(item.Budget || ""); $('#txtRevenue', page).val(item.Revenue || ""); $('#txtCriticRating', page).val(item.CriticRating || ""); $('#txtCriticRatingSummary', page).val(item.CriticRatingSummary || ""); $('#txtIndexNumber', page).val(item.IndexNumber || ""); $('#txtParentIndexNumber', page).val(item.ParentIndexNumber || ""); $('#txtPlayers', page).val(item.Players || ""); $('#txtAlbum', page).val(item.Album || ""); $('#txtAlbumArtist', page).val(item.AlbumArtist || ""); var artists = item.Artists || []; $('#txtArtist', page).val(artists.join(',')); var date; if (item.PremiereDate) { try { date = parseISO8601Date(item.PremiereDate, { toLocal: true }); $('#txtPremiereDate', page).val(date.toISOString().slice(0, 10)); } catch (e) { $('#txtPremiereDate', page).val(''); } } else { $('#txtPremiereDate', page).val(''); } if (item.EndDate) { try { date = parseISO8601Date(item.EndDate, { toLocal: true }); $('#txtEndDate', page).val(date.toISOString().slice(0, 10)); } catch (e) { $('#txtEndDate', page).val(''); } } else { $('#txtEndDate', page).val(''); } $('#txtProductionYear', page).val(item.ProductionYear || ""); $('#txtAirTime', page).val(convertTo24HourFormat(item.AirTime || "")); $('#txtOriginalAspectRatio', page).val(item.AspectRatio || ""); var providerIds = item.ProviderIds || {}; $('#txtGamesDb', page).val(providerIds.Gamesdb || ""); $('#txtImdb', page).val(providerIds.Imdb || ""); $('#txtTmdb', page).val(providerIds.Tmdb || ""); $('#txtTvdb', page).val(providerIds.Tvdb || ""); $('#txtTvCom', page).val(providerIds.Tvcom || ""); $('#txtMusicBrainz', page).val(providerIds.Musicbrainz || ""); $('#txtMusicBrainzReleaseGroupId', page).val(item.MusicBrainzReleaseGroupId || ""); $('#txtRottenTomatoes', page).val(providerIds.RottenTomatoes || ""); } function convertTo24HourFormat(time) { if (time == "") return time; var match = time.match(/^(\d+):(\d+)(.*)$/); if (match) { var hours = Number(match[1]); var minutes = Number(match[2]); var ampm = $.trim(match[3]); ampm = ampm.toUpperCase(); if (ampm == "PM" && hours < 12) hours = hours + 12; if (ampm == "AM" && hours == 12) hours = 0; var sHours = hours.toString(); var sMinutes = minutes.toString(); if (hours < 10) sHours = "0" + sHours; if (minutes < 10) sMinutes = "0" + sMinutes; return sHours + ":" + sMinutes; } else { return time; } } function convertTo12HourFormat(time) { if (time == "") return time; var hours = Number(time.match(/^(\d+)/)[1]); var minutes = Number(time.match(/:(\d+)/)[1]); var ampm = "AM"; if (hours >= 12) { ampm = "PM"; hours = hours - 12; hours = hours == 0 ? 12 : hours; } hours = hours == 0 ? 12 : hours; var sHours = hours.toString(); var sMinutes = minutes.toString(); if (hours < 10) sHours = "0" + sHours; if (minutes < 10) sMinutes = "0" + sMinutes; return sHours + ":" + sMinutes + " " + ampm; } function populateLanguages(allCultures, select) { var html = ""; html += ""; for (var i = 0, length = allCultures.length; i < length; i++) { var culture = allCultures[i]; html += ""; } select.html(html).selectmenu("refresh"); } function populateRatings(allParentalRatings, select) { var html = ""; html += ""; var ratings = []; var i, length, rating; for (i = 0, length = allParentalRatings.length; i < length; i++) { rating = allParentalRatings[i]; ratings.push({ Name: rating.Name, Value: rating.Name }); } for (i = 0, length = ratings.length; i < length; i++) { rating = ratings[i]; html += ""; } select.html(html).selectmenu("refresh"); } function populateStatus(select) { var html = ""; html += ""; html += ""; html += ""; select.html(html).selectmenu("refresh"); } function populateListView(list, items, sortCallback) { items = items || new Array(); if (typeof(sortCallback) === 'undefined') { items.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); } else { items = sortCallback(items); } var html = ''; for (var i = 0; i < items.length; i++) { html += '