{% extends "private/skeleton.html" %}
{% block content %}

<h3>
<a class="btn btn-outline-secondary" :href="'/note/' + note.id"><i class="fa fa-chevron-left"></i></a>
Редактирование заметки
</h3>
<hr />

<div class="form-group">
<label class="control-label" for="title">Заголовок</label>
<input class="form-control" id="title" name="title" type="text" v-model="note.title">
</div>

<div class="form-group">
<label class="control-label" for="body">Текст</label>
<textarea class="form-control" cols="40" id="body" name="body" v-model="note.body" rows="8"></textarea>
</div>

<div class="row mt-3">
<div class="col">
<button type="submit" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></i> Сохранить</button>
</div>
</div>


{% endblock %}

{% block breadcrumb %}
{% raw %}
<ol class="breadcrumb mt-3">
    <li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="/notes">Заметки</a></li>
    <li class="breadcrumb-item"><a :href="'/note/' + note.id" v-html="note.title"></a></li>
    <li class="breadcrumb-item active">Редактирование заметки</li>
</ol>
{% endraw %}
{% endblock %}

{% block script %}
{% import 'inc/editor.js' as editor %}
{{ editor.plugin('tinymce') }}

<script type="text/javascript">
var app = new Vue({
    el: '#app',
    data: {
        note: {{ pagedata['note']|tojson|safe }}
    },
    methods: {
        send: function () {
            /* Сохранить */
            let vm = this;
{{ editor.getValue('"body"', 'vm.note.body', type='tinymce') }}
            axios.post(
                '/api',
                {
                    "jsonrpc": "2.0",
                    "method": "note.update",
                    "params": {
                        "id": vm.note.id,
                        "title": vm.note.title,
                        "body": vm.note.body
                    },
                    "id": 1
                }
            ).then(
                function(response) {
                    if ('result' in response.data) {
                        window.location.href = '/note/' + response.data['result'].id;
                    }
                }
            );
        }
    },
    mounted: function () {
{{ editor.tinymce('"body"') }}
    }
})
</script>
{% endblock %}
