<tal:block metal:use-macro="python:here.getLayoutTool().getCurrentSkin().folder_administration_macro.macros['page']">

<h1 metal:fill-slot="title" i18n:translate="">Right-side portlets</h1>

<tal:block metal:fill-slot="section">
	<script type="text/javascript">
	<!--
	
	function add()
	{
		var selectleft = document.frmportlets.available;
		var selectright = document.frmportlets.portlets;
		var i;
		for(i = 0; i < selectleft.options.length; i++)
		{
			if(selectleft.options[i].selected)
			{
				var o = document.createElement( "option");
				o.text = selectleft.options[i].text;
				o.value = selectleft.options[i].value;
				selectright.options[selectright.options.length] = o;
				selectleft.remove(i);
				i--;
			}
		}
	}
	function remove()
	{
		var selectleft = document.frmportlets.available;
		var selectright = document.frmportlets.portlets;
		var i;
		for( i = 0; i < selectright.options.length; i++)
		{
			if(selectright.options[i].selected)
			{
				var o = document.createElement( "option");
				o.text = selectright.options[i].text;
				o.value = selectright.options[i].value;
				selectleft.options[selectleft.options.length] = o;
				selectright.remove(i);
				i--;
			}
		}
	}
	
	function moveup()
	{
		var selectright = document.frmportlets.portlets;
		var i;
		for( i = 0; i < selectright.options.length; i++)
		{
			if(selectright.options[i].selected && (i > 0))
			{
				var o1 = document.createElement( "option");
				o1.text = selectright.options[i-1].text;
				o1.value = selectright.options[i-1].value;
				var o2 = document.createElement( "option");
				o2.text = selectright.options[i].text;
				o2.value = selectright.options[i].value;
				selectright.options[i-1] = o2;
				selectright.options[i] = o1;
				selectright.options[i-1].selected = true;
			}
		}
	}
	
	function movedown()
	{
		var selectright = document.frmportlets.portlets;
		var i;
		for( i = selectright.options.length-1; i >= 0; i--)
		{
			if(selectright.options[i].selected && (i < selectright.options.length-1))
			{
				var o1 = document.createElement( "option");
				o1.text = selectright.options[i].text;
				o1.value = selectright.options[i].value;
				var o2 = document.createElement( "option");
				o2.text = selectright.options[i+1].text;
				o2.value = selectright.options[i+1].value;
				selectright.options[i] = o2;
				selectright.options[i+1] = o1;
				selectright.options[i+1].selected = true;
			}
		}
	}
	
	function dosubmit()
	{
		var selectright = document.frmportlets.portlets;
		var i;
		for( i = 0; i < selectright.options.length; i++)
		{
			selectright.options[i].selected = true;
		}
		//document.frmportlets.submit();
	}
	
	// -->
	</script>

	<tal:block tal:define="mode python:request.get('mode', '');
		location python:request.get('location', '');
		location_obj python:test(location=='', None, here.getFolderByPath(location));
		records python:here.get_right_portlets_locations(here.absolute_url(1))">
		<p i18n:translate="">This page allows you to establish the list of portlets displayed in the right side of this folder and its sub-folders.
		You are presented with the hierarchical structure of this folder: click on a (sub)folder link to select it (skip the selection if you are choosing portlets for the entire folder) then choose the corresponding portlets.</p>
		<form name="frmportlets" method="post" tal:attributes="action string:${here/absolute_url}/admin_folder_portlets">
		<input type="hidden" name="mode" tal:attributes="value mode" />
		<input type="hidden" name="location" tal:attributes="value location" />
		<table border="0" cellspacing="4" cellpadding="4">
		<tr>
			<td class="form-label" width="20%" valign="top" i18n:translate="">Location</td>
			<td colspan="4">
				<tal:block tal:condition="python:mode=='edit'">
					<strong tal:condition="python:location_obj is None" i18n:translate="">Portal front page</strong>
					<strong tal:condition="python:location_obj is not None" tal:content="location_obj/title_or_id">location</strong>
					<input type="hidden" name="folder" tal:attributes="value location" />
				</tal:block>
				<tal:block tal:condition="python:mode!='edit'">
				<script type="text/javascript">
				<!--
				function fTreeClick(expand)
				{
					document.frmportlets.action = '';
					document.frmportlets.expand.value = expand;
				}
				function fTreeNodeClick(node_path)
				{
					document.frmportlets.folder.value = node_path;
				}
				//-->
				</script>
				<tal:block tal:define="expand python:request.get('expand', '');
										expand_list python:here.splitToList(expand);
										tree python:here.getSiteMap(expand_list, here, 0);
										folder python:request.get('folder', '')">
				<table border="0" cellspacing="1" cellpadding="1" width="100%">
				<tr tal:repeat="tree_node tree">
					<td>
						<table border="0" cellspacing="1" cellpadding="1">
							<tr>
								<td>
									<img tal:repeat="i python:range(0, tree_node[2])" src="misc_/Naaya/square.gif" alt="" />
									<tal:block tal:condition="python:tree_node[1]==-1">
										<img src="misc_/Naaya/square.gif" alt="" />
									</tal:block>
									<tal:block
										tal:define="node_expand python:here.processCollapse(expand_list, tree_node[0].absolute_url(1))"
										tal:condition="python:tree_node[1]==0">
										<input type="image" tal:attributes="onclick string:javascript:fTreeClick('${node_expand}')" 
										src="misc_/Naaya/minus.gif" alt="Collapse node" />
									</tal:block>
									<tal:block
										tal:define="node_expand python:here.processExpand(expand_list, tree_node[0].absolute_url(1))"
										tal:condition="python:tree_node[1]==1">
										<input type="image" tal:attributes="onclick string:javascript:fTreeClick('${node_expand}')" 
										src="misc_/Naaya/plus.gif" alt="Expand node" />
									</tal:block>
								</td>
								<td><img tal:attributes="src python:tree_node[0].icon" alt="" /></td>
								<td><a tal:define="node_path python:tree_node[0].absolute_url(1)" tal:attributes="href string:javascript:fTreeNodeClick('${node_path}')" tal:content="python:tree_node[0].title_or_id()">folder</a></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<input type="text" name="folder" tal:attributes="value folder" size="35" readonly="readonly" />
					</td>
				</tr>
				</table>
				<input type="hidden" name="expand" tal:attributes="value expand">
				</tal:block>
				</tal:block>
			</td>
		</tr>
		<tr>
			<td class="form-label" valign="top" i18n:translate="">Available portlets</td>
			<td>
				<select name="available" size="10" multiple="multiple"
					tal:define="available_portlets python:test(mode=='edit', here.get_available_right_locations_objects(location), here.getPortletsTool().getPortlets())">
					<option tal:repeat="item available_portlets"
							tal:attributes="value item/id"
							tal:content="item/title_or_id">portlet</option>
				</select>
			</td>
			<td valign="middle">
				<input type="button" value="Add ->" onclick="javascript:add();"/>
				<br /><br />
				<input type="button" value="<- Remove" onclick="javascript:remove();" />
			</td>
			<td>
				<select name="portlets" size="10" multiple="multiple"
					tal:define="current_portlets python:test(mode=='edit', here.get_right_portlets_locations_objects(location_obj), [])">
					<option tal:repeat="item current_portlets"
							tal:attributes="value item/id"
							tal:content="item/title_or_id">portlet</option>
				</select>
			</td>
			<td valign="middle">
				<input type="button" value="Move Up" onclick="javascript:moveup();" />
				<br /><br />
				<input type="button" value="Move Down" onclick="javascript:movedown();" />
			</td>
		</tr>
		<tr>
			<td></td>
			<td colspan="4"><input type="submit" value="Save changes" i18n:attributes="value" onclick="javascript:dosubmit();" /></td>
		</tr>
		</table>
		</form>

		<h2 i18n:translate="">Right-side portlets defined in this folder</h2>
		<p i18n:translate="">You are presented with the list of locations (subfolders or folder's front page) from this folder
		where right-side portlets have been defined. Click on a location to edit its list of right side portlets.</p>
		<form method="post" tal:attributes="action string:${here/absolute_url}/admin_folder_portlets">
		<table border="0" cellspacing="0" cellpadding="0" width="95%" class="datatable">
			<tr>
				<th width="1%"></th>
				<th width="60%" i18n:translate="">Location</th>
				<th width="40%" i18n:translate="">Portlets</th>
			</tr>
			<tr tal:repeat="record python:records.keys()">
				<td></td>
				<td valign="top">
					<a tal:attributes="href string:${here/absolute_url}/administration_portlets_html?mode=edit&location=${record}" tal:content="python:here.getFolderByPath(record).title_or_id()">location</a>
				</td>
				<td>
					<tal:block tal:repeat="item python:map(here.getPortletsTool().getPortletById, records[record])">
						<tal:block tal:condition="python:item is not None">
							<input type="checkbox" name="portlets" tal:attributes="value python:'%s||%s' % (record, item.id)" />
							<tal:block tal:content="item/title_or_id" />
							<br />
						</tal:block>
					</tal:block>
				</td>
			</tr>
			<tr>
				<td></td>
				<td colspan="2"><input type="submit" name="delete" value="Delete"/></td>
			</tr>
		</table>
		<input type="hidden" name="mode" value="delete" i18n:attributes="value" />
		</form>
	</tal:block>
</tal:block>

</tal:block>
