{% extends "html/notebook/base_aux.html" %}
{#
INPUT:
- worksheet - an instance of Worksheet
- username - a string containing a username
- filename_ - the name of the file
- file_is_image - a boolean stating whether the file is an image
- file_is_text - a boolean stating whether the file is a text file
- text_file_content - a string containing the content of a text file
#}

{% block page_id %}datafile-page{% endblock %}

{% block more_css %}
<style type="text/css">
    .CodeMirror-line-numbers {
	border-right: 1px dotted blue;
	font-family: monospace;
	font-size: 10pt;
	line-height: 1.1em;
	margin: 0;
	padding: 0.4em 0.3em;
	text-align: right;
    }
</style>
{% endblock %}

{% block more_javascript %}
<script type="text/javascript" src="/javascript/codemirror/js/codemirror.js"></script>
{% endblock %}

{% set path = "/home/%s/data/%s"|format(worksheet.filename(), filename_) %}

{% block sharebar_title %}
{{ gettext('Data file') }}: {{ filename_ }}
{% endblock %}

{% block after_sharebar %}
<p>{{ gettext('You may download <a href="%(p)s">%(f)s</a> or create a link to this file in worksheet ', p=path, f=filename_) |safe }} <select onchange="go_option(this);" class="worksheet">
<option selected>{{ gettext('select worksheet') }}</option>
{% for worksheet in notebook.active_worksheets_for(username) %}
    <option value='link_datafile("{{ worksheet.filename() }}","{{ filename_ }}")'>{{ worksheet.name() }}</option>
{% endfor %}
</select> {{ gettext('or <a href="/home/%(wf)s/datafile?name=%(f)s&action=delete">delete %(f)s.</a>', wf=worksheet.filename(), f=filename_) |safe }}</p>

<p>{{ gettext("Access %(f)s in this worksheet by typing <tt>DATA+'%(f)s'</tt>. Here DATA is a special variable that gives the exact path to all data files uploaded to this worksheet.", f=filename_) |safe }}</p>

<hr class="usercontrol" />

{% if file_is_image %}
<div align=center><img src="{{ path }}"></div>
{% elif file_is_text %}
<form method="post" action="savedatafile" enctype="multipart/form-data">
    <input type="submit" value="{{ gettext('Save Changes') }}" name="button_save" /> <input type="submit" value="{{ gettext('Cancel') }}" name="button_cancel" style="display:block" />
    <div style="border: 1px solid black; padding: 0px;">
        <textarea class="edit" name="textfield" rows=20 cols=100 id="textfield" style="overflow: auto;">{{ text_file_content }}</textarea>
    </div>
    <script type="text/javascript">
    $(document).ready(function () {
	CodeMirror.fromTextArea('textfield', {
	    parserfile: "../contrib/python/js/parsepython.js",
	    stylesheet: "/javascript/codemirror/contrib/python/css/pythoncolors.css",
	    path: "/javascript/codemirror/js/",
	    height: '25.0em',
	    width: '100%',
	    indentUnit: 4,
	    lineNumbers: true,
	    textWrapping: false,
            parserConfig: {
		'pythonVersion': 2,
		'strictErrors': true
	    }
	}); 
      });
    </script>
    <input type="hidden" name="filename" value="{{ filename_ }}" id="filename" />
</form>
{% endif %}
{% endblock %}
