<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      eventCookie="@@@eventCookie@@@" dtvPlatform="@@@dtvPlatform@@@">

<head>
    <base href="***feed.getBaseHref()***" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Democracy Channel View</title>

    <link href="resource:css/main.css" rel="stylesheet" type="text/css" />
    <t:include filename="dynamic.js" />
    <t:include filename="settings.js" />
    <script type="text/javascript" src="resource:templates/osxdnd.js" />
    <t:execOnLoad><![CDATA[
feed = views.feeds.getObjectByID(int(kargs['id']))
filters.switchNewItemsChannel(feed)
sorts.switchUnwatchedFirstChannel(feed)

def showDownloadsFilter(x):
    return showDownloads

def showWatchableFilter(x):
    return showWatchableItems

def showNewFilter(x):
    isNew = filters.newItems(x)
    # need to make call newItems() so that the filter remembers if the item
    # was flagged as new or not.
    return showNewItems and (allItemsMode or isNew)

def updateSearchString(newSearch):
    global searchTerm
    if len(newSearch) == 0:
        searchTerm = None
    else:
        searchTerm = newSearch
    allItems.recomputeFilters()

def toggleDownloadsView(handle):
    global showDownloads
    showDownloads = not showDownloads
    allDownloadingItems.recomputeFilter(downloadingItems)
    handle.forceUpdate()

def toggleWatchableView(handle):
    global showWatchableItems
    showWatchableItems = not showWatchableItems
    allWatchableItems.recomputeFilter(watchableItems)
    handle.forceUpdate()

def toggleNewItemsView(handle):
    global showNewItems
    showNewItems = not showNewItems
    matchingItems.recomputeFilter(newItems)
    handle.forceUpdate()

def toggleAllItemsMode(handle):
    global allItemsMode
    allItemsMode = not allItemsMode
    matchingItems.recomputeFilter(newItems)
    handle.forceUpdate()

global searchTerm, showDownloads, showWatchableItems, showNewItems, allItemsMode
searchTerm = None

# The main section
allItemsMode = False

# Initial states of views in this template
showDownloads = False
showNewItems = True
showWatchableItems = True

allItems = views.items.filterWithIndex(indexes.itemsByFeed, feed.getID())
matchingItems = allItems.filter(lambda x: filters.matchingItems(x, searchTerm), sortFunc=sorts.item)
newItems = matchingItems.filter(showNewFilter, sortFunc=sorts.item)

allDownloadingItems = matchingItems.filter(filters.downloadingItems,sortFunc=sorts.item)
downloadingItems = allDownloadingItems.filter(showDownloadsFilter,sortFunc=sorts.item)
allWatchableItems = matchingItems.filter(filters.watchableItems,sortFunc=sorts.itemsUnwatchedFirst)
watchableItems = allWatchableItems.filter(showWatchableFilter,sortFunc=sorts.itemsUnwatchedFirst)

thisFeedView = views.feeds.filter(lambda x: x is feed)

showNewItems = (len(watchableItems) == 0) or len(newItems) > 0

if len(newItems) == 0:
    allItemsMode = True
    matchingItems.recomputeFilter(newItems)

feed.updateIcons()
isFolder = False
]]>
    </t:execOnLoad>
    <t:execOnUnload><![CDATA[
matchingItems.unlink()
thisFeedView.unlink()
if feed.idExists():
    feed.markAsViewed()
]]>
    </t:execOnUnload>

</head>

<body onkeydown="sendKeyToSearchBox(event);">
<div id="feed-settings">
    <t:includeTemplate filename="feed-settings" />
</div>
    
<!-- TITLE BAR ************************************************************ -->
<div id="main-titlebar">
        <img id="main-icon" src="***feed.getThumbnail()***" alt=""/>
	<div id="main-titlebar-center">
	    <div t:updateForView="thisFeedView">
                <h1 id="main-title" t:replaceMarkup="feed.getTitle()" />
	    </div>
            <div id="main-subtitle">
                    <input id="search-box" type="search" placeholder="Search Channel" onfocus="startEditSearch(this, null)" onblur="endEditSearch()" />
            </div>
            <div t:updateForView="matchingItems">
            <div t:hideIf="searchTerm is None">
                <div class="white-button-left save-search-channel">
                <div class="white-button-right">
                <div class="white-button-middle">
                    <a href="#" onclick="return eventURL('action:addChannelSearchFeed?term=@@@searchTerm@@@&amp;id=@@@feed.getID()@@@');">Save This Search</a>
                </div>
                </div>
                </div>
            </div>
            </div>
        </div>
        <div id="main-titlebar-right">
            <a id="main-titlebar-recommend" href="mailto:?subject=@@@feed.getTitle()@@@&amp;body=%0D%0A%0D%0AYou should check out the Internet TV channel &quot;@@@feed.getTitle()@@@&quot;. If you don't have the Democracy Player, you can get it here:%0D%0A%0D%0Ahttp://www.getdemocracy.com/%0D%0A%0D%0AAnd then subscribe to this channel:%0D%0A%0D%0A@@@feed.getURL()@@@" i18n:translate="">Recommend</a>
            <a id="main-titlebar-settings" href="#"
                onclick="return showSettings();" i18n:translate="">Settings</a>
        <div id="main-titlebar-auto">
                <form name="setAuto">
                <input type="hidden" name="feed" value="@@@feed.getID()@@@" />
		<span id="auto-checkbox-container">
                <span t:showIf="feed.isAutoDownloadable()">
                        <input type="checkbox" name="automatic" id="automatic" value="1" checked="checked" onclick="setAutoDownloadableFeed();" />
                </span>
                <span t:hideIf="feed.isAutoDownloadable()">
                        <input type="checkbox" name="automatic" id="automatic" value="1"                   onclick="setAutoDownloadableFeed();" />
                </span>
		</span>
                <span id="auto-label" i18n:translate=""><label for="automatic">Auto Download</label></span>
                </form>          
        </div>
		
        </div>
</div>
<!-- / TITLE BAR -->
<!-- CHANNEL CONTAINER **************************************************** -->
<div id="main-container">
    <div class="main-container-scraping" t:showIf="feed.isScraped() and feed.isUpdating()" t:updateHideOnView="thisFeedView">
    <div class="scraping-indicator">
      <img align="left" src="resource:images/scraping-indicator-left.gif" />
      <img align="right" src="resource:images/scraping-indicator-right.gif" />
      <div class="scraping-content" i18n:translate="">Looking for videos 
      at this URL</div>
    </div>
    </div>
    <t:includeTemplate filename="channel-content" />
</div>
<!-- / CHANNEL ITEMS LIST -->

</body>
</html>
