{% extends 'editor/editor.html' %}

{% block css %}
    <link href = "{{ url('static_assets', filename='js/codemirror/lib/codemirror.css') }}"
          rel  = "stylesheet" />
    
    {{ super() }}
{% endblock %}

{% block javascript %}
    {{ super() }}
    
    <script src="{{ url('static_assets', filename='js/codemirror/lib/codemirror.js') }}"></script>
    <script src="{{ url('static_assets', filename='js/codemirror/mode/jinja2/jinja2.js') }}"></script>
    <script src="{{ url('static_assets', filename='js/codemirror/mode/markdown/markdown.js') }}"></script>
    <script src="{{ url('static_assets', filename='js/codemirror/mode/sparql/sparql.js') }}"></script>
    <script src="{{ url('static_assets', filename='js/codemirror/mode/turtle/turtle.js') }}"></script>
    <script src="{{ url('static_assets', filename='js/commonmark.js') }}"></script>
    
    <script src="{{ url('static_assets', filename='js/editor/edit.js') }}" id="editor_script" data-type="{{ type }}"></script>
{% endblock %}

{% block main %}
    
    {# The form used for submitting changes #}
    <form id="form_content" method="post" action=""></form>
    
    {% if type == 'article' %}
        <div class="article">
            <div>
                <textarea id="content" name="content" maxlength="10485760" form="form_content">{{ content }}</textarea>
            </div>
            <div id="preview"></div>
        </div>
    {% endif %}
    
    {% if type == 'file' %}
        <div class="file">
            <p class="padding">
                Direct link: <a href="{{ url('blob', filename=node_id) }}" target="_blank">{{ node_id }}</a>
            </p>
            
            <textarea id="content" name="content" maxlength="10485760" form="form_content">{{ content }}</textarea>
        </div>
    {% endif %}
    
    {% if type == 'query' %}
        <div class="query">
            <textarea id="content" name="content" maxlength="10485760" form="form_content">{{ content }}</textarea>
        </div>
    {% endif %}
    
    {% if type == 'template' %}
        <div class="template">
            <textarea id="content" name="content" maxlength="10485760" form="form_content">{{ content }}</textarea>
        </div>
    {% endif %}
    
    {% if type == 'topic' %}
        <div class="topic">
            <textarea id="content" name="content" maxlength="10485760" form="form_content">{{ content }}</textarea>
        </div>
    {% endif %}
    
    <footer>
        <div>
            Describe your changes
        </div>
        <div>
            <input type="text" name="edit_summary" maxlength="1024" placeholder="" required form="form_content" />
        </div>
        <div class="licensing">
            By publishing changes, you irrevocably agree to release your contribution
            under the CC-BY-SA 4.0 License. You agree that a hyperlink or URL is
            sufficient attribution under the Creative Commons license.
        </div>
        <div>
            <input type="hidden" name="revision" value="{{ revision_number if revision_number is number }}"
                   form="form_content" />
            <input type="submit" value="Save" form="form_content" class="button button_default" />
            
            {# "Cancel" button #}
            {% if type == 'article' or type == 'topic' %}
                <a href="{{ url('node', id=node_id) }}">Cancel</a>
            {% elif type == 'file' %}
                <a href="{{ url('files') }}">Cancel</a>
            {% elif type == 'template' %}
                <a href="{{ url('templates') }}">Cancel</a>
            {% elif type == 'query' %}
                <a href="{{ url('queries') }}">Cancel</a>
            {% endif %}
        </div>
    </footer>
    
{% endblock %}
