<metal:block metal:use-macro="here/standard_template_macro">

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

<tal:block define="xls python:here.rstk['we_provide']('Excel import')">
<h1 tal:content="here/title_or_id" i18n:translate="" />

<div class="floated-buttons"><span class="buttons">
	<a tal:attributes="href here/aq_parent/absolute_url" i18n:translate="">Back to index</a></span>
</div>

<p tal:define="folder python:here.aq_parent.absolute_url(1)" i18n:translate="">
  You can import structured information to
  <i i18n:name="folder" tal:content="folder" /> from a file. Select the
  object type, download the template containing the requested columns to be
  filled in, and then upload the filled in file.
</p>
<p i18n:translate="">
  When selecting an object type, the generated template will replicate the
  fields of that object type's edit form, which you will fill in.
</p>
<form name="csv_import" action="" method="post" enctype="multipart/form-data">

<div class="field">
    <label i18n:translate="">Step 1: select object type</label>
    <select name="meta_type">
    <option tal:define="sel python:options.get('meta_type', None);
                        schema_tool python:here.getSite().getSchemaTool();
                        schemas python:schema_tool.listSchemas(installed=True)"
            tal:repeat="schema python:schemas.iteritems()"
            tal:attributes="value python:schema[0];
                            selected python:test(schema[0] == sel,
                                                 'selected', None)"
            tal:content="python:schema[1].title_or_id()" />
    </select>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        if ($('#file_type').length == 0 || $('#file_type').val() == 'CSV'){
            $('#csv_specifications').show();
        }
        else{
            $('#csv_specifications').hide();
        }
        $('#file_type').change(function(){
                if($(this).val() == 'CSV'){
                    $('#csv_specifications').show();
                    }
                else{
                    $('#csv_specifications').hide();
                }
            })
    })
</script>
<div class="field" tal:condition="xls">
   <label for="file_type"
          i18n:translate="">Select file import format</label>
   <select id="file_type" name="file_type">
       <option value="CSV" i18n:translate="">CSV</option>
       <option value="Excel" i18n:translate="">Microsoft Excel</option>
   </select>
</div>
<tal:block condition="not:xls">
    <input type="hidden" name="file_type" value="CSV"/>
</tal:block>

<div class="field">
    <label for="template:method" i18n:translate="">
        Step 2: download the template, fill out rows</label>
    <input type="hidden" name="as_attachment:boolean" value="True" />
    <input type="submit" name="template:method" value="Download template"/>
</div>

<div class="field">
    <label for="data" i18n:translate="">Step 3: upload the filled in file</label>
    <input type="file" id="data" name="data"/><br />
</div>

<metal:block use-macro="here/csv_specifications/macros/csv_specifications"/>

<div class="field">
    <input type="submit" name="do_import:method" value="Upload data" />
</div>

</form>

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

</metal:block>
