<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:t="http://www.participatorypolitics.org/"
      xmlns:i18n="http://www.participatoryculture.org/i18n"
      eventCookie="@@@eventCookie@@@" dtvPlatform="@@@dtvPlatform@@@">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <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[

filters.switchNewItemsChannel("library")
sorts.switchUnwatchedFirstChannel("library")

def searchFilter(x):
    return filters.matchingItems(x, app.controller.librarySearchTerm)

matchingItems = views.uniqueWatchableItems.filter(lambda x:searchFilter(x) and x.getFeedURL() != "dtv:singleFeed",sortFunc=sorts.itemSortLibrary.sort,resort=True)

def updateSearchString(newSearch):
    if len(newSearch) == 0:
        app.controller.librarySearchTerm = None
    else:
        app.controller.librarySearchTerm = newSearch
    views.uniqueWatchableItems.recomputeFilter(matchingItems)

def setSortBy(by, section, handle):
    sorts.itemSortLibrary.setSortBy(by)
    views.uniqueWatchableItems.recomputeSort(matchingItems)
    handle.forceUpdate()

]]>
    </t:execOnLoad>
    <t:execOnUnload><![CDATA[
matchingItems.unlink()
]]>
    </t:execOnUnload>
</head>

<body onkeydown="sendKeyToSearchBox(event);">

<!-- TITLE BAR ************************************************************ -->
<div id="main-titlebar">
    <div id="main-icon" class="noborder"><img src="resource:images/collection-icon.png" /></div>
    <h1 id="main-title" i18n:translate="">Library</h1>
    <div id="search-box-container">
        <div t:showIf="app.controller.librarySearchTerm is None">
            <input id="search-box" type="search" onfocus="onSearchFocus(this)" onblur="endEditSearch()" value="***_('Find')***" />
        </div>
        <div t:showIf="app.controller.librarySearchTerm is not None">
            <input id="search-box" type="search" onfocus="onSearchFocus(this)" onblur="endEditSearch()" value="***app.controller.librarySearchTerm***" searching="1"/>
        </div>
    </div>
</div>
<!-- / TITLE BAR -->

<div id="main-container">

    <!-- SORT BAR ************************************************************* -->
    <div t:updateForView="matchingItems">
        <div t:hideIf="matchingItems.len() == 0">
            <t:executeTemplate filename="static-tab-sort-bar" 
                    itemSort="sorts.itemSortLibrary"
                    section="'main'" />
        </div>
    </div>
    <!-- / SORT BAR -->
    <div id="main-unwatched">
	<!-- VIDEOS ************************************************** -->
        <div t:repeatForView="matchingItems" t:repeatTemplate='download-item' t:containerDiv="true" />
	<!-- / VIDEOS -->
    </div>
	
</div>

</body>
</html>
