<metal:block define-macro="listing">

<tal:block define="site_url python:here.getSite().absolute_url();
	listing_info folder_listing_info|here/folder_listing_info;
	folders_list python:listing_info['folders'];
	objects_list object_list_custom|python:listing_info['objects'];
	btn_select python:listing_info['btn_select'];
	btn_delete python:listing_info['btn_delete'];
	btn_copy python:listing_info['btn_copy'];
	btn_cut python:listing_info['btn_cut'];
	btn_paste python:listing_info['btn_paste'];
	can_operate python:listing_info['can_operate'];
	ratings here/folder_listing_ratings;
	iframe python: bool(request.get('iframe', 0))">

<metal:block define-slot="folder-listing">
<tal:block condition="iframe" on-error="here/rstk/catch_unauthorized">
	<!DOCTYPE html>
	<tal:block replace="structure python:'<' +'html>'"></tal:block>
	<tal:block tal:define="skin_files_path python:here.getLayoutTool().get_skin_files_path();
	layout_path python:here.getSite().getLayoutTool().absolute_url();">
		<metal:block use-macro="python: here.standard_template_macro('standard-head-links')"></metal:block>
	</tal:block>
	<tal:block replace="structure python:'<' +'body>'"></tal:block>
</tal:block>
<script type="text/javascript">
$(document).ready(function(){

	var deleteObjects = function(action) {
		$( "#dialog-delete-confirm" ).dialog({
		    open: function() {
                $(this).siblings(".ui-dialog-buttonpane").find("button:eq(1)").focus();
		    },
			resizable: false,
			height: 200,
			width: 500,
			modal: true,
			draggable: false,
			buttons: {
				"Delete items": function() {
                                    submit_form_action(action);
				},
				"Cancel": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	};

	// Multiple items operations
	$('.select-all').click(function(e){
		//Select toggle for all items
		var input_button = $(this).attr('id') == 'btn_select';
		var checked = input_button ? $(this).hasClass('clicked') : !$(this).attr('checked');
		if (input_button){//not an input[type=checkbox]
			$(this).toggleClass('clicked');
		}
		$('#folderfile_list td.checkbox input[type=checkbox]').attr('checked', !checked);
	});

	$('.action-button').click(function(e){
		//Copy, cut, paste... buttons
		e.preventDefault()

		// The form.action and the alert messages, set message to false to allow no selection
		var multiple_action_messages = {
			'copyObjects': gettext('Please select one or more items to copy.'),
			'cutObjects': gettext('Please select one or more items to cut.'),
			'pasteObjects': false,
			'deleteObjects': gettext('Please select one or more items to delete.'),
			'renameobject_html': gettext('Please select one or more items to rename.')
		};

		var action = $(this).attr('name').split(':')[0];

		if (!$("#folderfile_list td.checkbox input[type=checkbox]:checked").length > 0 && multiple_action_messages[action] !== false){
			alert(multiple_action_messages[action]);
			return false;
		}

		if(action == "deleteObjects") {
		    deleteObjects(action);
		}else {
                    submit_form_action(action);
                }
	});
})

function submit_form_action(action){
    var form = $('#folder_listing');
    form.attr('action', action);
    return form.submit();
}
</script>

<metal:block define-slot="menu_extension">
</metal:block>

<form id="folder_listing" name="objectItems" method="post" action=".">
	<metal:block define-slot="toolbar">
		<div id="toolbar" tal:condition="python:btn_select or btn_copy or btn_cut or btn_paste or btn_delete">
			<metal:block define-slot="toolbar_default">
				<input type="submit" value="Copy" class="action-button" name="copyObjects:method"
					i18n:attributes="value"
					tal:condition="btn_copy" />
				<input type="submit" value="Cut" class="action-button" name="cutObjects:method"
					i18n:attributes="value"
					tal:condition="btn_cut" />
				<input type="submit" value="Paste" class="action-button" name="pasteObjects:method"
					i18n:attributes="value"
					tal:condition="btn_paste" />
				<input type="submit" value="Delete" class="action-button" name="deleteObjects:method"
					i18n:attributes="value"
					tal:condition="btn_delete" />
				<input type="submit" value="Change item ID" class="action-button" name="renameobject_html:method"
					i18n:attributes="value"
					tal:condition="python: here.rename_id and btn_delete" />
			</metal:block>
			<metal:block define-slot="toolbar_extend">
				<tal:comment condition="nothing">
					Fill this slot to add custom buttons.
				</tal:comment>
			</metal:block>
		</div>
	</metal:block>
	<table border="0" cellpadding="0" cellspacing="0" id="folderfile_list">
		<metal:block define-slot="table_head">
			<tr tal:condition="can_operate">
				<metal:block define-slot="table_head_default">
					<th class="checkbox"
						tal:condition="btn_select">
						<input type="checkbox" class="select-all" />
					</th>
					<th class="type" i18n:translate="Type (translate as a noun)">Type</th>
					<th class="title-column" i18n:translate="">Title</th>

					<th class="checkin" i18n:translate="">Version</th>
					<th class="edit" i18n:translate="">Edit</th>

				</metal:block>
				<metal:block define-slot="table_head_extend">
					<tal:comment condition="nothing">
						Fill this slot to add custom columns (heading for columns goes here).
					</tal:comment>
					<th tal:condition="ratings"
						class="rating" i18n:translate="">Rating</th>
				</metal:block>
			</tr>
		</metal:block>
		<tr tal:repeat="folder_info folders_list">
			<metal:block define-slot="table_folders_default">
				<tal:block define="
					del_permission python:folder_info['del_permission'];
					copy_permission python:folder_info['copy_permission'];
					edit_permission python:folder_info['edit_permission'];
					versionable python:folder_info['versionable'];
					editable python:folder_info['editable'];
					folder python:folder_info['self'];
					" on-error="here/rstk/catch_unauthorized">
					<td class="checkbox" tal:condition="btn_select">
						<input tal:condition="python:del_permission or copy_permission"
							type="checkbox" name="id" tal:attributes="value folder/id" />
					</td>
					<td class="type">
						<img tal:define="icon folder_info/view/get_icon"
							 tal:condition="icon"
							 tal:attributes="src icon/url;
											 alt icon/title;
											 title icon/title" />
					</td>
					<td class="title-column">
						<a tal:attributes="href folder/absolute_url" tal:content="folder/title_or_id" />
						<em tal:condition="folder/can_be_seen"
							tal:content="folder_info/view/get_info_text" />
						<span class="available_langs" tal:condition="python:here.item_has_title(folder, folder.title)">
							<span i18n:translate="">Item only translated in </span>
							<span tal:repeat="lang here/gl_get_languages_map">
								<a tal:content="python:' %s' % lang['title']"
									tal:condition="python:not lang['selected'] and folder.getLocalProperty('title', lang['id'])"
									tal:attributes="href python:'gl_changeLanguage?old_lang=%s' % (lang['id'])" />
							</span>
						</span>
						<tal:block tal:condition="folder/can_be_seen">
							<tal:block tal:condition="folder/has_restrictions" i18n:translate="">
							[Limited access]
							</tal:block>
						</tal:block>
						<tal:block tal:condition="python:not folder.can_be_seen()" i18n:translate="">
							[Restricted access]
						</tal:block>
						<tal:block condition="folder/discussion|nothing">
						<tal:block define="count_comments folder/count_comments" condition="count_comments" on-error="string:">
							[<span tal:replace="count_comments" />
							<span tal:omit-tag="" i18n:translate="">comment(s)</span>]
						</tal:block>
						</tal:block>
					</td>

					<td class="checkin" tal:condition="edit_permission">
						<tal:block condition="not:versionable">n/a</tal:block>
						<a tal:condition="python:versionable and editable" tal:attributes="href string:${folder/absolute_url}/startVersion">
							<img src="misc_/Naaya/checkout" alt="Checkout - start new versionable" i18n:attributes="alt" />
						</a>
						<a tal:condition="python:versionable and not editable" tal:attributes="href string:${folder/absolute_url}/edit_html">
							<img src="misc_/Naaya/checkin" alt="Version control" i18n:attributes="alt" />
						</a>
					</td>
					<td class="edit" tal:condition="edit_permission">
						<a tal:condition="editable" tal:attributes="href string:${folder/absolute_url}/edit_html">
							<img src="misc_/Naaya/edit" alt="Edit" i18n:attributes="alt" />
						</a>
						<tal:block condition="not:editable">n/a</tal:block>
					</td>
					<td tal:condition="ratings" class="rating">
						<tal:block condition="folder/user_rating_view|nothing"
							replace="structure folder/user_rating_stars"/>
					</td>
				</tal:block>
			</metal:block>
			<metal:block define-slot="table_folders_extend">
				<tal:comment condition="nothing">
					Fill this slot to add custom columns (content for folders goes here).
				</tal:comment>
			</metal:block>
		</tr>
		<tr tal:repeat="object_info objects_list">
			<metal:block define-slot="table_objects_default">
				<tal:block define="
					del_permission python:object_info['del_permission'];
					copy_permission python:object_info['copy_permission'];
					edit_permission python:object_info['edit_permission'];
					versionable python:object_info['versionable'];
					editable python:object_info['editable'];
					object python:object_info['self'];
					" on-error="here/rstk/catch_unauthorized">
					<td class="checkbox" tal:condition="btn_select">
						<input tal:condition="python:del_permission or copy_permission"
							type="checkbox" name="id" tal:attributes="value object/id" />
					</td>
					<td class="type">
						<img tal:define="icon object_info/view/get_icon"
							 tal:condition="icon"
							 tal:attributes="src icon/url;
											 alt icon/title;
											 title icon/title" />
					</td>
					<td class="title-column">
						<a tal:attributes="href object/absolute_url" tal:content="object/title_or_id" />
						<a tal:define="download_url object_info/view/get_download_url"
						   tal:condition="download_url"
						   tal:attributes="href download_url;"
						   title="Download"
						   i18n:attributes="title">
						   <img tal:attributes="src string:${site_url}/misc_/Naaya/download-file.png"
								alt="Download"
								i18n:attributes="alt" />
						</a>
						<em tal:condition="object/can_be_seen"
							tal:content="object_info/view/get_info_text" />
						<span class="available_langs" tal:condition="python:here.item_has_title(object, object.title)">
							<span i18n:translate="">Item only translated in </span>
							<span tal:repeat="lang here/gl_get_languages_map">
								<a tal:content="python:' %s' % lang['title']"
									tal:condition="python:not lang['selected'] and object.getLocalProperty('title', lang['id'])"
									tal:attributes="href python:'gl_changeLanguage?old_lang=%s' % (lang['id'])" />
							</span>
						</span>
						<tal:block condition="object/discussion|nothing">
						<tal:block define="count_comments object/count_comments" condition="count_comments" on-error="string:">
							[<span tal:replace="count_comments" />
							<span tal:omit-tag="" i18n:translate="">comment(s)</span>]
						</tal:block>
						</tal:block>
					</td>

					<td class="checkin" tal:condition="edit_permission">
						<tal:block condition="not:versionable">n/a</tal:block>
						<a tal:condition="python:versionable and editable" tal:attributes="href string:${object/absolute_url}/startVersion">
							<img src="misc_/Naaya/checkout" alt="Checkout - start new versionable" i18n:attributes="alt" />
						</a>
						<a tal:condition="python:versionable and not editable" tal:attributes="href string:${object/absolute_url}/edit_html">
							<img src="misc_/Naaya/checkin" alt="Version control" i18n:attributes="alt" />
						</a>
					</td>
					<td class="edit" tal:condition="edit_permission">
						<a tal:condition="editable" tal:attributes="href string:${object/absolute_url}/edit_html">
							<img src="misc_/Naaya/edit" alt="Edit" i18n:attributes="alt" />
						</a>
						<tal:block condition="not:editable">n/a</tal:block>
					</td>
					<td tal:condition="ratings" class="type">
						<tal:block define="user_rating object/user_rating_stars_numbers|nothing"
							condition="object/is_ratable|nothing" replace="structure user_rating"/>
					</td>

				</tal:block>
			</metal:block>
			<metal:block define-slot="table_objects_extend">
				<tal:comment condition="nothing">
					Fill this slot to add custom columns (content for objects goes here).
				</tal:comment>
			</metal:block>
		</tr>
	</table>
</form>

<metal:block use-macro="python: here.getFormsTool().getForm('delete_confirmation').macros['delete_confirmation']"></metal:block>

</metal:block>
<tal:block condition="iframe"><br />
<tal:block replace="structure python:'</' +'body>'"></tal:block>
<tal:block replace="structure python:'</' +'html>'"></tal:block>
</tal:block>
</tal:block>
</metal:block>
