{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!-- $Id$ -->
<H1>{$layout.pagetitle}</H1>
<table class="lmsbox lms-ui-background-cycle">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 1%;">
		<col style="width: 1%;">
		<col style="width: 1%;">
		<col style="width: 96%;">
		<col style="width: 1%;">
	</colgroup>
	<thead>
		<tr>
			<td class="nobr">
				{icon name="cashsource"}
				{trans("Name:")}
			</td>
			<td class="nobr">
				{trans("ID:")}
			</td>
			<td class="nobr">
				{trans("Main bank account:")}
			</td>
			<td class="text-right nobr">
				{trans("Default")}
			</td>
			<td>
				{trans("Description:")}
			</td>
			<td class="nobr">
				{button icon="add" label="Add source" href="?m=cashsourceadd"}
			</td>
		</tr>
    </thead>
    <tbody>
		{foreach $sourcelist as $source}
			<tr class="highlight{if $source.deleted == 1} blend{/if}" data-name="{$source.name}">
				<td data-target-url="?m=cashsourceedit&id={$source.id}" class="nobr">
					{icon name="cashsource"}
					<strong>{$source.name}</strong>
				</td>
				<td data-target-url="?m=cashsourceedit&id={$source.id}">
					({$source.id|string_format:"%04d"})
				</td>
				<td class="nobr" data-target-url="?m=cashsourceedit&id={$source.id}">
					{if $source.account}
						{format_bankaccount($source.account)}
					{/if}
				</td>
				<td class="text-rightr" data-target-url="?m=cashsourceedit&id={$source.id}">
					{if $source.isdefault}{icon name="checked" tip="yes"}{/if}
				</td>
				<td data-target-url="?m=cashsourceedit&id={$source.id}">
					{$source.description|escape}
				</td>
				<td class="text-right nobr">
					{if $source.deleted == 1}
						{button type="link" icon="disconnected" tip="Enable" href="?m=cashsourcelist&action=enable&id={$source.id}"}
					{else}
						{button type="link" icon="connected" tip="Disable" href="?m=cashsourcelist&action=disable&id={$source.id}"}
					{/if}
					{button type="link" class="delete-cashsource" icon="delete" tip="Delete" data_resource_id=$source.id}
					{button type="link" icon="edit" tip="Edit" href="?m=cashsourceedit&id={$source.id}"}
				</td>
			</tr>
		{foreachelse}
			<tr>
				<td colspan="6" class="empty-table">
					{trans("There are no sources in database.")}
				</td>
			</tr>
		{/foreach}
	</tbody>
	<tfoot>
		<tr>
			<td colspan="6" class="text-right nobr">
				{button icon="add" label="Add source" href="?m=cashsourceadd"}
			</td>
		</tr>
    </tfoot>
</table>

<script>

	$(function() {
		$('.delete-cashsource').click(function () {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove source '$a'?", name), this).done(function () {
				location.href = '?m=cashsourcedel&id=' + $(this).attr('data-resource-id');
			});
			return false;
		});
	});

</script>
{/block}
