Skip to content
editnote.blade.php 2.22 KiB
Newer Older
Alyx's avatar
Alyx committed
@extends('layouts.app')

@section('content')

Alyx's avatar
Alyx committed
    <form id="noteform">
        <input type="text" id="cleartextTitle">
        <div id="test-editor">
Alyx's avatar
Alyx committed
            <div class="form-group">
                <label for="noteeditor">Entry</label>
                <textarea class="form-control" id="noteeditor" rows="10"></textarea>
            </div>        </div>
Alyx's avatar
Alyx committed
        <p>
            <button id="editor-submit" type="submit" class="btn btn-success">Save</button>
             <span id="savedstatus" class="text-muted">Last saved <span id="saved-time"></span></span>
        </p>
Alyx's avatar
Alyx committed

Alyx's avatar
Alyx committed
    </form>
Alyx's avatar
Alyx committed

@endsection
@section('css')
    <link rel="stylesheet" href="/editormd/css/editormd.css"/>
@endsection
@section('js')
    <script src="/js/aes.js"></script>
Alyx's avatar
Alyx committed
    <script src="/js/moment.js"></script>
Alyx's avatar
Alyx committed
    <script src="/js/app.js"></script>
    <script src="/editormd/editormd.min.js"></script>
Alyx's avatar
Alyx committed
    <script src="/editormd/languages/en.js"></script>
Alyx's avatar
Alyx committed
    <script type="text/javascript">
Alyx's avatar
Alyx committed
        $(document).ready(function () {
Alyx's avatar
Alyx committed
            loadNote();
Alyx's avatar
Alyx committed

        });
Alyx's avatar
Alyx committed

Alyx's avatar
Alyx committed

Alyx's avatar
Alyx committed
        function loadNote() {
            $.ajax({
                type: "GET",
                url: '/api/getnote/{{$id}}',
                success: function (data) {
Alyx's avatar
Alyx committed

                    $('#noteeditor').html(decryptString(data.body));
                    $('#cleartextTitle').val(decryptString(data.title));
                    $('#saved-time').html(moment(data.updated_at).calendar());
Alyx's avatar
Alyx committed
                },
                error: function (request, status, error) {
                }
            });
        }
Alyx's avatar
Alyx committed

        $("#noteform").submit(function (e) {

            e.preventDefault(); // avoid to execute the actual submit of the form.
            encryptedTitle = CryptoJS.AES.encrypt($("#cleartextTitle").val(), sessionStorage.getItem('key')).toString();
Alyx's avatar
Alyx committed
            encryptedBody = CryptoJS.AES.encrypt($("#noteeditor").val(), sessionStorage.getItem('key')).toString();
Alyx's avatar
Alyx committed
            $.post("/note/edit/{{$id}}", {
                "_token": "{{ csrf_token() }}",
                title: encryptedTitle,
                body: encryptedBody
            }).done(function (data) {
                $('#saved-time').html(moment(data.updated_at).calendar());
Alyx's avatar
Alyx committed
            });
Alyx's avatar
Alyx committed
        });
Alyx's avatar
Alyx committed


    </script>


@endsection