<!-- Template for main page (rig and server list) -->
<div style="margin:auto;padding:20px;">

[% UNLESS user_info.uid %]
<h1 style="margin:auto;padding:50px;"> Welcome to [% data.name %]</h1>
[% END %]
[% IF user_info.uid -%]

[% IF data.listservers.size > 1 -%]
[% count = 0 -%]
<h2>Listservers</h2>
<table class=server_list>
<tr>
[% FOR i IN data.listservers -%]
[% count = count + 1 -%]
<th>
<form method=post action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/main.cgi">
[% INCLUDE print_hidden.tt %]
<input type=submit title="" value="[% i%]" class="rfcbutton" id="[% i %]">
</form>
</th>
[% IF count > 3 %]</tr><tr>[% count = 0 %][% END %]
[% END -%]
</tr>
</table>
[% END -%]

<h1>Available servers and rigs on listserver [% data.listserver %]</h1>

[% UNLESS data.rig_list.size > 0 -%]
<h2>No server listr found, using local list</h2>
[% END -%]

<table class=server_list>
[% FOR i IN data.rig_list.sort -%]
<tr><th>
[% IF user_info.admin %]
<form method=post action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/global_conf.cgi">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=hidden name=action value=conf >
<input type=submit title="" value="Configure [% i %]" class="rfcbutton server_btn" id="list_[% i %]">
</form>
[% ELSE -%]
[% i %]
[% END -%]
</th>
[% mode = '_active_rigs' -%]
[% sname = "$i$mode" -%]
[% count = 0 -%]
[% FOR j IN data.cache.$sname.split('[\s\t]+') -%]
<td>
<form method=post action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/rig_main.cgi">
<input type=hidden name=rig value="[% j%]">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=submit title="" value="Rig [% j %]" class="rfcbutton">
</form>
</td>
[% count = count + 1 -%]
[% IF count > 8 -%]
</tr><tr><td></td>
[% count = 0 -%]
[% END -%]
[% END -%]
</tr>
[% END -%]

[% UNLESS data.rig_list.size > 0 -%]
<tr><th>
[% IF user_info.admin -%]
<form method=post action="/cgi-bin/celltest/global_conf.cgi">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=submit title="" value="Configure [% i %]" class="rfcbutton server_btn">
</form>
[% ELSE -%]
[% i %]
[% END -%]
</th>
[% count = 0 -%]
[% FOR j IN data.local_list -%]
[% IF count > 8 -%]
</tr><tr><td></td>
[% count = 0 -%]
[% END -%]
[% count = count + 1 %]
<td>
<form method=post action="/cgi-bin/celltest/rig_main.cgi">
<input type=hidden name=rig value="[% j%]">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=submit title="" value="Rig [% j %]" class="rfcbutton">
</form>
</td>
[% END -%]
</tr>


[% END -%]
</table>

[% ELSE -%]

[% IF data.listservers.size > 1 -%]
<h2>Listservers</h2>
<table class=server_list>
<tr>
[% count = 0 -%]
[% FOR i IN data.listservers -%]
[% count = count + 1 -%]
<th>
<form method=post action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/prelogin.cgi">
<input type=submit title="" value="[% i.ucfirst %]" class="rfcbutton server_btn" id="list_[% i %]">
</form>
</th>
[% IF count > 3 %]</tr><tr>[% count = 0 %][% END -%]
[% END -%]
</tr>
</table>
[% END -%]

[% END -%]

<h2>Data on all test stations on listserver [% data.listserver %]</h2>

<table class=server_list>
[% FOR i IN data.rig_list.sort -%]
<tr><th id=show_data_[% i %]>
[% i.ucfirst %]
</th>
[% count = 0 -%]
[% mode = '_rigs' %]
[% sname = "$i$mode" %]
[% FOR j IN data.cache.$sname.split('[\s\t]+') %]
[% IF count > 8 -%]
</tr><tr><td></td>
[% count = 0 -%]
[% END -%]
[% count = count + 1 %]
<td>

[% IF user_info.uid %]
<form action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/list_tests.cgi" method=post name="show_test_rig_[% j %]">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=hidden name=rig value="[% j %]" >
<input type=hidden name=target_test value="[% nav.target_test %]" >
<input type=submit title="" value="Rig [% j %]" class="rfcbutton">
</form>
[% ELSE %]
<button type=button title="You need to login to access data" class="rfcbutton" onclick="alert('You need to login to access data')">Rig [% j %]</button> 
[% END %]
<!--<button class=rfcbutton onclick="openInNewTab('http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/show_data.cgi?name=[% user_info.name %]&pass=[% user_info.pass %]&url=http[% IF data.https %]s[% END %]://[% i %]/rig[% j %]/')">Rig [% j %]</button>-->

</td>
[% END -%]
</tr>
[% END -%]

[% UNLESS data.rig_list.size > 0 %]
<tr><th>
Localhost
</th>
[% count = 0 -%]
[% FOR j IN data.local_list -%]
[% IF count > 8 -%]
</tr><tr><td></td>
[% count = 0 -%]
[% END -%]
[% count = count + 1 %]
<td>

[% IF user_info.uid %]
<form action="http[% IF data.https %]s[% END %]://[% i %]/cgi-bin/celltest/list_tests.cgi" method=post name="show_test_rig_[% j %]">
<input type=hidden name=name value="[% user_info.name %]" >
<input type=hidden name=pass value="[% user_info.pass %]" >
<input type=hidden name=forceutf8 value="&#x2713;" >
<input type=hidden name=sudo value="[% user_info.sudo %]" >
<input type=hidden name=rig value="[% j %]" >
<input type=submit title="" value="Rig [% j %]" class="rfcbutton">
</form>
[% ELSE %]
<button type=button title="You need to login to access data" onclick="alert('You need to login to access data')" class="rfcbutton">Rig [% j %]</button> 
[% END %]

<!--<button class=rfcbutton onclick="openInNewTab('/cgi-bin/show_data.cgi?name=[% user_info.name %]&pass=[% user_info.pass %]&url=https://[% hostname %]/rig[% j %]/')">Rig [% j %]</button>-->
</td>
[% END -%]
</tr>

[% END -%]
</table>




<style>

.server_btn {
    width:100%;
}

.server_list {
    margin:auto;
    padding:5px;
    text-align:left;
}

.server_list th, .server_list td { 
    padding:5px;
}

.rfcbutton {
    min-width:80px;
}

</style>

</div>

<script>

[% FOR i IN data.listservers %]
/*get_server_name('http[% IF data.https %]s[% END %]://[% i %]',function(res){if (!res) {return false;};document.getElementById('list_'+'[% i %]').value = 'Configure '+ res;document.getElementById('show_data_'+'[% i %]').innerHTML = res},'&name=[% user_info.name %]&pass=[% user_info.pass %]');*/
[% END %]

[% FOR i IN data.rig_list.sort -%]
get_server_name('http[% IF data.https %]s[% END %]://[% i %]',function(res){if (!res) {return false;};document.getElementById('list_'+'[% i %]').value = 'Configure '+ res;document.getElementById('show_data_'+'[% i %]').innerHTML = res},'&name=[% user_info.name %]&pass=[% user_info.pass %]');
[% END %]



function openInNewTab(url) {
    var win = window.open(url, '_blank');
    win.focus();
}

[% IF nav.target_rig %]

document.addEventListener('DOMContentLoaded', function() {
   document.show_test_rig_[% nav.target_rig %].submit();
}, false);

[% END %]

</script>