{% init op = "view" %}
{% init error = "" %}

<script type="text/javascript" src="/static/lib/wangEditor/wangEditor-3.1.1.min.js"></script>

{% if op == "view" %}
    <div class="card">
        {% include note/component/view_header.html %}
    </div>
    <div class="card">
        {% include note/component/note_path.html %}
    </div>
    <div class="card">
        <div id="editor" class="row">
            {% raw file.data %}
        </div>
    </div>
{% else %}
    <div class="card">
        <div class="card-title btn-line-height">
            <span>文档编辑器 - {{file.name}}</span>
            <div class="float-right">
                <input id="saveBtn" type="button" value="保存" data-note-id="{{file.id}}" 
                data-note-version="{{file.version}}" onclick="xnote.note.savePost(this)">
                {% include common/button/back_button.html %}
            </div>
        </div>
    </div>

    <div class="card">
        {% set rows = file.data.count('\n') %}
        <div class="alert">{{error}}</div>
        <form method="POST" enctype="multipart/form-data">
            <input name="version" value="{{file.version}}" class="hide">
            <input name="type" value="html" class="hide"/>
            <textarea id="data" name="data" style="width:100%;margin-top:10px;font-family:monospace;" rows={{rows}} class="hide">{{file.data}}</textarea>

            <div id="toolbar" style="border:1px solid #ccc;background-color: #f1f1f1;"></div>
            <div id="editor" style="height: 500px;border:1px solid #ccc;border-top: none;">
            </div>
        </form>

        <script type="text/javascript">
            xnote.note.initWangEditor();
        </script>
    </div>
{% end %}
