<!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[
#print templateState
global feed, searchTerm, showDownloads, showWatchableItems, showNewItems, allItemsMode, allItems, watchableItems, matchingItems, newItems

def _setFeed(kargs):
    global feed, allItemsMode, showDownloads, showNewItems, showWatchableItems, searchTerm

    searchTerm = None

    # The main section
    allItemsMode = False
    
    # Initial states of views in this template
    showDownloads = False
    showNewItems = True
    showWatchableItems = True

    feed = views.feeds.getObjectByID(int(kargs['id']))
    filters.switchNewItemsChannel(feed)
    sorts.switchUnwatchedFirstChannel(feed)

def _updateView ():
    global showNewItems, allItemsMode

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

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

    feed.updateIcons()

def _reInit(*args, **kargs):
    global feed, allItems, showDownloads, showWatchableItems, showNewItems, allItemsMode, watchableItems, matchingItems, newItems

    if feed.idExists():
        feed.markAsViewed()

    #print "reinitting %s" % repr(kargs)
    _setFeed(kargs)

    allItems.changeIndexValue(indexes.itemsByFeed, int(kargs['id']))
    views.feeds.recomputeFilter(thisFeedView)

    _updateView()

reInit = lambda *args, **kargs: _reInit(*args, **kargs)

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()

_setFeed(kargs)

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)

_updateView()

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

</head>

<body onkeydown="sendKeyToSearchBox(event);">
<div id="feed-settings">
  <div t:updateForView="thisFeedView">
    <t:includeTemplate filename="feed-settings" />
  </div>
</div>
    
<!-- TITLE BAR ************************************************************ -->

<div id="main-titlebar">
        <div t:updateForView="thisFeedView">
          <img id="main-icon" src="***feed.getThumbnail()***" alt=""/>
        </div>
	<div id="main-titlebar-center">
	    <div t:updateForView="thisFeedView">
                <h1 id="main-title" t:replaceMarkup="feed.getTitle()" />
                <div id="main-subtitle" >
                  <input id="search-box" type="search" onfocus="onSearchFocus(this)" onblur="endEditSearch()" value="***_('Search Channel')***"/>
                </div>
	    </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 Search</a>
                </div>
                </div>
                </div>
            </div>
            </div>
        </div>
        <div id="main-titlebar-right">
            <a id="main-titlebar-recommend" href="#" onclick="return recommendChannel('@@@feed.getTitle()@@@', '@@@feed.getURL()@@@');" i18n:translate="">Recommend</a>
            <a id="main-titlebar-settings" href="#"
                onclick="return showSettings();" i18n:translate="">Settings</a>
        <div id="main-titlebar-auto">
           <div t:updateForView="thisFeedView">
                <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>
</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>
    <div class="hide-channel-title">
        <t:includeTemplate filename="channel-content" />
    </div>
</div>
<!-- / CHANNEL ITEMS LIST -->

</body>
</html>
