## -*- coding: utf-8 -*-
<%inherit file="/base/base.html"/>

<%block name="title">
    ${_('Journal')}
</%block>

<%def name="breadcrumbs_links()">
    <form id="filter_form" class="pull-left form-inline input-group-sm">
        <input class="form-control q_filter_box ${'' if c.search_term else 'initial'}" id="j_filter" size="15" type="text" name="filter" value="${c.search_term or _('journal filter...')}"/>
        <span data-toggle="popover" data-content="${h.journal_filter_help()}">?</span>
        <input type='submit' value="${_('Filter')}" class="btn btn-default btn-xs"/>
        ${_('Journal')} - ${ungettext('%s Entry', '%s Entries', c.journal_pager.item_count) % (c.journal_pager.item_count)}
    </form>
</%def>

<%block name="header_menu">
    ${self.menu('journal')}
</%block>

<%block name="head_extra">
  <link href="${h.url('journal_atom', api_key=request.authuser.api_key)}" rel="alternate" title="${_('ATOM journal feed')}" type="application/atom+xml" />
  <link href="${h.url('journal_rss', api_key=request.authuser.api_key)}" rel="alternate" title="${_('RSS journal feed')}" type="application/rss+xml" />
</%block>

<%def name="main()">
    <div class="panel panel-primary">
        <div class="panel-heading clearfix">
            <div class="pull-left">
                ${self.breadcrumbs()}
            </div>
            <div class="pull-right panel-title">
                <a href="${h.url('my_account_watched')}"><i class="icon-eye"></i>${_('Watched Repositories')}</a>
                <a href="${h.url('my_account_repos')}"><i class="icon-database"></i>${_('My Repositories')}</a>
                <a id="refresh" href="${h.url('journal')}"><i class="icon-arrows-cw"></i></a>
                <a href="${h.url('journal_atom', api_key=request.authuser.api_key)}"><i class="icon-rss-squared"></i></a>
            </div>
        </div>
        <div id="journal" class="panel-body">
            <%include file='journal_data.html'/>
        </div>
    </div>

<script>
'use strict';

    $('#j_filter').click(function(){
        var $jfilter = $('#j_filter');
        if($jfilter.hasClass('initial')){
            $jfilter.val('');
        }
    });
    function fix_j_filter_width(len){
        $('#j_filter').css('width', Math.max(80, len*6.50)+'px');
    }
    $('#j_filter').keyup(function(){
        fix_j_filter_width($('#j_filter').val().length);
    });
    $('#filter_form').submit(function(e){
        e.preventDefault();
        var val = $('#j_filter').val();
        window.location = ${h.js(url.current(filter='__FILTER__'))}.replace('__FILTER__',val);
    });
    fix_j_filter_width($('#j_filter').val().length);

    $('#refresh').click(function(e){
        asynchtml(${h.js(h.url.current(filter=c.search_term))}, $("#journal"), function(){
            show_more_event();
            tooltip_activate();
            });
        e.preventDefault();
    });

</script>

<script>
    'use strict';
    $(document).ready(function(){
        var $journal = $('#journal');
        $journal.on('click','.pager_link',function(e){
            asynchtml(e.target.href, $journal, function(){
                show_more_event();
                tooltip_activate();
            });
            e.preventDefault();
        });
        $('#journal').on('click','.show_more',function(e){
            var el = e.target;
            $('#'+el.id.substring(1)).show();
            $(el.parentNode).hide();
        });
    });
</script>
</%def>
