<form action="index.cgi?show=list" method="post" id="form">
<input type="hidden" name="show" value="list" />
<input type="hidden" id="do" name="do" value="" />

<div id="list">
    <table class="list" summary="[% gettext('Main torrents list') %]">
    <colgroup>
        <col width="1%"/>
        <col width="26px"/>
        <col width="47%"/>
        <col width="24px"/>
        <col width="24px"/>
        <col width="5%"/>
        <col width="10%"/>
        <col width="10%"/>
        <col width="5%"/>
        <col width="5%"/>
        <col width="5%"/>
        <col width="5%"/>
        <col width="5%"/>
    </colgroup>
    <thead>
        <tr>
            <th class="select">
                <input type="checkbox" class="all" id="all"
                    [% IF data.all == 'true' %]checked="checked"[% END %]
                    title="[% gettext('Select/Unselect all') %]"
                 />
            </th>
            <th class="img" abbr="[% gettext('St') %]"
                title="[% gettext('Status') %]"/>
            <th class="name" abbr="[% gettext('Nm') %]">
                [% gettext('Name') %]
            </th>
            <th class="custom" abbr="[% gettext('Cs') %]"
                title="[% gettext('Custom') %]"/>
            <th class="message" abbr="[% gettext('Msg') %]"
                title="[% gettext('Message') %]"/>
            <th class="num" abbr="[% gettext('Pr') %]">
                [% gettext('Priority') %]
            </th>
            <th class="size" abbr="[% gettext('Sz') %]">
                [% gettext('Size') %]
            </th>
            <th class="done" abbr="[% gettext('Dn') %]">
                [% gettext('Done') %]
            </th>
            <th class="status" abbr="[% gettext('St') %]">
                [% gettext('Status') %]
            </th>
            <th class="peers" abbr="[% gettext('Pe') %]">
                [% gettext('Peers') %]
            </th>
            <th class="down_speed" abbr="[% gettext('DS') %]">
                [% gettext('Down Speed') %]
            </th>
            <th class="up_speed" abbr="[% gettext('US') %]">
                [% gettext('Up Speed') %]
            </th>
            <th class="rate" abbr="[% gettext('Rt') %]">
                [% gettext('Rate') %]
            </th>
        </tr>
    </thead>

    <tbody>
    [% FOR torrent = data.list.list %]
        [%
            SET class = [];
            IF loop.index % 2; class.push('odd'); ELSE; class.push('even'); END;
            IF data.current == torrent.hash; class.push('selected'); END;
            UNLESS torrent.is_active; class.push('inactive'); END;
        %]
            <tr class="[% class.join(' ') %]">
                <td class="select">
                    <input
                        [% IF data.hash.${torrent.hash} %]
                            checked="checked"
                        [% END %]
                        type="checkbox"
                        name="hash[]"
                        value="[% torrent.hash %]"/>
                </td>
                <td class="img">
                    [% IF torrent.hashing %]<div class="img hashing"/>
                    [% ELSIF torrent.complete %]
                        [% IF torrent.is_active %]<div class="img seeding"/>
                        [% ELSE %]
                            [% IF torrent.state %]
                                <div class="img seeding paused"/>
                            [% ELSE %]
                                <div class="img seeding stoped"/>
                            [% END %]
                        [% END %]
                    [% ELSE %]
                        [% IF torrent.is_active %]<div class="img downloading"/>
                        [% ELSE %]
                            [% IF torrent.state %]
                                <div class="img downloading paused"/>
                            [% ELSE %]
                                <div class="img downloading stoped"/>
                            [% END %]
                        [% END %]
                    [% END %]
                </td>
                <td class="name">[% torrent.name %]</td>
                [%
                    SET message     = [];
                    SET max_custom  = data.list.list.0.custom_count || 5;
                    SET customs     = [ 1.. max_custom];
                    FOR num IN customs;
                        SET c = 'custom' _ num;
                        IF torrent.${c};
                            message.push(gettext('Custom') _ ' ' _ num _ ': ' _
                                torrent.${c});
                        END;
                    END;
                    SET class = ['custom'];
                    class.push('has_custom') IF message.size;
                %]
                <td class="[% class.join(' ')%]"
                    title='[% message.join("\n") | html %]'/>
                <td
                    [%
                        SET class = ['message'];
                        IF torrent.message; class.push('warning'); END;
                    %]
                    class="[% class.join(' ') %]"
                    [% IF torrent.message %]
                        title="[% torrent.message | html %]"
                    [% END %]
                />
                <td class="num info">[% gettext(torrent.priority_str) %]</td>
                <td class="size digit">
                    [% torrent.size_bytes.as_human_size %]
                    <span class="data">[% torrent.size_bytes %]</span>
                </td>
                <td class="done info">
                    [% torrent.percent %]
                    <div class="indicator">
                        <div class="percent"
                            style="width: [% torrent.percent %];" />
                    </div>
                </td>
                <td class="status info">
                    [%
                        IF torrent.hashing;         gettext('Hashing');
                        ELSIF torrent.complete;
                            IF torrent.is_active;   gettext('Seeding');
                            ELSE;                   gettext('Finished');
                            END;
                        ELSE;
                            IF torrent.is_active;   gettext('Downloading');
                            ELSE;
                                IF torrent.state;
                                    gettext('Paused');
                                ELSE;
                                    gettext('Stoped');
                                END;
                            END;
                        END;
                    %]
                </td>
                <td class="peers digit">[% torrent.peers_connected %]</td>
                <td class="down_speed digit">
                    [% torrent.down_rate.as_human_speed %]
                    <span class="data">[% torrent.down_rate %]</span>
                </td>
                <td class="up_speed digit">
                    [% torrent.up_rate.as_human_speed %]
                    <span class="data">[% torrent.up_rate %]</span>
                </td>
                [% SET class = ['rate', 'digit'] %]
                [% IF torrent.ratio >= 1.0; class.push('positive');
                   ELSE; class.push('negative');
                   END %]
                <td class="[% class.join(' ') %]">
                    [% torrent.ratio %]
                </td>
            </tr>
    [% END %]
    </tbody>
    </table>
</div>

</form>
