<% 
    use obfui::cmn;
    my ($dirstr,$qpv,$dirs,$files,$dire,$prj,$modeselect_html,$dirsep,$opts) = @_;
    
    my @dirs_path = split($dirsep,$dirstr);
    shift @dirs_path if $dirs_path[0] eq '';
%>
<script language=javascript>
<!--
function select_all(do_select)
{
    var f = document.forms['fmain'];
    for(var idx=0; idx < f.length; ++idx)
    {
	var i = document.forms['fmain'][idx];
	if (!i['name'])	continue;
	if (i.name.indexOf('_direntry_') ==0)
	{
	    i.checked = do_select;
	}
    }
}
-->
</script>
<form method=post name=fmain>
<input type=hidden name=havevals value=1>
<input type=hidden name=dir value="<%= $dirstr %>" >
<input type=hidden name=sortby value=<%$ $qpv->{sortby} %>>
<%
if (@dirs_path) {
    my $curdir = '';
%><%= __('Directory: ') %>
<a href=project.files?dir=<%? '/' %>&sortby<%$ $qpv->{sortby} %>>
<%= __('<TOP>') %></a> / 
<%
    foreach (@dirs_path)
    {
	my $d = $_;
	$curdir .= $dirsep . $d;
%>
<a href=project.files?dir=<%? length($curdir) ? $curdir : '/'
     %>&sortby<%$ $qpv->{sortby} %>><%= $d %></a> / 
<%
    }
} %>
<p>
<% $forge->include('wgt-gobtn',__('Sort by ext'), 
    'project.files?sortby=ext&dir=' . $forge->escape_uri($dirstr) ) %>
<% $forge->include('wgt-gobtn',__('Sort by name'), 
    'project.files?sortby=name&dir=' . $forge->escape_uri($dirstr) ) %>
<p>
<table class=filebrowser>
<thead>
<tr><th></th><th class=name><%= __('Name') %></th>
    <th class=mode><%= __('Mode') %></th>
<tbody>
<% 
    my $i = 0;
    foreach ($dirs,$files) {
	my $idx = 0;
	foreach my $e (@$_) {
	    my $nm = $e->[0];
	    my $cbnm = '_direntry_' . join('',map { sprintf('%02x',ord($_))} 
			    split(//,$nm));
	    my $wgtnm = $i ? 'file' : 'dir';
	    $forge->include('wgt-direntry-' . $wgtnm, $cbnm, $nm, $dirstr,
		    "${dirstr}/$nm", $e->[1],$idx);
	    ++$idx;
	}
	++$i;
 } %>
</tbody>
</table><p>

<br>
<% $forge->include('wgt-jsbtn',__('Select all'),  'select_all(1)' ) %>
<% $forge->include('wgt-jsbtn',__('Unselect all'),  'select_all(0)' ) %>
<p>
<h3><%= __('Operations with selected objects:')%></h3>
<input type=checkbox class=checkbox name=recursive checked>
<%$ hstr('files.recursive',__('Apply to subdirectories if object is a directory')) %>
<br>
<div class=wideselect>
<%$ $modeselect_html %>
<br>
<% $forge->include('wgt-submitbtn-wide',
	__('Assign processing mode'), 'setmode'); %>
</div>
<p>
<% $forge->include('wgt-submitbtn',
	__('Force rebuilding'), 'touchin'); %>
<% $forge->include('wgt-submitbtn',
	__('Block next rebuilding'), 'touchout'); %>

<br>
<% $forge->include('wgt-submitbtn',
	__('Add to project'), 'manage'); %>

<% $forge->include('wgt-submitbtn',
	__('Stop managing'), 'unmanage'); %>
<p>

<div class=wideselect>
<input type=text class=text style='width:30em;' name=newname>
<br>
<% $forge->include('wgt-submitbtn-wide',
	__('Rename object in metadata of project'), 'setname'); %>
</div>
</form>
