<%inherit file="jm2l:templates/layout.mako"/>
<%namespace name="helpers" file="jm2l:templates/helpers.mako"/>
<%def name="jsAddOn()"> 
    <script src="/vendor/repeatable-fields/js/repeatable-fields.js"></script>
<script type="text/javascript">
jQuery(function() {
	jQuery('.repeat').each(function() {
		jQuery(this).repeatable_fields({
			wrapper: 'table',
			container: 'tbody',
			row: 'tr',
			cell: 'td',
		});
	});
});
</script>

</%def>
<h2>Gestion des catégories pour les entités</h2>

<form method="post" action="#">
<div class="repeat">
  <table class="table table-striped table-bordered">
	<tbody data-rf-row-count="${len(TiersOpt.get_entity_type())}" class="container ui-sortable">
	<tr style="display: none;" class="template row">
		##<td width="10%"><span class="move btn btn-mini btn-info">Move</span></td>
		<td class="cell">
			<strong>Catégorie</strong>
			<input style="width:80%" disabled="" name="collection[{{row-count-placeholder}}][title]" 
				class="form-control" type="text">
			<table class="table table-striped table-bordered">
			  <caption><strong>Sous Catégories</strong></caption>			
			  <tbody data-rf-row-count="0" style="" class="container ui-sortable">
				<tr style="display: none;" class="template row">
					##<td width="10%"><span class="move btn btn-mini btn-info">Move</span></td>
					<td class="cell">
						<input style="margin-bottom:0" 
							name="collection[{{row-count-placeholder}}][{{row-count-placeholder}}][id]" 
							class="form-control" type="text">
					</td>
					<td><span class="remove btn btn-mini btn-danger"><i class="icon-remove-sign icon-white"></i> Suppr.</span></td>
				</tr>
			  </tbody>
			  <tfoot>
				<tr>
					<td colspan="3" style="text-align:center;"><span class="add btn btn-mini btn-success">Ajouter une sous-catégorie</span></td>
				</tr>
			  </tfoot>
			</table>
		</td>
		
		<td style="width:60px"><span class="remove btn btn-mini btn-danger"><i class="icon-remove-sign icon-white"></i> Suppr.</span></td>
	</tr>
% for num, (opt, optcounter) in enumerate(TiersOpt.get_entity_type()):	
	<tr class="row">
		##<td width="10%"><span class="move btn btn-mini btn-info">Move</span></td>
		<td class="cell">
			<strong>Catégorie</strong>
			<input style="width:70%" name="collection[${opt.slug_entity_type}][title]" 
				class="form-control" type="text" value="${opt.entity_type}"> ( ${optcounter} entité${["","s"][optcounter>1]} )
			<table class="table table-striped table-bordered">
			  <caption><strong>Sous Catégories</strong></caption>
			  <tbody data-rf-row-count="${len(TiersOpt.get_entity_sub_type(opt.entity_type))}" style="" class="container ui-sortable">
				<tr style="display: none;" class="template row">
					##<td width="10%"><span class="move btn btn-mini btn-info">Move</span></td>
					<td class="cell">		
						<input style="margin-bottom:0;width:95%;" 
							name="collection[${opt.slug_entity_type}][{{row-count-placeholder}}][id]"
							class="form-control" type="text">
					</td>
					<td style="width:70px;"><span class="remove btn btn-mini btn-danger"><i class="icon-remove-sign icon-white"></i> Suppr.</span></td>
				</tr>				
		% for nums, (sopt, soptcounter) in enumerate(TiersOpt.get_entity_sub_type(opt.entity_type)):				
				<tr class="row" display: table-row;>
					##<td width="10%"><span class="move btn btn-mini btn-info">Move</span></td>
					<td class="cell">
						<input style="margin-bottom:0;width:80%;"
							name="collection[${opt.slug_entity_type}][${nums}][${sopt.uid}]" 
							class="form-control" type="text" value="${sopt.entity_subtype}">
						( ${soptcounter} entité${["","s"][soptcounter>1]} )
					</td>
					% if soptcounter:
						<td style="width:70px;"></td>
					% else:
						<td style="width:70px;"><span class="remove btn btn-mini btn-danger"><i class="icon-remove-sign icon-white"></i> Suppr.</span></td>
					% endif
				</tr>
		% endfor
			  </tbody>
			  <tfoot>
				<tr>
					<td colspan="3" style="text-align:center;">
						<span class="add btn btn-mini btn-success">Ajouter une sous-catégorie à ${opt.entity_type}</span>
					</td>
				</tr>
			  </tfoot>				
			</table>
		</td>
	% if optcounter:					
		<td style="width:70px;"></td>
	% else:
		<td style="width:70px;"><span class="remove btn btn-mini btn-danger"><i class="icon-remove-sign icon-white"></i> Suppr.</span></td>
	% endif
	</tr>
% endfor
	</tbody>
	<tfoot>
		<tr>
			<td colspan="2" style="text-align:center;"><span class="add btn btn-mini btn-success">Ajouter une catégorie</span></td>
		</tr>
	</tfoot>	
  </table>
</div>

	<input type="submit" class="btn btn-primary" value="Enregistrer les modifications" />
</form>
