<!-- Modal -->
<div class="modal fade" id="form-edit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Thêm mới</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label class="">Tên công việc <span style="color: red">(*)</span></label>
                        <input type="text" class="form-control" id="task_name" name="task_name" autofocus autocomplete="false">
                    </div>
                    <div class="form-group">
                        <label class="">Chọn độ ưu tiên <span style="color: red">(*)</span></label>
                        <select class="form-control" id="task_priority" name="task_priority">
                            <option value="0">Thấp</option>
                            <option value="1">Bình thường</option>
                            <option value="2">Trung bình</option>
                            <option value="3">Cao</option>
                            <option value="4">Rất cao</option>
                            <option value="5">Vô đối</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="">Mô tả thêm công việc</label>
                        <textarea class="form-control" rows="3" id="task_description" name="task_description" autocomplete="false"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Hủy bỏ</button>
                <button type="button" class="btn btn-primary" id="btn-save">Lưu lại</button>
            </div>
        </div>
    </div>
</div>

<script>
    $('#btn-save').click(function () {
        var name = $('#task_name').val();
        var priority = $('#task_priority').val();
        var description = $('#task_description').val();

        jQuery.ajax({
            url: "/task/store",
            type: 'POST',
            dataType: 'JSON',
            data: {
                name: name,
                priority: priority,
                description: description
            },
            success: function(result) {
                console.log(result)
                if (result.code == 200) {
                    location.reload();
                }
            },
            error: function (jqXhr, textStatus, errorMessage) {}
        });
    });
</script>