define(["datetime", "itemHelper", "css!./indicators.css", "material-icons"], function(datetime, itemHelper) { "use strict"; function enableProgressIndicator(item) { return "Video" === item.MediaType && "TvChannel" !== item.Type || ("AudioBook" === item.Type || "AudioPodcast" === item.Type) } function getProgressHtml(pct, options) { var containerClass = "itemProgressBar"; return options && options.containerClass && (containerClass += " " + options.containerClass), '
' } function getAutoTimeProgressHtml(pct, options, isRecording, start, end) { var containerClass = "itemProgressBar"; options && options.containerClass && (containerClass += " " + options.containerClass); var foregroundClass = "itemProgressBarForeground"; return isRecording && (foregroundClass += " itemProgressBarForeground-recording"), '
' } function getProgressBarHtml(item, options) { var pct; if (enableProgressIndicator(item) && "Recording" !== item.Type) { var userData = options ? options.userData || item.UserData : item.UserData; if (userData && (pct = userData.PlayedPercentage) && pct < 100) return getProgressHtml(pct, options) } if (("Program" === item.Type || "Timer" === item.Type || "Recording" === item.Type) && item.StartDate && item.EndDate) { var startDate = 0, endDate = 1; try { startDate = datetime.parseISO8601Date(item.StartDate).getTime() } catch (err) {} try { endDate = datetime.parseISO8601Date(item.EndDate).getTime() } catch (err) {} if ((pct = ((new Date).getTime() - startDate) / (endDate - startDate) * 100) > 0 && pct < 100) { return getAutoTimeProgressHtml(pct, options, "Timer" === item.Type || "Recording" === item.Type || item.TimerId, startDate, endDate) } } return "" } function enablePlayedIndicator(item) { return itemHelper.canMarkPlayed(item) } function getPlayedIndicator(item) { if (enablePlayedIndicator(item)) { var userData = item.UserData || {}; if (userData.UnplayedItemCount) return '
' + userData.UnplayedItemCount + "
"; if (userData.PlayedPercentage && userData.PlayedPercentage >= 100 || userData.Played) return '
' } return "" } function getCountIndicatorHtml(count) { return '
' + count + "
" } function getChildCountIndicatorHtml(item, options) { var minCount = 0; return options && (minCount = options.minCount || minCount), item.ChildCount && item.ChildCount > minCount ? getCountIndicatorHtml(item.ChildCount) : "" } function getTimerIndicator(item) { var status; if ("SeriesTimer" === item.Type) return ''; if (item.TimerId || item.SeriesTimerId) status = item.Status || "Cancelled"; else { if ("Timer" !== item.Type) return ""; status = item.Status } return item.SeriesTimerId ? "Cancelled" !== status ? '' : '' : '' } function getSyncIndicator(item) { return 100 === item.SyncPercent ? '
' : null != item.SyncPercent ? '
' : "" } function getTypeIndicator(item) { return "Video" === item.Type ? '
' : "Folder" === item.Type || "PhotoAlbum" === item.Type ? '
' : "Photo" === item.Type ? '
' : "" } function getMissingIndicator(item) { if ("Episode" === item.Type && "Virtual" === item.LocationType) { if (item.PremiereDate) try { if (datetime.parseISO8601Date(item.PremiereDate).getTime() > (new Date).getTime()) return '
Unaired
' } catch (err) {} return '
Missing
' } return "" } function onAutoTimeProgress() { var start = parseInt(this.getAttribute("data-starttime")), end = parseInt(this.getAttribute("data-endtime")), now = (new Date).getTime(), total = end - start, pct = (now - start) / total * 100; pct = Math.min(100, pct), pct = Math.max(0, pct), this.querySelector(".itemProgressBarForeground").style.width = pct + "%" } var ProgressBarPrototype = Object.create(HTMLDivElement.prototype); return ProgressBarPrototype.attachedCallback = function() { this.timeInterval && clearInterval(this.timeInterval), "time" === this.getAttribute("data-automode") && (this.timeInterval = setInterval(onAutoTimeProgress.bind(this), 6e4)) }, ProgressBarPrototype.detachedCallback = function() { this.timeInterval && (clearInterval(this.timeInterval), this.timeInterval = null) }, document.registerElement("emby-progressbar", { prototype: ProgressBarPrototype, extends: "div" }), { getProgressBarHtml: getProgressBarHtml, getPlayedIndicatorHtml: getPlayedIndicator, getChildCountIndicatorHtml: getChildCountIndicatorHtml, enableProgressIndicator: enableProgressIndicator, getTimerIndicator: getTimerIndicator, enablePlayedIndicator: enablePlayedIndicator, getSyncIndicator: getSyncIndicator, getTypeIndicator: getTypeIndicator, getMissingIndicator: getMissingIndicator } });