<!-- Macro for edit form -->
<metal:block define-macro="page" tal:define="
	languages here/gl_get_languages_mapping;
	site here/getSite;
	curr_lang python:request.get('lang', None) or here.gl_get_selected_language();
	curr_lang_label python:here.gl_get_language_name(curr_lang);
    schema_helper python:here.get_schema_helper(lang=curr_lang);
">

<metal:block use-macro="python:here.standard_template_macro('light')">
<metal:block fill-slot="body">

<tal:block tal:condition="python:(not here.hasVersion()) or (here.hasVersion() and here.isVersionAuthor())">

<!-- Scripts -->
<metal:block define-slot="scripts">
	<script type="text/javascript" tal:attributes="src string:${here/getSitePath}/core_js"></script>
	<script type="text/javascript" tal:attributes="src string:${here/getSitePath}/calendar_js"></script>
	<script type="text/javascript" tal:attributes="src string:${here/getSitePath}/datetime_js"></script>
	<script type="text/javascript" tal:attributes="src string:${here/getSitePath}/common_js"></script>
	<script type="text/javascript" tal:attributes="src string:${here/getSitePath}/jstree/jquery.tree.min.js"></script>
	<tal:block tal:define="editor here/getEditorTool" tal:replace="structure editor/includeLibs" />
</metal:block>
<metal:block define-slot="custom_scripts" />

<!-- Document header -->
<h1 metal:define-slot="title" tal:content="string:Edit ${schema_helper/get_meta_label}" i18n:translate="" />
<div metal:define-slot="buttons" class="floated-buttons"><span class="buttons">
	<a tal:attributes="href here/absolute_url" i18n:translate="">Back to index</a></span>
</div>
<p metal:define-slot="description">
	<tal:block i18n:translate="">
		Change the properties in the form below and click <strong i18n:name="save-button" i18n:translate="">Save changes</strong>. Fields marked with <span i18n:name="mandatory" class="mandatory_field">*</span> are mandatory.
	</tal:block>
</p>

<!-- Versioning -->
<div metal:define-slot="version_box"
	class="version_box" tal:condition="here/hasVersion">
	<p i18n:translate="">
		<strong i18n:name="working-version" i18n:translate="">You are working on a version of this item.</strong>
		In order to save the work done in the version and make it accessible to all
		end users, click on the <strong i18n:name="commit-button" i18n:translate="">Commit</strong> button. To permanently
		discard the work done in the version, click on the
		<strong i18n:name="discard-button" i18n:translate="">Discard</strong> button.
	</p>
	<form action=".">
		<input type="submit" value="Commit" i18n:attributes="value" name="commitVersion:method" />
		<input type="submit" value="Discard" i18n:attributes="value" name="discardVersion:method" />
	</form>
</div>

<div class="edit-holder" tal:attributes="style python:'background-color: %s' % here.utHexColors(curr_lang)">

<!-- Translation bar on top -->
<div metal:define-slot="translate_on_top" class="translate-top translate">
	<metal:block use-macro="python:here.getFormsTool().getForm('site_macro_edit').macros['translation_bar']" />
</div>

<div condition="not:here/hasVersion" style="float:right">
<tal:comment condition="nothing">
	XXX Support these features in versions, too.
</tal:comment>

<!-- Fill fields from language -->
<metal:block use-macro="python:here.getFormsTool().getForm('site_macro_schema_edit').macros['update_from_version']" />

<!-- Switch content language box -->
<div style="display:none" i18n:translate="" id="confirmSwMessage">
	This action will move current translation to selected one.
	The target translation will be lost. Are you sure?
</div>
<script type="text/javascript">
<!--
var swMsg = document.getElementById('confirmSwMessage').innerHTML;
//-->
</script>
<fieldset metal:define-slot="update_content_language" class="edit_right_box"
	tal:condition="python:len(languages) > 1 and getattr(site, 'switch_language', 0)">
	<form name="switch_to_language" action="." method="post">
		<legend i18n:translate="">Choose correct language</legend>
		<label for="switch_to" i18n:translate="">Mark as</label>
		<select name="switch_to" id="switch_to">
			<tal:block repeat="language languages">
			<option tal:condition="python:language['code'] != curr_lang"
				tal:attributes="value language/code"
				tal:content="language/name" i18n:translate="" />
			</tal:block>
		</select>
		<input type="hidden" name="lang" tal:attributes="value curr_lang" />
		<input type="submit" name="switchToLanguage:method"
			onclick="javascript:return window.confirm(swMsg)"
			value="Ok" i18n:attributes="value"/>
		<p>
			<span i18n:translate="">The text currently displayed is marked as</span>
			<strong tal:content="curr_lang_label" />.
			<span i18n:translate="">If this is not the case, choose the right language and click Ok.</span>
		</p>
	</form>
</fieldset>
</div>

<!-- Edit form -->
<form name="frmEdit" class="edit-object-form" method="post" action="." enctype="multipart/form-data">

<!-- Submit buttons-->
<div class="field" metal:define-slot="submit_buttons">
	<input type="submit" value="Save changes" i18n:attributes="value" name="saveProperties:method"/>
</div>

<!-- Custom boxes -->
<metal:block define-slot="custom_boxes" />

<!-- Schema properties -->
<tal:block metal:define-slot="schema_properties"
        repeat="form_item schema_helper/form_items">
    <tal:block replace="structure form_item/html" />
</tal:block>

<!-- Custom properties -->
<tal:block metal:define-slot="custom_properties" />

<!-- Hidden inputs  -->
<metal:block define-slot="hidden_inputs">
	<input type="hidden" name="lang" tal:attributes="value curr_lang" />
</metal:block>

<!-- Submit buttons-->
<div class="field" metal:define-slot="submit_buttons">
	<input type="submit" value="Save changes" i18n:attributes="value" name="saveProperties:method"/>
</div>

<!-- Translation bar on bottom -->
<div metal:define-slot="translate_on_bottom" class="translate-bottom translate">
	<metal:block use-macro="python:here.getFormsTool().getForm('site_macro_edit').macros['translation_bar']" />
</div>

<!-- Custom bottom content -->
<metal:block define-slot="bottom_content" />

</form>
</div>
</tal:block>

<!-- Object not editable -->
<metal:block define-slot="not_editable">
	<p tal:condition="python:here.hasVersion() and (not here.isVersionAuthor())">
		<strong>This object is checked out for editing by another user.</strong>
	</p>
</metal:block>

<tal:block define="schema_helper python:here.get_schema_helper()" content="schema_helper/del_schema_session_values" />

</metal:block>
</metal:block>

</metal:block>

<!-- Macro for update from other version box -->
<metal:block define-macro="update_from_version">
<div class="translate_bar_right" tal:condition="python:len(languages) > 1">
	<form action="." method="post">
		<label for="from_lang" i18n:translate="">Fill the fields below from</label>
		<select name="from_lang" id="from_lang">
			<tal:block repeat="language languages">
			<option tal:condition="python:language['code'] != curr_lang"
				tal:attributes="value language/code"
				tal:content="language/name" i18n:translate="" />
			</tal:block>
		</select>
		<input type="hidden" name="lang" tal:attributes="value curr_lang" />
		<input type="submit" name="updateSessionFrom:method" value="Ok" i18n:attributes="value"/>
	</form>
</div>
</metal:block>
