<!--
 @author Maciej_Wawryk
 -->
{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
    <h1>{$layout.pagetitle}</h1>
    <table class="lmsbox lms-ui-background-cycle">
	<colgroup>
	    <col style="width: 97%;">
	    <col style="width: 1%;">
	    <col style="width: 1%;">
	    <col style="width: 1%;">
	</colgroup>
	<thead>
	    <tr>
		<td scope="col" class="nobr">
			{icon name="usergroup" label="Name"}<br>
			{icon name="description" label="Description"}
		</td>
		<td scope="col" class="text-right lighter">{trans("ID:")}</td>
		<td scope="col" class="text-right lighter">{trans("Members:")}</td>
		<td scope="col" class="text-right nobr">{button icon="add" label="New Group" href="?m=usergroupadd"}</td>
	    </tr>
	</thead>
	<tfoot>
	    <tr>
		<td colspan="2" class="text-right bold nobr">{icon name="total" label="Total"}</td>
		<td class="text-right bold">{$listdata.totalcount|default:"0"}</td>
		<td class="text-right bold">{t a=$listdata.total|default:"0"}Total: $a{/t}</td>
	    </tr>
	</tfoot>
	<tbody>
	    {foreach $usergrouplist as $usergroup}
		<tr class="highlight" data-target-url="?m=usergroupinfo&id={$usergroup.id}" data-name="{$usergroup.name}">
		    <td>
			{icon name="usergroup" label=$usergroup.name}<br>
			{if $usergroup.description}{icon name="description" label=$usergroup.description}{/if}
		    </td>
		    <td class="text-right">
				({$usergroup.id|string_format:"%04d"})
		    </td>
		    <td class="text-right">
				{$usergroup.userscount}
		    </td>
		    <td class="lms-ui-buttons text-right nobr">
			{if $usergroup.userscount}
				{button type="link" icon="delete" tip="Delete" class="delete-usergroup-alert"}
			{else}
				{button type="link" icon="delete" tip="Delete" class="delete-usergroup" href="?m=usergroupdel&id={$usergroup.id}"}
			{/if}
			{button type="link" icon="edit" tip="Edit" href="?m=usergroupedit&id={$usergroup.id}"}
			{button type="link" href="?m=usergroupinfo&id={$usergroup.id}" icon="info" tip="Info"}
		    </td>
		</tr>
	    {foreachelse}
			<tr>
				<td colspan="4" class="empty-table">
					{trans("There are no such groups in database.")}
				</td>
			</tr>
		{/foreach}
	</tbody>
    </table>
	<script>
		$('.delete-usergroup').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			console.log('name=', name);
			confirmDialog($t("Are you sure, you want to remove group '$a'?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
		$('.delete-usergroup-alert').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			alertDialog($t("Group '$a' has members and cannot be deleted!", name), this);
			return;
		});
	</script>

{/block}
