%# $Id$

% use Mojo::Util qw(dumper);
% my $t = $c->app->tail;

% unless ($c->req->param('next')) {
%   layout 'default';
%   title 'Maacom';
    <h5 class="text-center"><%= $t->file %></h5>
    <div class="callout">
        <small><div id="log">
%          foreach my $line (@{$t->first}) {
              <%= $line %><br/>
%          }
        </div></small>
    </div>
    <div class="text-center">
        <div id="clear" class="button">Clear</div>
        <div id="pause" class="button">Pause</div>
    </div>

%   $c->session(pos => $t->pos);
    <script>
        function aTail () { 
            $.get("", { next : "yes" },
                    function (data) {
                        $("#log").append(data);
                        $('html,body').animate({
                                scrollTop: document.body.scrollHeight},
                                "slow"
                        );
            });
        };

        $("#clear").click(function() {
            $("#log").empty();
        });

        var tailRun = 1;
        var timerId = setInterval(function(){ aTail(); }, 2000);

        $("#pause").click(function() {
            if (tailRun == 1) {
                clearInterval(timerId);
                $("#pause").html("Pause");
                $("#pause").toggleClass("secondary");
                tailRun = 0;
            } else {
                timerId = setInterval(function() {aTail()}, 2000);
                $("#pause").html("Pause");
                $("#pause").toggleClass("secondary");
                tailRun = 1;
            }
        });
    </script>
% }

% if ($c->req->param('next')) {
%   $t->pos($c->session('pos'));
%   foreach my $line (@{$t->last}) {
        <%= $line %><br/>
%   }
%   $c->session(pos => $t->pos);
% }
%#EOF
