{{define "title"}}{{call $.T "home"}}{{end}}
{{define "contclass"}}cont-home{{end}}
{{define "content"}}
      <!-- Contain the table within a grid, as for better sizing -->
      <div class="results box">
          <table>
          <thead class="torrent-info">
          <tr>
              {{ if HasAdmin $.User }}
              <th class="tr-cb"><input type="checkbox" name="select_all" onchange="TorrentsMod.selectAll(this.checked)"></th>
              {{end}}
              <th class="tr-cat">{{call $.T "category"}}</th>
              <th class="tr-name">
                <a href="{{ genSearchWithOrdering .URL "1" }}">{{call $.T "name"}}<span class="sort-arrows">{{ genSortArrows .URL "1" }}</span></a>
              </th>
              <th class="tr-cs"></th>
              <th class="tr-links"></th>
              <th class="tr-size hide-xs"><a href="{{ genSearchWithOrdering .URL "4" }}">{{call $.T "size"}}<span class="sort-arrows">{{ genSortArrows .URL "4" }}</span></a></th>

              <th class="tr-se hide-xs">
                <a href="{{ genSearchWithOrdering .URL "5" }}">{{call $.T "S"}}<span class="sort-arrows">{{ genSortArrows .URL "5" }}</span></a>
              </th>
              <th class="tr-le hide-xs">
                <a href="{{ genSearchWithOrdering .URL "6" }}">{{call $.T "L"}}<span class="sort-arrows">{{ genSortArrows .URL "6" }}</span></a>
              </th>
              <th class="tr-dl hide-xs">
                <a href="{{ genSearchWithOrdering .URL "7" }}">{{call $.T "D"}}<span class="sort-arrows">{{ genSortArrows .URL "7" }}</span></a>
              </th>
              <!-- <th><span class="glyphicon glyphicon-comment"></span></th> -->
              <th class="tr-date hide-xs"><a href="{{ genSearchWithOrdering .URL "2" }}">{{call $.T "date"}}<span class="sort-arrows">{{ genSortArrows .URL "2" }}</span></a></th>
          </tr>
          </thead>
          <tbody>
          {{ range .Models}}
          <tr id="torrent_{{ .ID }}" class="torrent-info
              {{if eq .Status 2}}remake{{end}}
              {{if eq .Status 3}}trusted{{end}}
              {{if eq .Status 4}}aplus{{end}}" >
                {{ if HasAdmin $.User }}
              <td class="tr-cb">
                <input data-name="{{ .Name }}" type="checkbox" id="torrent_cb_{{ .ID }}" name="torrent_id" value="{{ .ID }}">
              </td>
                {{ end }}
              <td class="tr-cat home-td">
                  <a href="{{$.URL.Parse (printf "/search?c=%s_%s" .Category .SubCategory) }}">
                      {{ if Sukebei }}
                      <img alt="{{ call $.T (CategoryName .Category .SubCategory) }}" src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (CategoryName .Category .SubCategory) }}">
                      {{ else }}
                      <img alt="{{ call $.T (CategoryName .Category .SubCategory) }}" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (CategoryName .Category .SubCategory) }}">
                      {{ end}}
                  </a>
              </td>
              <td class="tr-name home-td">
                  <a href="{{genRoute "view_torrent" "id" ( print .ID ) }}">
                      {{.Name}}
                  </a>
              </td>
              <td class="tr-cs home-td">
              {{ if gt (len .Comments) 0 }}
                  <span>{{len .Comments}}</span>
              {{end}}
              </td>
              <td class="tr-links home-td">
                  <a href="{{.Magnet}}" title="{{ call $.T "magnet_link" }}">
                      <div class="magnet-icon"></div>
                  </a>
                  {{if ne .TorrentLink ""}}
                  <a href="{{.TorrentLink}}" title="{{ call $.T "torrent_file" }}">
                      <div class="download-icon"></div>
                  </a>
                  {{end}}
              </td>
              <td class="tr-size home-td hide-xs">
                  {{ fileSize .Filesize $.T }}
              </td>
              {{if .LastScrape.IsZero}}
              <td class="home-td hide-xs" colspan="3">{{call $.T "unknown"}}</td>
              {{else}}
              <td class="tr-se home-td hide-xs">{{.Seeders}}</td>
              <td class="tr-le home-td hide-xs">{{.Leechers}}</td>
              <td class="tr-dl home-td hide-xs">{{.Completed}}</td>
              {{end}}
              <td class="tr-date home-td date-short hide-xs">{{.Date}}</td>
          </tr>
          {{end}}
          </tbody>
      </table>
    </div>
    {{ if HasAdmin $.User }}
    <div class="modtools">
        <button id="show_actions" data-toggle-text="{{call $.T "hide_mod_tools"}}">{{call $.T "show_mod_tools"}}</button>
        <span class="actions">
            <span class="btn-group">
                <select class="cb_action" name="category_id">
                    <option value="">{{call $.T "category"}}</option>
                    {{ range $name_cat, $id_cat := (GetCategories true) }}
                    <option value="{{ $id_cat }}">{{call $.T $name_cat }}</option>
                    {{ end }}
                </select>
                <input class="cb_action" type="text" name="owner_id" placeholder="{{ call $.T "owner_id_placeholder" }}">
                <select class="cb_action" name="status_id">
                    <option value="">{{call $.T "torrent_status"}}</option>
                    <option value="5">{{ call $.T "torrent_status_blocked" }}</option>
                    <option value="1">{{call $.T "torrent_status_normal"}}</option>
                    <option value="2" >{{call $.T "torrent_status_remake"}}</option>
                    <option value="3">{{call $.T "trusted"}}</option>
                    <option value="4">A+</option>
                </select>
                <button class="cb_action" id="edit">{{ call $.T "edit" }}</button>
            </span>
            <span class="btn-group">
                <button class="cb_action" id="lock_delete">{{ call $.T "lock_delete" }}</button>
                <button class="cb_action" id="delete">{{ call $.T "delete" }}</button>
            </span>
            <span class="btn-group">
                <button class="cb_submit" id="modal_active">{{ call $.T "save_changes" }}</button>
            </span>
        </span>
    </div>
    <!-- Modal -->
    <div id="modal_mod_tools" class="modal">
        <!-- Modal content -->
        <div class="modal-content">
            <div class="modal-header">
                <span class="close">&times;</span>
                <h2>{{ call $.T "following_changes_applied" }}</h2>
            </div>
            <div class="modal-body">
                <h3>{{ call $.T "changes_in_following_order" }}</h3>
                <div class="progress-bar" id="progress_modtool" style="display: none;"><div class="progress-green"></div></div>
                <hr>
                <div class="logs_mess" style="display: none;"></div>
                <h2>{{ call $.T "edit_changes" }}</h2>
                <div class="edit_changes"></div>
                <h2>{{ call $.T "delete_changes" }}</h2>
                <div class="delete_changes"></div>
            </div>
            <div class="modal-footer">
                <span><button id="confirm_changes" onclick="TorrentsMod.ApplyChanges();">{{ call $.T "yes"}}</button>
                <button class="close" onclick="Modal.CloseActive();">{{ call $.T "no"}}</button></span>
                <h3>{{ call $.T "are_you_sure" }} </h3>
            </div>
        </div>
    </div>
    {{end}}
{{end}}
{{ define "footer_js"}}
<script type="text/javascript" src="{{ $.URL.Parse "/js/template.js" }}"></script>
<script type="text/javascript" src="{{ $.URL.Parse "/js/query.js" }}"></script>
<script type="text/javascript" src="{{ $.URL.Parse "/js/modal.js" }}"></script>
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrents.js" }}"></script>
{{ if HasAdmin $.User }}
<script type="text/javascript" src="{{ $.URL.Parse "/js/translation.js" }}"></script>
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrentsMod.js" }}"></script>
    <script type="text/javascript">
    // We add translations string
        T.Add({
            try_new_attempt: "{{ call $.T "try_new_attempt" }}",
            query_is_broken: "{{ call $.T "query_is_broken" }}",
            query_executed_success: "{{ call $.T "query_executed_success" }}",
            all_operations_done: "{{ call $.T "all_operations_done" }}",
            refreshing_in: "{{ call $.T "refreshing_in" }}",
            delete_reports_with_torrents: "{{ call $.T "delete_reports_with_torrents" }}",
            with_st: "{{ call $.T "with_st" }}",
            and_reports: "{{ call $.T "and_reports" }}",
            reports: "{{ call $.T "reports" }}",
            lock: "{{ call $.T "lock" }}",
            status_js: "{{ call $.T "status_js" }}",
            owner_id_js: "{{ call $.T "owner_id_js" }}",
            category_js: "{{ call $.T "category_js" }}",
            no_changes: "{{ call $.T "no_changes" }}",
            query_nb: "{{ call $.T "query_nb" }}"
        });
    // Modal initialization
        Modal.Init({elements: document.getElementsByClassName("modal"),
            button: "#modal_active",
            before: function() {
                TorrentsMod.generatingModal();
            },
            close: function() {
                TorrentsMod.resetModal();
            }
        });
    // Templates initialization
        Templates.Add("torrents.delete.item", function(torrent) {
            return '<div class="delete_item" id="list_item_'+torrent.id+'"><span>'+Templates.EncodeEntities(torrent.name)+'</span>'+
            '<a href="#" onclick="return TorrentsMod.RemoveItemFromQueue('+torrent.key+', '+torrent.id+')"><i class="trash-icon"></i></a></div>'
        });
        Templates.Add("torrents.delete.block", function(torrentQuery){
            return '<div class="delete_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
            '<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">'+T.r("query_nb", torrentQuery.unique_id)+
            '</h3>'+
            '<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
            '</span></div>'+
            '<div class="list">'+torrentQuery.list+'</div></div>';
        });
        Templates.Add("torrents.edit.item", function(torrent) {
            return '<div class="edit_item" id="list_item_'+torrent.id+'"><span>'+Templates.EncodeEntities(torrent.name)+'</span>'+
            '<a href="#" onclick="return TorrentsMod.RemoveItemFromQueue('+torrent.key+', '+torrent.id+')"><i class="trash-icon"></i></a></div>'
        });
        Templates.Add("torrents.edit.block", function(torrentQuery){
            return '<div class="edit_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
            '<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">'+T.r("query_nb", torrentQuery.unique_id)+
            '</h3>'+
            '<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
            '</span></div>'+
            '<div class="list">'+torrentQuery.list+'</div></div>';
        });
        Templates.Add("torrents.logs.error", function(msg) {
            return '<div class="error">'+msg+'</div>';
        });
        Templates.Add("torrents.logs.success", function(msg) {
            return '<div class="success">'+msg+'</div>';
        });
        </script>
{{end}}
<!-- JS Template for torrents ajax -->
    <script type="text/javascript">
        Templates.Add("torrents.item", function(torrent) {
            return "<tr id=\"torrent_" + torrent.id + "\" class=\"torrent-info"+ ((torrent.status == 2) ? " remake" : ((torrent.status == 3) ? " trusted" : ((torrent.status == 3) ? " aplus" : "" )))+"\">"+
            {{ if HasAdmin $.User }}
              "<td class=\"tr-cb\""+ ((TorrentsMod.enabled) ? "style=\"display:table-cell;\"" : "") +">"+
                "<input data-name=\""+Templates.EncodeEntities(torrent.name)+"\" type=\"checkbox\" id=\"torrent_cb_"+torrent.id+"\" name=\"torrent_id\" value=\""+torrent.id+"\">"+
              "</td>"+
            {{ end }}
              "<td class=\"tr-cat home-td\">"+
                  "<a href=\"{{$.URL.Parse "/search?c=" }}"+ torrent.category + "_" + torrent.sub_category +"\">"+
                      {{ if Sukebei }}
                      "<img src=\"{{ $.URL.Parse "/img/torrents/sukebei/" }}"+ torrent.category + torrent.sub_category+".png\" title=\""+ torrent.CategoryName +"\">"+
                      {{ else }}
                      "<img src=\"{{ $.URL.Parse "/img/torrents/" }}"+ torrent.sub_category +".png\" title=\""+ torrent.CategoryName +"\">"+
                      {{ end }}
                  "</a>"+
              "</td>"+
              "<td class=\"tr-name home-td\"><a href=\"/view/"+torrent.id+"\">"+Templates.EncodeEntities(torrent.name) +"</a></td>"+
              "<td class=\"tr-cs home-td hide-xs\">"+
              ((torrent.comments.length > 0) ? "<i class=\"comment-icon\" title=\"{{ call $.T "comments" }}\">" + torrent.comments.length + "</i>" : "")+
              "</td>"+
              "<td class=\"tr-links home-td\">"+
                  "<a href=\""+torrent.magnet +"\" title=\"{{ call $.T "magnet_link" }}\">"+
                      "<div class=\"magnet-icon\"></div>"+
                  "</a>"+(torrent.torrent != "" ? " <a href=\""+torrent.torrent+"\" title=\"{{ call $.T "torrent_file" }}\"><div class=\"download-icon\"></div></a>" : "") +
              "</td>"+
              "<td class=\"tr-size home-td hide-xs\">"+humanFileSize(torrent.filesize)+"</td>"+
              "<td class=\"tr-se home-td hide-xs\">"+torrent.seeders+"</td>"+
              "<td class=\"tr-le home-td hide-xs\">"+torrent.leechers+"</td>"+
              "<td class=\"tr-dl home-td hide-xs\">"+torrent.completed+"</td>"+
              "<td class=\"tr-date home-td date-short hide-xs\">"+torrent.date+"</td>"+
          "</tr>";
        });
        Torrents.LastID = {{ lastID .URL .Models }};
        if (Torrents.LastID > 0) Torrents.CanRefresh = true;     
    </script>
{{end}}