<!-- Macro for edit form -->
<metal:block define-macro="page"
             extend-macro="python:here.standard_template_macro('light')">

<metal:block metal:fill-slot="body">

<tal:block 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);"
	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>
	<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" i18n:translate="">Edit object</h1>
<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>

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

<!-- 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 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>
</tal:block>

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

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

<!-- Document title -->
<div class="field" metal:define-slot="doc_title">
	<label for="title"><span i18n:translate="" tal:omit-tag="">Title</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'title')" class="mandatory_field"> *</span></label>
	<input type="text" name="title:utf8:ustring" id="title" size="50" tal:attributes="value python:here.getSession('title', here.getVersionLocalProperty('title', curr_lang))" />
</div>

<!-- Document description -->
<div class="field" metal:define-slot="doc_description">
	<label for="description"><span i18n:translate="" tal:omit-tag="">Description</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'description')" class="mandatory_field"> *</span></label>
	<span tal:define="editor here/getEditorTool" tal:replace="structure python:editor.render('description', curr_lang, image_support=True)" />
	<textarea id="description" name="description:utf8:ustring" class="mceEditor" tal:content="python:here.getSession('description', here.getVersionLocalProperty('description', curr_lang))" rows="20" cols="72" />
</div>

<!-- Document coverage -->
<div class="field" metal:define-slot="doc_coverage" tal:define="coverage_glossary here/get_coverage_glossary">
	<label for="coverage"><span i18n:translate="" tal:omit-tag="">Geographical coverage</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'coverage')" class="mandatory_field"> *</span></label>
	<tal:block tal:condition="python:coverage_glossary is None">
		<p i18n:translate=""><strong i18n:name="tip" i18n:translate="">Tip:</strong> in order to specify more values, separate them by commas</p>
	</tal:block>
	<tal:block tal:condition="python:coverage_glossary is not None">
		<p i18n:translate=""><strong i18n:name="tip" i18n:translate="">Tip:</strong> you can type free text in the field below or pick words from the list. In order to specify more values, separate them by commas.</p>
	</tal:block>
	<input type="text" name="coverage:utf8:ustring" id="coverage" size="50" tal:attributes="value python:here.getSession('coverage', here.getVersionLocalProperty('coverage', curr_lang))" />
	<tal:block tal:condition="python:coverage_glossary is not None">
		<label for="pick-coverage" class="invisible" i18n:translate="">Pick coverage</label><input type="button" value="Pick" id="pick-coverage" tal:attributes="onclick string:javascript:fPick('${coverage_glossary/absolute_url}/GlossMap_html?ctrl=coverage&amp;lang=${curr_lang}');" />
	</tal:block>
</div>

<!-- Document keywords -->
<div class="field" metal:define-slot="doc_keywords" tal:define="keywords_glossary here/get_keywords_glossary">
	<label for="keywords"><span i18n:translate="" tal:omit-tag="">Keywords</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'keywords')" class="mandatory_field"> *</span></label>
	<tal:block tal:condition="python:keywords_glossary is not None">
		<p i18n:translate=""><strong i18n:name="tip" i18n:translate="">Tip:</strong> you can type free text in the field below or pick words from the list</p>
	</tal:block>
	<input type="text" name="keywords:utf8:ustring" id="keywords" size="50" tal:attributes="value python:here.getSession('keywords', here.getVersionLocalProperty('keywords', curr_lang))" />
	<tal:block tal:condition="python:keywords_glossary is not None">
		<label for="pick-keywords" class="invisible" i18n:translate="">Pick keywords</label><input type="button" value="Pick" id="pick-keywords" tal:attributes="onclick string:javascript:fPick('${keywords_glossary/absolute_url}/GlossMap_html?ctrl=keywords&amp;lang=${curr_lang}');" />
	</tal:block>
</div>

<!-- Document sortorder -->
<div class="field" metal:define-slot="doc_sortorder">
	<label for="sortorder"><span i18n:translate="" tal:omit-tag="">Sort order</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'sortorder')" class="mandatory_field"> *</span></label>
	<input type="text" name="sortorder" id="sortorder" size="2" tal:attributes="value python:here.getSession('sortorder', here.getVersionProperty('sortorder'))" />
</div>

<!-- Document release date -->
<div class="field" metal:define-slot="doc_releasedate">
	<label for="releasedate"><span i18n:translate="" tal:omit-tag="">Release date</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'releasedate')" class="mandatory_field"> *</span></label>
	<input type="text" name="releasedate" class="vDateField" id="releasedate" size="10" tal:attributes="value python:here.getSession('releasedate', here.utConvertDateTimeObjToString(here.getVersionProperty('releasedate')))" />
	<noscript><em i18n:translate="">dd/mm/yyyy</em></noscript>
</div>

<!-- Document discussion -->
<div class="field" metal:define-slot="doc_discussion">
	<label for="discussion"><span i18n:translate="" tal:omit-tag="">Open for comments</span><span tal:condition="python:here.get_pluggable_item_property_mandatory(here.meta_type, 'discussion')" class="mandatory_field"> *</span></label>
	<input type="checkbox" name="discussion" id="discussion" tal:attributes="checked python:test(here.getSession('discussion', here.discussion), 'checked', '')" />
</div>

<!-- 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>

<span tal:content="python:here.del_pluggable_item_session(here.meta_type)" tal:omit-tag="" />
</metal:block>

</metal:block>

<!-- Macro for translation bar -->
<metal:block define-macro="translation_bar"  tal:define="
languages here/gl_get_languages_mapping;
curr_lang python:request.get('lang', None) or here.gl_get_selected_language();
color python:here.utHexColors(curr_lang);">

<span i18n:translate="" tal:omit-tag="">Translate in</span>
<tal:block tal:repeat="language languages">
	<div class="current" tal:condition="python:language['code'] == curr_lang"
						 tal:attributes="style python:'background-color: %s' % here.utHexColors(curr_lang)">
		<span tal:content="python:language['name']" i18n:translate=""/>
	</div>
	<a tal:condition="python:language['code'] != curr_lang"
		tal:attributes="href string:?lang=${language/code};
						title python:language['name'];
                        style python:'background-color: %s' % here.utHexColors(language['code'])"
        i18n:attributes="title">
		<span tal:content="python:language['name']" i18n:translate="" />
	</a>
</tal:block>
</metal:block>
